ColorPlus
A color picker with support for additional color value formats.
Important: This component is still under development and should be considered experimental. The API is subject to breaking changes outside of the wider library's semver until the Svelte Tweakpane UI 2.0 release.
Wraps the color control from the Color Plus plugin.
This component looks very similar to the Tweakpane-native <Color> control, but it adds support for all CSS Color Module Level 4 color formats, named-color strings, color arrays / tuples, a wider range of color objects, and a revised color picker with support for wide-gamut color spaces.
Its API is a superset of Tweakpane's built-in color input, so <ColorPlus> can generally be used as a drop-in replacement for <Color>.
<ColorPlus> is a dynamic component. The alpha prop is available for number values, while the type prop is available for object and tuple / array values. Other props are shared by every supported value type.
The gamuts and gamutLabel defaults adapt to the initially bound color's model: sRGB-bound models get a simple sRGB picker, while wide and perceptual models get Display P3 boundaries and a gamut label. The text fields also open in a mode appropriate to that model.
<ColorPlus> might replace the <Color> control entirely in the next major version of svelte-tweakpane-ui. Please report any issues you encounter.
Usage outside of a <Pane> component will implicitly wrap the color picker in <Pane position="inline">.
Example
Section titled “Example”<script lang="ts"> import { ColorPlus } from 'svelte-tweakpane-ui'
let startColor = 'oklch(93.7% 0.199 105deg / 1)' let endColor = 'oklch(70.2% 0.322 328deg / 1)'</script>
<ColorPlus bind:value={startColor} label="Start Color" /><ColorPlus bind:value={endColor} label="End Color" />
<div class="demo" style:--a={startColor} style:--b={endColor}></div>
<style> .demo { aspect-ratio: 1; width: 100%; background: linear-gradient(to top, var(--a), var(--b)); }</style>Dynamic Props
This component has dynamic props, which means the available props can change depending on the value or type of other props.
Props contingent on certain conditions are annotated below with a dynamic flag, and include explanations of the “conditions” affecting the prop’s availability. More Info →
disabledSection titled “disabled” | |
| Description | Prevent interactivity and gray out the control. |
|---|---|
| Type | boolean |
| Default | false |
| optional | |
| Description | Custom color scheme. If undefined, inherits default Tweakpane theme equivalent to
|
|---|---|
| Type | Theme |
| Default | undefined |
| optional | |
| Description | Text displayed next to control. |
|---|---|
| Type | string |
| Default | undefined |
| bindablerequired | |
| Description | The value to control. A color value to control. Use a CSS color or named-color string, a packed number, a three- or four-item RGB(A) tuple, or a supported RGB, HSL, HSV / HSB, HWB, Lab, or LCH object shape. The value's type determines whether the |
|---|---|
| Type | ColorPlusValue |
userExpandableSection titled “userExpandable” | |
| Description | Allow users to interactively expand / contract the picker. |
|---|---|
| Type | boolean |
| Default | true |
expandedSection titled “expanded” | |
| Description | Expand or collapse the input's picker. |
|---|---|
| Type | boolean |
| Default | false |
pickerSection titled “picker” | |
| Description | The style of value "picker" to use in the input. |
|---|---|
| Type | 'inline' | 'popup' |
| Default | 'popup' |
constrainSection titled “constrain” | |
| Description | Keep the color inside the widest gamut configured in Picks on the palette plane snap to the in-gamut frontier, while slider moves, typed text, and externally bound values shed chroma (at constant lightness and hue) to fit. Set to |
|---|---|
| Type | boolean |
| Default | true |
formatLockedSection titled “formatLocked” | |
| Description | Whether a valid color entered in the picker's text field is converted back to the bound value's original format. Set to |
|---|---|
| Type | boolean |
| Default | true |
gamutLabelSection titled “gamutLabel” | |
| Description | Draw the name of the narrowest configured gamut that holds the current color in the picker plane's bottom-left corner. The default adapts to the initially bound color's model. |
|---|---|
| Type | boolean |
| Default | false for sRGB-bound models; true for wide / perceptual models |
gamutLinesSection titled “gamutLines” | |
| Description | Which configured gamut boundaries are stroked over the picker plane.
|
|---|---|
| Type | GamutLines |
| Default | 'inner' |
gamutsSection titled “gamuts” | |
| Description | RGB gamuts whose boundaries the OKLCH picker draws, as an array of ids. Both colorjs ids and their CSS aliases are accepted: The default adapts to the initially bound color's model. |
|---|---|
| Type | string[] |
| Default | ['srgb'] for sRGB-bound models; ['srgb', 'p3'] for wide / perceptual models |
paletteChannelsSection titled “paletteChannels” | |
| Description | Which OKLCH channels map to the picker plane's axes and the slider, as
|
|---|---|
| Type | PlaneLayout |
| Default | 'CL_H' |
paletteProjectionSection titled “paletteProjection” | |
| Description | How the picker plane projects the gamut volume onto its rectangle.
|
|---|---|
| Type | PaletteProjection |
| Default | 'okhsv' |
swatchFallbackSection titled “swatchFallback” | |
| Description | How the swatch preview's fallback triangle forces an out-of-gamut color into sRGB.
Only affects the swatch preview, never the color value itself. |
|---|---|
| Type | GamutMethod |
| Default | 'clip' |
textFieldsSection titled “textFields” | |
| Description | Show the color model drop-down and per-channel text inputs below the picker palette. Set to |
|---|---|
| Type | boolean |
| Default | true |
| optionaldynamic | |
| Description | Treat the number as carrying an alpha component in its lowest byte
(e.g. |
|---|---|
| Type | boolean |
| Default | false |
| Conditions | Available when value is a number. |
| optionaldynamic | |
| Description | Whether coordinate channels are floats from 0.0 to 1.0, or integers in their native ranges (0 to 255 for RGB, 0 to 360 for hue, and so on). Alpha channels always use the 0.0 to 1.0 range. |
|---|---|
| Type | ColorType |
| Default | 'int' |
| Conditions | Available when value is an object or value is a tuple / array. |
Events
Section titled “Events” changeSection titled “change” | |
| Description | Fires when This event is provided for advanced use cases. It's usually preferred to
bind to the The |
|---|---|
| Extends | ValueChangeEvent |
| Type | ColorPlusChangeEvent |