Chroma Panel

Search documentation

Find a page or section

ChannelSlider

One channel at a time, backed by a real input[type=range].

Anatomy

import { ChannelSlider } from "chroma-panel";
 
<ChannelSlider
  label="Hue"
  min={0}
  max={360}
  read={(c) => c.h}
  write={(h, c) => ({ ...c, h })}
/>;

Keyboard handling and screen-reader announcements come from the browser, because the track is a real <input type="range">.

Only inside a panel

This is one of the parts the built-in modes are made of. It reads the colour through usePanel(), so it only works inside a ChromaPanel — typically in a custom mode. For a picker outside the panel, use the store and hooks.

API reference

Props

PropTypeDefaultDescription
label*stringAccessible name, announced as text — "Hue 210 degrees", not a bare number.
shortLabelstringThe letter shown beside the track, such as H. Falls back to label.
min*numberLowest value the channel takes.
max*numberHighest value the channel takes.
stepnumber1Arrow-key increment. Shift and Page step by ten.
read*(color: Hsva) => numberPulls this channel's value out of the current colour.
write*(value: number, current: Hsva) => HsvaMerges a new value back into the colour. Returning a whole Hsva rather than one channel is what preserves hue at the extremes.
gradient(color: Hsva) => stringBuilds the CSS gradient painted behind the track for the current colour. Omit for a plain track.
channelstringSets data-cp-channel on the track, so CSS can target one channel.
formatValue(value: number) => stringFormats the announced value, for units the label cannot carry. Defaults to the rounded number.
classNamestringClass on the slider row.