@gluestack-ui/icon
Version:
A universal headless icon component for React Native, Next.js & React
36 lines (35 loc) • 1.24 kB
JSX
import React from 'react';
import { Svg } from 'react-native-svg';
import { createIcon } from '../createIcon';
export { Svg };
export const PrimitiveIcon = React.forwardRef(({ height, width, fill, color, classNameColor, size, stroke = 'currentColor', as: AsComp, style, ...props }, ref) => {
color = color ?? classNameColor;
const sizeProps = React.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} style={style} {...sizeProps} {...colorProps}/>);
}
return (<Svg ref={ref} height={height} width={width} {...colorProps} {...props}/>);
});
export const UIIcon = createIcon({
Root: PrimitiveIcon,
});