Badge
Badges pop in, a count rolls its digits up or down when the number changes, and a status dot sends out one ring each time the badge's text or count changes.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/badgeThis adds components/keyframery/badge.tsx and its primitive to your project, and installs UI SDK, along with agent-content, which it builds on. The motion tokens are added to your global CSS the first time you install a component.
Usage
import { Badge } from "@/components/keyframery/badge"
export default function Usage() {
return <Badge>New</Badge>
}Examples
Variants
Count
Pass count and the digits roll to each new number. Past max it shows 99+.
Status dot
dot adds a coloured dot before the label, for a status.
Motion
| Move | What you see |
|---|---|
| Pop | A badge pops in from 60% of its size. |
| Roll | A count rolls its digits up or down; a new leading digit rises in. |
| Pop | A status dot sends out one ring when its value changes. |
Timing and springiness follow the motion style you set. To change how fast this badge moves, pass speed:
<Badge speed="fast">
…
</Badge>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--badge-face | Variant surface | --primary / --secondary; destructive 12% (dark 18%); success green 14% (dark 18%) |
--badge-ink | Variant label | --primary-foreground / --secondary-foreground / --foreground / --destructive; success green mix 82% (dark green) |
--badge-border | Outline hairline | --input |
--badge-height | Badge height | 1.25rem |
--badge-gap | Icon and label gap | 0.375rem |
--badge-radius | Corners | calc(infinity * 1px) |
--badge-padding | Horizontal padding | 0.5rem |
--badge-font | Label size | 11px |
API reference
Every part takes className and children, along with the props of the element it renders. The parts are rendered by UI SDK, so they also take render, to draw your own element, and a function of their state for className and style.
Badge
Renders a <span>, and takes its props too.
Prop
Type
Roll
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
BadgeDot: a<span>
Accessibility
Roles, keyboard and focus are declared on the component's UI SDK primitive, and state is announced through the matching ARIA attributes. More in Accessibility.
Built on UI SDK's core
UI SDK doesn't ship a badge, so this one is defined with its core: one definePrimitive in components/keyframery/core/badge-core.ts, with no React in it. UI SDK's adapters can render that same definition in Vue, Svelte, Solid and web components. To keep your own styling and take only the motion, import from @/components/keyframery/primitives/badge.
Questions
How does the animated Badge for UI SDK move?
Pop: A badge pops in from 60% of its size. Roll: A count rolls its digits up or down; a new leading digit rises in. Pop: A status dot sends out one ring when its value changes.
Do I need Motion or Framer Motion for the animated Badge?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
UI SDK has no badge. How is this one built on UI SDK?
Its behaviour is one definition written with UI SDK's core (definePrimitive), in components/keyframery/core/badge-core.ts. Its parts are rendered by UI SDK's adapter, so they take render, state-based class names and data-slot, like every UI SDK component.
What happens to the Badge when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.