Skip to content
API 风格:

ColorPicker 颜色选择器 ​

LhColorPicker 颜色选择器:饱和度板、色相 / 透明度滑杆、hex / rgb 双格式与预设色板。

基础用法 ​

基础用法
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhColorPicker } from '@lh-ui/vue3'

const color = ref('#2B4C7C')
const color2 = ref('#3A7D5A')
</script>

<template>
<div class="demo-row">
  <LhColorPicker v-model="color" />
  <LhColorPicker v-model="color2" format="rgb" />
</div>
</template>
vue
<script>
import { LhColorPicker } from '@lh-ui/vue3'

export default {
  components: { LhColorPicker },
  data() {
    return {
      color: '#2B4C7C',
      color2: '#3A7D5A',
    }
  },
}
</script>

<template>
<div class="demo-row">
  <LhColorPicker v-model="color" />
  <LhColorPicker v-model="color2" format="rgb" />
</div>
</template>
透明度与预设色板
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhColorPicker } from '@lh-ui/vue3'

const color3 = ref('#A63D40')
const predefine = ['#2B4C7C', '#3A7D5A', '#B8860B', '#A63D40', '#666B70']
</script>

<template>
<LhColorPicker v-model="color3" show-alpha :predefine="predefine" />
</template>
vue
<script>
import { LhColorPicker } from '@lh-ui/vue3'

export default {
  components: { LhColorPicker },
  data() {
    return {
      color3: '#A63D40',
    }
  },
}
</script>

<template>
<LhColorPicker v-model="color3" show-alpha :predefine="predefine" />
</template>

ColorPicker API ​

Props ​

属性名说明类型默认值
modelValue颜色值(v-model,hex 或 rgb() 字符串,按 format 输出)string''
format输出格式:hex / rgb"hex" | "rgb"'hex'
showAlpha透明度通道(开启后输出 8 位 hex / rgba())booleanfalse
predefine预设色板string[]() => []
size尺寸"small" | "medium" | "large" | "mini" | "x-large"'medium'
disabled禁用booleanfalse
clearable清除(置空)按钮booleanfalse
placeholder空值时的占位提示string''
ariaLabel触发器的无障碍名称(未传时取语言包文案)string—
sx快速布局属性,转内联样式作用于根元素LhSxProps—

Events ​

属性名说明类型
update:modelValue颜色变化时触发(v-model)(value: string)
change颜色变化时触发(value: string)
clear点击清除按钮时触发()

无障碍 ​

  • 色相 / 透明度滑杆为 role="slider",支持方向键微调(Shift 加速)
  • 触发器为键盘可达按钮(Enter / 空格展开面板),点击面板外部或 Esc 关闭

类型定义 ​

本组件对外导出的 TypeScript 类型结构如下(自动提取自 packages/components/color-picker/src/types.ts 与 @lh-ui/share/core/* 源码,点击各条目展开查看完整定义;属性说明见上方 Props 表):

LhColorPickerProps
ts
export interface LhColorPickerProps {
  /** 颜色值(受控 v-model,hex 或 rgb() 字符串,按 format 输出) */
  modelValue?: string
  /** 输出格式(默认 hex) */
  format?: LhColorFormat
  /** 透明度通道(开启后输出 8 位 hex / rgba()) */
  showAlpha?: boolean
  /** 预设色板 */
  predefine?: string[]
  /** 尺寸 */
  size?: LhComponentSize
  /** 禁用 */
  disabled?: boolean
  /** 清除(置空)按钮 */
  clearable?: boolean
  /** 占位提示(空值时) */
  placeholder?: string
  /** 无障碍名称(未传时取语言包 colorPicker.label) */
  ariaLabel?: string
  /** sx 快速布局属性 */
  sx?: LhSxProps
}
LhColorPickerSize
ts
export type LhColorPickerSize = LhComponentSize