react-hook-form-bound field: a labeled group of color swatches bound to a single hex value. Wraps the @uxf/ui/color-radio-group primitive and manages its value, isInvalid, and helperText from form state.
Use @uxf/form/color-radio-group for a single color choice from a fixed set of swatches inside a @uxf/form form — it registers the field with react-hook-form via control/name. For a standalone, manually-controlled swatch group (outside a form), use the @uxf/ui/color-radio-group twin directly.
import { ColorRadioGroup } from "@uxf/form/color-radio-group";
import { Form } from "@uxf/form/form";
import { HexColor } from "@uxf/ui/types";
import { useForm } from "react-hook-form";
interface FormData {
color: HexColor | null;
}
const OPTIONS: { value: HexColor; label: string }[] = [
{ value: "#ff0000", label: "Red" },
{ value: "#00ff00", label: "Green" },
{ value: "#0000ff", label: "Blue" },
];
function Example() {
const formApi = useForm<FormData>({ defaultValues: { color: null } });
return (
<Form formApi={formApi} id="example" onSubmit={(values) => console.log(values)}>
<ColorRadioGroup control={formApi.control} isRequired label="Pick a color" name="color" options={OPTIONS} />
</Form>
);
}
Value is the selected hex color (`#${string}` | null).
ColorRadioGroupProps<FormData> = ControlProps<FormData> + the visual props of the @uxf/ui/color-radio-group twin (minus the ones this field manages: isFocused, isInvalid, name, onChange, value) + the field props below.
| Prop | Type | Default | Description |
|---|---|---|---|
control |
Control<FormData> |
— | Required. The control from useForm. |
name |
FieldPath<FormData> |
— | Required. Field path in the form values. |
options |
ColorRadioGroupOption[] |
— | Required. Swatches to render ({ value, label, disabled? }); see the twin. |
rules |
RegisterOptions |
— | Extra react-hook-form rules; merged with the built-in required rule. |
shouldUnregister |
boolean |
— | Unregister the field (drop its value) on unmount. |
isRequired |
boolean |
false |
Adds a required rule and the required indicator. |
requiredMessage |
string |
localized | Message for the required rule. |
onChange |
(value: `#${string}` | null, event?) => void |
— | Called after the field value updates. |
onChangeConfirm |
(value: `#${string}` | null) => Promise<boolean> |
— | Async guard run before committing a change; the value is written only if it resolves true. |
All other props (label, hiddenLabel, helperText, …) are forwarded to the twin — see @uxf/ui/color-radio-group.
isRequired adds a required rule; its message defaults to a localized string (EN: "This field is required") and can be overridden with requiredMessage.rules; the field-level error is shown as the twin's helperText and sets isInvalid.options is empty.Form — it reads the form context (formId, and inherits isDisabled / isReadOnly) and needs a react-hook-form control.@uxf/ui/color-radio-group, so include that component's stylesheet(s) and the @uxf/ui token layer — see @uxf/ui/color-radio-group.@uxf/ui/color-radio-group