Skip to content
Eskais UI

Forms

Prism Picker

A hue picker built on optics: a white beam refracts through a glass prism (Snell's law, a Cauchy dispersion curve), a dial turns the prism, and the wavelength that leaves through a fixed exit slit is the colour, from the CIE 1931 observer through OKLCH to sRGB. UI SDK's slider in nanometres, painted additively on a canvas only when it changes, with setWavelength and setHue for agents.

Example

Hex
#00deff
cyan
Wavelength
480 nm
Hue
213° OKLCH
188° HSL
Prism
−8.1°

Turn the prism to pick a colour.

Inspired by @ctatedev (opens in a new tab)

Installation

npx shadcn@latest add @eskais/prism-picker
Brings alongaction-refusal

Usage

Import
import { PrismPicker, prismPickerLabels } from "@/components/ui/prism-picker"import { prismPicker } from "@/components/ui/prism-picker-primitive"import {  angleAt,  colourAt,  colourName,  dialDegrees,  readingAt,  sceneTilt,  wavelengthAtAngle,} from "@/components/ui/prism-picker-dial"import {  colourAtHue,  cieXyz,  exitAngle,  hueAtWavelength,  luminousEfficiency,  maxWavelength,  minWavelength,  prismRadius,  prismVertices,  redEndHue,  refractiveIndex,  rotationForWavelength,  rotationRange,  slitDirection,  spectralHue,  trace,  violetHue,  wavelengthAtHue,  scaleAt,  wavelengthAtScale,  beamHeight,} from "@/components/ui/prism-picker-optics"import { layoutFor, paintScene, ringRadius, stageCentre } from "@/components/ui/prism-picker-scene"import { usePrismPickerScene } from "@/components/ui/use-prism-picker-scene"

Reach for it where picking a hue is part of the experience, like a brand or theme playground: the light is physics, not decoration. For any colour, alpha or a typed value, use ColorPicker.

API reference

PrismPicker

PropTypeDefault
labelrequiredThe accessible name of the picker as a whole.string–
valueThe picked wavelength in nm, a whole number from 380 to 700. Pass it to control the picker.number–
defaultValuenumber520
onValueChangeRuns on every step of a drag or a key, with UI SDK's slider details (`reason`, `source`, `cancel()`).(value: number, details: SliderValueChangeDetails) => void–
onValueCommitRuns once a drag or a key press that changed the value ends, for saving.(value: number) => void–
onColorChangeRuns with the colour on every change, with the same details.(color: PrismColor, details: SliderValueChangeDetails) => void–
disabledbooleanfalse
nameSubmits the wavelength under this name in a form.string–
labelsOverrides any label; `names` overrides colour names one by one.Partial<Omit<PrismPickerLabels, "names">> & { names?: Partial<ColourNames> }–
classNameClasses for the root; a function gets the picker's state.string | ((state: PrismPickerState) => string | undefined)–
onPaintCalled with each canvas paint's duration in ms, for measuring.(milliseconds: number) => void–

Other exports

prismPickerLabelsprismPickerangleAtcolourAtcolourNamedialDegreesreadingAtsceneTiltwavelengthAtAnglecolourAtHuecieXyzexitAnglehueAtWavelengthluminousEfficiencymaxWavelengthminWavelengthprismRadiusprismVerticesredEndHuerefractiveIndexrotationForWavelengthrotationRangeslitDirectionspectralHuetracevioletHuewavelengthAtHuescaleAtwavelengthAtScalebeamHeightlayoutForpaintSceneringRadiusstageCentreusePrismPickerScenetype PrismColortype PrismPickerLabelstype PrismPickerPropstype PrismPickerStatetype PrismPickerOptionstype PrismSlidertype ColourNamestype Readingtype PickedColourtype Rgbtype Tracetype Vectype Layouttype SceneTargetstype PrismCanvases

Accessibility

  • The dial is a slider in nanometres: arrows step 1 nm, Page Up and Page Down 10, Home and End go to 380 and 700, and it reads as "470 nm, blue".
  • Touch takes the ring and 24px either side of it, and the prism inside; the page scrolls everywhere else. The knob keeps a 44px hit area.
  • Under reduced motion the prism jumps instead of gliding; the light stays.
  • The stage is dark in every theme, so the focus ring on it is white; the readout below follows the theme.

Agent actions

Agents find it by its label and call setWavelength (380 to 700) or setHue (OKLCH degrees); a magenta or purple hue fails the step with why, since no single wavelength shows it.

Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.