-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧩
WOR-5
Optimize icon block/menu (#87)
- Loading branch information
1 parent
15c124f
commit 443e61e
Showing
36 changed files
with
13,847 additions
and
292 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
29 changes: 29 additions & 0 deletions
29
packages/ui/src/components/shared/icon-block/create-lucide-icon.ts
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,29 @@ | ||
import { createElement, forwardRef } from "react"; | ||
import { Icon, type IconNode, type LucideProps } from "lucide-react"; | ||
|
||
import { cn, toPascalCase } from "@swy/ui/lib"; | ||
|
||
import { iconNodes } from "./data"; | ||
import type { LucideName } from "./types"; | ||
|
||
/** | ||
* Create a Lucide icon component | ||
*/ | ||
export const createLucideIcon = (name: LucideName) => { | ||
const nodeWithKeys = iconNodes[name].map(([elem, attrs], i) => [ | ||
elem, | ||
{ ...attrs, key: `${name}-${i}` }, | ||
]) as IconNode; | ||
const Component = forwardRef<SVGSVGElement, LucideProps>( | ||
({ className, ...props }, ref) => | ||
createElement(Icon, { | ||
ref, | ||
iconNode: nodeWithKeys, | ||
className: cn(`lucide-${name}`, className), | ||
...props, | ||
}), | ||
); | ||
|
||
Component.displayName = toPascalCase(name); | ||
return Component; | ||
}; |
Oops, something went wrong.