UIIconPicker
UIIconPicker
A component that allows users to browse and select icons from various icon sets, with search functionality and custom rendering options.
<template> <UIIconPicker :id="'icon-picker-1'" :title="$t('iconPicker.title')" :searchPlaceholder="$t('iconPicker.search')" :trigger="'click'" :placement="'bottom-start'" :preLoad="'outline'" @onSelected="handleIconSelect" > <template #trigger> <UIButton> <template #icon> <component :is="selectedIcon || 'IconPlus'" /> </template> {{ $t('iconPicker.selectIcon') }} </UIButton> </template> </UIIconPicker></template>
<script setup lang="ts">const selectedIcon = ref<string | null>(null)
const handleIconSelect = (iconName: string) => { selectedIcon.value = iconName console.log('Selected icon:', iconName)}</script>Props
id(string, required): Unique identifiertitle(string): Picker titlesearchPlaceholder(string): Search input placeholdertrigger(‘hover’ | ‘click’ | ‘focus’ | ‘manual’): Trigger modeplacement(string): Dropdown placementpreLoad(string): Preload icon setdisabled(boolean): Disable the pickerloading(boolean): Show loading statevalue(string): Selected icon namesize(‘small’ | ‘medium’ | ‘large’): Icon size
Events
update:value: Emitted when icon selection changesonSelected: Emitted when an icon is selectedonSearch: Emitted when search input changesonClose: Emitted when picker closes
Slots
trigger: Custom trigger contentheader: Custom header contentfooter: Custom footer contentempty: Custom empty state contentloading: Custom loading state content
Usage Examples
- Basic Usage:
<template> <UIIconPicker v-model:value="selectedIcon" @onSelected="handleSelect" /></template>
<script setup>const selectedIcon = ref('')const handleSelect = (icon: string) => { console.log('Selected:', icon)}</script>- Custom Trigger:
<template> <UIIconPicker v-model:value="icon"> <template #trigger> <div class="flex items-center gap-2 p-2 border rounded"> <component :is="icon || 'IconPlaceholder'" /> <span>{{ icon ? 'Change Icon' : 'Select Icon' }}</span> </div> </template> </UIIconPicker></template>- With Search and Categories:
<template> <UIIconPicker v-model:value="icon" :searchPlaceholder="'Search icons...'" :preLoad="'all'" > <template #header> <div class="flex gap-2 p-2"> <UIButton v-for="category in categories" :key="category" @click="filterByCategory(category)" > {{ category }} </UIButton> </div> </template> </UIIconPicker></template>- In Form Context:
<template> <UIForm> <UIFormItem label="Select Icon" name="icon"> <UIIconPicker v-model:value="formState.icon" :disabled="loading" /> </UIFormItem> </UIForm></template>Best Practices
-
Icon Management:
- Organize icons by categories
- Provide clear icon names
- Include icon previews
- Support multiple icon styles
-
User Experience:
- Enable quick icon search
- Show recently used icons
- Provide category filters
- Include icon tooltips
-
Accessibility:
- Support keyboard navigation
- Include ARIA labels
- Provide clear focus states
- Use descriptive icon names
-
Performance:
- Lazy load icon sets
- Optimize icon rendering
- Cache search results
- Minimize re-renders
-
Integration:
- Support design system
- Enable custom icon sets
- Allow icon customization
- Provide icon utilities
Icon Sets
The component supports various icon sets:
- Outline icons (24px)
- Solid icons (24px)
- Custom icon sets
To use custom icon sets:
<template> <UIIconPicker :customIcons="customIconSet" :preLoad="'custom'" /></template>
<script setup>const customIconSet = { icons: { 'custom-icon-1': CustomIcon1Component, 'custom-icon-2': CustomIcon2Component }, categories: { 'Custom': ['custom-icon-1', 'custom-icon-2'] }}</script>