SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

ColorArea

A two-dimensional saturation/brightness picking square for a given hue, built from two overlaid native <input type="range"> elements.

#246bb3hue 210° · saturation 80% · brightness 70%
View code
tsx
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.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Usage

typescript
import { ColorArea } from "@sdxc/ui/color";

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.

  • ColorArea
  • ColorArea.SaturationThumbdirection stays fixed left-to-right regardless of the page's own dir, 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/direction stay fixed regardless of the page's own dir, 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.

PropTypeDefaultRequiredDescription
huenumber—NoHue, 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.
saturationnumber—NoCurrent saturation (x-axis position), 0–100, for a square whose position the consumer tracks itself.
defaultSaturationnumber—NoStarting saturation (x-axis position), 0–100, for a square that never tracks its own position.
valuenumber—NoCurrent brightness (y-axis position), 0–100, for a square whose position the consumer tracks itself.
defaultValuenumber—NoStarting 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">.

@sdxc/ui

Can’t find it? Contact us