Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 91x 3x 3x 3x 3x 91x 91x 91x 91x 91x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 58x 58x 58x 58x 58x 58x 58x 58x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 1x 1x 1x 1x 1x | import React from 'react';
import { cn } from '@/lib/core';
import { BadgeProps } from '@/types/ui';
/**
* Badge Component
*
* Small status indicators and labels.
* Perfect for tags, counts, and status displays.
*
* @example
* ```tsx
* <Badge variant="success">Active</Badge>
* <Badge variant="error" dot>Offline</Badge>
* <Badge variant="primary" pill>New</Badge>
* <Badge size="sm">99+</Badge>
* ```
*/
export const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(
(
{
variant = 'default',
size = 'md',
dot = false,
pill = false,
className,
children,
...props
},
ref
) => {
const baseStyles = `
inline-flex items-center gap-1.5 font-medium
transition-colors duration-200
`;
const variantStyles = {
default: 'bg-gray-100 text-gray-800',
primary: 'bg-blue-100 text-blue-800',
secondary: 'bg-purple-100 text-purple-800',
success: 'bg-green-100 text-green-800',
warning: 'bg-yellow-100 text-yellow-800',
error: 'bg-red-100 text-red-800',
discount: 'bg-red-500 text-white',
new: 'bg-green-500 text-white',
featured: 'bg-purple-500 text-white'};
const sizeStyles = {
sm: 'px-2 py-0.5 text-xs',
md: 'px-2.5 py-1 text-sm',
lg: 'px-3 py-1.5 text-base'};
const shapeStyles = pill ? 'rounded-full' : 'rounded';
const dotColors = {
default: 'bg-gray-600',
primary: 'bg-blue-600',
secondary: 'bg-purple-600',
success: 'bg-green-600',
warning: 'bg-yellow-600',
error: 'bg-red-600',
discount: 'bg-red-700',
new: 'bg-green-700',
featured: 'bg-purple-700'};
return (
<span
ref={ref}
className={cn(
baseStyles,
variantStyles[variant],
sizeStyles[size],
shapeStyles,
className
)}
{...props}
>
{dot && (
<span
className={cn('w-2 h-2 rounded-full', dotColors[variant])}
aria-hidden="true"
/>
)}
{children}
</span>
);
}
);
Badge.displayName = 'Badge';
/**
* DiscountBadge - Specialized discount badge
*/
export interface DiscountBadgeProps extends Omit<BadgeProps, 'variant'> {
/** Discount percentage */
percentage?: number;
}
export const DiscountBadge = React.forwardRef<HTMLSpanElement, DiscountBadgeProps>(
({ percentage, children, ...props }, ref) => {
const content = children || (percentage ? `${percentage}% OFF` : 'Sale');
return (
<Badge ref={ref} variant="discount" {...props}>
{content}
</Badge>
);
}
);
DiscountBadge.displayName = 'DiscountBadge';
/**
* NewBadge - "New" product badge
*/
export const NewBadge = React.forwardRef<HTMLSpanElement, Omit<BadgeProps, 'variant' | 'children'>>(
(props, ref) => {
return (
<Badge ref={ref} variant="new" {...props}>
New
</Badge>
);
}
);
NewBadge.displayName = 'NewBadge';
/**
* FeaturedBadge - "Featured" product badge
*/
export const FeaturedBadge = React.forwardRef<HTMLSpanElement, Omit<BadgeProps, 'variant' | 'children'>>(
(props, ref) => {
return (
<Badge ref={ref} variant="featured" {...props}>
Featured
</Badge>
);
}
);
FeaturedBadge.displayName = 'FeaturedBadge';
export default Badge;
|