Badge
<sl-badge> | SlBadge
Badges are used to draw attention and display statuses or counts.
<sl-badge>Primary</sl-badge>
import SlBadge from '@yoummday/ymmd-shoelace/dist/react/badge'; const App = () => <SlBadge>Badge</SlBadge>;
Examples
Variants
Set the variant attribute to change the badge’s variant.
<!-- shoelace's variants--> <sl-badge variant="success">Success</sl-badge> <sl-badge variant="warning">Warning</sl-badge> <sl-badge variant="danger">Danger</sl-badge> <br><br> <!-- yoummday additions --> <sl-badge variant="neutral">Neutral</sl-badge> <sl-badge variant="light">Light</sl-badge> <sl-badge variant="info">Info</sl-badge> <sl-badge variant="dark">Dark</sl-badge> <sl-badge variant="lotuslight">Lotuslight</sl-badge> <sl-badge variant="graylight">Graylight</sl-badge> <sl-badge variant="lotus">Lotus</sl-badge> <sl-badge variant="blue">Blue</sl-badge> <sl-badge variant="gray">Gray</sl-badge> <sl-badge variant="purplelight">Purplelight</sl-badge> <sl-badge variant="greenlight">Greenlight</sl-badge> <sl-badge variant="greenmint">Greenmint</sl-badge> <sl-badge variant="salmon">Salmon</sl-badge> <sl-badge variant="beige">Beige</sl-badge> <sl-badge variant="cyanlight">Cyanlight</sl-badge> <sl-badge variant="pinklight">Pinklight</sl-badge> <sl-badge variant="yellowlight">Yellowlight</sl-badge> <sl-badge variant="purpledark">Purpledark</sl-badge> <sl-badge variant="bluelight">Bluelight</sl-badge> <sl-badge variant="teallight">Teallight</sl-badge> <sl-badge variant="gray2">Gray2</sl-badge> <sl-badge variant="brandlight">Brandlight</sl-badge> <br><br> <sl-badge variant="indicator">Indicator 0%</sl-badge> <sl-badge variant="indicator" style="--indicator-percent: 10%">Indicator 10%</sl-badge> <sl-badge variant="indicator" style="--indicator-percent: 20%">Indicator 20%</sl-badge> <sl-badge variant="indicator" style="--indicator-percent: 30%">Indicator 30%</sl-badge> <sl-badge variant="indicator" style="--indicator-percent: 40%">Indicator 40%</sl-badge> <sl-badge variant="indicator" style="--indicator-percent: 50%">Indicator 50%</sl-badge> <sl-badge variant="indicator" style="--indicator-percent: 60%">Indicator 60%</sl-badge> <sl-badge variant="indicator" style="--indicator-percent: 70%">Indicator 70%</sl-badge> <sl-badge variant="indicator" style="--indicator-percent: 80%">Indicator 80%</sl-badge> <sl-badge variant="indicator" style="--indicator-percent: 90%">Indicator 90%</sl-badge> <sl-badge variant="indicator" style="--indicator-percent: 100%">Indicator 100%</sl-badge>
import SlBadge from '@yoummday/ymmd-shoelace/dist/react/badge'; const App = () => ( <> <SlBadge variant="primary">Primary</SlBadge> <SlBadge variant="success">Success</SlBadge> <SlBadge variant="neutral">Neutral</SlBadge> <SlBadge variant="warning">Warning</SlBadge> <SlBadge variant="danger">Danger</SlBadge> </> );
Pill Badges
Use the pill attribute to give badges rounded edges.
<sl-badge variant="primary" pill>Primary</sl-badge> <sl-badge variant="success" pill>Success</sl-badge> <sl-badge variant="warning" pill>Warning</sl-badge> <sl-badge variant="danger" pill>Danger</sl-badge>
import SlBadge from '@yoummday/ymmd-shoelace/dist/react/badge'; const App = () => ( <> <SlBadge variant="primary" pill> Primary </SlBadge> <SlBadge variant="success" pill> Success </SlBadge> <SlBadge variant="warning" pill> Warning </SlBadge> <SlBadge variant="danger" pill> Danger </SlBadge> </> );
With Icon
Just insert an sl-icon.
<sl-badge variant="primary"><sl-icon name="mdi:emoticon-poop"></sl-icon>Primary</sl-badge> <sl-badge variant="success" pill><sl-icon name="mdi:check"></sl-icon> Success</sl-badge> <sl-badge variant="warning" pill><sl-icon name="mdi:alarm"></sl-icon> Warning</sl-badge> <sl-badge variant="danger" pill>Danger <sl-icon name="mdi:nuke"></sl-icon></sl-badge>
import SlBadge from '@yoummday/ymmd-shoelace/dist/react/badge'; const App = () => ( <> <SlBadge variant="primary" pill> Primary </SlBadge> <SlBadge variant="success" pill> Success </SlBadge> <SlBadge variant="warning" pill> Warning </SlBadge> <SlBadge variant="danger" pill> Danger </SlBadge> </> );
Pulsating Badges
Use the pulse attribute to draw attention to the badge with a subtle animation.
<div class="badge-pulse"> <sl-badge variant="primary" pill pulse>1</sl-badge> <sl-badge variant="success" pill pulse>1</sl-badge> <sl-badge variant="warning" pill pulse>1</sl-badge> <sl-badge variant="danger" pill pulse>1</sl-badge> </div> <style> .badge-pulse sl-badge:not(:last-of-type) { margin-right: 1rem; } </style>
import SlBadge from '@yoummday/ymmd-shoelace/dist/react/badge'; const css = ` .badge-pulse sl-badge:not(:last-of-type) { margin-right: 1rem; } `; const App = () => ( <> <div className="badge-pulse"> <SlBadge variant="primary" pill pulse> 1 </SlBadge> <SlBadge variant="success" pill pulse> 1 </SlBadge> <SlBadge variant="warning" pill pulse> 1 </SlBadge> <SlBadge variant="danger" pill pulse> 1 </SlBadge> </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.
<sl-button> Requests <sl-badge pill>30</sl-badge> </sl-button> <sl-button style="margin-inline-start: 1rem;"> Warnings <sl-badge variant="warning" pill>8</sl-badge> </sl-button> <sl-button style="margin-inline-start: 1rem;"> Errors <sl-badge variant="danger" pill>6</sl-badge> </sl-button>
import SlBadge from '@yoummday/ymmd-shoelace/dist/react/badge'; import SlButton from '@yoummday/ymmd-shoelace/dist/react/button'; const App = () => ( <> <SlButton> Requests <SlBadge pill>30</SlBadge> </SlButton> <SlButton style={{ marginInlineStart: '1rem' }}> Warnings <SlBadge variant="warning" pill> 8 </SlBadge> </SlButton> <SlButton style={{ marginInlineStart: '1rem' }}> Errors <SlBadge variant="danger" pill> 6 </SlBadge> </SlButton> </> );
With Menu Items
When including badges in menu items, use the suffix slot to make sure they’re aligned
correctly.
<sl-menu style="max-width: 240px;"> <sl-menu-label>Messages</sl-menu-label> <sl-menu-item>Comments <sl-badge slot="suffix" variant="neutral" pill>4</sl-badge></sl-menu-item> <sl-menu-item>Replies <sl-badge slot="suffix" variant="neutral" pill>12</sl-badge></sl-menu-item> </sl-menu>
import SlBadge from '@yoummday/ymmd-shoelace/dist/react/badge'; import SlButton from '@yoummday/ymmd-shoelace/dist/react/button'; import SlMenu from '@yoummday/ymmd-shoelace/dist/react/menu'; import SlMenuItem from '@yoummday/ymmd-shoelace/dist/react/menu-item'; import SlMenuLabel from '@yoummday/ymmd-shoelace/dist/react/menu-label'; const App = () => ( <SlMenu style={{ maxWidth: '240px', border: 'solid 1px var(--sl-panel-border-color)', borderRadius: 'var(--sl-border-radius-medium)' }} > <SlMenuLabel>Messages</SlMenuLabel> <SlMenuItem> Comments <SlBadge slot="suffix" variant="neutral" pill> 4 </SlBadge> </SlMenuItem> <SlMenuItem> Replies <SlBadge slot="suffix" variant="neutral" pill> 12 </SlBadge> </SlMenuItem> </SlMenu> );
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://v2-48-10.yoummday-theme.pages.dev/components/badge/badge.js"></script>
To import this component from the CDN using a JavaScript import:
import 'https://v2-48-10.yoummday-theme.pages.dev/components/badge/badge.js';
To import this component using a bundler:
import '@yoummday/ymmd-shoelace/dist/components/badge/badge.js';
To import this component as a React component:
import SlBadge from '@yoummday/ymmd-shoelace/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. |
|
Variant
|
'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.
Custom Properties
| Name | Description | Default |
|---|---|---|
--indicator-percent |
The percentage of green when variant is indicator. |
Learn more about customizing CSS custom properties.
Parts
| Name | Description |
|---|---|
base |
The component’s base wrapper. |
Learn more about customizing CSS parts.