IconPicker 图标选择器
在可搜索网格中选择图标,图标集合由调用方提供
查看代码收起代码
vue
<script setup lang="ts">
import { ZIconPicker } from '@codex-proxy/ui'
import { Circle, Cloud, Folder, Heart, Moon, Square, Star, Sun } from '@lucide/vue'
import { shallowRef } from 'vue'
const value = shallowRef<string>()
const options = [
{ value: 'circle', label: '圆形', icon: Circle },
{ value: 'square', label: '方形', icon: Square },
{ value: 'star', label: '星星', icon: Star },
{ value: 'heart', label: '爱心', icon: Heart },
{ value: 'cloud', label: '云朵', icon: Cloud },
{ value: 'sun', label: '太阳', icon: Sun },
{ value: 'moon', label: '月亮', icon: Moon },
{ value: 'folder', label: '文件夹', icon: Folder, disabled: true },
]
</script>
<template>
<ZIconPicker v-model="value" :options="options" clearable aria-label="图标" class="w-72 max-w-full" />
</template>交互
点击字段后搜索名称或标识,方向键进入并浏览网格,Enter 选择;Escape 关闭并返回字段,Tab 或 Shift+Tab 关闭并继续切换字段
面板与字段等宽,并受视口边界约束;可用高度不足时仅滚动图标列表
悬停或键盘聚焦图标时显示名称。已选项置顶,图标随滚动按批渲染,支持异步 Vue 图标组件。选项集合、业务默认值及保存由应用管理
API
| 属性 | 说明 | 默认值 |
|---|---|---|
v-model | 选项标识 string,空值为 undefined | — |
options | { value: string, label: string, icon: Component, disabled?: boolean }[] | 必填 |
size | small / default / large,继承表单或 ConfigProvider | default |
disabled | 禁用选择和清空 | false |
clearable | 显示字段内清除操作 | false |
placeholder | 空值时显示的文本,不写入绑定值 | 语言包 |
clear-label | 清除按钮的可访问名称 | 语言包 |
validate-event | 选择、清空及离开字段时触发表单校验 | true |
通过 FormItem 或 aria-label 为字段命名,字段的错误、必填及辅助信息沿用 Form 合同
事件:change(value)、clear()、visible-change(open)、focus(event)、blur(event)。外部更新值不触发用户事件
实例:focus()、blur()、open()、close()、clear()