Icons
Icons are inline SVGs. Their color follows the text color (currentColor), and their size is set by the size prop of NsIcon: xs 12px, sm 14px, md 16px, lg 18px or xl 24px, defaulting to md. Sizes are fixed pixel values and don't follow the parent's font size. See Icon for the full API.
Basic Usage
<script setup lang="ts">
import { NsIcon } from '@ns/ui'
</script>
<template>
<NsIcon name="search" />
<NsIcon name="success" color="#52c41a" size="lg" />
<NsIcon name="loading" spin />
</template>
Many components have props like icon that also take an icon name, for example <NsButton icon="plus">Add</NsButton>.
Icon List
name can only be one of the names below. A name outside this list doesn't throw, but the icon becomes a blank 1em×1em box (16px by default) that pushes the text next to it.
| 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 zoom-in zoom-out rotate-left rotate-right fullscreen |
| 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 |
Custom Icons
The default slot of NsIcon accepts any SVG, and size, color and rotation props still apply:
<template>
<NsIcon 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>
</NsIcon>
</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 and is read out by screen readers as the aria-label: name="custom" above is read as "custom", so give custom icons a meaningful name.
Using Icon Data Directly
@ns/icons exports the raw icon data for rendering icons yourself:
import { icons, iconList, iconGroups } from '@ns/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
Each icon can also be imported on its own by its camelCase name: import { arrowUp, chevronLeft } from '@ns/icons'.