Skip to content

HyColorSlider

Usage examples on this page are written for Lit / plain HTML (<hy-color-slider>). The same component ships as HyColorSlider in @whitespaceux/harmony-react (native React 19), with typed wrappers for Angular, Solid, Svelte, and Vue. The API reference below applies to all frameworks.

A numeric slider whose track is painted with an OKLCH gradient for the selected channel (hue, chroma, or lightness). Wraps hy-slider and feeds it a gradient overlay via the track slot.

Two use cases

  1. Color picker — three instances (h, c, l) sharing state. The caller owns hue, chroma, lightness and updates them from the event detail on each input.
  2. Numeric dial with color context — a single slider whose value is not directly an OKLCH coordinate (e.g. a chroma multiplier on 0–1, or a vibrancy multiplier on 0–2). Override min / max / step independently of the channel; the gradient stays in the OKLCH-valid range and provides visual context even though the slider value runs past gamut.

Controlled only

The component never mutates its own hue/chroma/lightness. Parents must listen to input (live) or change (on commit) and update the props to reflect the new state.

Examples

OKLCH color picker (hue channel)

javascript
<hy-color-slider
type="h"
label="Hue"
hue="210"
chroma="0.12"
lightness="0.65"
></hy-color-slider>
<script>
const slider = document.querySelector('hy-color-slider');
// Controlled: echo the adjusted channel back onto the props.
slider.addEventListener('input', (e) => {
slider.hue = e.detail.h;
});
</script>

Tuner-style chroma multiplier (custom 0-1 range)

html
<hy-color-slider
  type="c"
  label="Chroma"
  hint="saturation"
  max="1"
  hue="210"
  chroma="0.5"
  lightness="0.65"
></hy-color-slider>

API

Properties

PropertyAttributeTypeDefaultDescription
typetype'h' | 'c' | 'l''h'Which OKLCH channel the gradient represents.
huehuenumber0Current hue (0–360) — used to paint c and l gradients and in event detail.
chromachromanumber0.1Current chroma (absolute OKLCH chroma, typically 0–0.4) — used to paint h and l gradients.
lightnesslightnessnumber0.7Current lightness (0–1) — used to paint h and c gradients.
minminnumber | undefinedMinimum slider value. Defaults per type: h=0, c=0, l=0. Override to support arbitrary numeric scales (e.g. chroma multiplier 0–1).
maxmaxnumber | undefinedMaximum slider value. Defaults per type: h=360, c=0.4, l=1. Override to support arbitrary numeric scales.
stepstepnumber | undefinedStep granularity. Defaults per type: h=1, c=0.01, l=0.01.
maxChromaGradientmax-chroma-gradientnumber0.4Maximum chroma used when rendering the chroma gradient (the "saturated end" of type=c). Caps chroma within sRGB gamut. Slider values are governed by max independently.
labellabelstring''Primary label. Defaults per type: "Hue", "Chroma", "Lightness".
hinthintstring''Secondary hint text under the label.
helperTexthelper-textstring''Helper text displayed below the slider.
errorMessageerror-messagestring''Error message (auto-raises error state on the inner slider).
suffixsuffixstring''String appended to the value readout. Defaults per type: "°" for h, "" for c/l.
sizesize'small' | 'medium' | 'large''medium'Size variant (forwarded to inner slider).
variantvariant'default' | 'success' | 'warning' | 'danger''default'Visual variant (forwarded to inner slider).
layoutlayout'block' | 'inline''block'Row layout (forwarded to inner slider). block (default) stacks label above the slider; inline puts label+hint on the left, slider in the middle, value on the right. Set --hy-slider-label-column-width on a wrapping container so stacked sliders align.
disableddisabledbooleanfalseDisabled state.
errorerrorbooleanfalseError state.
hideValuehide-valuebooleanfalseHide the numeric value readout.
displayPrecisiondisplay-precisionnumber | undefinedDecimal places shown in the value readout. Forwarded to hy-slider — auto-inferred from step when unset (e.g. step=0.01 → 2 decimals).
formatValue(value: number) => string | undefinedCustom formatter for the value readout. Forwarded to hy-slider — when set, owns the full display string (suffix is not appended).
namenamestring''Form field name (forwarded to inner slider).
inputIdinput-idstring''Explicit input ID (forwarded to inner slider).
valuenumberCurrent channel value, derived from hue/chroma/lightness.

Events

EventDetailDescription
inputFires during drag / keyboard adjustment. Detail: ColorSliderEventDetail.
changeFires when the value is committed. Detail: ColorSliderEventDetail.

CSS Parts

PartDescription
baseThe inner slider's base wrapper (re-exported)
labelThe inner slider's label (re-exported)
rowThe inner slider's row (re-exported)
inputThe inner slider's native range input (re-exported)
trackThe inner slider's track (re-exported)
fillThe inner slider's progress fill (re-exported; hidden by default)
thumbThe inner slider's thumb (re-exported)
valueThe inner slider's numeric readout (re-exported)
helper-textThe inner slider's helper text (re-exported)
error-messageThe inner slider's error message (re-exported)

Methods

focus()

Focuses the inner slider's range input.

blur()

Blurs the inner slider.

Built with Lit. Documented with VitePress.