Icon

Displays an icon from a variety of icon libraries.

UnaUI integrates Iconify to provide a wide variety of icons from multiple collections. Iconify ensures a consistent icon usage across different collections.

By default, UnaUI includes the following icon collections:

To add more icon collections, follow these steps:

Install the desired icon collection using your preferred package manager:

pnpm
yarn
npm
pnpm add -D @iconify-icons/[collection-name]

Examples

Basic

Preview
Code
Hover

Shortcuts

These icons are configured by default. They are used globally in the components such as NInput, NAlert, NButton, and more.

shortcuts/config/icons.ts
export const staticIcons = {
  'i-loading': 'i-tabler-loader-2',
  'i-warning': 'i-tabler-alert-triangle-filled',
  'i-error': 'i-tabler-exclamation-circle-filled',
  'i-success': 'i-tabler-circle-check-filled',
  'i-info': 'i-tabler-info-circle-filled',
  'i-close': 'i-tabler-x',
  'i-check': 'i-tabler-check',
  'i-dot': 'i-tabler-circle-filled',
}
Preview
Code

Presets

shortcuts/icon.ts
type IconPrefix = 'icon'

export const staticIcon: Record<`${IconPrefix}-${string}`, string> = {
  // base
  'icon-base': 'flex-none',
}

export const dynamicIcon: [RegExp, (params: RegExpExecArray) => string][] = []

export const icon = [
  ...dynamicIcon,
  staticIcon,
]

Props

types/icon.ts
import type { HTMLAttributes } from 'vue'

export interface NIconProps {
  /**
   * Icon name
   *
   * @example
   * 'i-heroicons-chevron-up'
   */
  name: HTMLAttributes['class']
}

Components

Icon.vue
<script setup lang="ts">
import type { NIconProps } from '../../types'

defineProps<NIconProps>()
</script>

<template>
  <span icon-base :class="name" />
</template>