#Overview
Toggle Switches are used with Forms (Code).
Show codeHide code
export const ToggleSwitchFieldDemo = () => {
const form = useForm<{ isChecked: boolean }>();
return (
<StyledForm onSubmit={form.handleSubmit(() => {})}>
<ToggleSwitchField form={form} name="isChecked">
An option
</ToggleSwitchField>
<StyledButton type="submit">Submit</StyledButton>
</StyledForm>
);
};
Name | Type | Default | Description |
---|---|---|---|
children * | ReactNode | - | Label for the toggle switch |
form * | UseFormReturn<TFieldValues> | - | The connected form that the form field is part of |
name * | TFieldName | - | The name of the input being registered from the form |
defaultChecked | boolean | - | If true, the toggle switch is checked initially, for uncontrolled mode, mutually exclusive with |
disabled | boolean |
| If true, the toggle switch is disabled |
onChange | ChangeEventHandler<HTMLInputElement> | - | The change event handler |
#Outside of a form
Name | Type | Default | Description | Controls |
---|---|---|---|---|
children * | ReactNode | - | Label for the toggle switch | |
checked | boolean | - | If true, the toggle switch is checked, mutually exclusive with | |
defaultChecked | boolean | - | If true, the toggle switch is checked initially, for uncontrolled mode, mutually exclusive with | |
disabled | boolean |
| If true, the toggle switch is disabled | |
onChange | ChangeEventHandler<HTMLInputElement> | - | The change event handler | - |
import { ToggleSwitch } from "@blocks/form";
export const SimpleSwitch = () => <ToggleSwitch>Label</ToggleSwitch>;
#Colors
- Token
BORDER_ACTIVATED_FOCUS
#0003#fff4#0003#fff4BORDER_FOCUS
#0003#fff4#0003#fff4LABEL_TEXT
#000#fff#000#fffLABEL_TEXT_ACTIVATED
#000#fff#000#fffLABEL_TEXT_ACTIVATED_DISABLED
#000#fff#000#fffLABEL_TEXT_ACTIVATED_FOCUS
#000#fff#000#fffLABEL_TEXT_DISABLED
#000#fff#000#fffLABEL_TEXT_FOCUS
#000#fff#000#fffSWITCH
#fff#111#fff#111SWITCH_ACTIVATED
#fff#111#fff#111SWITCH_ACTIVATED_DISABLED
#fff#111#fff#111SWITCH_ACTIVATED_FOCUS
#fff#111#fff#111SWITCH_DISABLED
#fff#111#fff#111SWITCH_FOCUS
#fff#111#fff#111TOGGLE
#bbb#fff#bbb#fffTOGGLE_ACTIVATED
#7c4#8d6#059#17cTOGGLE_ACTIVATED_DISABLED
#7c4#8d6#059#17cTOGGLE_ACTIVATED_FOCUS
#7c4#8d6#059#17cTOGGLE_DISABLED
#bbb#fff#bbb#fffTOGGLE_FOCUS
#bbb#fff#bbb#fff