ColorArea
A two-dimensional saturation/brightness picking square for a given hue, built from two overlaid native <input type="range"> elements.
View code
let saturation = 80;
let brightness = 70;
<div mix={[vstack({ gap: 3, align: "start" })]}>
<ColorArea
aria-label="Saturation and brightness"
hue={HUE}
saturation={saturation}
value={brightness}
mix={[
colorAreaDrag(),
on<HTMLDivElement, "ui:color-area-change">("ui:color-area-change", (event) => {
saturation = event.x;
brightness = event.y;
void handle.update();
}),
]}
>
<ColorArea.SaturationThumb data-color-area-axis="x" aria-label="Saturation" />
<ColorArea.ValueThumb data-color-area-axis="y" aria-label="Brightness" />
</ColorArea>
<div mix={[hstack({ gap: 3, align: "center" })]}>
<ColorSwatch
size="lg"
shape="rounded"
value={formatHex({ ...hsvToRgb({ h: HUE, s: saturation, v: brightness }), a: 1 })}
/>
<div mix={[vstack({ gap: 0, align: "start" })]}>
<span mix={[font("mono"), text("sm"), weight("medium")]}>
{formatHex({ ...hsvToRgb({ h: HUE, s: saturation, v: brightness }), a: 1 })}
</span>
<span mix={[text("xs"), fg("neutral")]}>
hue {HUE}° · saturation {Math.round(saturation)}% · brightness {Math.round(brightness)}%
</span>
</div>
</div>
</div>Installation
An ordinary dependency: install it, import the theme once, and import the component where it is used.
npm add @sdxc/uiimport "@sdxc/ui/theme.css";Usage
import { ColorArea } from "@sdxc/ui";Renders the root <div>'s picking-square background: literal black/white
gradient stops are the fixed brightness/saturation math primaries, and the
hue's hsl() composes through bg(), since it passes (-values unchanged.
Composition
The parts the component publishes, each a static property of the host.
ColorAreaColorArea.SaturationThumbdirectionstays fixed left-to-right regardless of the page's owndir, matching the root gradient's physical axes; only this thumb's own line accepts pointer input, so elsewhere a click reaches the axis line beneath it.ColorArea.ValueThumbwriting-mode/directionstay fixed regardless of the page's owndir, so this line travels block-end (black) to block-start, the low-at-the- bottom convention; pointer layering matches ColorArea.SaturationThumb.
Props
Read from the component's own types, so every prop, every default and every allowed value is listed.
| Prop | Type | Description |
|---|---|---|
hue? | number | Hue, in degrees 0–360, the square's background renders every reachable saturation/brightness combination for. Defaults to DEFAULT_HUE. Typically driven by a hue control alongside this one, re-rendering on change. |
saturation? | number | Current saturation (x-axis position), 0–100, for a square whose position the consumer tracks itself. |
defaultSaturation? | number | Starting saturation (x-axis position), 0–100, for a square that never tracks its own position. |
value? | number | Current brightness (y-axis position), 0–100, for a square whose position the consumer tracks itself. |
defaultValue? | number | Starting brightness (y-axis position), 0–100, for a square that never tracks its own position. |
Also accepts everything in TagProps<"div">.
ColorArea.SaturationThumb
Also accepts everything in Omit<TagProps<"input">, "type" | "role">.
ColorArea.ValueThumb
Also accepts everything in Omit<TagProps<"input">, "type" | "role">.