Files
webawesome/docs/pages/components/switch.md
Cory LaViska 015429e05d sl => wa
2023-09-08 13:45:49 -04:00

2.0 KiB

meta, layout
meta layout
title description
Switch Switches allow the user to toggle an option on or off.
component
<wa-switch>Switch</wa-switch>
import WaSwitch from '@shoelace-style/shoelace/dist/react/switch';

const App = () => <WaSwitch>Switch</WaSwitch>;

:::tip This component works with standard <form> elements. Please refer to the section on form controls to learn more about form submission and client-side validation. :::

Examples

Checked

Use the checked attribute to activate the switch.

<wa-switch checked>Checked</wa-switch>
import WaSwitch from '@shoelace-style/shoelace/dist/react/switch';

const App = () => <WaSwitch checked>Checked</WaSwitch>;

Disabled

Use the disabled attribute to disable the switch.

<wa-switch disabled>Disabled</wa-switch>
import WaSwitch from '@shoelace-style/shoelace/dist/react/switch';

const App = () => <WaSwitch disabled>Disabled</WaSwitch>;

Sizes

Use the size attribute to change a switch's size.

<wa-switch size="small">Small</wa-switch>
<br />
<wa-switch size="medium">Medium</wa-switch>
<br />
<wa-switch size="large">Large</wa-switch>
import WaSwitch from '@shoelace-style/shoelace/dist/react/switch';

const App = () => (
  <>
    <WaSwitch size="small">Small</WaSwitch>
    <br />
    <WaSwitch size="medium">Medium</WaSwitch>
    <br />
    <WaSwitch size="large">Large</WaSwitch>
  </>
);

Custom Styles

Use the available custom properties to change how the switch is styled.

<wa-switch style="--width: 80px; --height: 40px; --thumb-size: 36px;">Really big</wa-switch>

{% raw %}

import WaSwitch from '@shoelace-style/shoelace/dist/react/switch';

const App = () => (
  <WaSwitch
    style={{
      '--width': '80px',
      '--height': '32px',
      '--thumb-size': '26px'
    }}
  />
);

{% endraw %}