Badge
<mf-badge> | MfBadge
Badges are used to draw attention and display statuses or counts.
<mf-badge>Badge</mf-badge>
import MfBadge from 'maf-ui-kit/dist/react/badge'; const App = () => <MfBadge>Badge</MfBadge>;
Examples
Variants
Set the variant attribute to change the badge’s variant.
<mf-badge variant="primary">Primary</mf-badge> <mf-badge variant="success">Success</mf-badge> <mf-badge variant="neutral">Neutral</mf-badge> <mf-badge variant="warning">Warning</mf-badge> <mf-badge variant="danger">Danger</mf-badge>
import MfBadge from 'maf-ui-kit/dist/react/badge'; const App = () => ( <> <MfBadge variant="primary">Primary</MfBadge> <MfBadge variant="success">Success</MfBadge> <MfBadge variant="neutral">Neutral</MfBadge> <MfBadge variant="warning">Warning</MfBadge> <MfBadge variant="danger">Danger</MfBadge> </> );
Pill Badges
Use the pill attribute to give badges rounded edges.
<mf-badge variant="primary" pill>Primary</mf-badge> <mf-badge variant="success" pill>Success</mf-badge> <mf-badge variant="neutral" pill>Neutral</mf-badge> <mf-badge variant="warning" pill>Warning</mf-badge> <mf-badge variant="danger" pill>Danger</mf-badge>
import MfBadge from 'maf-ui-kit/dist/react/badge'; const App = () => ( <> <MfBadge variant="primary" pill> Primary </MfBadge> <MfBadge variant="success" pill> Success </MfBadge> <MfBadge variant="neutral" pill> Neutral </MfBadge> <MfBadge variant="warning" pill> Warning </MfBadge> <MfBadge variant="danger" pill> Danger </MfBadge> </> );
Pulsating Badges
Use the pulse attribute to draw attention to the badge with a subtle animation.
<div class="badge-pulse"> <mf-badge variant="primary" pill pulse>1</mf-badge> <mf-badge variant="success" pill pulse>1</mf-badge> <mf-badge variant="neutral" pill pulse>1</mf-badge> <mf-badge variant="warning" pill pulse>1</mf-badge> <mf-badge variant="danger" pill pulse>1</mf-badge> </div> <style> .badge-pulse mf-badge:not(:last-of-type) { margin-right: 1rem; } </style>
import MfBadge from 'maf-ui-kit/dist/react/badge'; const css = ` .badge-pulse mf-badge:not(:last-of-type) { margin-right: 1rem; } `; const App = () => ( <> <div className="badge-pulse"> <MfBadge variant="primary" pill pulse> 1 </MfBadge> <MfBadge variant="success" pill pulse> 1 </MfBadge> <MfBadge variant="neutral" pill pulse> 1 </MfBadge> <MfBadge variant="warning" pill pulse> 1 </MfBadge> <MfBadge variant="danger" pill pulse> 1 </MfBadge> </div> <style>{css}</style> </> );
With Buttons
One of the most common use cases for badges is attaching them to buttons. To make this easier, badges will be automatically positioned at the top-right when they’re a child of a button.
<mf-button> Requests <mf-badge pill>30</mf-badge> </mf-button> <mf-button style="margin-inline-start: 1rem;"> Warnings <mf-badge variant="warning" pill>8</mf-badge> </mf-button> <mf-button style="margin-inline-start: 1rem;"> Errors <mf-badge variant="danger" pill>6</mf-badge> </mf-button>
import MfBadge from 'maf-ui-kit/dist/react/badge'; import MfButton from 'maf-ui-kit/dist/react/button'; const App = () => ( <> <MfButton> Requests <MfBadge pill>30</MfBadge> </MfButton> <MfButton style={{ marginInlineStart: '1rem' }}> Warnings <MfBadge variant="warning" pill> 8 </MfBadge> </MfButton> <MfButton style={{ marginInlineStart: '1rem' }}> Errors <MfBadge variant="danger" pill> 6 </MfBadge> </MfButton> </> );
With Menu Items
When including badges in menu items, use the suffix slot to make sure they’re aligned
correctly.
<mf-menu style="max-width: 240px;"> <mf-menu-label>Messages</mf-menu-label> <mf-menu-item>Comments <mf-badge slot="suffix" variant="neutral" pill>4</mf-badge></mf-menu-item> <mf-menu-item>Replies <mf-badge slot="suffix" variant="neutral" pill>12</mf-badge></mf-menu-item> </mf-menu>
import MfBadge from 'maf-ui-kit/dist/react/badge'; import MfButton from 'maf-ui-kit/dist/react/button'; import MfMenu from 'maf-ui-kit/dist/react/menu'; import MfMenuItem from 'maf-ui-kit/dist/react/menu-item'; import MfMenuLabel from 'maf-ui-kit/dist/react/menu-label'; const App = () => ( <MfMenu style={{ maxWidth: '240px', border: 'solid 1px var(--mf-panel-border-color)', borderRadius: 'var(--mf-border-radius-medium)' }} > <MfMenuLabel>Messages</MfMenuLabel> <MfMenuItem> Comments <MfBadge slot="suffix" variant="neutral" pill> 4 </MfBadge> </MfMenuItem> <MfMenuItem> Replies <MfBadge slot="suffix" variant="neutral" pill> 12 </MfBadge> </MfMenuItem> </MfMenu> );
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/badge/badge.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/badge/badge.js';
To import this component using a bundler:
import 'maf-ui-kit/dist/components/badge/badge.js';
To import this component as a React component:
import MfBadge from 'maf-ui-kit/dist/react/badge';
slots
| Name | Description |
|---|---|
| (default) | The badge’s content. |
Learn more about using slots.
Properties
| Name | Description | Reflects | Type | Default |
|---|---|---|---|---|
variant
|
The badge’s theme variant. |
|
'primary' | 'success' | 'neutral' | 'warning' | 'danger'
|
'primary'
|
pill
|
Draws a pill-style badge with rounded edges. |
|
boolean
|
false
|
pulse
|
Makes the badge pulsate to draw attention. |
|
boolean
|
false
|
updateComplete |
A read-only promise that resolves when the component has finished updating. |
Learn more about attributes and properties.
Parts
| Name | Description |
|---|---|
base |
The component’s base wrapper. |
Learn more about customizing CSS parts.