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'