mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-12 13:38:32 +00:00
fix: preserve builder color prop types
This commit is contained in:
@@ -85,7 +85,7 @@ const Icon = forwardRef<SVGSVGElement, IconComponentProps>(
|
|||||||
const hasAccessibleProp = Boolean(children) || hasA11yProp(rest);
|
const hasAccessibleProp = Boolean(children) || hasA11yProp(rest);
|
||||||
|
|
||||||
const [, svgAttributes, builtIconNode = []] = buildLucideIconForReact(icon, {
|
const [, svgAttributes, builtIconNode = []] = buildLucideIconForReact(icon, {
|
||||||
color: (color ?? contextColor) as string,
|
color: color ?? contextColor,
|
||||||
width: width ?? size ?? contextSize,
|
width: width ?? size ?? contextSize,
|
||||||
height: height ?? size ?? contextSize,
|
height: height ?? size ?? contextSize,
|
||||||
strokeWidth: strokeWidth ?? contextStrokeWidth,
|
strokeWidth: strokeWidth ?? contextStrokeWidth,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import buildLucideIconNode from './buildLucideIconNode';
|
import buildLucideIconNode from './buildLucideIconNode';
|
||||||
import type { LucideBuildParams, LucideIconData, LucideIconNode } from './types';
|
import type { LucideBuildParams, LucideIconData, LucideIconNode, SVGProps } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a React-compatible Lucide icon node (an svgson-like format) from a Lucide icon object.
|
* Creates a React-compatible Lucide icon node (an svgson-like format) from a Lucide icon object.
|
||||||
@@ -7,9 +7,9 @@ import type { LucideBuildParams, LucideIconData, LucideIconNode } from './types'
|
|||||||
* @param icon The icon to build.
|
* @param icon The icon to build.
|
||||||
* @param params Additional build parameters.
|
* @param params Additional build parameters.
|
||||||
*/
|
*/
|
||||||
function buildLucideIconForReact(
|
function buildLucideIconForReact<TProps extends Record<string, unknown> = SVGProps>(
|
||||||
icon: LucideIconData,
|
icon: LucideIconData<string, TProps>,
|
||||||
params: LucideBuildParams = {},
|
params: LucideBuildParams<TProps> = {} as LucideBuildParams<TProps>,
|
||||||
): LucideIconNode {
|
): LucideIconNode {
|
||||||
return buildLucideIconNode(icon, {
|
return buildLucideIconNode(icon, {
|
||||||
...params,
|
...params,
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ function isDefined<T>(value: T | null | undefined): value is T {
|
|||||||
* @param icon The icon to build.
|
* @param icon The icon to build.
|
||||||
* @param params Additional build parameters.
|
* @param params Additional build parameters.
|
||||||
*/
|
*/
|
||||||
function buildLucideIconNode(icon: LucideIconData, params: LucideBuildParams = {}): LucideIconNode {
|
function buildLucideIconNode<TProps extends Record<string, unknown> = SVGProps>(
|
||||||
|
icon: LucideIconData<string, TProps>,
|
||||||
|
params: LucideBuildParams<TProps> = {} as LucideBuildParams<TProps>,
|
||||||
|
): LucideIconNode {
|
||||||
const attributeNames = params.attributeNames ?? {};
|
const attributeNames = params.attributeNames ?? {};
|
||||||
const getAttributeName = (attributeName: string) =>
|
const getAttributeName = (attributeName: string) =>
|
||||||
attributeNames[attributeName] ?? attributeName;
|
attributeNames[attributeName] ?? attributeName;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export type LucideBuildParams<TProps extends Record<string, unknown> = SVGProps>
|
|||||||
/**
|
/**
|
||||||
* The color of the icon.
|
* The color of the icon.
|
||||||
*/
|
*/
|
||||||
color?: string;
|
color?: TProps extends { color?: infer TColor } ? TColor : string;
|
||||||
/**
|
/**
|
||||||
* The stroke width.
|
* The stroke width.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user