shoelace/docs/components/tag.md

148 wiersze
3.0 KiB
Markdown
Czysty Zwykły widok Historia

2020-07-15 21:30:37 +00:00
# Tag
[component-header:sl-tag]
Tags are used as labels to organize things or to indicate a selection.
```html preview
2021-12-13 22:38:40 +00:00
<sl-tag variant="primary">Primary</sl-tag>
<sl-tag variant="success">Success</sl-tag>
<sl-tag variant="neutral">Neutral</sl-tag>
<sl-tag variant="warning">Warning</sl-tag>
<sl-tag variant="danger">Danger</sl-tag>
2020-07-15 21:30:37 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlTag } from '@shoelace-style/shoelace/dist/react';
const App = () => (
<>
2021-12-13 22:38:40 +00:00
<SlTag variant="primary">Primary</SlTag>
<SlTag variant="success">Success</SlTag>
<SlTag variant="neutral">Neutral</SlTag>
<SlTag variant="warning">Warning</SlTag>
2022-03-02 15:10:41 +00:00
<SlTag variant="danger">Danger</SlTag>
2021-11-04 22:12:47 +00:00
</>
);
```
2020-07-15 21:30:37 +00:00
## Examples
2020-08-25 20:23:33 +00:00
### Sizes
2020-07-15 21:30:37 +00:00
2021-07-08 21:41:10 +00:00
Use the `size` attribute to change a tab's size.
2020-07-15 21:30:37 +00:00
```html preview
<sl-tag size="small">Small</sl-tag>
<sl-tag size="medium">Medium</sl-tag>
<sl-tag size="large">Large</sl-tag>
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlTag } from '@shoelace-style/shoelace/dist/react';
const App = () => (
<>
<SlTag size="small">Small</SlTag>
<SlTag size="medium">Medium</SlTag>
<SlTag size="large">Large</SlTag>
</>
);
```
2020-07-15 21:30:37 +00:00
### Pill
2021-07-08 21:41:10 +00:00
Use the `pill` attribute to give tabs rounded edges.
2020-07-15 21:30:37 +00:00
```html preview
<sl-tag size="small" pill>Small</sl-tag>
<sl-tag size="medium" pill>Medium</sl-tag>
<sl-tag size="large" pill>Large</sl-tag>
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlTag } from '@shoelace-style/shoelace/dist/react';
const App = () => (
<>
2022-03-02 15:10:41 +00:00
<SlTag size="small" pill>
Small
</SlTag>
<SlTag size="medium" pill>
Medium
</SlTag>
<SlTag size="large" pill>
Large
</SlTag>
2021-11-04 22:12:47 +00:00
</>
);
```
2021-10-07 13:52:23 +00:00
### Removable
2020-07-15 21:30:37 +00:00
2021-10-07 13:52:23 +00:00
Use the `removable` attribute to add a remove button to the tag.
2020-07-15 21:30:37 +00:00
```html preview
2021-10-07 13:52:23 +00:00
<div class="tags-removable">
<sl-tag size="small" removable>Small</sl-tag>
<sl-tag size="medium" removable>Medium</sl-tag>
<sl-tag size="large" removable>Large</sl-tag>
2020-07-20 20:20:58 +00:00
</div>
<script>
2021-10-07 13:52:23 +00:00
const div = document.querySelector('.tags-removable');
2020-07-20 20:20:58 +00:00
2021-10-07 13:52:23 +00:00
div.addEventListener('sl-remove', event => {
2020-07-20 20:20:58 +00:00
const tag = event.target;
tag.style.opacity = '0';
2022-03-02 15:10:41 +00:00
setTimeout(() => (tag.style.opacity = '1'), 2000);
2020-07-20 20:20:58 +00:00
});
</script>
<style>
2021-10-07 13:52:23 +00:00
.tags-removable sl-tag {
2020-07-20 20:20:58 +00:00
transition: var(--sl-transition-medium) opacity;
}
</style>
2020-07-15 21:30:37 +00:00
```
2021-11-04 22:12:47 +00:00
```jsx react
import { SlTag } from '@shoelace-style/shoelace/dist/react';
const css = `
.tags-removable sl-tag {
transition: var(--sl-transition-medium) opacity;
}
`;
const App = () => {
function handleRemove(event) {
const tag = event.target;
tag.style.opacity = '0';
2022-03-02 15:10:41 +00:00
setTimeout(() => (tag.style.opacity = '1'), 2000);
2021-11-04 22:12:47 +00:00
}
return (
<>
2021-11-05 14:06:06 +00:00
<div className="tags-removable">
2021-11-04 22:12:47 +00:00
<SlTag size="small" removable onSlRemove={handleRemove}>
Small
</SlTag>
<SlTag size="medium" removable onSlRemove={handleRemove}>
Medium
</SlTag>
<SlTag size="large" removable onSlRemove={handleRemove}>
Large
</SlTag>
</div>
<style>{css}</style>
</>
2022-03-02 15:10:41 +00:00
);
2021-11-04 22:12:47 +00:00
};
```
2020-07-15 21:30:37 +00:00
[component-metadata:sl-tag]