# ColorPicker カラーピッカー
トリガーをクリックしてカラーパネルを開きます。彩度/明度ボード、色相スライダー、透明度スライダー、16 進入力、定義済みのカラーパレットを備え、hex と rgb の 2 つの出力形式をサポートします。
カラーピッカー
<template>
<div class="demo-col" style="gap: 18px;">
<div class="demo-row" style="gap: 12px; flex-wrap: wrap;">
<LhColorPicker v-model="color" />
<LhColorPicker v-model="color" format="rgb" />
<LhColorPicker v-model="color" size="small" />
<LhColorPicker v-model="color" size="large" />
</div>
<div class="demo-row" style="gap: 12px; flex-wrap: wrap;">
<LhColorPicker v-model="color" :show-alpha="false" />
<LhColorPicker v-model="color" disabled />
<LhColorPicker v-model="empty" />
</div>
<LhColorPicker v-model="color" :predefine="predefine" />
<p class="demo-note">現在の色:{{ color || '(空)' }};定義済み色をクリックするとパネルが自動的に閉じます。</p>
</div>
</template>
<script>
export default {
data() {
return {
color: '#2B4C7C',
empty: '',
predefine: ['#3A7D5A', '#A63D40', '#B8860B', '#2C2C2C', '#FAF6F0'],
}
},
}
</script>
# Props
| Prop | 説明 | 型 | 初期値 |
|---|---|---|---|
| value(v-model) | 色値(hex / rgb() / rgba() 文字列) | string | — |
| format | 出力形式(hex では a<1 のとき 8 桁の #rrggbbaa) | 'hex' \| 'rgb' | 'hex' |
| size | サイズ | 'small' \| 'medium' \| 'large' | 'medium' |
| disabled | 無効 | boolean | false |
| showAlpha | 透明度スライダーを表示 | boolean | true |
| predefine | 定義済みカラーのリスト | string[] | — |
| teleportTarget | ポップアップのマウント先(Vue2 に Teleport はない) | string \| HTMLElement | 'body' |
| sx | sx 簡易レイアウトプロパティ | — | — |
# Events
| Event | 説明 | コールバック引数 |
|---|---|---|
| input | v-model(Vue2 セマンティクス) | (value: string) |
| change | 色が変化した | (value: string) |
# インタラクションと精度の規約
- 彩度ボード / 色相スライダー / 透明度スライダーのドラッグ中は v-model にリアルタイムに反映;定義済み色のクリック後、パネルは自動的に閉じる
- hex / rgb 入力と定義済み色は解析値をそのまま正確にコミット;スライダー経路は HSV 中間状態を挟むため、チャネル値に 1 単位の量子化誤差がある(core の色相丸めと s/v の小数 2 桁量子化、既定のセマンティクス)
- トリガーの表示はバインド値のみ;無効な文字列はプレースホルダーにフォールバックし、空状態とみなす
- キーボード:Enter / Space でパネルを開き、Escape で閉じる;パネル外のクリックで自動的に閉じる
# アクセシビリティ
トリガーは role="button" + aria-haspopup="dialog"、パネルは dialog としてポップアップ、色相 / 透明度スライダーは role="slider" と aria-valuenow を持つ。
Copyright © 2024-2026 FengMo WenXue