ColorPickerRoot
ColorPickerRoot объединяет кнопку с образцом цвета и всплывающую панель, а интерфейс редактирования оставляет слотам. Слот trigger получает текущий стиль образца, слот по умолчанию — текущее значение Color из SceneGraph.
Событие openChange сообщает начало и завершение взаимодействия с выбором цвета. cancel вызывается перед закрытием по Escape, поэтому компонент, использующий BindableValue, может одной операцией отменить удаление привязки и изменение краски. Простое открытие панели или получение фокуса не меняет цвет.
vue
<script setup lang="ts">
import { ref } from 'vue'
import type { Color } from '@pairdraw/scene-graph/primitives'
import { ColorPickerRoot } from '@pairdraw/vue/primitives/ColorPicker'
const color = ref<Color>({ r: 0.2, g: 0.5, b: 0.9, a: 1 })
</script>
<template>
<ColorPickerRoot
:color="color"
@update="color = $event"
@open-change="open => console.log(open)"
@cancel="console.log('cancel')"
>
<template #trigger="{ style }">
<button :style="style" aria-label="Edit color" />
</template>
<template #default="{ color: currentColor }">
<output>{{ currentColor.r }}, {{ currentColor.g }}, {{ currentColor.b }}</output>
</template>
</ColorPickerRoot>
</template>Сгенерированный справочник API
ColorPickerRoot
Generated from packages/vue/src/primitives/ColorPicker/ColorPickerRoot.vue
Props
| Prop | Default | Type |
|---|---|---|
color* | — | Color |
label | "Edit color" | string | undefined |
ui | — | ColorPickerUI | undefined |
colorProfileThe profile the color is stored in; the trigger's swatch then draws the color the canvas draws.
Defaults to sRGB. | "srgb" | ColorProfile | undefined |
escapeRevertsFor a colour with no undo history, such as a preference: Escape closing the picker puts back
the colour it opened with. Otherwise Escape keeps the edit, as Figma's picker does. | false | boolean | undefined |
keepOpenWhether a press outside the picker should leave it open, such as one that samples the canvas. | — | PickerKeepOpen | undefined |
Events
| Event | Payload | Description |
|---|---|---|
cancel | [cause: PickerCancelCause] | |
commit | [] | |
update | [color: Color] | |
openChange | [open: boolean] |
Slots
| Slot | Props | Description |
|---|---|---|
trigger | { style: { background: string; }; } | |
default | { color: Color; update: (next: Color) => void; } |