Icons

Icons

SIcon renders Iconify or project SVG data without icon fonts or global icon CSS. It never initiates API requests. Both Iconify and local SVG build plugins emit only statically referenced or safelisted icons.

Sax components ship a small built-in Carbon fallback for their own default controls, so pagination arrows, close buttons, picker affordances and table actions remain visible without configuring Carbon. Explicit iconData and application registrations take precedence. IconPicker contains candidate names only: opening it loads missing candidates from its configured API. No candidate SVG catalog is embedded in the component library.

This integration targets Vite 4, 5, and 8. A Webpack adapter is intentionally not shipped.

Find an icon

Search the Iconify icon sets, then copy the displayed prefix:name value.

  • Carbon — the default visual language used by Sax components, shortened to cb: in these examples.
  • BoxIcons — use the friendly bx: alias in Sax templates.
  • BoxIcons Solid — use bxs:.
  • BoxIcons Logos — use bxl:.
<s-icon name="cb:add" />
<s-icon name="bx:book" />
<s-icon name="bxs:heart" />

Install

Install the build plugin:

pnpm add -D sax-design-vue-iconify

Configure collections and dynamic safelist

Create sax-icons.config.ts at the project root. API mode does not require any @iconify-json/* package:

import { defineSaxIconConfig } from 'sax-design-vue-iconify'

export default defineSaxIconConfig({
  mode: 'api',
  collections: {
    cb: 'carbon',
    bx: 'bx',
  },
  // Required only for values that cannot be discovered statically,
  // such as icon names returned by an API.
  safelist: ['cb:add', 'bx:book'],
})

Each left-hand key is the short prefix used by the application. Each value is an Iconify collection name. API mode requests only icons found by static scanning or safelist, then caches responses in node_modules/.cache/sax-design-vue-iconify. The first build needs network access; later builds reuse the cache.

For offline, version-pinned builds, use the default local mode and install collection packages:

pnpm add -D @iconify-json/carbon @iconify-json/bx

Remove mode: 'api' or set mode: 'local'. Use api.baseUrl, api.cacheDir, and api.timeout to customize the endpoint, cache path, and timeout. Set cacheDir: false to disable disk caching.

API mode exposes three selectable endpoints and uses the first one by default. Pick another entry explicitly, or pass a private Iconify-compatible URL:

import {
  DEFAULT_API_ENDPOINTS,
  defineSaxIconConfig,
} from 'sax-design-vue-iconify'

export default defineSaxIconConfig({
  mode: 'api',
  collections: { cb: 'carbon' },
  api: {
    // 0: Iconify, 1: SimpleSVG, 2: UniSVG
    baseUrl: DEFAULT_API_ENDPOINTS[1],
  },
})

Register the Vite plugin before Vue:

import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import { saxIcons } from 'sax-design-vue-iconify/vite'
import iconConfig from './sax-icons.config'

export default defineConfig({
  plugins: [saxIcons(iconConfig), vue()],
})

The plugin injects the safelist registry into Vite HTML entries automatically. No entry-file registration code is needed.

Local SVG files

Place home.svg, user.svg, and other assets in src/assets/svgs/, then register the directory in vite.config.ts:

import vue from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import { signSvgs } from 'sax-design-vue-iconify/vite'

export default defineConfig({
  plugins: [
    signSvgs([
      { preset: 'lo', url: 'src/assets/svgs/*.svg' },
      { preset: 'brand', url: 'src/assets/brands/**/*.svg' },
    ]),
    vue(),
  ],
})

url accepts a file, glob, or array of globs relative to Vite root. *.svg matches one directory; **/*.svg includes subdirectories. Scanning happens in the development server and build process, without browser access to the filesystem.

<template>
  <s-icon name="lo-home" />
  <s-button icon="lo-user">Users</s-button>
  <s-icon :name="selectedIcon" />
</template>

<script setup lang="ts">
import { ref } from 'vue'
const selectedIcon = ref('lo-home')
</script>

Names use preset-filename without .svg, preserving filename case. Subdirectories do not affect names; duplicate basenames within one preset fail the build. Assign different presets to directories containing the same filenames. This plugin can coexist with saxIcons(...).

Scanning builds a filename index; only literal names found in application source and explicit safelist entries become SVG modules. This includes name="lo-home", icon="lo-home", and configuration strings such as { icon: 'lo-home' }. Identical SVG data shares one module across files and presets. Unreferenced SVGs are not parsed or emitted. File changes automatically reload the development page.

Names assembled at runtime or returned by an API need a safelist:

signSvgs([{ preset: 'lo', url: 'src/assets/svgs/**/*.svg' }], {
  safelist: ['lo-home', 'lo-user'],
})

When used together with saxIcons, local names may also be included in its shared safelist. Both paths reference the same per-icon modules.

SVG viewBox, paths, colors and gradients are preserved. Files without viewBox need positive numeric width and height. Author currentColor when an icon should inherit text color; black fills are not automatically recolored. Inline SVG and icon morphing feature limitations still apply.

Literal names register through imports inserted into their source module, including SSR. Safelists register automatically in HTML entries. For SSR or entries without HTML, import the local safelist module before rendering:

/// <reference types="sax-design-vue-iconify/virtual" />
import 'virtual:sax-svgs/register'

Tree shaking

Static names are discovered automatically:

<s-icon name="cb:add" />

The build obtains add from an installed collection or Iconify API and emits only that SVG data. Registering Carbon does not place the complete collection in the browser bundle or create runtime browser requests.

Dynamic names are not statically knowable:

<s-icon :name="record.icon" />

Add every possible dynamic value to safelist. Only those entries are emitted.

Size, color, rotation, and rolling

color defaults to currentColor, so icons inherit surrounding text and theme colors.

Set rolling to true to use the --sax-icon-rolling-duration CSS default of 0.9s. A positive number sets seconds per revolution through an inline CSS variable override; smaller values rotate faster:

<s-icon name="cb:renew" rolling />
<s-icon name="cb:renew" :rolling="1.8" />

Common examples

PropertyTypeDefaultDescription
namestring—Registered Iconify name in prefix:name format.
sizenumber | string1emWidth and height. Numbers use pixels.
colorstringcurrentColorCSS color or Sax color token.
rotatenumber | string0Rotation. Numbers use degrees.
fliphorizontal | vertical | both—Mirrors the icon.
rollingboolean | numberfalseRotates continuously; number is seconds per turn.
labelstring—Accessible name. Without it the icon is decorative.

Icon morphing

Add morph to SIcon to animate changes to name. For example, use your page’s expanded state to switch between the expand and collapse arrows.

New or disappearing native stroke contours draw and retract along their original paths. Filled artwork keeps geometry interpolation and compound holes. Selecting another icon during a transition continues from the displayed geometry and paint.

Copied
<s-icon :name="expanded ? 'cb:chevron-up' : 'cb:chevron-down'" morph />

Choose an example and click “Switch icon”. Duration controls how long the transition takes; Animation style controls how it settles. The multicolor and gradient examples supply SVG through iconData and use the same morph options.

Global morphing

Set icon.morph when installing the library or through SConfigProvider to enable morphing for icons in that scope. Components that render SIcon, such as the icon property of Button and Tab, inherit the setting. Local morph options override defaults; pass :morph="false" to disable an individual icon.

Copied
app.use(SaxDesignVue, {
  icon: { morph: { duration: 360, spring: 'snappy' } },
})
<s-config-provider :icon="{ morph: { duration: 400 } }">
  <s-button
    :icon="expanded ? 'cb:chevron-up' : 'cb:chevron-down'"
    @click="expanded = !expanded"
  >Expand / collapse</s-button>
  <s-icon name="cb:pin" :morph="false" />
</s-config-provider>
PropertyTypeDefaultDescription
morphboolean | IconMorphOptionsfalseEnable morphing, or pass an object to adjust the animation.
morph.durationnumber360Duration in milliseconds; 0 switches immediately.
morph.spring‘smooth’ | ‘snappy’ | ‘bouncy’snappysmooth settles gently; snappy adds a subtle bounce; bouncy adds a stronger bounce.

The first icon appears without animating. The system’s reduced-motion preference disables transitions. Interrupted changes continue from the current picture. Unsupported SVG masks, filters or patterns switch directly to the new icon.

morph-start fires when an animation begins and morph-end when it finishes. Both receive { elapsed }, the elapsed time in milliseconds. An animation interrupted by a new icon does not emit completion.

Last Updated: 2026-10-28, 06:17:56 UTC
Copied