shoelace/docs/components/switch.md

78 wiersze
1.5 KiB
Markdown
Czysty Zwykły widok Historia

2020-07-15 21:30:37 +00:00
# Switch
[component-header:sl-switch]
Switches allow the user to toggle an option on or off.
```html preview
2020-08-24 14:02:45 +00:00
<sl-switch>Switch</sl-switch>
2020-07-15 21:30:37 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlSwitch } from '@shoelace-style/shoelace/dist/react';
const App = () => (
<SlSwitch>Switch</SlSwitch>
);
```
?> This component works with standard `<form>` elements. Please refer to the section on [form controls](/getting-started/form-controls) to learn more about form submission and client-side validation.
2020-07-15 21:30:37 +00:00
## Examples
### Checked
Use the `checked` attribute to activate the switch.
```html preview
<sl-switch checked>Checked</sl-switch>
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlSwitch } from '@shoelace-style/shoelace/dist/react';
const App = () => (
<SlSwitch checked>Checked</SlSwitch>
);
```
2020-07-15 21:30:37 +00:00
### Disabled
Use the `disabled` attribute to disable the switch.
```html preview
<sl-switch disabled>Disabled</sl-switch>
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlSwitch } from '@shoelace-style/shoelace/dist/react';
const App = () => (
<SlSwitch disabled>Disabled</SlSwitch>
);
```
### Custom Size
Use the available custom properties to make the switch a different size.
```html preview
2020-12-22 14:40:11 +00:00
<sl-switch style="--width: 80px; --height: 32px; --thumb-size: 26px;"></sl-switch>
```
2020-07-15 21:30:37 +00:00
2021-11-04 22:12:47 +00:00
```jsx react
import { SlSwitch } from '@shoelace-style/shoelace/dist/react';
const App = () => (
<SlSwitch
style={{
'--width': '80px',
'--height': '32px',
'--thumb-size': '26px'
}}
/>
);
```
2020-07-15 21:30:37 +00:00
[component-metadata:sl-switch]