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'