# ColorPicker 顏色選擇
點擊觸發器打開調色面板:飽和度/明度板、色相滑桿、透明度滑桿、十六進位輸入與預設色板,支援 hex 與 rgb 兩種輸出格式。
顏色選擇
<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
| 屬性 | 說明 | 型別 | 預設值 |
|---|---|---|---|
| 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
| 事件 | 說明 | 回呼參數 |
|---|---|---|
| input | v-model(Vue2 語義) | (value: string) |
| change | 顏色變化 | (value: string) |
# 互動與精度約定
- 拖動飽和度板/色相滑桿/透明度滑桿時即時提交 v-model;點擊預設色後自動關閉面板
- hex / rgb 輸入與預設色按解析值精確提交;滑桿路徑經 HSV 中間態,通道值存在 1 位量化損耗(core 的色相取整與 s/v 兩位小數量化,屬既定語義)
- 觸發器回顯只看綁定值;非法值字串回退佔位文案並標記空態
- 鍵盤:Enter / 空格打開面板,Escape 關閉;點擊面板外部自動關閉
# 無障礙
觸發器為 role="button" + aria-haspopup="dialog",面板以 dialog 彈出,色相/透明度滑桿帶 role="slider" 與 aria-valuenow。
Copyright © 2024-2026 风默文学 | 宁ICP备2024006574号 |
苏公网安备32040002010537