-
-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(icon-component): Creating icons with iconNodes (#1997)
* Add useIconComponent, lucide-react * Add concept useIconComponent * add useIconComponents to packages * Add icon component * Add icon component * Add tests for react packages * Reset changes in icons * Add types * Add support for Icon components in Lucide Vue Next * update tests * Update tests * Enable Svelte component * Fix lucide-react-native tests * Update Solid package * update snapshots * Add docs * add docs * Update tests * Formatting * Formatting * Update package lock * Remove `useIconComponent` * Update guides * Update exports preact and solid package * Formatting * Format createIcons.ts * Add lucide lab repo link in docs
- Loading branch information
1 parent
65deefa
commit e50582e
Showing
77 changed files
with
1,706 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { h, toChildArray } from 'preact'; | ||
import defaultAttributes from './defaultAttributes'; | ||
import type { IconNode, LucideProps } from './types'; | ||
|
||
interface IconComponentProps extends LucideProps { | ||
iconNode: IconNode; | ||
} | ||
|
||
/** | ||
* Lucide icon component | ||
* | ||
* @component Icon | ||
* @param {object} props | ||
* @param {string} props.color - The color of the icon | ||
* @param {number} props.size - The size of the icon | ||
* @param {number} props.strokeWidth - The stroke width of the icon | ||
* @param {boolean} props.absoluteStrokeWidth - Whether to use absolute stroke width | ||
* @param {string} props.class - The class name of the icon | ||
* @param {IconNode} props.children - The children of the icon | ||
* @param {IconNode} props.iconNode - The icon node of the icon | ||
* | ||
* @returns {ForwardRefExoticComponent} LucideIcon | ||
*/ | ||
const Icon = ({ | ||
color = 'currentColor', | ||
size = 24, | ||
strokeWidth = 2, | ||
absoluteStrokeWidth, | ||
children, | ||
iconNode, | ||
class: classes = '', | ||
...rest | ||
}: IconComponentProps) => | ||
h( | ||
'svg', | ||
{ | ||
...defaultAttributes, | ||
width: String(size), | ||
height: size, | ||
stroke: color, | ||
['stroke-width' as 'strokeWidth']: absoluteStrokeWidth | ||
? (Number(strokeWidth) * 24) / Number(size) | ||
: strokeWidth, | ||
class: ['lucide', classes].join(' '), | ||
...rest, | ||
}, | ||
[...iconNode.map(([tag, attrs]) => h(tag, attrs)), ...toChildArray(children)], | ||
); | ||
|
||
export default Icon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
export * from './icons'; | ||
export * as icons from './icons'; | ||
export * from './aliases'; | ||
export * from './types'; | ||
|
||
export { default as createLucideIcon } from './createLucideIcon'; | ||
export { default as Icon } from './Icon'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { type FunctionComponent, type JSX } from 'preact'; | ||
|
||
export type IconNode = [elementName: keyof JSX.IntrinsicElements, attrs: Record<string, string>][]; | ||
|
||
export interface LucideProps extends Partial<Omit<JSX.SVGAttributes, 'ref' | 'size'>> { | ||
color?: string; | ||
size?: string | number; | ||
strokeWidth?: string | number; | ||
absoluteStrokeWidth?: boolean; | ||
} | ||
|
||
export type LucideIcon = FunctionComponent<LucideProps>; |
Oops, something went wrong.