ColorPicker 颜色选择器
LhColorPicker 颜色选择器:饱和度板、色相 / 透明度滑杆、hex / rgb 双格式与预设色板。
基础用法
基础用法
#2b4c7c
rgb(58, 125, 90)
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhColorPicker } from '@lh-ui/vue3'
const color = ref('#2B4C7C')
const color2 = ref('#3A7D5A')
</script>
<template>
<div class="demo-row">
<LhColorPicker v-model="color" />
<LhColorPicker v-model="color2" format="rgb" />
</div>
</template>vue
<script>
import { LhColorPicker } from '@lh-ui/vue3'
export default {
components: { LhColorPicker },
data() {
return {
color: '#2B4C7C',
color2: '#3A7D5A',
}
},
}
</script>
<template>
<div class="demo-row">
<LhColorPicker v-model="color" />
<LhColorPicker v-model="color2" format="rgb" />
</div>
</template>透明度与预设色板
#a63d40
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhColorPicker } from '@lh-ui/vue3'
const color3 = ref('#A63D40')
const predefine = ['#2B4C7C', '#3A7D5A', '#B8860B', '#A63D40', '#666B70']
</script>
<template>
<LhColorPicker v-model="color3" show-alpha :predefine="predefine" />
</template>vue
<script>
import { LhColorPicker } from '@lh-ui/vue3'
export default {
components: { LhColorPicker },
data() {
return {
color3: '#A63D40',
}
},
}
</script>
<template>
<LhColorPicker v-model="color3" show-alpha :predefine="predefine" />
</template>ColorPicker API
Props
| 属性名 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| modelValue | 颜色值(v-model,hex 或 rgb() 字符串,按 format 输出) | string | '' |
| format | 输出格式:hex / rgb | "hex" | "rgb" | 'hex' |
| showAlpha | 透明度通道(开启后输出 8 位 hex / rgba()) | boolean | false |
| predefine | 预设色板 | string[] | () => [] |
| size | 尺寸 | "small" | "medium" | "large" | "mini" | "x-large" | 'medium' |
| disabled | 禁用 | boolean | false |
| clearable | 清除(置空)按钮 | boolean | false |
| placeholder | 空值时的占位提示 | string | '' |
| ariaLabel | 触发器的无障碍名称(未传时取语言包文案) | string | — |
| sx | 快速布局属性,转内联样式作用于根元素 | LhSxProps | — |
Events
| 属性名 | 说明 | 类型 |
|---|---|---|
| update:modelValue | 颜色变化时触发(v-model) | (value: string) |
| change | 颜色变化时触发 | (value: string) |
| clear | 点击清除按钮时触发 | () |
无障碍
- 色相 / 透明度滑杆为
role="slider",支持方向键微调(Shift 加速) - 触发器为键盘可达按钮(Enter / 空格展开面板),点击面板外部或 Esc 关闭
类型定义
本组件对外导出的 TypeScript 类型结构如下(自动提取自 packages/components/color-picker/src/types.ts 与 @lh-ui/share/core/* 源码,点击各条目展开查看完整定义;属性说明见上方 Props 表):
LhColorPickerProps
ts
export interface LhColorPickerProps {
/** 颜色值(受控 v-model,hex 或 rgb() 字符串,按 format 输出) */
modelValue?: string
/** 输出格式(默认 hex) */
format?: LhColorFormat
/** 透明度通道(开启后输出 8 位 hex / rgba()) */
showAlpha?: boolean
/** 预设色板 */
predefine?: string[]
/** 尺寸 */
size?: LhComponentSize
/** 禁用 */
disabled?: boolean
/** 清除(置空)按钮 */
clearable?: boolean
/** 占位提示(空值时) */
placeholder?: string
/** 无障碍名称(未传时取语言包 colorPicker.label) */
ariaLabel?: string
/** sx 快速布局属性 */
sx?: LhSxProps
}LhColorPickerSize
ts
export type LhColorPickerSize = LhComponentSize
