mirror of
https://github.com/shoelace-style/webawesome.git
synced 2026-01-12 12:09:26 +00:00
2.0 KiB
2.0 KiB
meta, layout
| meta | layout | ||||
|---|---|---|---|---|---|
|
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 %}