0.6.10 ā€¢ Published 1 day ago

nuxt-icon v0.6.10

Weekly downloads
-
License
MIT
Repository
github
Last release
1 day ago

nuxt-icon

Nuxt Icon

npm version npm downloads License Nuxt

Add 200,000+ ready to use icons to your Nuxt application, based on Iconify.

Features āœØ

  • Nuxt 3 ready
  • SSR friendly
  • Support 200,000 open-source vector icons via Iconify
  • Support both CSS mode / SVG mode
  • Custom SVG support (via Vue component, or via local SVG files)

!NOTE You are viewing the v1.0 version of this module, which is a complete rewrite for a better developer experience and performance. If you are migrating from v0.6, please check this PR for the full list of changes.

Setup ā›“ļø

Run the following command to add the module to your project:

npx nuxi module add icon

That's it, you can now use the <Icon /> in your components!

āœØ If you are using VS Code, you can use the Iconify IntelliSense extension by @antfu

Usage šŸ‘Œ

Props:

  • name (required): icon name or global component name
  • size: icon size (default: 1em)
  • mode: icon rendering mode (svg or css, default: css)

Attributes:

When using an icon from Iconify, an <span> or <svg> will be created based on the rendering mode, you can give all the attributes of the native element.

<Icon name="uil:github" color="black" />

Iconify dataset

You can use any name from the https://icones.js.org collection:

<Icon name="uil:github" />

It supports the i- prefix (for example, i-uil-github).

It's highly recommended to install the icon data locally with

npm i -D @iconify-json/collection-name

For example, to use the uil:github icon, install it's collection with @iconify-json/uil. This way the icons can be served locally or from your serverless functions, which is faster and more reliable on both SSR and client-side.

Vue component

When the name matches a global registered component, it will be rendered as that component (in this case mode will be ignored):

<Icon name="MyComponent" />

Note that MyComponent needs to be inside components/global/ folder (see example).

Custom Local Collections

You can use local SVG files to create a custom Iconify collection.

For example, place your icons' SVG files under a folder on your choice, for example ./assets/my-icons:

assets/my-icons
ā”œā”€ā”€ foo.svg
ā”œā”€ā”€ bar-outline.svg

In your nuxt.config.ts, add an item in icon.customCollections:

export default defineNuxtConfig({
  modules: [
    'nuxt-icon'
  ],
  icon: {
    customCollections: [
      {
        prefix: 'my-icon',
        dir: './assets/my-icons'
      },
    ],
  },
})

Then you can use the icons like this:

<template>
  <Icon name="my-icon:foo" />
  <Icon name="my-icon:bar-outline" />
</template>

Configuration āš™ļø

To update the default size (1em) of the <Icon />, create an app.config.ts with the icon.size property.

Update the default class (.icon) of the <Icon /> with the icon.class property, for a headless Icon, set icon.class: ''`.

You can also define aliases to make swapping out icons easier by leveraging the icon.aliases property.

// app.config.ts
export default defineAppConfig({
  icon: {
    size: '24px', // default <Icon> size applied
    class: 'icon', // default <Icon> class applied
    mode: 'css', // default <Icon> mode applied
    aliases: {
      'nuxt': 'logos:nuxt-icon',
    }
  }
})

The icons will have the default size of 24px and the nuxt icon will be available:

<Icon name="nuxt" />

By default, this module will create a server endpoint /api/_nuxt_icon/:collection to serve the icons from your local server bundle. When requesting an icon that does not exist in the local bundle, it will fallback to requesting the official Iconify API. You can disable the fallback by setting icon.fallbackToApi to false, or set up your own Iconify API and update icon.iconifyApiEndpoint to your own API endpoint.

Render Function

You can use the Icon component in a render function (useful if you create a functional component), for this you can import it from #components:

import { Icon } from '#components'

See an example of a <MyIcon> component:

<script setup>
import { Icon } from '#components'

const MyIcon = h(Icon, { name: 'uil:twitter' })
</script>

<template>
  <p><MyIcon /></p>
</template>

Contributing šŸ™

  1. Clone this repository
  2. Install dependencies using pnpm install (install pnpm with corepack enable, learn more)
  3. Run npm run dev:prepare to generate type stubs.
  4. Use npm run dev to start playground in development mode.

Credits šŸ’Œ

License šŸ“Ž

MIT License

@myevery/nuxt-ui@vernaillen/nuxt3-base@infinitebrahmanuniverse/nolb-nuxtav-themefepem-base-test@everything-registry/sub-chunk-2357@ucstu/fast-nuxt-appfastnuxt@builto/uikarboardlistify-thememangudinlagirajinmonkeynuxtuiixwebgerimismalamseninnuxt-telegram-miniappspatepangdeuioxecorepileuleuyanteanxt-uinuxt-og-imagenuxt-content-elysiumnuxt-daisyuinuxt-editablenuxt-editable-alphanuxt-simple-robotsnuxt-seo-uinuxt-archnuxt-arch-devnuxt-website-themenuxt-ui-radio-gp-cardnuxt-ui-customnuxt-legopromotty-coresf-docs-base@idealcodeio/nuxt-landing-page-base@idealcodeio/nuxt-medusa-basesenp-uisedanbosok@jcamp/shuriken-ui-nuxt@lunaplex/dashui@luxorus/nuxt-snackbar@josepuma/ui-kit@learnvue/themecontent-unocsscontent-wind@pergel/module-box@pergel/module-ui@plsr/nuxt-layer-base@samiebuka/nuxt-playground@shuriken-ui/nuxt@webcreators/nuxt-dynamic-layer@thombruce/tnt@zalastax/nolb-nuxt@quieromicasa/quieromicasa-shared-layer@redcollege/ui-kit@wstudiou/ui@toantranmei/mei-nuxt3-ui@sigveh/nuxt-baseyuebing@olivierbelaud/saas-base@nuxt-admin/module@nuxt-themes/prose@nuxt-themes/typography@nuxt-awesome/themeui.felgraf.devtehmusimhujan@mrrhq/shadcn-pro-edgeusebootstrap@nuxt/ui@nuxt/ui-edgevinca-ui@exactpro/docs-web-toolkit@enab/uipkganakketigaanaklanangteaanakwadontea@fdcn/popcorn@faridsafwan/layers@alexsun-top/nuxt-base-layerartimojo-cmsblanked@cgvweb/ui@classement-des-associations/website-theme@angsanley/nuxt-ui@canopassoftware/blog-components@canopassoftware/canopas-blog-components@canopassoftware/nuxt-blog-kit@cpreston321/nuxt-cv@cssninja/nuxt-ui@cssninja/stylobuilto-ui@disedia/website-core@dienst3/nuxt-daisyui@crearis/base@d0rich/nuxt-design-systemccsfasswea-ui
1.0.0-beta.4

1 day ago

1.0.0-beta.2

8 days ago

1.0.0-beta.3

8 days ago

1.0.0-beta.1

8 days ago

0.6.10

2 months ago

0.6.9

2 months ago

0.6.8

4 months ago

0.6.7

5 months ago

0.6.6

6 months ago

0.6.3

6 months ago

0.6.2

6 months ago

0.6.5

6 months ago

0.6.4

6 months ago

0.6.1

7 months ago

0.6.0

7 months ago

0.5.0

9 months ago

0.4.1

12 months ago

0.4.2

11 months ago

0.4.0

1 year ago

0.2.11

1 year ago

0.2.10

1 year ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.3.2

1 year ago

0.2.3

1 year ago

0.3.1

1 year ago

0.2.2

1 year ago

0.2.5

1 year ago

0.3.3

1 year ago

0.2.4

1 year ago

0.1.8

1 year ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago