Format code

This commit is contained in:
Eric Fennis
2025-07-04 17:40:28 +02:00
parent 701c2fb6b2
commit d1d57d3c85

View File

@@ -4,14 +4,13 @@ import defaultAttributes from './defaultAttributes';
// Create interface extending SVGAttributes
export interface SVGProps extends Partial<SVGAttributes> {
size?: 24 | number
strokeWidth?: number | string
absoluteStrokeWidth?: boolean
size?: 24 | number;
strokeWidth?: number | string;
absoluteStrokeWidth?: boolean;
}
export type IconNode = [elementName: string, attrs: Record<string, string>][]
export type Icon = FunctionalComponent<SVGProps>
export type IconNode = [elementName: string, attrs: Record<string, string>][];
export type Icon = FunctionalComponent<SVGProps>;
/**
* Converts string to KebabCase
* Copied from scripts/helper. If anyone knows how to properly import it here
@@ -20,11 +19,14 @@ export type Icon = FunctionalComponent<SVGProps>
* @param {string} string
* @returns {string} A kebabized string
*/
export const toKebabCase = (string: string) => string.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
export const toKebabCase = (string: string) =>
string.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
const createLucideIcon = (iconName: string, iconNode: IconNode): Icon => (
const createLucideIcon =
(iconName: string, iconNode: IconNode): Icon =>
(
{ size, strokeWidth = 2, absoluteStrokeWidth, color, class: classes, ...props }, // props
{ attrs, slots } // context
{ attrs, slots }, // context
) => {
return h(
'svg',
@@ -33,16 +35,15 @@ const createLucideIcon = (iconName: string, iconNode: IconNode): Icon => (
width: size || defaultAttributes.width,
height: size || defaultAttributes.height,
stroke: color || defaultAttributes.stroke,
'stroke-width': absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
'stroke-width': absoluteStrokeWidth
? (Number(strokeWidth) * 24) / Number(size)
: strokeWidth,
...attrs,
class: ['lucide', `lucide-${toKebabCase(iconName)}`],
...props,
},
[
...iconNode.map(child => h(...child)),
...(slots.default ? [slots.default()] : [])
],
[...iconNode.map((child) => h(...child)), ...(slots.default ? [slots.default()] : [])],
);
};
};
export default createLucideIcon;