Badge
This page is currently under construction
Lism UI (@lism-css/ui) is still in preparation.
A component for displaying badges.
Overview
↓
Preview
BadgeBadge
<Cluster g="15"> <Badge>Badge</Badge> <Badge variant="outline">Badge</Badge></Cluster><div class="l--cluster -g:15"> <span class="b--badge">Badge</span> <span class="b--badge b--badge--outline">Badge</span></div>Styles
The Badge base styles are defined in the following CSS.
_style.css
@layer lism-block {
.b--badge {
--c: var(--base);
--bgc: var(--text);
--bdc: transparent;
--bdw: 1px;
--hl: var(--hl--xs);
display: inline-flex;
color: var(--c);
background-color: var(--bgc);
font-size: var(--fz--xs);
padding: 0.25em 0.5em;
gap: 0.375em;
border-radius: var(--bdrs--99);
/* 異なる variant を並べてもサイズに差が出ないようにborderを常に指定 */
border: solid var(--bdw) var(--bdc);
/* u--cboxと併用した時に関連する変数 */
--cbox-cPct: 75%;
}
.b--badge--outline {
--c: var(--text);
--bgc: transparent;
--bdc: currentColor;
}
} The full source code is available on GitHub.
Usage
Provided as Badge (b--badge) from the @lism-css/ui package.
Import
import { Badge } from '@lism-css/ui/react'; import { Badge } from '@lism-css/ui/astro'; <link href="https://cdn.jsdelivr.net/npm/@lism-css/ui@0.30.0/dist/style.css" rel="stylesheet" /> Props
| Prop | Description |
|---|---|
variant |
Outputs the b--badge--{variant} class. An outline style is provided by default. |
Examples
Using the color palette
↓
Example
BadgeBadgeBadgeBadgeBadgeBadgeBadgeBadgeBadge
<Cluster g="15"> <Badge>Badge</Badge> <Badge bgc="red">Badge</Badge> <Badge bgc="orange">Badge</Badge> <Badge bgc="yellow">Badge</Badge> <Badge bgc="green">Badge</Badge> <Badge bgc="blue">Badge</Badge> <Badge bgc="purple">Badge</Badge> <Badge bgc="pink">Badge</Badge> <Badge bgc="gray">Badge</Badge></Cluster><div class="l--cluster -g:15"> <span class="b--badge">Badge</span> <span class="b--badge -bgc" style="--bgc: var(--red)">Badge</span> <span class="b--badge -bgc" style="--bgc: var(--orange)">Badge</span> ...</div>variant: outline
An outline style is available out of the box.
↓
variant='outline'BadgeBadgeBadgeBadgeBadgeBadgeBadgeBadgeBadge
<Cluster g="15"> <Badge variant="outline">Badge</Badge> <Badge variant="outline" c="red">Badge</Badge> <Badge variant="outline" c="orange">Badge</Badge> ...</Cluster><div class="l--cluster -g:15"> <span class="b--badge b--badge--outline">Badge</span> <span class="b--badge b--badge--outline -c" style="--c: var(--red)">Badge</span> <span class="b--badge b--badge--outline -c" style="--c: var(--orange)">Badge</span> ...</div>Using with u--cbox
↓
Styling example using the
u--cbox classRedOrangeYellowGreenBluePurplePinkGray
<Cluster g="15"> <Badge util="cbox" keycolor="red">Red</Badge> <Badge util="cbox" keycolor="orange">Orange</Badge> <Badge util="cbox" keycolor="yellow">Yellow</Badge> ...</Cluster><div class="l--cluster -g:15"> <span class="b--badge u--cbox" style="--keycolor: var(--red)">Red</span> <span class="b--badge u--cbox" style="--keycolor: var(--orange)">Orange</span> <span class="b--badge u--cbox" style="--keycolor: var(--yellow)">Yellow</span> ...</div>Adjusting styles
Since the padding is defined in em units, changing the font size with fz scales the whole badge accordingly. The border radius can be adjusted with bdrs.
↓
Adjusting size
BadgeBadgeBadge
<Cluster g="15" ai="center"> <Badge>Badge</Badge> <Badge fz="s">Badge</Badge> <Badge fz="m">Badge</Badge></Cluster><div class="l--cluster -g:15 -ai:center"> <span class="b--badge">Badge</span> <span class="b--badge -fz:s">Badge</span> <span class="b--badge -fz:m">Badge</span></div> ↓
Adjusting border radius
BadgeBadgeBadge
<Cluster g="15" ai="center"> <Badge>Badge</Badge> <Badge bdrs="10">Badge</Badge> <Badge bdrs="0">Badge</Badge></Cluster><div class="l--cluster -g:15 -ai:center"> <span class="b--badge">Badge</span> <span class="b--badge -bdrs:10">Badge</span> <span class="b--badge -bdrs:0">Badge</span></div>Using with an icon
↓
Example
BadgeBadge
import { CheckIcon, TagIcon } from '@lism-css/icons/react';
<Cluster g="15" ai="center"> <Badge ai="center"> <Icon icon={CheckIcon} />Badge</Badge> <Badge variant="outline" ai="center"> <Icon icon={TagIcon} />Badge</Badge></Cluster><div class="l--cluster -g:15 -ai:center"> <span class="b--badge -ai:center"> <svg class="a--icon" aria-hidden="true">...</svg>Badge </span> <span class="b--badge b--badge--outline -ai:center"> <svg class="a--icon" aria-hidden="true">...</svg>Badge </span></div>Without @lism-css/ui
This example builds a Badge with lism-css primitives only, without @lism-css/ui.
↓
Example
BadgeBadge
<Cluster g="15"> <Lism as="span" fz="xs" hl="xs" py="5" px="10" bgc="text" c="base" bdrs="99">Badge</Lism> <Lism as="span" fz="xs" hl="xs" py="5" px="10" bd bdc="current" bdrs="99">Badge</Lism></Cluster><div class="l--cluster -g:15"> <span class="-fz:xs -hl:xs -py:5 -px:10 -bgc:text -c:base -bdrs:99">Badge</span> <span class="-fz:xs -hl:xs -py:5 -px:10 -bd -bdc:current -bdrs:99">Badge</span></div>