mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-16 18:47:43 +01:00
Format code
This commit is contained in:
@@ -4,14 +4,13 @@ import defaultAttributes from './defaultAttributes';
|
|||||||
|
|
||||||
// Create interface extending SVGAttributes
|
// Create interface extending SVGAttributes
|
||||||
export interface SVGProps extends Partial<SVGAttributes> {
|
export interface SVGProps extends Partial<SVGAttributes> {
|
||||||
size?: 24 | number
|
size?: 24 | number;
|
||||||
strokeWidth?: number | string
|
strokeWidth?: number | string;
|
||||||
absoluteStrokeWidth?: boolean
|
absoluteStrokeWidth?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type IconNode = [elementName: string, attrs: Record<string, string>][];
|
||||||
export type IconNode = [elementName: string, attrs: Record<string, string>][]
|
export type Icon = FunctionalComponent<SVGProps>;
|
||||||
export type Icon = FunctionalComponent<SVGProps>
|
|
||||||
/**
|
/**
|
||||||
* Converts string to KebabCase
|
* Converts string to KebabCase
|
||||||
* Copied from scripts/helper. If anyone knows how to properly import it here
|
* Copied from scripts/helper. If anyone knows how to properly import it here
|
||||||
@@ -20,29 +19,31 @@ export type Icon = FunctionalComponent<SVGProps>
|
|||||||
* @param {string} string
|
* @param {string} string
|
||||||
* @returns {string} A kebabized 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 =
|
||||||
{ size, strokeWidth = 2, absoluteStrokeWidth, color, class: classes, ...props }, // props
|
(iconName: string, iconNode: IconNode): Icon =>
|
||||||
{ attrs, slots } // context
|
(
|
||||||
|
{ size, strokeWidth = 2, absoluteStrokeWidth, color, class: classes, ...props }, // props
|
||||||
|
{ attrs, slots }, // context
|
||||||
) => {
|
) => {
|
||||||
return h(
|
return h(
|
||||||
'svg',
|
'svg',
|
||||||
{
|
{
|
||||||
...defaultAttributes,
|
...defaultAttributes,
|
||||||
width: size || defaultAttributes.width,
|
width: size || defaultAttributes.width,
|
||||||
height: size || defaultAttributes.height,
|
height: size || defaultAttributes.height,
|
||||||
stroke: color || defaultAttributes.stroke,
|
stroke: color || defaultAttributes.stroke,
|
||||||
'stroke-width': absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
|
'stroke-width': absoluteStrokeWidth
|
||||||
...attrs,
|
? (Number(strokeWidth) * 24) / Number(size)
|
||||||
class: ['lucide', `lucide-${toKebabCase(iconName)}`],
|
: strokeWidth,
|
||||||
...props,
|
...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;
|
export default createLucideIcon;
|
||||||
|
|||||||
Reference in New Issue
Block a user