Badge
A hand-drawn styled badge component for displaying status, notifications, and labels with a sketchy aesthetic.
Badge
The Badge component in Faiz UI provides a hand-drawn sketch aesthetic for displaying status indicators, notifications, labels, and other small pieces of information. It supports various colors, sizes, shapes, and positioning options to match different use cases.
Features
- 🎨 Hand-drawn aesthetic - Unique visual style with slight rotations, shadows, and organic feel
- 🎯 Multiple variants - Solid, outline, ghost, light, flat, and sketchy styles
- 🌈 Rich color palette - Seven semantic colors for different contexts
- 📏 Flexible sizing - Five size options from extra small to extra large
- 🔢 Numeric support - Built-in handling for counts with max limits and zero display control
- 📍 Positioning - Absolute positioning for notification badges
- 🔴 Dot variant - Minimal status indicators without text
- 🎭 Icon integration - Support for icons with flexible placement
- ♿ Accessibility first - Comprehensive ARIA support and semantic HTML
- 🎨 Custom styling - Easy customization with Tailwind CSS classes
Installation
Usage
Colors
Badges come in various color options to convey different meanings and priority levels.
Variants
The Badge component offers multiple style variants to suit different UI contexts.
Sizes
Control the size of badges to match your design requirements.
Shapes
Customize the shape of badges with different border radius options.
With Icons
Add icons to badges to provide additional context and visual appeal.
Numeric Badges
Perfect for displaying counts, notifications, and other numeric values. The Badge component automatically handles numeric formatting, including max limits and zero display control.
Key Features:
- Max prop: Numbers exceeding the max value display as "max+" (e.g., 150 with max=99 shows "99+")
- ShowZero prop: Control whether zero values are displayed or hidden
- Automatic ARIA labels: Generates appropriate accessibility labels for screen readers
Dot Variant
Use the dot variant for simple status indicators without text.
Positioned Badges
Position badges relative to other elements for notification indicators. Perfect for showing unread counts, status indicators, or alerts on buttons, avatars, and icons.
Available Positions:
top-right
- Most common for notification countstop-left
- Alternative positioning for alertsbottom-right
- Status indicators and secondary infobottom-left
- Less common, for specific use casescenter
- Centered positioningstatic
- Default inline positioning
Custom Styles
Apply custom styles using Tailwind CSS classes to create unique badge appearances.
Sketchy Variant
The signature sketchy style variant enhances the hand-drawn aesthetic.
Accessibility Features
The Badge component includes comprehensive accessibility support.
Common Use Cases
Notification Badges
Status Indicators
Content Labels
Best Practices
- Use semantic colors: Choose colors that match the meaning (error for alerts, success for positive states)
- Keep text concise: Badges work best with short labels or numbers
- Consider accessibility: Always provide appropriate ARIA labels, especially for dot variants
- Use positioning wisely: Positioned badges should enhance, not obstruct, the parent element
- Maintain consistency: Use the same badge styles throughout your application for similar purposes
Props
Prop | Type | Default | Description |
---|---|---|---|
color | 'default' | 'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'info' | 'primary' | The color theme of the badge |
variant | 'solid' | 'outline' | 'ghost' | 'light' | 'flat' | 'sketchy' | 'solid' | The visual style variant of the badge |
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' | The size of the badge |
shape | 'rounded' | 'pill' | 'square' | 'full' | 'rounded' | The shape/border radius of the badge |
isDot | boolean | false | Whether to render as a dot indicator |
position | 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'center' | 'static' | 'static' | Position for notification badges |
icon | React.ReactNode | undefined | Icon to display in the badge |
iconPlacement | 'before' | 'after' | 'before' | Whether to show icon before or after content |
max | number | undefined | Maximum number to display (shows "max+" when exceeded) |
showZero | boolean | false | Whether to show zero values |
isDisabled | boolean | false | Whether the badge is disabled |
customStyles | string | undefined | Custom Tailwind CSS classes |
aria-label | string | undefined | ARIA label for accessibility |