The Badge component is a small status indicator that displays short pieces of information. It's commonly used to show status, categories, counts, or labels in user interfaces.
import { Badge } from '@dashflowx/core'export default function BadgeExample() {return (<Badgetype="span"textContent="New"variant="default"size="md"/>)}
Preview:
NewThe primary badge style with blue background.
<Badgetype="span"textContent="Default"variant="default"size="md"/>
Preview:
DefaultA subtle badge with gray background.
<Badgetype="span"textContent="Secondary"variant="secondary"size="md"/>
Preview:
SecondaryA badge with border and transparent background.
<Badgetype="span"textContent="Outline"variant="outline"size="md"/>
Preview:
OutlineA badge for errors or dangerous actions.
<Badgetype="span"textContent="Error"variant="destructive"size="md"/>
Preview:
Error<Badgetype="span"textContent="Small"variant="default"size="sm"/>
Preview:
Small<Badgetype="span"textContent="Medium"variant="default"size="md"/>
Preview:
Medium<Badgetype="span"textContent="Large"variant="default"size="lg"/>
Preview:
Large| Prop | Type | Default | Description |
|---|---|---|---|
type | any | - | The HTML element type or React component |
textContent | string | JSX.Element | - | The text content of the badge |
variant | 'outline' | 'secondary' | 'default' | 'destructive' | 'outline' | The visual style variant of the badge |
size | 'sm' | 'md' | 'lg' | 'md' | The size of the badge |
icon | JSX.Element | - | Optional icon to display in the badge |
library | 'react' | 'next' | 'react' | The library type for routing |
path | string | - | The path for navigation (when used as link) |
className | string | - | Additional CSS classes for the badge container |
iconClassName | string | - | Additional CSS classes for the icon |
textClassName | string | - | Additional CSS classes for the text content |
import { CheckIcon } from '@heroicons/react/24/outline'<Badgetype="span"textContent="Verified"variant="default"size="md"icon={<CheckIcon className="w-3 h-3" />}/>
Preview:
✓Verified<Badgetype="a"textContent="View Details"variant="outline"size="md"library="next"path="/details"/>
Preview:
View Details<Badgetype="span"textContent="Custom"variant="secondary"size="md"className="bg-purple-100 text-purple-800"textClassName="font-bold"/>
Preview:
Custom<div className="flex gap-2"><Badge type="span" textContent="Active" variant="default" size="md" /><Badge type="span" textContent="Pending" variant="secondary" size="md" /><Badge type="span" textContent="Inactive" variant="outline" size="md" /><Badge type="span" textContent="Error" variant="destructive" size="md" /></div>
Preview:
ActivePendingInactiveError<div className="space-y-2"><div className="flex items-center gap-2"><span>User Status:</span><Badge type="span" textContent="Online" variant="default" size="md" /></div><div className="flex items-center gap-2"><span>Order Status:</span><Badge type="span" textContent="Shipped" variant="secondary" size="md" /></div></div>
<div className="flex flex-wrap gap-2"><Badge type="span" textContent="React" variant="outline" size="md" /><Badge type="span" textContent="TypeScript" variant="outline" size="md" /><Badge type="span" textContent="Next.js" variant="outline" size="md" /></div>
<div className="flex items-center gap-2"><span>Notifications</span><Badge type="span" textContent="5" variant="destructive" size="md" /></div>
<Badgetype="button"textContent="Click me"variant="default"size="md"onClick={() => console.log('Badge clicked')}/>
The Badge component includes proper accessibility features:
- Semantic HTML: Uses appropriate HTML elements based on the
typeprop - Screen readers: Properly announces badge content
- Keyboard navigation: Supports keyboard interaction when used as buttons or links
- Color contrast: Ensures sufficient contrast for all variants
Choose variants that match the content and context.
// ✅ Good - Appropriate variants for different states<Badge type="span" textContent="Success" variant="default" size="md" /><Badge type="span" textContent="Warning" variant="secondary" size="md" /><Badge type="span" textContent="Error" variant="destructive" size="md" />
Use badges consistently throughout your application.
// ✅ Good - Consistent badge usage for status{users.map(user => (<div key={user.id}><span>{user.name}</span><Badgetype="span"textContent={user.status}variant={user.status === 'active' ? 'default' : 'secondary'}size="md"/></div>))}
Use clear, concise text that conveys the intended meaning.
// ❌ Bad - Unclear meaning<Badge type="span" textContent="X" variant="default" size="md" />// ✅ Good - Clear meaning<Badge type="span" textContent="Premium" variant="default" size="md" />
Keep badge content short and concise.
// ❌ Bad - Too long<Badge type="span" textContent="This is a very long badge text that should be avoided" variant="default" size="md" />// ✅ Good - Concise<Badge type="span" textContent="New" variant="default" size="md" />
You can create custom badge styles using CSS classes:
<Badgetype="span"textContent="Custom"variant="outline"size="md"className="bg-gradient-to-r from-purple-500 to-pink-500 text-white border-0"/>
Use icons to enhance badge meaning:
import { StarIcon } from '@heroicons/react/24/solid'<Badgetype="span"textContent="Featured"variant="default"size="md"icon={<StarIcon className="w-3 h-3" />}/>
- Tag: Similar to badge but typically used for categorization
- Chip: Interactive badge-like component for selection
- Label: Text label component
- Status: Specialized status indicator component
For the complete API reference and advanced usage patterns, see the Badge API documentation.
