feat!: new icon approach by antfu · Pull Request #154 · nuxt/icon
Navigation Menu
- Notifications You must be signed in to change notification settings
- Fork 89
Conversation
This PR introduces a brand new icon approach that works much better with SSR (no flicking on the client side) and should help reduce the load of Iconify's public API by a lot.
Breaking Changes
<Icon>and<IconCSS>is merged together, use<Icon mode="svg">and<Icon mode="css"><Icon>now default usingcssmode, (seticon.mode: 'svg'to use the previous beahvor<IconCSS>component is removed- Emoji-as-name is no longer supported
- Slot fallback is not supported yet
- App config key changed from
nuxtIcontoicon - App config schema changes
iconifyApiOptionshas been removediconifyApiOptions.url->iconifyApiEndpointiconifyApiOptions.publicApiFallback->fallbackToApi(default: true)
New Features
- Support loading icons for local icons folder, close [Feature Request]: SVG folder for offline mode and custom SVGs #131
Approaches
- Create a
/api/_nuxt_icon/endpoint that will serve the icons from server-bundle, or fallback to Iconify API (fallback to use public API whenssr:false - CSS Mode:
<Icon name="icon-name" mode="css" />will render the icon as a CSS class, SSR is supported by injecting compiled CSS into HTML.- On the client side, it will look up the registered CSS selectors. If the class is already presented, it will skip icon rendering (compatible with pre-compiled UnoCSS icons-as-css solution, TW support is still in research)
- SVG Mode:
<Icon name="icon-name" mode="svg" />component will useuseAsyncStateto fetch the icon data from the server (local fetch when SSR) and force Iconify to render the icon to SSR. Hydrate the data back on client side.- For dynamic icons that are presented on the server side, no client request will be made.
- For dynamic icons that are presented only on the client side, a client request to
/api/_nuxt_icon/will be made to fetch the icon data (cached event handler).
TODOs
- Update docs
@antfu Would that be pertinent to add an option to append aria-hidden="true" on every icon?
I'm not sure it's a good idea for @nuxt/ui to configure this for all icons but this could be a nice addition anyway for nuxt-icon users 😊
antfu
deleted the
feat/new
branch
(set icon.defaultMode: 'svg' to use the previous beahvor)
its icon.defaultMode: 'svg' or icon.mode: 'svg' 😅
This was referenced
Aug 16, 2024This 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