Skip to content

Commit

Permalink
feat(Icon): switch to nuxt-icon with dynamic prop or app config (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac committed Nov 6, 2023
1 parent 196e9ac commit c601fc6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 531 deletions.
32 changes: 30 additions & 2 deletions docs/content/2.elements/7.icon.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
description: Display an icon from Iconify library.
description: Display any icon (100,000+) from Iconify.
links:
- label: GitHub
icon: i-simple-icons-github
Expand All @@ -8,6 +8,8 @@ links:

## Usage

Use the `name` prop by following this pattern: `i-{collection_name}-{icon_name}`. You can search any icon from [Iconify](https://iconify.design/) using https://icones.js.org.

::component-card
---
props:
Expand All @@ -16,9 +18,35 @@ props:
::

::callout{icon="i-heroicons-exclamation-triangle"}
When playing with the `name` prop above, you won't be able to use any icon you want as icons are bundled on build as explained in the [theming section](/getting-started/theming#icons).
You won't be able to use any icon in the `name` prop here as icons are bundled using [egoist/tailwindcss-icons](https://github.com/egoist/tailwindcss-icons), read more about this in [Theming](/getting-started/theming#icons).
::

### Dynamic :u-badge{label="New" class="align-middle ml-2 !rounded-full" variant="subtle"}

You can use the `dynamic` prop to enable dynamic icon loading. This will use [`nuxt-icon`](https://github.com/nuxt-modules/icon) instead and allow you to use any icon from [Iconify](https://iconify.design/) as well as the `{collection_name}:{icon_name}` pattern.

This can be quite useful when using [dynamic class names](https://tailwindcss.com/docs/content-configuration#dynamic-class-names) or for icons that are not bundled by default (fetched from a database for example).

::component-card
---
props:
name: 'i-ph-rocket-launch'
dynamic: true
---
::

You can also change the default behavior of the `dynamic` prop by setting the `ui.icons.dynamic` option in your `app.config.ts`.

```ts [app.config.ts]
export default defineAppConfig({
ui: {
icons: {
dynamic: true
}
}
})
```

## Props

:component-props
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@vueuse/math": "^10.5.0",
"defu": "^6.1.3",
"fuse.js": "^6.6.2",
"nuxt-icon": "^0.6.3",
"ohash": "^1.1.3",
"pathe": "^1.1.1",
"scule": "^1.0.0",
Expand Down
Loading

1 comment on commit c601fc6

@vercel
Copy link

@vercel vercel bot commented on c601fc6 Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-git-dev-nuxt-js.vercel.app
ui.nuxt.com
ui-nuxt-js.vercel.app

Please sign in to comment.