ColorPickerRoot
ColorPickerRoot łączy przycisk z próbką koloru z wyskakującym panelem, a sam interfejs edytora pozostawia slotom. Slot trigger otrzymuje bieżący styl próbki, a slot domyślny bieżący kolor z grafu sceny.
openChange zgłasza pełne granice interakcji z próbnikiem. cancel jest emitowane przed zamknięciem klawiszem Escape, dzięki czemu komponenty korzystające z BindableValue mogą razem wycofać odłączenie zmiennej i zmianę farby. Otwarcie próbnika lub ustawienie na nim fokusu nie emituje aktualizacji koloru.
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>Wygenerowana dokumentacja 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; } |