mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-10 13:18:25 +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 [, svgAttributes, builtIconNode = []] = buildLucideIconForReact(icon, {
|
||||
color: (color ?? contextColor) as string,
|
||||
color: color ?? contextColor,
|
||||
width: width ?? size ?? contextSize,
|
||||
height: height ?? size ?? contextSize,
|
||||
strokeWidth: strokeWidth ?? contextStrokeWidth,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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.
|
||||
@@ -7,9 +7,9 @@ import type { LucideBuildParams, LucideIconData, LucideIconNode } from './types'
|
||||
* @param icon The icon to build.
|
||||
* @param params Additional build parameters.
|
||||
*/
|
||||
function buildLucideIconForReact(
|
||||
icon: LucideIconData,
|
||||
params: LucideBuildParams = {},
|
||||
function buildLucideIconForReact<TProps extends Record<string, unknown> = SVGProps>(
|
||||
icon: LucideIconData<string, TProps>,
|
||||
params: LucideBuildParams<TProps> = {} as LucideBuildParams<TProps>,
|
||||
): LucideIconNode {
|
||||
return buildLucideIconNode(icon, {
|
||||
...params,
|
||||
|
||||
@@ -12,7 +12,10 @@ function isDefined<T>(value: T | null | undefined): value is T {
|
||||
* @param icon The icon to build.
|
||||
* @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 getAttributeName = (attributeName: string) =>
|
||||
attributeNames[attributeName] ?? attributeName;
|
||||
|
||||
@@ -33,7 +33,7 @@ export type LucideBuildParams<TProps extends Record<string, unknown> = SVGProps>
|
||||
/**
|
||||
* The color of the icon.
|
||||
*/
|
||||
color?: string;
|
||||
color?: TProps extends { color?: infer TColor } ? TColor : string;
|
||||
/**
|
||||
* The stroke width.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user