Skip to content

Commit

Permalink
remove extra space in svg class attribute (#1703)
Browse files Browse the repository at this point in the history
* remove extra space in svg class attribute

* Update packages/lucide-react/src/createLucideIcon.ts

Co-authored-by: Jakob Guddas <[email protected]>

---------

Co-authored-by: Jakob Guddas <[email protected]>
  • Loading branch information
Sukomal07 and jguddas authored Nov 28, 2023
1 parent 1a09e7f commit 84b3c46
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions packages/lucide-react/src/createLucideIcon.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { forwardRef, createElement, ReactSVG, SVGProps, ForwardRefExoticComponent, RefAttributes } from 'react';
import {
forwardRef,
createElement,
ReactSVG,
SVGProps,
ForwardRefExoticComponent,
RefAttributes,
} from 'react';
import defaultAttributes from './defaultAttributes';

export type IconNode = [elementName: keyof ReactSVG, attrs: Record<string, string>][]
export type IconNode = [elementName: keyof ReactSVG, attrs: Record<string, string>][];

export type SVGAttributes = Partial<SVGProps<SVGSVGElement>>
type ComponentAttributes = RefAttributes<SVGSVGElement> & SVGAttributes
export type SVGAttributes = Partial<SVGProps<SVGSVGElement>>;
type ComponentAttributes = RefAttributes<SVGSVGElement> & SVGAttributes;

export interface LucideProps extends ComponentAttributes {
size?: string | number
absoluteStrokeWidth?: boolean
size?: string | number;
absoluteStrokeWidth?: boolean;
}

export type LucideIcon = ForwardRefExoticComponent<LucideProps>;
Expand All @@ -20,7 +27,11 @@ export type LucideIcon = ForwardRefExoticComponent<LucideProps>;
* @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()
.trim();

const createLucideIcon = (iconName: string, iconNode: IconNode): LucideIcon => {
const Component = forwardRef<SVGSVGElement, LucideProps>(
Expand All @@ -39,16 +50,14 @@ const createLucideIcon = (iconName: string, iconNode: IconNode): LucideIcon => {
},
[
...iconNode.map(([tag, attrs]) => createElement(tag, attrs)),
...(
(Array.isArray(children) ? children : [children]) || []
)
],
),
...(Array.isArray(children) ? children : [children]),
]
)
);

Component.displayName = `${iconName}`;

return Component;
};

export default createLucideIcon
export default createLucideIcon;

0 comments on commit 84b3c46

Please sign in to comment.