Switch
This component toggles the state of a single item from on to off or from one criteria to another.
Basic Usage
import { Switch, SwitchInput, SwitchLabel } from '@krakentech/coral';
<Switch>
<Stack alignItems="center">
<SwitchInput />
<SwitchLabel label="Switch" />
</Stack>
</Switch>Properties
checked
const [isChecked, setIsChecked] = useState(true);
const onChange = (e: any) => {
setIsChecked(e.target.checked);
};
<Switch checked={isChecked} onChange={onChange}>
<SwitchInput />
</Switch>
<Button size="small" onClick={() => setIsChecked(!isChecked)}>
{isChecked ? 'Uncheck' : 'Check'}
</Button>disabled
<Switch disabled>
<Stack alignItems="center">
<SwitchInput />
<SwitchLabel label="Switch" />
</Stack>
</Switch>error / errorMessage
<Switch error errorMessage="Please check this option">
<Stack alignItems="center">
<SwitchInput />
<SwitchLabel label="Switch" />
</Stack>
</Switch>Please check this option
behaviour
<Switch behaviour="toggle">
<Stack alignItems="center">
<SwitchLabel label="Switch" />
<SwitchInput />
<SwitchLabel label="Switch" />
</Stack>
</Switch>theme
<Switch theme="secondary500">
<Stack alignItems="center">
<SwitchLabel label="Switch" />
<SwitchInput />
<SwitchLabel label="Switch" />
</Stack>
</Switch>Event Handling
<Switch
disabled
onChange={(event, isChecked) => {}}
onBlur={() => {}}
>
<SwitchInput />
</Switch>Full API
Design
Good to know
Choose a switch if you want a user to easily toggle between one option to another for example: Electricity OR Gas and Electricity. Using a switch should make it super easy for a user to compare available options such a seeing the prices for an electric only tariff compared to a gas and electric tariff.
Component breakdown
- Colour: Voltage & Ice
- Label: Body 2
Last updated on