Icon
An icon rendered from a class, a built-in name, or a resource.
Usage
Class Icons
<template>
<!-- Remix Icon -->
<i class="i-ri-home-line" />
<i class="i-ri-search-line" />
<i class="i-ri-settings-3-line" />
<!-- Carbon -->
<i class="i-carbon-user" />
<i class="i-carbon-folder" />
<!-- Simple Icons (brand) -->
<i class="i-simple-icons-github" />
<i class="i-simple-icons-visualstudiocode" />
</template>
TuffIcon
In TuffIcon (alias TxIcon), name takes a class or built-in name and icon takes a structured source.
<template>
<TuffIcon name="i-ri-home-line" />
<TuffIcon name="chevron-down" />
<TuffIcon :icon="{ type: 'emoji', value: '🚀' }" />
<TuffIcon :icon="{ type: 'url', value: '/app.svg', colorful: true }" />
</template>
TuffIcons Constants
@talex-touch/utils provides predefined icon constants.
import { TuffIcons, AppIcons } from '@talex-touch/utils'
// UI icons
TuffIcons.Home // 'i-ri-home-line'
TuffIcons.Search // 'i-ri-search-line'
TuffIcons.Settings // 'i-ri-settings-3-line'
// Brand icons
AppIcons.VSCode // 'i-simple-icons-visualstudiocode'
AppIcons.GitHub // 'i-simple-icons-github'
| Category | Constant | Class |
|---|---|---|
| Navigation | TuffIcons.Home | i-ri-home-line |
TuffIcons.Back | i-ri-arrow-left-line | |
TuffIcons.Forward | i-ri-arrow-right-line | |
TuffIcons.Menu | i-ri-menu-line | |
| Actions | TuffIcons.Search | i-ri-search-line |
TuffIcons.Add | i-ri-add-line | |
TuffIcons.Delete | i-ri-delete-bin-line | |
TuffIcons.Edit | i-ri-edit-line | |
TuffIcons.Copy | i-ri-file-copy-line | |
TuffIcons.Save | i-ri-save-line | |
TuffIcons.Download | i-ri-download-line | |
TuffIcons.Upload | i-ri-upload-line | |
TuffIcons.Refresh | i-ri-refresh-line | |
| Status | TuffIcons.Check | i-ri-check-line |
TuffIcons.Close | i-ri-close-line | |
TuffIcons.Warning | i-ri-error-warning-line | |
TuffIcons.Info | i-ri-information-line | |
TuffIcons.Error | i-ri-close-circle-line | |
| Files | TuffIcons.File | i-ri-file-line |
TuffIcons.Folder | i-ri-folder-line | |
TuffIcons.FileCode | i-ri-file-code-line | |
TuffIcons.FileImage | i-ri-image-line | |
| UI elements | TuffIcons.Settings | i-ri-settings-3-line |
TuffIcons.User | i-ri-user-line | |
TuffIcons.Star | i-ri-star-line | |
TuffIcons.Heart | i-ri-heart-line | |
TuffIcons.Lock | i-ri-lock-line | |
TuffIcons.Eye | i-ri-eye-line | |
| Brands | AppIcons.GitHub | i-simple-icons-github |
AppIcons.VSCode | i-simple-icons-visualstudiocode | |
AppIcons.Chrome | i-simple-icons-googlechrome | |
AppIcons.Discord | i-simple-icons-discord |
Custom Styles
<template>
<!-- Size -->
<i class="i-ri-home-line text-sm" />
<i class="i-ri-home-line text-base" />
<i class="i-ri-home-line text-xl" />
<i class="i-ri-home-line text-2xl" />
<!-- Color -->
<i class="i-ri-star-line text-yellow-500" />
<i class="i-ri-heart-fill text-red-500" />
<i class="i-ri-check-circle-fill text-green-500" />
<!-- Motion -->
<i class="i-ri-loader-4-line animate-spin" />
</template>
Status Indicator
tone on TxStatusIcon overlays a status dot on the icon's bottom-right corner.
Loading demo...
OS Icons
TxOsIcon detects the platform from platform and os.
Loading demo...
Icon Sources
type | Use |
|---|---|
class | Icon class name (recommended). |
emoji | Lightweight emphasis. |
file / url | Local or remote icons. |
builtin | Built-in icons: check, chevron-down, close, search, user, star, star-half, info, check-circle, x-circle, alert-triangle. |
Set colorful on the component or as icon.colorful.
Best Practices
- Prefer UnoCSS classes (
i-*) in product UI, since they inheritcurrentColor; useTxIconSourcefor status, URL / file resolution, or original colors. - Set
altonly when the icon itself carries meaning; let surrounding text describe decorative icons. - Keep
colorful=falsefor monochrome SVGs so they follow the theme; setcolorful=truefor brand marks and multi-color art. - Inject
TX_ICON_CONFIG_KEYonce at the app shell instead of passing resolvers to every icon. - Pair
TxOsIconwith visible platform text and size it with CSS font-size; treat the fallback glyph as a visual default, not a validation result.
API Reference
TxIcon
Props
| Property | Type | Default | Description |
|---|---|---|---|
| icon | - | Structured icon source (type / value); an alternative to name. | |
| name | - | Class or built-in icon name. | |
| size | - | Size in px; inherits the parent font size when omitted. | |
| colorful | Keeps the original SVG colors. | ||
| alt | Accessible name, written to title; also the alt of the fallback image. | ||
| empty | Fallback image URL shown when no icon resolves. | ||
| urlResolver | - | Overrides URL / file path resolution. | |
| svgFetcher | - | Overrides how SVG content is fetched. |
Slots
| Name | Props | Description |
|---|---|---|
empty | - | Replaces the fallback content shown when no icon resolves. |
TxStatusIcon
Props
| Property | Type | Default | Description |
|---|---|---|---|
| colorful | Keeps the original SVG colors; defaults to true, unlike TxIcon. | ||
| size | Size in px; defaults to 18, while TxIcon inherits the parent font size. | ||
| tone | Status dot at the bottom-right corner; hidden with none. | ||
| indicatorSize | Status dot size in px. | ||
| indicatorOffset | Status dot offset in px. |
icon, name, alt, and empty work as on TxIcon.
TxOsIcon
Props
| Property | Type | Default | Description |
|---|---|---|---|
| platform | Platform identifier such as darwin, win32, or linux. | ||
| os | Readable OS name, also used for detection. |
classIcon / getIcon
import { classIcon, getIcon } from '@talex-touch/utils'
const icon = classIcon('i-ri-star-line')
// { type: 'class', value: 'i-ri-star-line' }
const searchIcon = getIcon('Search')
// { type: 'class', value: 'i-ri-search-line' }
Icon sets
| Set | Prefix | Description |
|---|---|---|
| Remix Icon | i-ri- | General UI icons, outline / filled styles |
| Carbon | i-carbon- | IBM design system icons |
| Simple Icons | i-simple-icons- | Brand / logo icons |
Icon search
Browse and search every icon at Icônes.
Overview
- A
namestarting withi-renders as a class, a built-in name renders its SVG, and anything else renders as a class — showing nothing if no such class exists. filevalues and local absoluteurlvalues pass through the injectedfileProtocolorurlResolver.- With
colorful=false, a monochrome SVG whose content is readable (data URL orsvgFetcher) renders as acurrentColormask; multi-color or unreadable SVGs render as images. - An
icon.statusofloadingorerrortakes precedence over the icon. - With
alt, the root isrole="img"with atitle; without it, the root isaria-hidden="true". TxOsIconjoins and lowercasesplatformandosto detect macOS / Windows / Linux, falling back to macOS; its SVG isaria-hidden.
Technologies
shouldRenderSvgAsMaskchecks whether every paint color in an SVG is neutral orcurrentColorto decide on mask rendering.TX_ICON_CONFIG_KEYinjectsurlResolver,svgFetcher, andfileProtocol.- Source:
packages/tuffex/packages/components/src/icon/.
查看源码
packages/tuffex/packages/components/src/icon/index.ts