Skip to content

Commit

Permalink
Merge pull request #2440 from gluestack/fix/lucide-icon-color
Browse files Browse the repository at this point in the history
fix: lucide icon color issue in all the components
  • Loading branch information
Viraj-10 authored Sep 3, 2024
2 parents 7f4db49 + 0dcaa84 commit a34692a
Show file tree
Hide file tree
Showing 11 changed files with 369 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,28 @@ type IPrimitiveIcon = {
stroke?: string;
as?: React.ElementType;
className?: string;
classNameColor?: string;
};

const PrimitiveIcon = React.forwardRef<
React.ElementRef<typeof Svg>,
IPrimitiveIcon & React.ComponentPropsWithoutRef<typeof Svg>
IPrimitiveIcon
>(
(
{
height,
width,
fill,
color,
classNameColor,
size,
stroke = 'currentColor',
stroke,
as: AsComp,
...props
},
ref
) => {
color = color ?? classNameColor;
const sizeProps = useMemo(() => {
if (size) return { size };
if (height && width) return { height, width };
Expand All @@ -117,29 +120,21 @@ const PrimitiveIcon = React.forwardRef<
return {};
}, [size, height, width]);

const colorProps =
stroke === 'currentColor' && color !== undefined ? color : stroke;
let colorProps = {};
if (fill) {
colorProps = { ...colorProps, fill: fill };
}
if (stroke !== 'currentColor') {
colorProps = { ...colorProps, stroke: stroke };
} else if (stroke === 'currentColor' && color !== undefined) {
colorProps = { ...colorProps, stroke: color };
}

if (AsComp) {
return (
<AsComp
ref={ref}
fill={fill}
{...props}
{...sizeProps}
stroke={colorProps}
/>
);
return <AsComp ref={ref} {...props} {...sizeProps} {...colorProps} />;
}
return (
<Svg
ref={ref}
height={height}
width={width}
fill={fill}
stroke={colorProps}
{...props}
/>
<Svg ref={ref} height={height} width={width} {...colorProps} {...props} />
);
}
);
Expand Down Expand Up @@ -169,6 +164,7 @@ cssInterop(UIAccordion, { className: 'style' });
cssInterop(UIAccordion.Item, { className: 'style' });
cssInterop(UIAccordion.Header, { className: 'style' });
cssInterop(UIAccordion.Trigger, { className: 'style' });
//@ts-ignore
cssInterop(UIAccordion.Icon, { className: 'style' });
cssInterop(UIAccordion.TitleText, { className: 'style' });
cssInterop(UIAccordion.Content, { className: 'style' });
Expand All @@ -180,9 +176,8 @@ cssInterop(UIAccordion.Icon, {
nativeStyleToProp: {
height: true,
width: true,
// @ts-ignore
fill: true,
color: true,
color: 'classNameColor',
stroke: true,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,27 @@ type IPrimitiveIcon = {
stroke?: string;
as?: React.ElementType;
className?: string;
classNameColor?: string;
};
const PrimitiveIcon = React.forwardRef<
React.ElementRef<typeof Svg>,
IPrimitiveIcon & React.ComponentPropsWithoutRef<typeof Svg>
IPrimitiveIcon
>(
(
{
height,
width,
fill,
color,
classNameColor,
size,
stroke = 'currentColor',
stroke,
as: AsComp,
...props
},
ref
) => {
color = color ?? classNameColor;
const sizeProps = useMemo(() => {
if (size) return { size };
if (height && width) return { height, width };
Expand All @@ -60,29 +63,21 @@ const PrimitiveIcon = React.forwardRef<
return {};
}, [size, height, width]);

const colorProps =
stroke === 'currentColor' && color !== undefined ? color : stroke;
let colorProps = {};
if (fill) {
colorProps = { ...colorProps, fill: fill };
}
if (stroke !== 'currentColor') {
colorProps = { ...colorProps, stroke: stroke };
} else if (stroke === 'currentColor' && color !== undefined) {
colorProps = { ...colorProps, stroke: color };
}

if (AsComp) {
return (
<AsComp
ref={ref}
fill={fill}
{...props}
{...sizeProps}
stroke={colorProps}
/>
);
return <AsComp ref={ref} {...props} {...sizeProps} {...colorProps} />;
}
return (
<Svg
ref={ref}
height={height}
width={width}
fill={fill}
stroke={colorProps}
{...props}
/>
<Svg ref={ref} height={height} width={width} {...colorProps} {...props} />
);
}
);
Expand Down Expand Up @@ -142,15 +137,15 @@ cssInterop(UIActionsheet.FlatList, {
});
cssInterop(UIActionsheet.SectionList, { className: 'style' });
cssInterop(UIActionsheet.SectionHeaderText, { className: 'style' });
// @ts-ignore
cssInterop(UIActionsheet.Icon, {
className: {
target: 'style',
nativeStyleToProp: {
height: true,
width: true,
// @ts-ignore
fill: true,
color: true,
color: 'classNameColor',
stroke: true,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,37 +114,53 @@ type IPrimitiveIcon = React.ComponentPropsWithoutRef<typeof Svg> & {
stroke?: string;
as?: React.ElementType;
className?: string;
classNameColor?: string;
};

const PrimitiveIcon = React.forwardRef<
React.ElementRef<typeof Svg>,
IPrimitiveIcon
>(({ height, width, fill, color, size, stroke, as: AsComp, ...props }, ref) => {
const sizeProps = useMemo(() => {
if (size) return { size };
if (height && width) return { height, width };
if (height) return { height };
if (width) return { width };
return {};
}, [size, height, width]);
>(
(
{
height,
width,
fill,
color,
classNameColor,
size,
stroke,
as: AsComp,
...props
},
ref
) => {
color = color ?? classNameColor;
const sizeProps = useMemo(() => {
if (size) return { size };
if (height && width) return { height, width };
if (height) return { height };
if (width) return { width };
return {};
}, [size, height, width]);

let colorProps = {};
if (color) {
colorProps = { ...colorProps, color: color };
}
if (stroke) {
colorProps = { ...colorProps, stroke: stroke };
}
if (fill) {
colorProps = { ...colorProps, fill: fill };
}
if (AsComp) {
return <AsComp ref={ref} {...sizeProps} {...colorProps} {...props} />;
let colorProps = {};
if (fill) {
colorProps = { ...colorProps, fill: fill };
}
if (stroke !== 'currentColor') {
colorProps = { ...colorProps, stroke: stroke };
} else if (stroke === 'currentColor' && color !== undefined) {
colorProps = { ...colorProps, stroke: color };
}

if (AsComp) {
return <AsComp ref={ref} {...props} {...sizeProps} {...colorProps} />;
}
return (
<Svg ref={ref} height={height} width={width} {...colorProps} {...props} />
);
}
return (
<Svg ref={ref} height={height} width={width} {...colorProps} {...props} />
);
});
);

const IconWrapper = React.forwardRef<
React.ElementRef<typeof PrimitiveIcon>,
Expand All @@ -162,15 +178,16 @@ export const UIAlert = createAlert({
cssInterop(UIAlert, { className: 'style' });
//@ts-ignore
cssInterop(UIAlert.Text, { className: 'style' });
//@ts-ignore
cssInterop(IconWrapper, {
className: {
target: 'style',
nativeStyleToProp: {
height: true,
width: true,
// @ts-ignore
//@ts-ignore
fill: true,
color: true,
color: 'classNameColor',
stroke: true,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,49 +102,67 @@ type IPrimitiveIcon = React.ComponentPropsWithoutRef<typeof Svg> & {
stroke?: string;
as?: React.ElementType;
className?: string;
classNameColor?: string;
};

const PrimitiveIcon = React.forwardRef<
React.ElementRef<typeof Svg>,
IPrimitiveIcon
>(({ height, width, fill, color, size, stroke, as: AsComp, ...props }, ref) => {
const sizeProps = useMemo(() => {
if (size) return { size };
if (height && width) return { height, width };
if (height) return { height };
if (width) return { width };
return {};
}, [size, height, width]);

let colorProps = {};
if (color) {
colorProps = { ...colorProps, color: color };
}
if (stroke) {
colorProps = { ...colorProps, stroke: stroke };
}
if (fill) {
colorProps = { ...colorProps, fill: fill };
}
if (AsComp) {
return <AsComp ref={ref} {...sizeProps} {...colorProps} {...props} />;
>(
(
{
height,
width,
fill,
color,
classNameColor,
size,
stroke,
as: AsComp,
...props
},
ref
) => {
color = color ?? classNameColor;
const sizeProps = useMemo(() => {
if (size) return { size };
if (height && width) return { height, width };
if (height) return { height };
if (width) return { width };
return {};
}, [size, height, width]);

let colorProps = {};
if (fill) {
colorProps = { ...colorProps, fill: fill };
}
if (stroke !== 'currentColor') {
colorProps = { ...colorProps, stroke: stroke };
} else if (stroke === 'currentColor' && color !== undefined) {
colorProps = { ...colorProps, stroke: color };
}

if (AsComp) {
return <AsComp ref={ref} {...props} {...sizeProps} {...colorProps} />;
}
return (
<Svg ref={ref} height={height} width={width} {...colorProps} {...props} />
);
}
return (
<Svg ref={ref} height={height} width={width} {...colorProps} {...props} />
);
});
);

const ContextView = withStyleContext(View, SCOPE);
cssInterop(ContextView, { className: 'style' });
//@ts-ignore
cssInterop(PrimitiveIcon, {
className: {
target: 'style',
nativeStyleToProp: {
height: true,
width: true,
// @ts-ignore
//@ts-ignore
fill: true,
color: true,
color: 'classNameColor',
stroke: true,
},
},
Expand Down
Loading

0 comments on commit a34692a

Please sign in to comment.