mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-31 20:28:09 +01:00
feat(Icon): switch to nuxt-icon with dynamic prop or app config (#862)
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
description: Display an icon from Iconify library.
|
description: Display any icon (100,000+) from Iconify.
|
||||||
links:
|
links:
|
||||||
- label: GitHub
|
- label: GitHub
|
||||||
icon: i-simple-icons-github
|
icon: i-simple-icons-github
|
||||||
@@ -8,6 +8,8 @@ links:
|
|||||||
|
|
||||||
## Usage
|
## 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
|
::component-card
|
||||||
---
|
---
|
||||||
props:
|
props:
|
||||||
@@ -16,9 +18,35 @@ props:
|
|||||||
::
|
::
|
||||||
|
|
||||||
::callout{icon="i-heroicons-exclamation-triangle"}
|
::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
|
## Props
|
||||||
|
|
||||||
:component-props
|
:component-props
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
"@vueuse/math": "^10.5.0",
|
"@vueuse/math": "^10.5.0",
|
||||||
"defu": "^6.1.3",
|
"defu": "^6.1.3",
|
||||||
"fuse.js": "^6.6.2",
|
"fuse.js": "^6.6.2",
|
||||||
|
"nuxt-icon": "^0.6.3",
|
||||||
"ohash": "^1.1.3",
|
"ohash": "^1.1.3",
|
||||||
"pathe": "^1.1.1",
|
"pathe": "^1.1.1",
|
||||||
"scule": "^1.0.0",
|
"scule": "^1.0.0",
|
||||||
|
|||||||
550
pnpm-lock.yaml
generated
550
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
|||||||
import { defineNuxtModule, installModule, addComponentsDir, addImportsDir, createResolver, addPlugin } from '@nuxt/kit'
|
import { defineNuxtModule, installModule, addComponentsDir, addImportsDir, createResolver, addPlugin } from '@nuxt/kit'
|
||||||
import defaultColors from 'tailwindcss/colors.js'
|
import defaultColors from 'tailwindcss/colors.js'
|
||||||
import { defaultExtractor as createDefaultExtractor } from 'tailwindcss/lib/lib/defaultExtractor.js'
|
import { defaultExtractor as createDefaultExtractor } from 'tailwindcss/lib/lib/defaultExtractor.js'
|
||||||
import { iconsPlugin, getIconCollections } from '@egoist/tailwindcss-icons'
|
import { iconsPlugin, getIconCollections, type CollectionNames } from '@egoist/tailwindcss-icons'
|
||||||
import { name, version } from '../package.json'
|
import { name, version } from '../package.json'
|
||||||
import { generateSafelist, excludeColors, customSafelistExtractor } from './colors'
|
import { generateSafelist, excludeColors, customSafelistExtractor } from './colors'
|
||||||
import createTemplates from './templates'
|
import createTemplates from './templates'
|
||||||
@@ -46,7 +46,7 @@ export interface ModuleOptions {
|
|||||||
*/
|
*/
|
||||||
global?: boolean
|
global?: boolean
|
||||||
|
|
||||||
icons: string[] | string
|
icons: CollectionNames[] | 'all'
|
||||||
|
|
||||||
safelistColors?: string[]
|
safelistColors?: string[]
|
||||||
}
|
}
|
||||||
@@ -142,6 +142,7 @@ export default defineNuxtModule<ModuleOptions>({
|
|||||||
|
|
||||||
// Modules
|
// Modules
|
||||||
|
|
||||||
|
await installModule('nuxt-icon')
|
||||||
await installModule('@nuxtjs/color-mode', { classSuffix: '' })
|
await installModule('@nuxtjs/color-mode', { classSuffix: '' })
|
||||||
await installModule('@nuxtjs/tailwindcss', {
|
await installModule('@nuxtjs/tailwindcss', {
|
||||||
exposeConfig: true,
|
exposeConfig: true,
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
<template>
|
<template>
|
||||||
<span :class="name" />
|
<Icon v-if="dynamic" :name="name" />
|
||||||
|
<span v-else :class="name" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue'
|
import { defineComponent } from 'vue'
|
||||||
|
// @ts-expect-error
|
||||||
|
import appConfig from '#build/app.config'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
props: {
|
props: {
|
||||||
name: {
|
name: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
dynamic: {
|
||||||
|
type: Boolean,
|
||||||
|
default: () => !!appConfig.ui?.icons?.dynamic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user