navius

Color Picker

A saturation/value canvas, hue and alpha tracks, a hex field and preset swatches, all driving one HSVA model projected to a color string.

Value: #4F46E5

Features

  • The root owns the color as HSVA and projects it to Value through Format (hex / rgb / rgba / hsl / hsla).
  • The Area is a 2D slider (two grouped role="slider" thumbs, one per channel); the Hue and Alpha tracks each drive one channel. Every track is keyboard-drivable.
  • The Field commits a typed hex / rgb / hsl string; the Swatches are an APG listbox of presets. All surfaces write back to the same model.
  • Controlled via @bind-Value, uncontrolled via DefaultValue; a hidden input mirrors the projected string into form submission when Name is set.

Installation

Install the brain, or copy just this primitive in with the CLI.

Anatomy

Import the parts and compose only the ones you need. The Area's hue-fill and the track gradients are rendered inline (they are intrinsic to each control).

API Reference

NaviusColorPicker. Owns the HSVA color and projects it to Value. Renders a div. Value is two-way bindable.

Prop Type Default
Value string? -
ValueChanged EventCallback<string> -
DefaultValue string? -
Format string "hex"
AlphaEnabled bool false
Disabled bool false
ReadOnly bool false
Name string? -
ChildContent RenderFragment? -
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-color-picker] Present on the root
[data-disabled] Present when disabled

NaviusColorPickerArea. The 2D saturation/value canvas: a role=group with a visible saturation slider and a visually-hidden brightness slider. Renders a div.

Prop Type Default
AriaLabel string? "Color"
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-color-picker-area] Present on the canvas group
[data-navius-color-picker-area-thumb] The visible saturation (x) thumb
[data-navius-color-picker-area-thumb-y] The visually-hidden brightness (y) slider
[data-channel] "saturation" | "brightness"
[data-dragging] Present on a thumb while dragging
[data-disabled] Present when disabled

NaviusColorPickerHueSlider. The horizontal rainbow track with a role=slider thumb. Renders a div.

Prop Type Default
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-color-picker-hue] Present on the hue track
[data-navius-color-picker-hue-thumb] The hue slider thumb
[data-orientation] "horizontal"
[data-dragging] Present on the thumb while dragging

NaviusColorPickerAlphaSlider. The optional opacity track (transparent to opaque over a checkerboard). Only meaningful with AlphaEnabled. Renders a div.

Prop Type Default
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-color-picker-alpha] Present on the alpha track
[data-navius-color-picker-alpha-thumb] The alpha slider thumb
[data-orientation] "horizontal"
[data-dragging] Present on the thumb while dragging

NaviusColorPickerField. A text field that commits a typed hex / rgb / hsl on change; a bad value flips data-invalid without disturbing the color. Renders an input.

Prop Type Default
AriaLabel string? "Hex color"
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-color-picker-field] Present on the input
[data-invalid] Present when the typed value did not parse

NaviusColorPickerSwatch. A non-interactive preview of the current color (the color is its accessible name). Renders a div with role=img.

Prop Type Default
…attributes IDictionary<string, object>? -

NaviusColorPickerSwatches. A preset grid (APG listbox); auto-renders SwatchItems from Colors, or takes explicit children. Renders a div with role=listbox.

Prop Type Default
AriaLabel string? "Swatches"
Colors IReadOnlyList<string>? -
ChildContent RenderFragment? -
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-color-picker-swatches] Present on the listbox

NaviusColorPickerSwatchItem. One preset (role=option); click / Space / Enter applies it. Renders a button.

Prop Type Default
Value string ""
ChildContent RenderFragment? -
…attributes IDictionary<string, object>? -
Data attribute Values
[data-navius-color-picker-swatch-item] Present on the option button
[data-selected] Present when it matches the current color
[data-disabled] Present when disabled

Accessibility

The Area follows react-aria's ColorArea: a role="group" of two role="slider" thumbs, each exposing its own aria-valuenow, with aria-valuetext announcing the resulting color. The Hue and Alpha tracks are single sliders. The Swatches are an role="listbox" with a roving tabindex.

Key Description
Arrow keys (Area) Left/Right adjust saturation, Up/Down adjust brightness (Shift takes a larger step).
Home / End (Area) Jumps saturation to its extremes.
Arrow keys (Hue / Alpha) Decrement / increment the channel by 1 (1% for alpha); Shift or Page steps by 10.
Home / End (Hue / Alpha) Jumps the channel to its extremes.
Arrow keys (Swatches) Moves focus among the preset options.
Space / Enter (Swatches) Applies the focused preset.