react-hook-form-bound boolean field rendered as a labeled toggle button. Wraps the @uxf/ui/checkbox-button primitive and manages its value and isInvalid from form state.
Use @uxf/form/checkbox-button for a boolean choice that should look like a pressable button/pill inside a @uxf/form form — it registers the field with react-hook-form via control/name. For a standalone, manually-controlled toggle button (outside a form), use the @uxf/ui/checkbox-button twin directly. For a standard checkbox with a side label, use @uxf/form/checkbox-input.
import { CheckboxButton } from "@uxf/form/checkbox-button";
import { Form } from "@uxf/form/form";
import { useForm } from "react-hook-form";
interface FormData {
confirm: boolean;
}
function Example() {
const formApi = useForm<FormData>({ defaultValues: { confirm: false } });
return (
<Form formApi={formApi} id="example" onSubmit={(values) => console.log(values)}>
<CheckboxButton control={formApi.control} isRequired label="Confirm" name="confirm" />
</Form>
);
}
Value is boolean | undefined.
CheckboxButtonProps<FormData> = ControlProps<FormData> + the visual props of the @uxf/ui/checkbox-button 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. |
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: boolean | undefined, event?) => void |
— | Called after the field value updates. |
All other props (label, size, …) are forwarded to the twin — see @uxf/ui/checkbox-button.
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 sets the twin's isInvalid. (The twin has no helperText, so a required error styles the button but shows no message text.)Form — it reads the form context (formId, and inherits isDisabled / isReadOnly) and needs a react-hook-form control.@uxf/ui/checkbox-button, so include that component's stylesheet(s) and the @uxf/ui token layer — see @uxf/ui/checkbox-button.@uxf/ui/checkbox-button