-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add icon lib description for lucide-react #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
0f9902f
5b0da6c
31c7dda
93db85b
f69c496
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License Copyright (c) 2025 Dazl | ||
|
|
||
| Permission is hereby granted, free of | ||
| charge, to any person obtaining a copy of this software and associated | ||
| documentation files (the "Software"), to deal in the Software without | ||
| restriction, including without limitation the rights to use, copy, modify, merge, | ||
| publish, distribute, sublicense, and/or sell copies of the Software, and to | ||
| permit persons to whom the Software is furnished to do so, subject to the | ||
| following conditions: | ||
|
|
||
| The above copyright notice and this permission notice | ||
| (including the next paragraph) shall be included in all copies or substantial | ||
| portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
| ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO | ||
| EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | ||
| OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| THE SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # @dazl-libs/lucide-react | ||
|
|
||
| **dazl-lucide-react** is a utility library for working with the [Lucide](https://lucide.dev/) icon set in React projects. It provides utilities to list all available icons and access prerendered SVGs programmatically, making it easy to integrate Lucide icons into your workflows or build tools. | ||
|
|
||
| ## Features | ||
|
|
||
| - Retrieve a full list of Lucide icon names | ||
| - Access prerendered SVGs as data or files | ||
| - Utility functions for searching and filtering icons | ||
| - Works with the official Lucide icon set | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install @dazl-libs/lucide-react | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```js | ||
| import iconList from '@dazl-libs/lucide-react'; | ||
| import PrerenderdCameraSVG from '@dazl-libs/lucide-react/camera.svg'; | ||
|
|
||
| ## Prerendered SVGs | ||
|
|
||
| All icons are available as prerendered SVG strings or files, suitable for direct embedding or further processing. | ||
|
|
||
| ## License | ||
|
|
||
| [MIT](./LICENSE) | ||
|
AviVahl marked this conversation as resolved.
|
||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import React from 'react'; | ||
|
AviVahl marked this conversation as resolved.
|
||
| import { renderToStaticMarkup } from 'react-dom/server'; | ||
| import { nodeFs } from '@file-services/node'; | ||
| import * as lucideReact from 'lucide-react'; | ||
|
|
||
| interface IconData { | ||
| name: string; | ||
| aliases: string[]; | ||
| svgString: string; | ||
| } | ||
|
|
||
| interface IconTypeAugmentation { | ||
|
AviVahl marked this conversation as resolved.
|
||
| name: string; | ||
| aliases: string[]; | ||
| file: string; | ||
| } | ||
|
|
||
| interface TypeAugmentationFile { | ||
| icons: IconTypeAugmentation[]; | ||
| } | ||
|
|
||
| function buildIcons(): void { | ||
| const distDir = nodeFs.join(import.meta.dirname, 'dist'); | ||
|
Check failure on line 23 in packages/lucide-react/build.tsx
|
||
| const svgDir = nodeFs.join(distDir, 'svg'); | ||
|
|
||
| nodeFs.ensureDirectorySync(distDir); | ||
| nodeFs.ensureDirectorySync(svgDir); | ||
|
|
||
| const svgsByContent = new Map<string, IconData>(); | ||
|
|
||
| for (const [exportName, IconComponent] of Object.entries(lucideReact)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lucide-react exports the same icon 3 times:
So while we could list all 3, we could just list "Speaker", and use the "SpeakerIcon" export (for less code confusion)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could iterate on lucideReact.icons instead to avoid the duplicates |
||
| // Skip non-component exports | ||
| if (typeof IconComponent !== 'function' && typeof IconComponent !== 'object') { | ||
| continue; | ||
| } | ||
|
|
||
| if (!IconComponent) { | ||
| continue; | ||
| } | ||
|
|
||
| // Skip known utility functions | ||
| if (exportName === 'createLucideIcon' || exportName === 'Icon') { | ||
| continue; | ||
| } | ||
|
|
||
| // Icon components have uppercase first letter | ||
| if (exportName[0] !== exportName[0]?.toUpperCase()) { | ||
| continue; | ||
| } | ||
|
|
||
| try { | ||
| const svgString = renderToStaticMarkup( | ||
| React.createElement(IconComponent as React.ComponentType<{ size: number; strokeWidth: number }>, { | ||
| size: 24, | ||
| strokeWidth: 2, | ||
| }), | ||
| ); | ||
|
|
||
| // Check if we've seen this SVG content before | ||
| if (svgsByContent.has(svgString)) { | ||
| const existing = svgsByContent.get(svgString)!; | ||
| // Keep the shortest name | ||
| if (exportName.length < existing.name.length) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while this works for the Abc/LucideAbc/AbcIcon case, this makes no sense for icons that are being renamed (with the old one kept around)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you suggest?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iterate on |
||
| existing.aliases.push(existing.name); | ||
| existing.name = exportName; | ||
| } else { | ||
| existing.aliases.push(exportName); | ||
| } | ||
| } else { | ||
| svgsByContent.set(svgString, { | ||
| name: exportName, | ||
| aliases: [exportName], | ||
| svgString, | ||
| }); | ||
| } | ||
| } catch { | ||
| // Skip icons that fail to render | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| const iconsTypeAugmentation: IconTypeAugmentation[] = []; | ||
|
|
||
| // Save unique SVGs and build icons list | ||
| for (const { name, aliases, svgString } of svgsByContent.values()) { | ||
| const filename = `${name.toLowerCase()}.svg`; | ||
| const filepath = nodeFs.join(svgDir, filename); | ||
|
|
||
| // Save SVG file | ||
| nodeFs.writeFileSync(filepath, svgString); | ||
|
|
||
| // Add to icons list (use relative path from dist folder) | ||
| const iconEntry = { | ||
| name: name, | ||
| aliases: aliases, | ||
| file: `svg/${filename}`, | ||
| }; | ||
|
|
||
| iconsTypeAugmentation.push(iconEntry); | ||
|
AviVahl marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // Save type augmentation file | ||
| const typeAugmentationFile: TypeAugmentationFile = { | ||
| icons: iconsTypeAugmentation, | ||
| }; | ||
| const typeAugmentationPath = nodeFs.join(distDir, 'types-augmentation.json'); | ||
| nodeFs.writeFileSync(typeAugmentationPath, JSON.stringify(typeAugmentationFile, null, 2)); | ||
| } | ||
|
|
||
| export default buildIcons; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import buildIcons from './build.tsx'; | ||
|
|
||
| buildIcons(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "name": "@dazl-libs/lucide-react", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. scoped packages must have publishConfig
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, use "type": "module", like all our other packages
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. still missing |
||
| "version": "1.0.0", | ||
| "type": "module", | ||
| "license": "MIT", | ||
| "exports": { | ||
| ".": { | ||
| "import": "./dist/types-augmentation.json", | ||
| "require": "./dist/types-augmentation.json" | ||
| }, | ||
| "./*.svg": { | ||
| "import": "./dist/svg/*.svg", | ||
| "require": "./dist/svg/*.svg" | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "scripts": { | ||
| "build": "node do-build.ts", | ||
| "prepack": "npm run build" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure where you came up with this config. this tsconfig does not extend the root base one.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
| "extends": "../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "outDir": "./dist", | ||
| "jsx": "react-jsx" | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.