SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

ColorField

A labeled, described and validated color field.

Buttons, links and focus rings.

Panel and sheet backgrounds.

Destructive actions and failed states.

This one has not passed contrast against the surface yet.
View code
tsx
<form mix={[vstack({ gap: 5, align: "stretch" }), is("100%"), maxIs("22rem")]}>
	<ColorField name="brandColor" format="hex" defaultValue="#3b82f6" mix={[colorPreview()]}>
		<ColorField.Label>Brand</ColorField.Label>
		<ColorField.Description>Buttons, links and focus rings.</ColorField.Description>
	</ColorField>
	<ColorField name="surfaceColor" format="rgb" defaultValue="rgb(24 24 27)" mix={[colorPreview()]}>
		<ColorField.Label>Surface</ColorField.Label>
		<ColorField.Description>Panel and sheet backgrounds.</ColorField.Description>
	</ColorField>
	<ColorField name="dangerColor" format="hsl" defaultValue="hsl(0 84% 60%)" mix={[colorPreview()]}>
		<ColorField.Label>Danger</ColorField.Label>
		<ColorField.Description>Destructive actions and failed states.</ColorField.Description>
		<ColorField.Error>This one has not passed contrast against the surface yet.</ColorField.Error>
	</ColorField>
</form>

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 { ColorField } from "@sdxc/ui/color";

Renders a color field: a text control constrained by format's native pattern beside a ColorSwatch preview of the value, laid out with the parts the caller writes.

Examples

Invalid HSL value

White text on this color falls below a 4.5:1 contrast ratio.
View code
tsx
<ColorField name="themeColor" format="hsl" value="hsl(210, 90%, 55%)">
	<ColorField.Label>Theme color</ColorField.Label>
	<ColorField.Error>White text on this color falls below a 4.5:1 contrast ratio.</ColorField.Error>
</ColorField>

RGB with a hint

Buttons and links across your Acme workspace use this color.

View code
tsx
<ColorField name="brandColor" format="rgb" defaultValue="rgb(16, 185, 129)">
	<ColorField.Label>Brand color</ColorField.Label>
	<ColorField.Description>Buttons and links across your Acme workspace use this color.</ColorField.Description>
</ColorField>

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeDefaultRequiredDescription
color"brand" | "neutral" | "success" | "warning" | "danger"—NoSemantic color role for the control's focus ring. Defaults to "neutral" when omitted.
autoFocusboolean—NoNative autofocus. Defaults to true for the first invalid field of an enclosing Form's issues, so a server round-trip lands keyboard focus on the first problem while staying script-free.
format"hex" | "rgb" | "hsl"—NoNotation the control's pattern constrains typed entry to. Defaults to DEFAULT_FORMAT.
namestring—NoNative name; it also finds the enclosing Form's issue for this field.
valuestring—NoCurrent value, as a literal color string in format's notation, for a control a consumer tracks itself. This same string paints the preview.
defaultValuestring—NoInitial value, as a literal color string in format's notation, for a control left to the platform's own uncontrolled state. This same string paints the preview whenever value is unset.
placeholderstring—No
requiredboolean—No
disabledboolean—No
readOnlyboolean—No
autoCompletestring—No
childrenRemixNode—NoThe field's parts: .Label, .Description and .Error. The control row follows the caption, and the rest keep their order.

Also accepts everything in TagProps<"div">.

Types

NameValuesWhat it decides
Color"brand" | "neutral" | "success" | "warning" | "danger"Semantic color role for the control's keyboard focus ring, each mapped to its matching --ui-* variables.
Format"hex" | "rgb" | "hsl"Notation the control's typed value is constrained to through its native pattern: "hex" for #rgb/#rrggbb and their alpha forms, "rgb" for rgb()/rgba(), and "hsl" for hsl()/hsla().
@sdxc/ui

Can’t find it? Contact us