Color Picker

A colour, picked on an area, sliders, fields, presets or the screen — in HSV, HSL, sRGB or OKLCH, held to a gamut. Its value is a CSS colour; a form field.

FormsExperimental

Usage

Usage

#000000

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScColorPicker,  ScColorPickerArea,  ScColorPickerInput,  ScColorPickerSlider,  ScColorPickerSwatch,} from '@semantic-components/ui';
/** A brand colour: the area (saturation × brightness), the hue, the colour as text — any CSS colour typed, taken on Enter. */

Anatomy

Every part is optional and edits the same colour: an area for two channels, a slider for one, a field for the text, an input for a channel's number, presets, the screen's colour.

import { ScColorPicker, ScColorPickerArea, ScColorPickerChannelInput, ScColorPickerEyeDropper, ScColorPickerInput, ScColorPickerSlider, ScColorPickerSwatch, ScColorPickerSwatchItem, ScColorPickerSwatches } from '@semantic-components/ui';
<div scColorPicker aria-label="Brand color" [formField]="form.color">  <div scColorPickerArea aria-label="Color"></div>  <input scColorPickerSlider="hue" aria-label="Hue" />  <input scColorPickerSlider="alpha" aria-label="Opacity" />  <span scColorPickerSwatch></span>  <input scColorPickerInput aria-label="Hex" />  <input scColorPickerChannelInput="red" aria-label="Red" />  <div scColorPickerSwatches aria-label="Presets">    <button scColorPickerSwatchItem="#e11d48"><span class="sr-only">Rose</span></button>  </div>  <button scColorPickerEyeDropper>…</button></div>

Spaces, formats, gamut

space decides the channels: hsv (hue, saturation, brightness — the default), hsl, srgb (red, green, blue), oklch (lightness, chroma, hue); alpha in each. The area takes any two (x, y), a slider any one — painted with CSS, or on a canvas. The value is written as the space writes it (hex, hsl(), rgb(), oklch()) or as format says; any CSS colour goes in. The hue is kept through greys and black. OKLCH can leave sRGB: gamut holds it to sRGB (the default), Display P3, or nothing — dragged past it, the value is the nearest colour it holds, the parts data-out-of-gamut; let go, the thumb moves there.

Keyboard

KeyDoes (on the area, a slider)
←→↑↓ One step (the area: across and up); with Shift, ten
Page Up / Page DownA tenth of the range
Home / EndIts ends
Enter / Escape In the field: takes the text / puts the value back

Accessibility

  • A group (name it); the area a slider reading its two values ("76 %, 96 %"), a slider its value ("120°") — name each, and give your words in aria-valuetext.
  • The presets: a radio group, each named by you ("Rose"). The swatch is decorative: say the colour in text where it matters.
  • The eyedropper is disabled where the browser can't pick from the screen (data-unsupported).

Examples

All features

#000000

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  type ScColorFormat,  ScColorPicker,  ScColorPickerArea,  ScColorPickerEyeDropper,  ScColorPickerInput,  ScColorPickerSlider,  ScColorPickerSwatch,  ScColorPickerSwatchItem,

Spaces and channels

hsl(200 80% 50%)

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScColorPicker,  ScColorPickerArea,  ScColorPickerInput,  ScColorPickerSlider,} from '@semantic-components/ui';
/** space="hsl": the area hue × lightness (painted on a canvas), saturation on a vertical slider; written as hsl(). */@Component({

OKLCH

oklch(0.62 0.19 259)

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScColorPicker,  ScColorPickerArea,  ScColorPickerInput,  ScColorPickerSlider,  ScColorPickerSwatch,} from '@semantic-components/ui';
/** space="oklch", gamut="p3": chroma × lightness at the hue, wide colours held — past P3, the nearest it holds (data-out-of-gamut while dragging). */

Presets and channel inputs

#000000

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScColorPicker,  ScColorPickerChannelInput,  ScColorPickerEyeDropper,  ScColorPickerSwatch,  ScColorPickerSwatchItem,  ScColorPickerSwatches,  ScField,  ScLabel,

In a popover

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScButton,  ScColorPicker,  ScColorPickerArea,  ScColorPickerInput,  ScColorPickerSlider,  ScPopover,  ScPopoverPortal,  ScPopoverProvider,

Disabled

import { Component, ViewEncapsulation } from '@angular/core';import {  ScColorPicker,  ScColorPickerArea,  ScColorPickerInput,  ScColorPickerSlider,} from '@semantic-components/ui';
/** disabled: not focused, not changed. */@Component({

Read-only

#000000

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScColorPicker,  ScColorPickerArea,  ScColorPickerInput,  ScColorPickerSwatch,} from '@semantic-components/ui';
/** readonly: focusable, its value read — not changed. */@Component({

Commit

#000000

Saved: —

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScButton,  ScColorPicker,  ScColorPickerArea,  ScColorPickerSlider,} from '@semantic-components/ui';
/** [(value)] follows every step; (valueCommit) once a change finishes — to save. setColor() from outside. */@Component({

Form

Brand color
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, FormRoot, form, required } from '@angular/forms/signals';import {  ScButton,  ScColorPicker,  ScColorPickerArea,  ScColorPickerInput,  ScColorPickerSlider,  ScColorPickerSwatch,  ScField,

RTL

import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import {  ScColorPicker,  ScColorPickerArea,  ScColorPickerInput,  ScColorPickerSlider,} from '@semantic-components/ui';
/** In a right-to-left page: the sliders run as the text reads (their tracks painted the same way), the values in the locale’s digits. */

API reference

Each part takes class, merged over its own (cn: a later class wins). The corners are the style's (colorPicker); the eyedropper is its button.

PartSelectorDescription
ScColorPicker[scColorPicker] The colour: value, space, format, gamut; (valueCommit). exportAs: channel(), set(), setColor(), css(), pickFromScreen().
ScColorPickerAreadiv[scColorPickerArea] Two channels (x, y): a slider; CSS or a canvas.
ScColorPickerSliderinput[scColorPickerSlider] One channel on a native range; orientation.
ScColorPickerInputinput[scColorPickerInput] The colour as text: any CSS colour, on Enter or when left.
ScColorPickerChannelInputinput[scColorPickerChannelInput] One channel as a number, in its units.
ScColorPickerSwatch[scColorPickerSwatch] The colour, shown; decorative.
ScColorPickerSwatches / SwatchItem[scColorPickerSwatches], button[scColorPickerSwatchItem] Presets: a radio group of colours.
ScColorPickerEyeDropperbutton[scColorPickerEyeDropper] A colour from the screen; data-unsupported elsewhere.
InputTypeDefaultDescription
valuestring'' Two-way, or [formField]: a CSS colour; empty is none.
space'hsv' | 'hsl' | 'srgb' | 'oklch''hsv' The channels the parts edit.
format'hex' | 'rgb' | 'hsl' | 'oklch' | nullthe space’s How the value is written.
gamut'srgb' | 'p3' | false'srgb' The colours it holds.
disabled, readonly, invalid, touchedbooleanfalse Bound by [formField].