diff --git a/docs/.navigation.yml b/docs/.navigation.yml new file mode 100644 index 00000000..c8d0d599 --- /dev/null +++ b/docs/.navigation.yml @@ -0,0 +1 @@ +title: Nuxt Icon diff --git a/docs/1.usage.md b/docs/1.usage.md new file mode 100644 index 00000000..57642ba5 --- /dev/null +++ b/docs/1.usage.md @@ -0,0 +1,106 @@ +--- +title: Usage +description: 'Render any of the 200,000+ Iconify icons, or your own Vue components.' +--- + +**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, a `` or `` will be created based on the rendering mode, you can give [all the attributes](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute) of the native element. + +```html + +``` + +**TailwindCSS v4**: + +When using TailwindCSS v4 with the `css` mode, you should configure the `cssLayer` in Nuxt's app config: + +```ts +// ~/app.config.ts +export default defineAppConfig({ + icon: { + mode: 'css', + cssLayer: 'base' + } +}) +``` + +## Iconify Dataset + +You can use any name from the https://icones.js.org collection: + +```html + +``` + +It supports the `i-` prefix (for example, `i-uil-github`). + +It's highly recommended to install the icon data locally with + +```bash +npm i -D @iconify-json/collection-name +``` + +For example, to use the `uil:github` icon, install its 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. + +> [!NOTE] +> You may also know you can install `@iconify/json` package to include all iconify icons. This is not recommended because it will increase your server bundle size and building performance. If you choose to do so, we'd recommend to explicitly specify the collection names you need: +> +> ```ts +> export default defineNuxtConfig({ +> modules: ['@nuxt/icon'], +> icon: { +> serverBundle: { +> collections: ['uil', 'mdi'] // +> +> +> +> +> +> ``` diff --git a/docs/4.customization.md b/docs/4.customization.md new file mode 100644 index 00000000..9d04fd24 --- /dev/null +++ b/docs/4.customization.md @@ -0,0 +1,88 @@ +--- +title: Icon Customization +description: 'Change stroke width, colors and more at render time.' +--- + +To update the default size (`1em`) of the ``, create an `app.config.ts` with the `icon.size` property. + +Update the default class (`.icon`) of the `` 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. + +> [!NOTE] +> Note it's `app.config.ts` and not `nuxt.config.ts` for runtime configs. + +```ts +// app.config.ts +export default defineAppConfig({ + icon: { + size: '24px', // default size applied + class: 'icon', // default class applied + mode: 'css', // default mode applied + aliases: { + 'nuxt': 'logos:nuxt-icon', + }, + cssLayer: 'base' // set the css layer to inject to + } +}) +``` + +The icons will have the default size of `24px` and the `nuxt` icon will be available: + +```html + +``` + +By default, this module will create a server endpoint `/api/_nuxt_icon/:collection` to serve the icons from your local server bundle (you can override the default path by setting `icon.localApiEndpoint` to your desired path). When requesting an icon that does not exist in the local bundle, it will fallback to requesting [the official Iconify API](https://api.iconify.design). You can disable the fallback by setting `icon.fallbackToApi` to `false`, or set up [your own Iconify API](https://iconify.design/docs/api/hosting.html) and update `icon.iconifyApiEndpoint` to your own API endpoint. + +**Customizing Icons with the customize Option** + +The customize option allows you to modify various aspects of the SVG icons used in your project. With this option, you can: + +- Change Stroke Width +- Change Colors +- Change Animation Duration +- Change Opacity +- Add Extra Shapes + +You have full control over SVG content with these customization options. + +In a Component +You can define a customize function within a component to apply various modifications to your icons. + +```vue + + + + + +``` + +In the App Configuration File: + +Alternatively, you can apply these customizations globally in the `app.config.ts` file. +```ts +// app.config.ts +export default defineAppConfig({ + icon: { + customize: (content: string, name: string, prefix: string, provider: string) => { + // ... + }, + } +}) +``` +With this configuration, all icons throughout your application will have these customizations applied consistently. diff --git a/docs/5.custom-collections.md b/docs/5.custom-collections.md new file mode 100644 index 00000000..f55fe83f --- /dev/null +++ b/docs/5.custom-collections.md @@ -0,0 +1,132 @@ +--- +title: Custom Collections +description: 'Serve your own SVG files as an icon collection.' +--- + +You can use local SVG files to create a custom Iconify collection. + +For example, place your icons' SVG files under a folder of your choice, for example, `./assets/my-icons`: + +```bash +assets/my-icons +├── foo.svg +├── bar-outline.svg +``` + +In your `nuxt.config.ts`, add an item in `icon.customCollections`: + +```ts +export default defineNuxtConfig({ + modules: [ + '@nuxt/icon' + ], + icon: { + customCollections: [ + { + prefix: 'my-icon', + dir: './assets/my-icons', + // if you want to include all the icons in nested directories: + // recursive: true, + }, + ], + }, +}) +``` + +> [!NOTE] +> A relative `dir` is resolved from the directory of the project that declares it. When your project is used as an [extendable layer](https://nuxt.com/docs/4.x/getting-started/layers), the icons are loaded from the layer's own directory, not from the consuming project. Absolute paths, such as one built with `createResolver(import.meta.url)`, keep working as before. + +> [!NOTE] +> If you are running on Nuxt 4 with the new `app` directory, the assets directory is `'./app/assets/*'` instead of `'./assets/*'`. + +Then you can use the icons like this: + +```vue + +``` + +You can also pass a full custom `IconifyJSON` object: + +```ts +export default defineNuxtConfig({ + modules: [ + '@nuxt/icon' + ], + icon: { + customCollections: [ + { + prefix: 'paid-icons', + icons: { + 'nuxt': { body: '