Skip to main content

Switch

import { Switch } from '@enmovil/ui-design-system';

An on/off toggle with Enmovil colour variants. It can show labels inside the switch for the on and off states.

Properties​

PropertyTypeRequiredDefaultAllowed valuesDescription
variantstringNo'default''primary', 'default', 'secondary'Colour of the switch when it is on: default (grey), primary (primary colour) or secondary (success green). Defaults to default.
classNamestringNo——Extra CSS class added to the switch.
defaultCheckedbooleanNo——Whether the switch starts on when its state is not controlled with checked.
checkedChildrenReactNodeNo——Content shown inside the switch when it is on, such as "ON".
unCheckedChildrenReactNodeNo——Content shown inside the switch when it is off, such as "OFF".
disabledbooleanNo——Disables the switch, so it cannot be toggled.
Other attributes

Switch passes 12 further attributes through to the underlying element. They aren't part of the supported API and may change between releases, so use only the properties listed on this page.

Events​

NameSignatureWhen it fires
onChangeSwitchChangeEventHandlerFires when the switch is toggled, with the new checked state.
onClickSwitchChangeEventHandlerFires on every click, with the new checked state.
onFocusFocusEventHandler<HTMLButtonElement>Fires when the switch receives focus.
onBlurFocusEventHandler<HTMLButtonElement>Fires when the switch loses focus.
onMouseEnterMouseEventHandler<HTMLButtonElement>Fires when the pointer enters the switch.
onMouseLeaveMouseEventHandler<HTMLButtonElement>Fires when the pointer leaves the switch.

Children​

Switch does not accept children.

Variants​

Loading examples…

Playground​

Change the controls to see how the properties affect the component. Values the controls don't cover come from the Default Switch example.

Loading playground…

Storybook​

Open Switch in Storybook to try every story with the full set of controls.