Color Picker
Picks any color from a drag area or a typed hex value.
<arc-color-picker>Overview
ColorPicker has a saturation/lightness area where users click or drag a crosshair, a hue slider across the full 360 degrees under it, and a hex input with a preview swatch for typing a known color. Pass a presets array and a row of swatches appears under the hex input, with the active one outlined in the primary text color. Use presets for a brand palette or frequent colors. The area still allows any color.
arc-input fires on every frame of a drag across the area or the hue slider, so use it for a live preview. arc-change fires once the color is committed (pointer released, preset clicked, or a valid hex entered), so use it for anything expensive, like a save. Both carry the hex string.
Guidelines
Do
- Set a `label`, especially when there's more than one picker on the page
- Set the initial color with `value` in 6-digit hex (for example `#4d7ef7`)
- Put the picker in a popover or dropdown when horizontal space is tight
Don't
- Don't pass 3-digit hex shorthand (`#f00`). The component expects all six digits
- Don't use it when users choose from a fixed set. Use a select or a radio group
- Don't give it more than about 20 presets. The row wraps and gets crowded
- Don't put it in a container narrower than 260px. The area and the slider need the room
Features
- Values go in and come out as 6-digit hex strings. The HSL conversion happens inside
- The hex input checks its value on blur or Enter. An invalid value reverts to the current color
- Dragging uses `setPointerCapture`, so a drag keeps working when the pointer leaves the area
- Disabled pickers drop to 50% opacity and ignore the pointer
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-color-picker
label="Theme Color"
value="#4d7ef7"
></arc-color-picker>
<script>
const picker = document.querySelector('arc-color-picker');
picker.presets = ['#4d7ef7', '#22c55e', '#ef4444', '#eab308'];
// Live preview — fires on every drag frame
picker.addEventListener('arc-input', e => {
document.documentElement.style.setProperty('--accent-primary', e.detail.value);
});
// Committed color — fires once on release
picker.addEventListener('arc-change', e => {
console.log('Committed:', e.detail.value);
});
</script>import { ColorPicker } from '@arclux/arc-ui-react';
export default function Example() {
return (
<ColorPicker
label="Theme Color"
value="#4d7ef7"
presets={['#4d7ef7', '#22c55e', '#ef4444', '#eab308']}
onArcInput={(e) => console.log('Live:', e.detail.value)}
onArcChange={(e) => console.log('Committed:', e.detail.value)}
/>
);
}<script setup>
import { ColorPicker } from '@arclux/arc-ui-vue';
const presets = ['#4d7ef7', '#22c55e', '#ef4444', '#eab308'];
</script>
<template>
<ColorPicker
label="Theme Color"
value="#4d7ef7"
:presets="presets"
@arc-input="(e) => console.log('Live:', e.detail.value)"
@arc-change="(e) => console.log('Committed:', e.detail.value)"
/>
</template><script>
import { ColorPicker } from '@arclux/arc-ui-svelte';
const presets = ['#4d7ef7', '#22c55e', '#ef4444', '#eab308'];
</script>
<ColorPicker
label="Theme Color"
value="#4d7ef7"
{presets}
on:arc-input={(e) => console.log('Live:', e.detail.value)}
on:arc-change={(e) => console.log('Committed:', e.detail.value)}
/>import { Component } from '@angular/core';
import { ColorPicker } from '@arclux/arc-ui-angular';
@Component({
imports: [ColorPicker],
template: `
<arc-color-picker
label="Theme Color"
value="#4d7ef7"
[presets]="presets"
(arc-input)="onPreview($event)"
(arc-change)="onPick($event)"
></arc-color-picker>
`,
})
export class MyComponent {
presets = ['#4d7ef7', '#22c55e', '#ef4444', '#eab308'];
onPreview(e: CustomEvent) {
console.log('Live:', e.detail.value);
}
onPick(e: CustomEvent) {
console.log('Committed:', e.detail.value);
}
}import { ColorPicker } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<ColorPicker
label="Theme Color"
value="#4d7ef7"
presets={['#4d7ef7', '#22c55e', '#ef4444', '#eab308']}
onArcInput={(e) => console.log('Live:', e.detail.value)}
onArcChange={(e) => console.log('Committed:', e.detail.value)}
/>
);
}import { ColorPicker } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<ColorPicker
label="Theme Color"
value="#4d7ef7"
presets={['#4d7ef7', '#22c55e', '#ef4444', '#eab308']}
onArcInput={(e) => console.log('Live:', e.detail.value)}
onArcChange={(e) => console.log('Committed:', e.detail.value)}
/>
);
}API
valuestring'#4d7ef7'- Current color as a 6-digit hex string (e.g.
#4d7ef7). Reflected as an attribute. namestring''disabledbooleanfalse- Disables all interaction, reducing opacity to 40% and blocking pointer events.
labelstring''- Label text displayed above the picker in uppercase accent font.
presetsstring[][]- Array of hex color strings to display as quick-select swatches below the hex input.
readonlybooleanfalse- Prevents changing the color via the area, hue slider, hex input, or swatches while the picker stays focusable and the value still submits.
size'sm' | 'md' | 'lg''md'- Control size.
mdis the default;smandlgscale the swatch and trigger. formAssociatedbooleantruepropertiesobject{ // flag(), unlike `disabled`. The exclusion in props.js is specifically // about form-associated *platform* semantics: a `disabled` content // attribute that is merely present makes the element actually disabled // per the HTML spec, and formDisabledCallback assigns the property back, // so no converter can win. Neither of these is platform-mapped: // `required` is enforced by _computeValidity() below and `readonly` by // each component's own interaction handlers, so the stock converter buys // nothing here and costs the usual bug: `required="false"` read as true, // blocking submission of a form the author meant to leave optional. // Finding #48's shape, across all 26 form controls at once. required: flag(false), readonly: flag(false), }- Lit merges static properties up the prototype chain, so every consumer
gets these without declaring them.
requiredparticipates in constraint validation below;readonlyreflects for styling and is enforced by each component's interaction handlers (the mixin can't know which gestures mutate state). autoValidatesbooleantrue- Components that run their own constraint-validation logic (pattern checks, range checks) opt out of the automatic required sync by overriding this to false, and own the whole validity flag set instead.
formvalidityvalidationMessagerequiredbooleanfalse
Methods
checkValidity()boolean- Whether the control currently satisfies its constraints, per the native
constraint-validation API. Fires
invalidon the element when it does not, and reports nothing to the user. reportValidity()boolean- As checkValidity(), but also shows the browser's validation message against the control when it fails.
Events
arc-input- Fired continuously as the color changes, including every frame of a drag across the saturation area or hue track. Use for live previews.
event.detail.valuecontains the hex string. arc-change- Fired once the color is committed: the pointer released after a drag, a preset clicked, or a valid hex typed and blurred. Use for anything expensive.
event.detail.valuecontains the hex string.