Icons
Icons are inline SVGs. Their color follows the text color (currentColor), and their size is set by the size prop of HuiIcon: xs 12px, sm 14px, md 16px, lg 18px or xl 24px, defaulting to md. These sizes use fixed pixel values; use inherit to follow the parent's font size. See Icon for the full API.
Basic Usage
<script setup lang="ts">
import { HuiIcon } from '@nscode/handy-ui'
</script>
<template>
<HuiIcon name="search" />
<HuiIcon name="success" color="#52c41a" size="lg" />
<HuiIcon name="loading" spin />
</template>
Many components have props like icon that also take an icon name, for example <HuiButton icon="plus">Add</HuiButton>.
Icon List
name uses the built-in names below. Without a custom slot, an unknown name produces a development warning and leaves a blank 1em×1em box (16px by default).
| Group | Icon names |
|---|---|
| Direction and navigation | home menu apps top arrow-up arrow-down arrow-left arrow-right chevron-up chevron-down chevron-left chevron-right double-left double-right caret-up caret-down caret-left caret-right more-horizontal more-vertical |
| Actions | close check plus minus edit trash refresh copy save share link upload download filter sort drag lock eye eye-off eye-dropper zoom-in zoom-out rotate-left rotate-right fullscreen fullscreen-exit density pin |
| Status | success warning error info help loading star star-half heart clock calendar |
| User and general | user users setting search bell phone location mail |
| Files | file folder image table |
| Media | play pause replay skip-previous skip-next fast-rewind fast-forward volume-up volume-down volume-off pip subtitles |
| Editing, cropping and chat | undo redo format-bold format-italic format-underline format-strikethrough format-code format-quote format-list-bulleted format-list-numbered format-indent-increase format-indent-decrease format-align-left format-align-center format-align-right format-align-justify format-clear format-color-text format-color-fill format-heading horizontal-rule code-block link-off crop flip-horizontal flip-vertical send stop attach thumb-up thumb-down sparkle |
The 32 general-purpose editing, cropping and chat icons belong to the editor group and can be used independently in buttons, toolbars and content. Full screen exit uses the existing fullscreen-exit icon in Actions.
Player icons
Use these for playback, seeking, volume, picture-in-picture and subtitles. Full screen exit uses the existing fullscreen-exit icon.
<script setup lang="ts">
import { HuiIcon, HuiSpace } from '@nscode/handy-ui'
const names = [
'play',
'pause',
'replay',
'skip-previous',
'skip-next',
'fast-rewind',
'fast-forward',
'volume-up',
'volume-down',
'volume-off',
'pip',
'subtitles'
]
</script>
<template>
<HuiSpace wrap>
<HuiSpace v-for="name in names" :key="name" direction="vertical" align="center">
<HuiIcon :name="name" size="xl" /><span>{{ name }}</span>
</HuiSpace>
</HuiSpace>
</template>
Custom Icons
The default slot of HuiIcon accepts any SVG, and size, color and rotation props still apply:
<template>
<HuiIcon name="custom" size="lg" color="#1890ff">
<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2 2 7l10 5 10-5-10-5z" />
</svg>
</HuiIcon>
</template>
The SVG needs a viewBox, and its fill should be currentColor so it follows the color prop.
When the slot is provided, it takes precedence and the built-in icon for name isn't rendered. name is still required, but it does not provide an accessible name. Icons have aria-hidden="true" by default. Set aria-label explicitly to use role="img" and announce that label. Give an icon-only action button its accessible name on the button itself.
Using Icon Data Directly
@nscode/icons exports the raw icon data for rendering icons yourself:
import { icons, iconList, iconGroups } from '@nscode/icons'
icons['arrow-up'] // { name: 'arrow-up', svg: '<svg ...>...</svg>' }
iconList // all icons as an array, handy for an icon picker
iconGroups.navigation // by group: navigation, action, status, user, file, media, editor
iconGroups.media // playback, volume, picture-in-picture and subtitle icons
iconGroups.editor // 32 general-purpose editing, cropping and chat icons
icons['fullscreen-exit'] // reuse the full screen exit icon from Actions
Each icon can also be imported on its own by its camelCase name: import { arrowUp, chevronLeft } from '@nscode/icons'.