ColorField
A labeled, described and validated color field.
View code
<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.
npm add @sdxc/ui remiximport "@sdxc/ui/theme.css";Usage
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
<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
<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.
| Prop | Type | Default | Required | Description |
|---|---|---|---|---|
color | "brand" | "neutral" | "success" | "warning" | "danger" | — | No | Semantic color role for the control's focus ring. Defaults to "neutral" when omitted. |
autoFocus | boolean | — | No | Native 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" | — | No | Notation the control's pattern constrains typed entry to. Defaults to DEFAULT_FORMAT. |
name | string | — | No | Native name; it also finds the enclosing Form's issue for this field. |
value | string | — | No | Current value, as a literal color string in format's notation, for a control a consumer tracks itself. This same string paints the preview. |
defaultValue | string | — | No | Initial 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. |
placeholder | string | — | No | |
required | boolean | — | No | |
disabled | boolean | — | No | |
readOnly | boolean | — | No | |
autoComplete | string | — | No | |
children | RemixNode | — | No | The 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
| Name | Values | What 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(). |