Color Picker
FreeHSV gradient canvas picker with hue rail, alpha channel, hex input, preset swatches and 3 sizes.
</>sv-color-picker colorpickerinput
import { SvColorPickerComponent } from '@styloviz/forms/color-picker';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
An interactive demo for this component lives in the gallery.
Open live demoMore examples
Alpha + preset swatches
example.htmlAngular
1 lines
<sv-color-picker [showAlpha]="true" [swatches]="brandColors" format="hex" [(ngModel)]="color" />
Signal Forms
Bind it with `[formField]` from `@angular/forms/signals` — the control is a ControlValueAccessor, which Signal Forms drives on Angular 21 and 22 alike.
color-picker.signal-forms.tsTypeScript
22 lines
import { ChangeDetectionStrategy, Component, signal } from '@angular/core'; import { FormField, form, pattern, required } from '@angular/forms/signals'; import { SvColorPickerComponent } from '@styloviz/forms/color-picker'; @Component({ selector: 'app-color-picker-signal-forms', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, imports: [FormField, SvColorPickerComponent], template: ` <sv-color-picker [formField]="brand.primary" label="Primary colour" /> <p>Colour: {{ brand.primary().value() }} · valid: {{ brand.primary().valid() }}</p> `, }) export class ColorPickerSignalFormsExample { readonly model = signal({ primary: '#3b82f6' }); readonly brand = form(this.model, (path) => { required(path.primary); pattern(path.primary, /^#[0-9a-f]{6}$/i); }); }
When to use
Letting users pick an arbitrary color (theming, labels, calendars, design tools). You need HSV selection plus hex entry and brand preset swatches. For a fixed brand palette only, a swatch list or Select may suffice.
Async states
None — this component has nothing to load, so it has no loading, empty or error state to drive.
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| value | string (two-way) | '#3b82f6' | Selected color (two-way). |
| format | ColorPickerFormat | 'hex' | Output format: hex, rgb or hsl. |
| size | ColorPickerSize | 'md' | Picker size: sm, md or lg. |
| swatches | readonly ColorSwatch[] | defaultSwatches(this.labels) | Preset swatch palette. |
| disabled | boolean | false | Disable the picker. |
| label | string | '' | Accessible label for the control. |
| showAlpha | boolean | false | Show the alpha (transparency) channel. |
| contrastBackground | string | '' | A background to check the chosen colour against. |
| colorNamer | (hex: string) => string | `svColorName`, in the app's `core` labels | Turn the hex into words for assistive tech. |
| errorMessage | string | '' | Client-side validation message. |
| serverError | SvServerError | null | A rejection reported by the server about this value. Self-expiring. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| colorChange | string | Emitted with the new color whenever it changes. |
| valueChange | string | Emits the new `value` whenever it changes — the output half of `[(value)]`. |
Customization & theming
HSV canvas with a hue rail and optional `showAlpha` opacity channel; `format` outputs hex, rgb or hsl. Hex input plus configurable preset `swatches` ({ label, value }); `label`, `disabled`, three `size`s. Two-way bind `[(value)]` or a reactive control (CVA); listen to `(colorChange)`.
Forms integration
sv-color-picker— ControlValueAccessor.[formControl],formControlName,[(ngModel)]and Signal Forms[formField]all work.
Best practices
Do: Provide brand `swatches` so users land on on-brand colors quickly. Do: Expose the hex input for precise, copy-pasteable values. Tip: Only enable `showAlpha` when transparency is actually meaningful for the value.
Accessibility
The gradient, hue and opacity controls are `role="slider"` and fully keyboard-operable: Arrow keys adjust (Shift for larger steps), Home/End jump to the ends. Opening moves focus into the panel; Escape closes and returns focus to the trigger. Swatches expose `aria-label` + `aria-pressed`, and the hex input and sliders are labelled. Implements ControlValueAccessor — works with `[(ngModel)]`, `[formControl]` and `formControlName`; `formControl.disable()` disables the trigger.
Feedback on Color Picker
Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.