RFC: New icon api#62904
Conversation
|
Gut reaction: option 2 feels right. Option 1:
Option 2:
Option 3:
|
|
@camdencheek FWIW, unplugin-icons allows you to define custom icon sets that you can import in exactly the same way (i.e. My biggest concern with (1) and (2) (and We can also always create a custom wrapper around an icon to make it more ergonomic, e.g. create a
You can see the changes in |
Oh, neat! Definitely on board with
Am I understanding right that this is because the unplugin icon components are generated at compile time rather than pre-packaged as a list of components? TBH, I'm not terribly concerned about this. I always end up looking up the icons in the set anyways.
Another benefit is that we can limit it to only apply to children of the |
Only if we wrap it in another element. Which is probably fine to do. |
|
@camdencheek How do you feel about auto importing icons? I.e. with the right setup we can do import Icon from '$lib/Icon.svelte'
<Icon icon={ILucideHome} inline />It even seems to work with Typescript (it generates a .d.ts file, although I still get a warning, maybe from the Svelte LSP?) |
|
Cool! How does it know what (Also, I do not feel strongly about this, so feel free to go whatever direction makes most sense) |
|
It seems to look for variables that match |
+1 to this concern, it is always a case for me when I just can't find the icon that we have in Figma in the real world, there is a demo for MDI icons (kind of vitrine, but I'm not sure it's an actual world in English though) where you can find an icon set, but it doesn't make it any easier because we use different names in Figma for icons. So, I would like to solve this problem with autocomplete in another way, where we have our own demo in the storybook for all icons we have with search by name input; it would be easier for me to find an icon and see what it actually looks like. This being said, not having an autocomplete wouldn't be a problem for me if we had a searchable demo with icons. Case №3
This is probably the biggest stopper for me personally; we probably don't want to keep track manually of which icon is used and which isn't. But maybe this fact would force us to treat icons a bit more carefully (I doubt that would be the case though, too many things to worry about already besides icons, and people won't be tracking it really) In conclusion, I would go with approach №2 with or without autogenerated imports for icons. Would also add that we probably should have external or internal demo/overview for all icons we have, |
See also #62904. This PR adds a new icon component (`Icon2`), which takes an svg component imported by `unplugin-icons`. To make things easier the icons can be auto-imported via `unplugin-auto-import`. Usage example: ```js import Icon2 from '$lib/Icon2.svelte' <Icon2 icon={ILucideX} inline /> ``` `unplugin-icons` allows us to: - use other icon sets besides lucide, while using the same API. Other icon sets are necessary for file icons. `react-icons`, which we use in the React app, also pulls from multiple icon sets. - define our own icon sets See https://github.com/unplugin/unplugin-icons for more information. If it turns out that auto-importing (which involves generating TypeScrip types) doesn't work with our Bazel pipeline we can fall back to manual importing. This PR converts some icons as example.
This PR adds the ability to use Lucide icons. Because those icons work differently (you import an SVG element/component, not a text string), we also have to decide how we want to use these icons. Here are three proposals:
1) Import and use icon directly as component
Pro:
Cons:
2) Import icon and pass to icon component
Pro:
Cons:
3) Specify icon via string
where
Icondefines a map likePros:
iconproperty is defined accordinglyCons:
Approach (2) and (3) can also be combined and maybe we only provide string names for icons that are used in multiple places in the app. Then we have all the pros and lessen the cons.
Test plan
Manual testing.