Color Picker
Edit an exact color through native, text, channel, and spatial controls.
Usage
Native
Use the browser color input while keeping the same exact color value as the text controls.
Use the browser color input while keeping the same exact color value as the text controls.
<!-- Color Picker / Native -->
<script setup lang="ts">
import { ColorPickerAlphaSlider, ColorPickerArea, ColorPickerAreaThumb, ColorPickerFormatTrigger, ColorPickerHueSlider, ColorPickerRoot } from '@sectile/vue/color-picker'
</script>
<template>
<ColorPickerRoot v-slot="color" default-value="#5b6df680" allow-alpha name="accent">
<ColorPickerArea><ColorPickerAreaThumb /></ColorPickerArea>
<ColorPickerHueSlider /><ColorPickerAlphaSlider />
<ColorPickerFormatTrigger format="hsv">HSV</ColorPickerFormatTrigger>
<output>{{ color.text }}</output>
</ColorPickerRoot>
</template>Alpha
Edit the alpha channel together with the visible color channels.
Edit the alpha channel together with the visible color channels.
<!-- Color Picker / Alpha -->
<script setup lang="ts">
import { ColorPickerAlphaSlider, ColorPickerArea, ColorPickerAreaThumb, ColorPickerFormatTrigger, ColorPickerHueSlider, ColorPickerRoot } from '@sectile/vue/color-picker'
</script>
<template>
<ColorPickerRoot v-slot="color" default-value="#5b6df680" allow-alpha name="accent">
<ColorPickerArea><ColorPickerAreaThumb /></ColorPickerArea>
<ColorPickerHueSlider /><ColorPickerAlphaSlider />
<ColorPickerFormatTrigger format="hsv">HSV</ColorPickerFormatTrigger>
<output>{{ color.text }}</output>
</ColorPickerRoot>
</template>Controlled
Let the parent own the current value and apply accepted changes back to the component.
Let the parent own the current value and apply accepted changes back to the component.
<!-- Color Picker / Controlled -->
<script setup lang="ts">
import { ColorPickerAlphaSlider, ColorPickerArea, ColorPickerAreaThumb, ColorPickerFormatTrigger, ColorPickerHueSlider, ColorPickerRoot } from '@sectile/vue/color-picker'
</script>
<template>
<ColorPickerRoot v-slot="color" default-value="#5b6df680" allow-alpha name="accent">
<ColorPickerArea><ColorPickerAreaThumb /></ColorPickerArea>
<ColorPickerHueSlider /><ColorPickerAlphaSlider />
<ColorPickerFormatTrigger format="hsv">HSV</ColorPickerFormatTrigger>
<output>{{ color.text }}</output>
</ColorPickerRoot>
</template>API
Vue package: @sectile/vue/color-picker
ColorPickerRootColorPickerLabelColorPickerControlColorPickerNativeInputColorPickerTextInputColorPickerChannelInputColorPickerCoordinateInputColorPickerCoordinateSliderColorPickerAreaColorPickerAreaThumbColorPickerHueSliderColorPickerAlphaSliderColorPickerSwatchColorPickerValueTextColorPickerFormatTrigger
Props
ColorPickerRootProps
allowAlphaWhether the color value may include transparency.
alphaStepIncrement applied when the alpha channel changes.
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
channelStepIncrement applied when a color channel changes.
defaultDraftEditable draft used for uncontrolled initial state.
defaultFormatInitial uncontrolled color format.
defaultValueInitial value used when the component owns its state.
disabledWhether interaction is unavailable.
draftControlled editable draft before commit.
formID of the native form associated with the control.
formatControlled color format.
labelAccessible name announced for the control.
modelValueCurrent value when state is controlled by the parent.
nameName used for native form submission.
readonlyWhether the value can be inspected but not changed.
requiredWhether the control must contain a valid value before submission.
ColorPickerPartProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
ColorPickerChannelInputProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
channelColor channel edited by this input.
ColorPickerFormatTriggerProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
formatControlled color format.
ColorPickerCoordinateInputProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
coordinateCoordinate edited within the selected color model.
formatControlled color format.
ColorPickerCoordinateSliderProps
asElement or component rendered for this part.
asChildWhether to merge this part into its single child instead of rendering a wrapper.
coordinateCoordinate edited within the selected color model.
formatControlled color format.
Slots
ColorPickerRootSlotProps
areaCurrent two-dimensional color area state.
channelCurrent color channel.
coordinatesCurrent coordinates in the active color model.
cssColorCurrent color serialized for CSS.
disabledWhether interaction is unavailable.
draftCurrent uncommitted input text.
formatCurrent color format.
readonlyWhether the value can be inspected but not changed.
textFormatted text for the current value.
valueCurrent value exposed by this contract.
Events
ColorPickerRoot
update:draftEmitted when the editable draft changes.
update:formatEmitted when the requested color format changes.
update:modelValueEmitted when the component requests a new controlled value.
Other types
ColorPickerValueChangeHandler
type ColorPickerValueChangeHandler = (value: string) => voidColorPickerDraftChangeHandler
type ColorPickerDraftChangeHandler = (value: string | null) => voidColorPickerFormatChangeHandler
type ColorPickerFormatChangeHandler = (value: ColorFormat) => voidColorAreaValue
| Name | Type | Required |
|---|---|---|
x | number | Yes |
y | number | Yes |
hue | number | Yes |
alpha | number | Yes |
ColorChannel
type ColorChannel = 'red' | 'green' | 'blue' | 'alpha'ColorCoordinate
type ColorCoordinate = ColorChannel | 'hue' | 'saturation' | 'lightness' | 'value' | 'cyan' | 'magenta' | 'yellow' | 'black' | 'chroma'ColorCoordinateValue
| Name | Type | Required |
|---|---|---|
coordinate | ColorCoordinate | Yes |
label | string | Yes |
value | number | Yes |
min | number | Yes |
max | number | Yes |
step | number | Yes |
unit | '' | '%' | '°' | Yes |
ColorFormat
type ColorFormat = 'hex' | 'rgb' | 'hsl' | 'hsv' | 'cmyk' | 'oklch'ColorModel
type ColorModel = Exclude<ColorFormat, 'hex'>ColorPickerPolicies
| Name | Type | Required |
|---|---|---|
allowAlpha | boolean | — |
channelStep | number | — |
alphaStep | number | — |
ColorValue
type ColorValue = Rgba8Parts
Shared scope: [data-scope="color-picker"]. Combine it with a part selector to keep styles local to this component.
| Part | Selector | Role | Extra attributes |
|---|---|---|---|
root | [data-part="root"] | Defines the component boundary and owns its composed parts. | — |
label | [data-part="label"] | Labels the component control. | — |
control | [data-part="control"] | Groups the primary interactive controls. | — |
native-input | [data-part="native-input"] | Keeps the native form control available for submission and platform behavior. | — |
text-input | [data-part="text-input"] | Accepts a formatted text representation of the value. | — |
channel-input | [data-part="channel-input"] | Edits one color channel numerically. | — |
coordinate-input | [data-part="coordinate-input"] | Edits one coordinate of the current value. | — |
coordinate-slider | [data-part="coordinate-slider"] | Adjusts one coordinate over a bounded range. | — |
area | [data-part="area"] | Provides the two-dimensional interaction surface. | — |
area-thumb | [data-part="area-thumb"] | Marks and controls the selected point in the area. | — |
hue-slider | [data-part="hue-slider"] | Adjusts the color hue. | — |
alpha-slider | [data-part="alpha-slider"] | Adjusts color opacity. | — |
swatch | [data-part="swatch"] | Previews the selected color. | — |
value-text | [data-part="value-text"] | Displays the formatted value as text. | — |
format-trigger | [data-part="format-trigger"] | Changes the active value format. | — |
Keyboard interaction
| Key | Behavior |
|---|---|
| Arrow keys | Adjust the active color coordinate or slider. |
| Enter | Commit a typed color value. |
| Escape | Cancel the typed draft and restore the accepted color. |
Accessibility
Text inputs and sliders expose labels, ranges, current values, and channel purpose without relying on color alone.
