Color
NewA color area, channel slider, hex field, and swatch picker.
Preview
Installation
npx sigma-ui@latest add colorUsage
<script setup lang="ts">
import {
ColorArea,
ColorAreaArea,
ColorAreaThumb,
ColorField,
ColorFieldInput,
ColorSlider,
ColorSliderThumb,
ColorSliderTrack,
ColorSwatch,
} from '@/components/ui/color';
</script>
<template>
<ColorArea v-model="color">
<template #default="{ style }">
<ColorAreaArea :style="style">
<ColorAreaThumb />
</ColorAreaArea>
</template>
</ColorArea>
<ColorSlider v-model="color" channel="hue">
<ColorSliderTrack />
<ColorSliderThumb />
</ColorSlider>
<ColorSwatch :color="color" />
<ColorField v-model="color">
<ColorFieldInput />
</ColorField>
</template>v-model is a color string. ColorArea defaults to the HSL space, with hue on the horizontal axis and saturation on the vertical axis. ColorSlider takes a channel such as hue, saturation, lightness, or alpha. ColorSwatchPicker selects one preset and can share the same v-model.
Examples
Picker
API Reference
ColorArea
Props
| Prop | Type | Default |
|---|---|---|
modelValueThe color value (controlled). Can be a hex string or Color object. | string | Color | - |
defaultValueThe default color value (uncontrolled). | string | Color | - |
colorSpaceThe color space to operate in. | ColorSpace | - |
xChannelColor channel for the horizontal (x) axis. | ColorChannel | - |
yChannelColor channel for the vertical (y) axis. | ColorChannel | - |
disabledWhen | boolean | - |
xNameThe name of the x channel input element for form submission. | string | - |
yNameThe name of the y channel input element for form submission. | string | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
Events
| Event | Payload |
|---|---|
update:modelValue | [value: string] |
update:color | [value: Color] |
change | [value: string] |
changeEnd | [value: string] |
Slots
| Slot | Scope |
|---|---|
defaultThe color surface. Receives the gradient style for the area. | { style: CSSProperties; } |
ColorAreaArea
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ColorAreaThumb
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ColorField
Props
| Prop | Type | Default |
|---|---|---|
modelValueThe color value (controlled). Can be a hex string or Color object. | string | Color | - |
defaultValueThe default color value (uncontrolled). | string | Color | - |
colorSpaceThe color space to operate in when displaying a channel. | ColorSpace | - |
channelThe color channel to display. If not provided, displays hex value. | ColorChannel | - |
placeholderPlaceholder text when the field is empty. | string | - |
disabledWhen | boolean | - |
readonlyWhen | boolean | - |
disableWheelChangeWhen | boolean | - |
localeThe locale to use for number formatting. | string | - |
stepCustom step value for increment/decrement. Defaults to channel step or 1 for hex. | number | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
Events
| Event | Payload |
|---|---|
update:modelValue | [value: string] |
update:color | [value: Color] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ColorFieldInput
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
ColorSlider
Props
| Prop | Type | Default |
|---|---|---|
modelValueThe color value (controlled). Can be a hex string or Color object. | string | Color | - |
defaultValueThe default color value (uncontrolled). | string | Color | - |
colorSpaceThe color space to operate in. | ColorSpace | - |
channelrequiredThe color channel that this slider manipulates. | ColorChannel | - |
orientationThe orientation of the slider. | DataOrientation | - |
dirThe reading direction of the slider. | Direction | - |
invertedWhether the slider is visually inverted. | boolean | - |
disabledWhen | boolean | - |
stepCustom step value for increment/decrement. Defaults to the channel's natural step. | number | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
Events
| Event | Payload |
|---|---|
update:modelValue | [value: string | Color] |
update:color | [value: Color] |
change | [value: string] |
changeEnd | [value: string] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ColorSliderThumb
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThumb content. Receives the channel name and its current value. | { channelName: string; channelValue: number; } |
ColorSliderTrack
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ColorSwatch
Props
| Prop | Type | Default |
|---|---|---|
colorThe color to display in the swatch as a hex string or Color object.
Example: | string | Color | - |
labelOptional accessible label for the color. If omitted, the color name will be derived from the color value. | string | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Slots
| Slot | Scope |
|---|---|
defaultReplaces the painted swatch. Receives the hex color and its alpha. | { color: string; alpha: number; } |
ColorSwatchPicker
Props
| Prop | Type | Default |
|---|---|---|
defaultValueThe value of the listbox when initially rendered. Use when you do not need to control the state of the Listbox | string | string[] | - |
modelValueThe controlled value of the listbox. Can be binded with | string | string[] | - |
multipleWhether multiple options can be selected or not. | boolean | - |
disabledWhen | boolean | - |
dirThe reading direction of the listbox when applicable. <br> If omitted, inherits globally from | Direction | - |
orientationThe orientation of the listbox. <br>Mainly so arrow navigation is done accordingly (left & right vs. up & down) | DataOrientation | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
nameThe name of the field. Submitted with its owning form as part of a name/value pair. | string | - |
requiredWhen | boolean | - |
highlightOnHoverWhen | boolean | - |
loopWhen | boolean | - |
selectionBehaviorHow multiple selection should behave in the collection. | "replace" | "toggle" | 'toggle' |
Events
| Event | Payload |
|---|---|
update:modelValueEvent handler called when the value changes. | [value: AcceptableValue] |
highlightEvent handler when highlighted element changes. | [payload: { ref: HTMLElement; value: AcceptableValue; }] |
entryFocusEvent handler called when container is being focused. Can be prevented. | [event: CustomEvent<any>] |
leaveEvent handler called when the mouse leave the container | [event: Event] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ColorSwatchPickerItem
Props
| Prop | Type | Default |
|---|---|---|
valuerequiredThe color to display in the swatch as a hex string.
Example: | string | - |
disabledWhen | boolean | - |
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
Events
| Event | Payload |
|---|---|
selectEvent handler called when the selecting item. <br> It can be prevented by calling | [event: SelectEvent$3<AcceptableValue>] |
Slots
| Slot | Scope |
|---|---|
defaultThe content of the component. | - |
ColorSwatchPickerItemSwatch
Props
| Prop | Type | Default |
|---|---|---|
asChildChange the default rendered element for the one passed as a child, merging their props and behavior. Read our Composition guide for more details. | boolean | - |
asThe element or component this component should render as. Can be overwritten by | AsTag | Component | "div" |
labelOptional accessible label for the color. If omitted, the color name will be derived from the color value. | string | - |
Accessibility
The area and the slider are sliders. The hex field is a text input, and each preset swatch is an option in a listbox.
| Key | Description |
|---|---|
| Tab | Moves focus between the swatches, the area, the slider, and the field. |
| Arrow keys | Move the focused thumb along its channel. |
| Enter or Space | Selects the focused preset. |