UI

Color picker

Choose an opaque hex color with pointer selection, keyboard controls or text entry.

Read Markdown

Web 0.2.0

Choose a color or enter its six-digit hex code.
  • Defaultlight7.93 : 1AA 4.5dark9.07 : 1AA 4.5
  • KeyboardArrowRightArrowLeftArrowUpArrowDownEndHomeTabShift+TabControlOrMeta+A#00ff00Enter
  • measured on 0.2.0
npx shadcn@latest add @maeso/color-picker
Size
23.0 kB gzipmeasured on 0.2.0

Usage

Supply a six-digit hex value and onChange, or defaultValue for local state. Text commits on blur or Enter. A name submits the committed value.

Accessibility

Provide a visible label. Tab reaches saturation, hue and text entry. Arrow keys adjust selection. Invalid text restores the selected color on blur.

When to use

Use for an opaque color chosen visually or by hex code. Alpha channels and eyedropper controls are outside this contract.

Install

Add this registry to your project's components.json once, before the first install. Keep your existing settings and other registries.

{
  "registries": {
    "@maeso": "http://127.0.0.1:4321/r/{name}.json"
  }
}

Then install the registry's default theme once, and import its sheet in the CSS entry that imports Tailwind. It paints every item from this registry.

npx shadcn@latest add @maeso/maeso
@import "./styles/theme.web.css";
npx shadcn@latest add @maeso/color-picker

Props

ColorPicker

PropTypeRequiredDescription
labelstringyes
defaultValuestring | undefinedno
disabledboolean | undefinedno
errorstring | undefinedno
hintstring | undefinedno
namestring | undefinedno
onChange((value: string) => void) | undefinedno
requiredboolean | undefinedno
valuestring | undefinedno

Proof

Contrast

measured on 0.2.0

StateForegroundBackgroundRatioFloor
defaultrgb(67 77 86)rgb(248 245 240)7.93AA 4.5
default (dark)rgb(181 182 182)rgb(7 21 34)9.07AA 4.5

Keyboard

measured on 0.2.0

KeyAction
ArrowRightIncrease hue
ArrowLeftDecrease hue
ArrowUpIncrease hue
ArrowDownDecrease hue
EndSet hue to the maximum
HomeSet hue to the minimum
TabMove focus from hue to hex input
Shift+TabMove focus from hex input to hue
ControlOrMeta+ASelect hex text for replacement
#00ff00Type a hex color draft
EnterCommit the hex color

Size

23007 gzip bytes · measured on 0.2.0

Example

import { ColorPicker } from "@/components/ui/_kit/forms/color-picker/ColorPicker";

const Example = () => (
		<div className="w-full max-w-105">
			<ColorPicker
				label="Brand color"
				defaultValue="#2563eb"
				name="brand"
				hint="Choose a color or enter its six-digit hex code."
			/>
		</div>
	);
export default Example;

not on native yet