react-hook-form-bound on/off switch. Wraps the @uxf/ui/toggle primitive and manages its value and isInvalid from form state.
Use @uxf/form/toggle for a single binary on/off setting inside a @uxf/form form — it registers the field with react-hook-form via control/name. For a standalone, manually-controlled switch (outside a form), use the @uxf/ui/toggle twin directly.
import { Toggle } from "@uxf/form/toggle";
import { Form } from "@uxf/form/form";
import { useForm } from "react-hook-form";
interface FormData {
notifications: boolean;
}
function Example() {
const formApi = useForm<FormData>({ defaultValues: { notifications: false } });
return (
<Form formApi={formApi} id="example" onSubmit={(values) => console.log(values)}>
<Toggle control={formApi.control} label="Notifications" name="notifications" />
</Form>
);
}
Value is boolean | undefined.
ToggleProps<FormData> = ControlProps<FormData> + the visual props of the @uxf/ui/toggle 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, variant, hiddenLabel, …) are forwarded to the twin — see @uxf/ui/toggle. Note: size is part of the props type but is not currently forwarded by this field.
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 switch 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/toggle, so include that component's stylesheet(s) and the @uxf/ui token layer — see @uxf/ui/toggle.@uxf/ui/toggle