Switch

Switches are used for switching between two states or an on-off state.

Example

Sizes

To have the larger or smaller switches, use the size property.

Controlled Switches

You can use the checked, and onChange properties to control the behaviour of the switch.

API

Learn more about the properties and the customization points.

Usage

import Switch from "@sonnat/ui/Switch";
//or
import { Switch } from "@sonnat/ui";

Properties

Note that the documentation avoids mentioning all the native props (there are a lot) in this section of the components.

Switch Properties
NameTypeDefaultDescription
classNamestring-Append to the class names applied to the component so you can override or extend the styles.
labelstring-If label was provided, a <label> element will be rendered next to the switch.
namestring-The name of the switch.
valuestring-The value of the switch. The DOM API casts this to a string.
The browser uses "on" as the default value.
size"large"
| "medium"
| "small"
"medium"The size of the switch.
autoFocusbooleanfalseIf true, the switch will be focused automatically.
fluidbooleanfalseIf true, the switch will fill the entire width of the parent.
readOnlybooleanfalseIf true, the switch will be read-only.
checkedboolean-If true, the switch will be checked.
defaultCheckedboolean-The default state of checked. Use when the component is not controlled.
disabledbooleanfalseIf true, the switch will be disabled.
requiredbooleanfalseIf true, the switch will be required.
hasErrorbooleanfalseIf true, the switch will indicate invalid input.
inputPropsobject-The properties applied to the input element.
labelPropsobject-The properties applied to the label element.
onChangefunction-The callback fires when the state has changed.
Signature: function(checkedState: boolean) => void
  • The ref is forwarded to the root element.
  • Any other properties supplied will be provided to the root element.