Skip to main content

Switch

Import

To add the Switch component to your project you can import it as follows:

import {Switch} from '@amalgamaco/embassy-ui'; 

Standalone

Example

import { Switch } from '@amalgamaco/embassy-ui';

<Switch/>

Props

initialValue

Sets the initial value of the switch.

TYPEREQUIREDDEFAULT
booleanNofalse
import { Switch } from '@amalgamaco/embassy-ui';

<Switch/>
<Switch initialValue={true}/>

disabled

If the Switch is disabled or not.

TYPEREQUIREDDEFAULT
booleanNofalse
import { Switch } from '@amalgamaco/embassy-ui';

<Switch disabled/>
<Switch disabled initialValue={true}/>

onChange

Callback that is called when the value of the switch changes.

TYPEREQUIREDDEFAULT
functionNo-
import { Switch } from '@amalgamaco/embassy-ui';

<Switch onChange={(value) => window.alert(`The switch is ${value ? "on" : "off"}`}/>

withIcon

If the switch should have an on/off icon.

TYPEREQUIREDDEFAULT
booleanNotrue

import { Switch } from '@amalgamaco/embassy-ui';

<Switch withIcon={false}/>

onIcon

The icon to be displayed when the switch is on.

TYPEREQUIREDDEFAULT
JSX.ElementNo"check"
import { Switch, Icon } from '@amalgamaco/embassy-ui';

<Switch onIcon={<Icon name="star"/>} initialValue={true}/>

offIcon

The icon to be displayed when the switch is off.

TYPEREQUIREDDEFAULT
JSX.ElementNo"x"
import { Switch, Icon } from '@amalgamaco/embassy-ui';

<Switch offIcon={<Icon name="rocket"/>}/>

animationDuration

The duration of the thumb slide animation.

TYPEREQUIREDDEFAULT
numberNo500
import { Switch } from '@amalgamaco/embassy-ui';

<Switch animationDuration={2000}/>

Pseudo Props

__switchContainer

Props to be applied to the container of the switch.

TYPEREQUIRED
IBoxPropsNo

__icon

Props to be applied to the internal Icon component showing the right icon.

TYPEREQUIRED
IIconPropsNo

__iconContainer

Props to be applied to the internal Box component which contains the label and the icons.

TYPEREQUIRED
IBoxPropsNo