Skip to content

API

Complete API documentation, including components, types, and functions.

YhIcon Component

Props

PropertyDescriptionTypeDefault
nameIcon name, supports the prefix:icon-name format.string''
iconIcon name (equivalent to name, but with higher priority).string''
svgCustom SVG string (excluding the <svg> tag).string''
componentVue componentComponentundefined
sizeIcon sizenumber | stringundefined
colorIcon colorstringundefined
spinWhether to show a spin animation.booleanfalse
rotateRotation angle (0, 90, 180, 270).number0

Slots

Slot NameDescription
defaultCustom icon content.

Events

No native events; supports transparent transmission of all native attributes.

Usage Examples

YhIcon Component Usage

Icon Component

An alias for YhIcon, fully compatible.

Icon Component Usage

Type Definitions

IconName

Icon name type.

typescript
type IconName = string

Supported formats:

  • Short name: 'home'
  • With prefix: 'mdi:home'
  • Slash separator: 'mdi/home'

IconSize

Icon size type.

typescript
type IconSize = number | string

Examples:

  • Number: 24
  • Pixel string: '24px'
  • CSS unit: '2em'

IconColor

Icon color type.

typescript
type IconColor = string

Examples:

  • Hexadecimal: '#409EFF'
  • Color name: 'red'
  • CSS variable: 'var(--yh-color-primary)'

IconRotate

Icon rotation angle type.

typescript
type IconRotate = 0 | 90 | 180 | 270

IconProps

Props type for the icon component.

typescript
interface IconProps {
  name?: IconName
  icon?: IconName
  svg?: string
  component?: Component
  size?: IconSize
  color?: IconColor
  spin?: boolean
  rotate?: IconRotate
}

IconCollection

Icon collection configuration type.

typescript
interface IconCollection {
  name: string
  prefix: string
  author?: string
  license?: string
  total: number
}

IconPreset

Icon preset type.

typescript
interface IconPreset {
  name: string
  prefix: string
  count: number
  description?: string
}

Utility Functions

parseIconName

Parses an icon name into the standard format.

typescript
function parseIconName(name: string): string

Parameters:

  • name: Icon name

Return Value: The parsed icon name.

Example:

typescript
import { parseIconName } from '@yh-ui/icons'

parseIconName('home') // 'mdi:home'
parseIconName('mdi:home') // 'mdi:home'
parseIconName('mdi/home') // 'mdi:home'

iconExists

Checks if an icon exists.

typescript
async function iconExists(name: string): Promise<boolean>

Parameters:

  • name: Icon name

Return Value: Whether the icon exists.

Example:

typescript
import { iconExists } from '@yh-ui/icons'

const exists = await iconExists('mdi:home')
console.log(exists) // true

getIconData

Retrieves the SVG data for an icon.

typescript
async function getIconData(name: string): Promise<IconifyIcon>

Parameters:

  • name: Icon name

Return Value: The SVG data of the icon.

Example:

typescript
import { getIconData } from '@yh-ui/icons'

const iconData = await getIconData('mdi:home')
console.log(iconData)

getCollectionPrefixes

Retrieves a list of available icon set prefixes.

typescript
function getCollectionPrefixes(): string[]

Example:

typescript
import { getCollectionPrefixes } from '@yh-ui/icons'

const prefixes = getCollectionPrefixes()
console.log(prefixes) // ['mdi', 'ep', 'lucide', ...]

Constants

AVAILABLE_COLLECTIONS

A complete list of all available icon collections.

typescript
const AVAILABLE_COLLECTIONS = [
  { prefix: 'mdi', name: 'Material Design Icons', count: 7000 },
  { prefix: 'ep', name: 'Element Plus', count: 200 },
  { prefix: 'lucide', name: 'Lucide', count: 1500 }
  // ...
] as const

A list of recommended icon set prefixes.

typescript
const RECOMMENDED_COLLECTIONS = ['mdi', 'ep', 'lucide', 'tabler', 'ri'] as const

COMMON_ICONS

A mapping of common icon aliases.

typescript
const COMMON_ICONS = {
  'arrow-up': 'mdi:arrow-up',
  'arrow-down': 'mdi:arrow-down',
  close: 'mdi:close',
  check: 'mdi:check',
  search: 'mdi:magnify'
  // ...
} as const

Vue Component Auto-import

When used in Nuxt, components are automatically imported:

vue
<template>
  <!-- No manual import required -->
  <YhIcon name="mdi:home" />
</template>

For detailed Nuxt integration, please refer to Using in Nuxt.

Released under the MIT License.