Switch
The Switch
component is a toggle switch that you can use to enable or
disable a setting or feature in your application. It’s especially useful to
let users turn something on or off or when you have any binary option that
users need to switch between.
Usage
To use the component, import the Switch
from the package:
Then, you can use it in your application by adding the Switch
component with the label
prop to provide the label for the switch input:
Selected
You can set the switch input to be selected by default by adding the defaultSelected
prop to the Switch
component. This will make the switch appear as when it’s toggled on. Users will be able to toggle it off if they want.
If you control the selected state through an external state, you can use the isSelected
prop instead to set the selected state of the switch input:
Disabled
You can disable the switch input by adding the isDisabled
prop to the Switch
component. This will disable the entire switch input. It will appear grayed out and users won’t be able to navigate the input, interact or toggle the switch:
Read-only
You can set the switch input as read-only by adding the isReadOnly
prop to the Switch
component. This will prevent the user from changing the switch state. The switch will still appear interactive, but users won’t be able to toggle it.
Description
You can add a description to the switch input to provide more context to the user. You can do this by adding the description
prop to the Switch
component:
Styles
The Switch
component has static classes, prefixed with .kubrick-Switch-
. You can use these static classes to
select and customize the component and its elements.
Selector | Description |
---|---|
root | The component root element. |
input | The element on the `Switch` component that appears as the input. |
label | The element that wraps the label text. |
description | The element that wraps the description text. |
Events
The Switch
component has static classes, prefixed with .kubrick-Switch-
. You can use these static classes to
select and customize the component and its elements.
Selector | Description |
---|---|
onChange | Triggered when the user toggles the switch input on and off. The function callback will receive the new selected state as a boolean. |