跳转到内容

颜色选择器 ColorPicker

默认使用输入型触发器。可以直接通过输入框编辑颜色,也可以展开面板精调。

color-modes 现在完整支持 monochromelinear-gradient。当允许渐变时,面板会提供模式切换、渐变 stop 编辑、角度设置,以及 gradient-only 的内联面板。

通过 recent-colorsswatch-colors 控制最近使用颜色与系统色板。最近使用颜色变化时会触发 recent-colors-change

设置 disabled 禁用选择器。

通过 format 切换输出格式。单色模式覆盖 HEXHEX8RGBRGBAHSLHSLAHSVHSVACMYKCSS 的字符串输出;渐变模式统一输出 linear-gradient(...) CSS 字符串。

使用 hide-trigger 可以内联渲染颜色面板。这一能力保留自旧版 API,便于旧场景迁移。

颜色选择器优先对齐 TDesign 的 smallmediumlarge,同时兼容旧版 mini

自定义触发元素。

可以通过 trigger-props 直接透传 TriggerProps 配置,行为与组件库里的 Trigger 保持一致。

参数名描述类型默认值
model-value (v-model)受控色值string-
value兼容 TDesign 的受控色值入口string-
default-value非受控默认色值string''
color-modes可用颜色模式('monochrome' | 'linear-gradient')[]['monochrome']
enable-multiple-gradient是否允许新增多个渐变 stopbooleantrue
format输出格式'HEX' | 'HEX8' | 'RGB' | 'RGBA' | 'HSL' | 'HSLA' | 'HSV' | 'HSVA' | 'CMYK' | 'CSS''RGB'
size尺寸'mini' | 'small' | 'medium' | 'large''medium'
clearable是否允许清空booleanfalse
enable-alpha是否启用透明通道booleanfalse
show-primary-color-preview是否展示主色预览块booleantrue
input-props透传到触发输入框的属性Record<string, unknown>-
trigger-props透传 Trigger 组件的属性Partial<TriggerProps>-
recent-colors最近使用颜色string[] | boolean | null[]
default-recent-colors最近使用颜色的非受控初始值string[] | boolean | null[]
swatch-colors系统色板string[] | null内置色板
disabled禁用booleanfalse
hide-trigger兼容旧版,仅渲染内联面板booleanfalse
history-colors旧版 recent-colors 别名string[]-
preset-colors旧版 swatch-colors 别名string[]-
show-history旧版开关,开启时使用 history-colorsbooleanfalse
show-preset旧版开关,开启时使用 preset-colorsbooleanfalse
disabled-alpha旧版 enable-alpha 反向别名booleanfalse
show-text旧版属性,保留兼容但不再建议新增使用booleanfalse
事件名描述参数
change颜色值变化时触发value: string
context: { color, trigger }
clear点击清空时触发{ e: MouseEvent }
popup-visible-change颜色面板展开和收起时触发visible: boolean
value: string
palette-bar-change色相条或透明度条变化时触发{ color }
recent-colors-change最近使用颜色变化时触发string[]
插槽名描述
default自定义触发器内容

本次实现以当前组件库的 ColorPicker 和 Trigger 约定为主,同时保留了旧版 @sdata/web-vue color-picker 的兼容桥接。

旧版能力新版建议
trigger-props直接透传 TriggerProps
history-colors + show-history迁移到 recent-colors
preset-colors + show-preset迁移到 swatch-colors
disabled-alpha迁移到 enable-alpha
show-text新版默认采用输入型触发器,一般无需再使用
hide-trigger仍可继续使用,作为内联面板模式

当前版本的迁移结论:

  • 单色与线性渐变都已经按 TDesign 能力接入,新的业务可直接使用 color-modesenable-multiple-gradient
  • 旧版常用 props 仍保留兼容桥接,但新增代码建议直接采用当前组件库的 trigger-props / TriggerProps 约定。
  • 渐变模式统一输出 CSS linear-gradient(...) 字符串;如果旧业务依赖旧版自定义结构,迁移时应直接改为标准 CSS 字符串。