ColorPicker 颜色选择器
HSV 面板取色器:饱和度 / 明度板 + 色相 / 透明度滑杆 + hex / rgb 输入 + 预设色板。
基础用法
基础用法
#2b4c7c
#8c2f3b
#3b6e4f
当前颜色:#2B4C7C
import { LhColorPicker } from '@lh-ui/react'
export default function Demo() {
return (
<LhColorPicker
defaultValue="#2B4C7C"
predefine={['#2B4C7C', '#8C2F3B', '#3B6E4F']}
showAlpha
clearable
/>
)
}
ColorPicker Props
| 属性 | 说明 | 类型 | 可选值 | 默认值 |
|---|---|---|---|---|
| value / defaultValue | 颜色值(受控 / 非受控,hex 或 rgb() 字符串) | string | — | — |
| onChange | 颜色值变化(按 format 输出) | (value: string) => void | — | — |
| onClear | 清除按钮点击(置空时触发) | () => void | — | — |
| format | 输出格式 | LhColorFormat | 'hex' | 'rgb' | 'hex' |
| showAlpha | 透明度通道(输出 8 位 hex / rgba()) | boolean | — | false |
| predefine | 预设色板 | string[] | — | — |
| size | 尺寸 | LhComponentSize | 'small' | 'medium' | 'large' | 'medium' |
| disabled | 禁用 | boolean | — | false |
| clearable | 清除(置空)按钮 | boolean | — | false |
| placeholder | 占位提示(空值时) | string | — | '' |
| ariaLabel | 无障碍名称(未传时取语言包 colorPicker.label) | string | — | — |
| sx | 快速布局属性 | SxProps | — | — |
Ref(LhColorPickerInstance)
| 方法 | 说明 |
|---|---|
| open() | 展开面板 |
| close() | 收起面板 |
交互细节
触发器 Enter / Space 开合、Esc 收起;滑杆为 APG slider 语义,方向键步进、Shift 大步长;面板经 Portal 挂 body 并由 useLhPopper 定位(翻转 / 夹回),面板内键盘事件不冒泡到触发器。
格式归一
输出值统一小写 hex / rgba();解析失败时输入框回退当前显示值,不上抛非法值。
样式
import '@lh-ui/react/style/color-picker'