Badge
A small label for a status, a count or a category.
Installation
Needs the arene setup first.
Install the packages it imports:
Set up the token layer and the StyleX compiler, if you have not already. See
Installation, and paste states.ts from the same page.
The badge's focus ring and invalid ring come from it. The badge also needs
interop.css, which sizes the icon.
Paste this source into the file named in its title.
Change the @/ imports if your project uses different aliases.
Usage
Variants
Pick a style with variant.
With icon
Set iconPosition to the side the icon is on, so the badge tightens its
padding there.
Loading
Render a Spinner and set iconPosition to its
side.
Link
Pass render to change the element the badge renders.
Badges have no built-in hover styles. Add a hover through xstyle when using
render for a link or another interactive element.
Custom colors
Pass xstyle to change the background, border and text colors.
API reference
Pass render to replace a part's element or compose it with another component.
Badge
Renders a span through Base UI's
useRender, so it accepts
render alongside every span attribute.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "secondary" | "destructive" | "outline" | "ghost" | "link" | "default" |
iconPosition | "start" | "end" | "both" | — |
render | ReactElement | ((props, state) => ReactElement) | <span /> |
xstyle | StyleXStyles | — |
className | string | — |
xstyle is merged last, so it beats the variant. className is concatenated
with no conflict resolution. Use it for plain-CSS hooks.
Setting aria-invalid switches the border and ring to the destructive pair.
badgeStyles
The style maps behind Badge. Spread them onto any element:
Merge className from the stylex.props() result by hand. A second
className attribute beside the spread replaces it.
| Key | What it is |
|---|---|
base | Shape and type, with the shared focus ring |
variants | One namespace per variant |
iconStart | Leading-icon padding |
iconEnd | Trailing-icon padding |
base is two styles, the badge's own and the shared states.focusRing. Set a
border of your own through --arene-border-color rather than borderColor. A
flat borderColor replaces the property with all of its conditions, so the ring loses its focus colour.
Keep the arene-icons class. interop.css sizes icons off it, and without it
a Phosphor icon keeps its default 1em size.
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-slot="badge" | the badge | Targets the badge from a parent |
data-variant | the badge | Reflects the variant prop, for styling from a parent |
CSS variables
| Variable | On | Effect |
|---|---|---|
--arene-icon-size | the badge | The icon's size, read by interop.css. Defaults to 12px |
--arene-border-color | the badge | The resting border colour the focus ring reads. outline sets it |