Tag
<mf-tag> | MfTag
Tags are used as labels to organize things or to indicate a selection.
<mf-tag variant="primary">Primary</mf-tag> <mf-tag variant="success">Success</mf-tag> <mf-tag variant="neutral">Neutral</mf-tag> <mf-tag variant="warning">Warning</mf-tag> <mf-tag variant="danger">Danger</mf-tag>
import MfTag from 'maf-ui-kit/dist/react/tag'; const App = () => ( <> <MfTag variant="primary">Primary</MfTag> <MfTag variant="success">Success</MfTag> <MfTag variant="neutral">Neutral</MfTag> <MfTag variant="warning">Warning</MfTag> <MfTag variant="danger">Danger</MfTag> </> );
Examples
Sizes
Use the size attribute to change a tab’s size.
<mf-tag size="small">Small</mf-tag> <mf-tag size="medium">Medium</mf-tag> <mf-tag size="large">Large</mf-tag>
import MfTag from 'maf-ui-kit/dist/react/tag'; const App = () => ( <> <MfTag size="small">Small</MfTag> <MfTag size="medium">Medium</MfTag> <MfTag size="large">Large</MfTag> </> );
Pill
Use the pill attribute to give tabs rounded edges.
<mf-tag size="small" pill>Small</mf-tag> <mf-tag size="medium" pill>Medium</mf-tag> <mf-tag size="large" pill>Large</mf-tag>
import MfTag from 'maf-ui-kit/dist/react/tag'; const App = () => ( <> <MfTag size="small" pill> Small </MfTag> <MfTag size="medium" pill> Medium </MfTag> <MfTag size="large" pill> Large </MfTag> </> );
Removable
Use the removable attribute to add a remove button to the tag.
<div class="tags-removable"> <mf-tag size="small" removable>Small</mf-tag> <mf-tag size="medium" removable>Medium</mf-tag> <mf-tag size="large" removable>Large</mf-tag> </div> <script> const div = document.querySelector('.tags-removable'); div.addEventListener('mf-remove', event => { const tag = event.target; tag.style.opacity = '0'; setTimeout(() => (tag.style.opacity = '1'), 2000); }); </script> <style> .tags-removable mf-tag { transition: var(--mf-transition-medium) opacity; } </style>
import MfTag from 'maf-ui-kit/dist/react/tag'; const css = ` .tags-removable mf-tag { transition: var(--mf-transition-medium) opacity; } `; const App = () => { function handleRemove(event) { const tag = event.target; tag.style.opacity = '0'; setTimeout(() => (tag.style.opacity = '1'), 2000); } return ( <> <div className="tags-removable"> <MfTag size="small" removable onMfRemove={handleRemove}> Small </MfTag> <MfTag size="medium" removable onMfRemove={handleRemove}> Medium </MfTag> <MfTag size="large" removable onMfRemove={handleRemove}> Large </MfTag> </div> <style>{css}</style> </> ); };
Importing
If you’re using the autoloader or the traditional loader, you can ignore this section. Otherwise, feel free to use any of the following snippets to cherry pick this component.
To import this component from the CDN using a script tag:
<script type="module" src="https://cdn.jsdelivr.net/npm/maf-ui-kit@0.0.1/cdn/components/tag/tag.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://cdn.jsdelivr.net/npm/maf-ui-kit@0.0.1/cdn/components/tag/tag.js';
To import this component using a bundler:
import 'maf-ui-kit/dist/components/tag/tag.js';
To import this component as a React component:
import MfTag from 'maf-ui-kit/dist/react/tag';
slots
| Name | Description |
|---|---|
| (default) | The tag’s content. |
Learn more about using slots.
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
variant
|
The tag’s theme variant. |
|
'primary' | 'success' | 'neutral' | 'warning' | 'danger' | 'text'
|
'neutral'
|
size
|
The tag’s size. |
|
'small' | 'medium' | 'large'
|
'medium'
|
pill
|
Draws a pill-style tag with rounded edges. |
|
boolean
|
false
|
removable
|
Makes the tag removable and shows a remove button. |
boolean
|
false
|
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Events
| Name | React Event | Description | Event Detail |
|---|---|---|---|
mf-remove |
onMfRemove |
Emitted when the remove button is activated. | - |
Learn more about events.
Parts
| Name | Description |
|---|---|
base |
The component’s base wrapper. |
content |
The tag’s content. |
remove-button |
The tag’s remove button, an <mf-icon-button>. |
remove-button__base |
The remove button’s exported base part. |
Learn more about customizing CSS parts.
Dependencies
This component automatically imports the following dependencies.
<mf-icon><mf-icon-button>