Skip to main content

Switch

Usage

Example


import { useState } from 'react';
import Switch from '@mavvy/m3-ui/Switch';

export function SwitchExample() {
const [selected, setSelected] = useState(false);

const handleClick = () => {
setSelected((value) => !value);
}

return (
<Switch
onClick={handleClick}
selected={selected}
color="primary"
/>
);
}

With Icon Example

export function SwitchExampleIcon() {
const [selected, setSelected] = useState(false);

const handleClick = () => {
setSelected((value) => !value);
}

return (
<List>
<Switch
onClick={handleClick}
selected={selected}
color="primary"
inactiveIcon="light_mode"
activeIcon='dark_mode'
/>
</List>
);
}
light_mode

Props

proptypedescription
selectedbooleanrequired. if true will show a selected state
onClick(event)=>voidon click handler
labelstringswitch component label
colorcolorswitch component color
disabledbooleanif true, disables the switch component
activeIconstringicon name to display if the state is selected
inactiveIconstringicon name to display if the state is not selected
activeIconPropsIconPropsprops of the Icon Component of the active icon
inactiveIconPropsIconPropsprops of the Icon Component of the inactive icon