-
Couldn't load subscription status.
- Fork 2.8k
Storybook: Story for reviewing Lucide icons #20631
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
Draft
Copilot
wants to merge
9
commits into
main
Choose a base branch
from
copilot/add-lucide-icons-to-storybook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+141
−0
Draft
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4b6820a
Initial plan
Copilot 742af50
Add unregistered Lucide icons story to Storybook
Copilot 2cb0947
minor adjustments
nielslyngsoe 488f253
show all icons
nielslyngsoe 50010fe
show all icons
nielslyngsoe cdb495f
remove unused story
nielslyngsoe 2dfcf50
Merge branch 'main' into copilot/add-lucide-icons-to-storybook
nielslyngsoe b9fadbd
adjustment
nielslyngsoe b2ce7bd
update
nielslyngsoe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
137 changes: 137 additions & 0 deletions
137
src/Umbraco.Web.UI.Client/src/packages/core/icon-registry/available-lucide-icons.stories.ts
This file contains hidden or 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,137 @@ | ||
| import iconDictionary from './icon-dictionary.json'; | ||
| import type { Meta, StoryObj } from '@storybook/web-components-vite'; | ||
|
|
||
| export default { | ||
| title: 'Generic Components/Icon/Available Lucide Icons', | ||
| id: 'available-lucide-icons', | ||
| } as Meta; | ||
|
|
||
| interface UnregisteredIcon { | ||
| name: string; | ||
| svgPath: string; | ||
| inUse?: boolean; | ||
| } | ||
|
|
||
| type LucideIconsData = Record<string, unknown>; | ||
|
|
||
| interface IconsResult { | ||
| icons: UnregisteredIcon[]; | ||
| stats: { | ||
| total: number; | ||
| registered: number; | ||
| unregistered: number; | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Get all unregistered Lucide icons | ||
| * @returns Promise with icons and statistics | ||
| */ | ||
| async function getUnregisteredIcons(): Promise<IconsResult> { | ||
| // Get all registered lucide icon file names (without .svg extension) | ||
| const registeredFiles = new Set( | ||
| iconDictionary.lucide | ||
| .filter((icon) => icon.file) // Filter out entries without a file property | ||
| .map((icon) => icon.file?.replace('.svg', '')), | ||
| ); | ||
|
|
||
| try { | ||
| // Fetch lucide icons from static directory | ||
| const response = await fetch('/lucide-static/icon-nodes.json'); | ||
| const lucideIcons: LucideIconsData = await response.json(); | ||
|
|
||
| const icons: UnregisteredIcon[] = Object.keys(lucideIcons) | ||
| .map((lucideName) => ({ | ||
| name: lucideName, | ||
| svgPath: `/lucide-static/icons/${lucideName}.svg`, | ||
| inUse: registeredFiles.has(lucideName), | ||
| })) | ||
| .sort((a, b) => a.name.localeCompare(b.name)); | ||
|
|
||
| return { | ||
| icons, | ||
| stats: { | ||
| total: Object.keys(lucideIcons).length, | ||
| registered: iconDictionary.lucide.filter((icon) => icon.file).length, | ||
| unregistered: icons.length, | ||
| }, | ||
| }; | ||
| } catch (error) { | ||
| console.error('Failed to load lucide icons:', error); | ||
| return { | ||
| icons: [], | ||
| stats: { total: 0, registered: iconDictionary.lucide.filter((icon) => icon.file).length, unregistered: 0 }, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| export const Docs: StoryObj = { | ||
| render: () => { | ||
| // Create a promise-based approach | ||
| const data = getUnregisteredIcons(); | ||
|
|
||
| // Return immediately with a loading state, then update | ||
| const container = document.createElement('div'); | ||
| container.innerHTML = '<div style="margin: var(--uui-size-layout-2);"><p>Loading...</p></div>'; | ||
|
|
||
| data.then(({ icons, stats }) => { | ||
| const grid = icons.map( | ||
| (icon) => ` | ||
| <div style=" | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| text-align: center; | ||
| width: 100%; | ||
| height: 100%; | ||
| padding: var(--uui-size-space-3); | ||
| ${ | ||
| icon.inUse | ||
| ? `border: 2px solid var(--uui-color-selected);` | ||
| : ` | ||
| border: 1px solid var(--uui-color-border); | ||
| ` | ||
| } | ||
| border-radius: var(--uui-border-radius); | ||
| background-color: var(--uui-color-surface);"> | ||
| <img | ||
| src="${icon.svgPath}" | ||
| alt="${icon.name}" | ||
| width="18" | ||
| height="18" | ||
| style="margin-bottom: 9px;" | ||
| loading="lazy" /> | ||
| <small style="word-break: break-word; opacity: 0.6;">${icon.name}</small> | ||
| </div> | ||
| `, | ||
| ); | ||
|
|
||
| container.innerHTML = ` | ||
| <div style="margin: var(--uui-size-layout-2);"> | ||
| <h2>Available Lucide Icons</h2> | ||
| <p> | ||
| <strong>Total Lucide Icons:</strong> ${stats.total}<br /> | ||
| <strong>Registered in CMS:</strong> ${stats.registered} (Marked with blue)<br /> | ||
nielslyngsoe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <strong>Unregistered:</strong> ${stats.unregistered} | ||
| </p> | ||
| <p style="color: var(--uui-color-text-secondary);"> | ||
| These icons are available in Lucide but not yet registered in the Umbraco CMS icon registry. | ||
| You can contribute new icon registrations by making a PR to the CMS source code. In the CMS Source Code add the desired icon by adding it to the 'icon-dictionary.json', under 'lucide'. Afterwards run 'npm run generate:icons'. | ||
| Note you can also add icons of your own interest in your own project, read the docs | ||
| </p> | ||
| </div> | ||
| <div style="display: grid; | ||
| grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); | ||
| grid-gap: var(--uui-size-layout-2); | ||
| margin: var(--uui-size-layout-2); | ||
| place-items: start; | ||
| justify-content: space-between;"> | ||
| ${grid.join('')} | ||
| </div> | ||
| `; | ||
| }); | ||
|
|
||
| return container; | ||
| }, | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.