|
| 1 | +import { tv } from 'tailwind-variants'; |
| 2 | +import type { VariantProps } from 'tailwind-variants'; |
| 3 | + |
| 4 | +export const badgeVariants = tv({ |
| 5 | + base: 'inline-flex items-center border font-semibold', |
| 6 | + variants: { |
| 7 | + color: { |
| 8 | + primary: 'border-primary text-primary', |
| 9 | + destructive: 'border-destructive text-destructive', |
| 10 | + success: 'border-success text-success', |
| 11 | + warning: 'border-warning text-warning', |
| 12 | + info: 'border-info text-info', |
| 13 | + carbon: 'border-carbon text-carbon', |
| 14 | + secondary: 'border-secondary-foreground/50 text-secondary-foreground', |
| 15 | + accent: 'border-accent-foreground/50 text-accent-foreground' |
| 16 | + }, |
| 17 | + variant: { |
| 18 | + solid: '', |
| 19 | + pure: 'bg-background text-foreground border-border', |
| 20 | + outline: 'bg-background', |
| 21 | + soft: 'border-0', |
| 22 | + ghost: '', |
| 23 | + raw: 'bg-transparent border-0' |
| 24 | + }, |
| 25 | + size: { |
| 26 | + xs: 'gap-0.5 h-3.5 px-1 text-4xs', |
| 27 | + sm: 'gap-0.75 h-4 px-1.5 text-3xs', |
| 28 | + md: 'gap-1 h-4.5 px-2 text-2xs', |
| 29 | + lg: 'gap-1.25 h-5 px-2.5 text-xs', |
| 30 | + xl: 'gap-1.5 h-6 px-3 text-sm', |
| 31 | + '2xl': 'gap-2 h-7 px-4 text-base' |
| 32 | + }, |
| 33 | + shape: { |
| 34 | + auto: 'rounded-md', |
| 35 | + rounded: 'rounded-full' |
| 36 | + } |
| 37 | + }, |
| 38 | + compoundVariants: [ |
| 39 | + { |
| 40 | + color: 'primary', |
| 41 | + variant: 'solid', |
| 42 | + class: `bg-primary text-primary-foreground` |
| 43 | + }, |
| 44 | + { |
| 45 | + color: 'destructive', |
| 46 | + variant: 'solid', |
| 47 | + class: `bg-destructive text-destructive-foreground` |
| 48 | + }, |
| 49 | + { |
| 50 | + color: 'success', |
| 51 | + variant: 'solid', |
| 52 | + class: `bg-success text-success-foreground` |
| 53 | + }, |
| 54 | + { |
| 55 | + color: 'warning', |
| 56 | + variant: 'solid', |
| 57 | + class: `bg-warning text-warning-foreground` |
| 58 | + }, |
| 59 | + { |
| 60 | + color: 'info', |
| 61 | + variant: 'solid', |
| 62 | + class: `bg-info text-info-foreground` |
| 63 | + }, |
| 64 | + { |
| 65 | + color: 'carbon', |
| 66 | + variant: 'solid', |
| 67 | + class: `bg-carbon text-carbon-foreground` |
| 68 | + }, |
| 69 | + { |
| 70 | + color: 'secondary', |
| 71 | + variant: 'solid', |
| 72 | + class: `bg-secondary text-secondary-foreground` |
| 73 | + }, |
| 74 | + { |
| 75 | + color: 'accent', |
| 76 | + variant: 'solid', |
| 77 | + class: `bg-accent text-accent-foreground` |
| 78 | + }, |
| 79 | + { |
| 80 | + color: 'primary', |
| 81 | + variant: ['soft', 'ghost'], |
| 82 | + class: 'bg-primary/10' |
| 83 | + }, |
| 84 | + { |
| 85 | + color: 'destructive', |
| 86 | + variant: ['soft', 'ghost'], |
| 87 | + class: 'bg-destructive/10' |
| 88 | + }, |
| 89 | + { |
| 90 | + color: 'success', |
| 91 | + variant: ['soft', 'ghost'], |
| 92 | + class: 'bg-success/10' |
| 93 | + }, |
| 94 | + { |
| 95 | + color: 'warning', |
| 96 | + variant: ['soft', 'ghost'], |
| 97 | + class: 'bg-warning/10' |
| 98 | + }, |
| 99 | + { |
| 100 | + color: 'info', |
| 101 | + variant: ['soft', 'ghost'], |
| 102 | + class: 'bg-info/10' |
| 103 | + }, |
| 104 | + { |
| 105 | + color: 'carbon', |
| 106 | + variant: ['soft', 'ghost'], |
| 107 | + class: 'bg-carbon/10' |
| 108 | + }, |
| 109 | + { |
| 110 | + color: 'secondary', |
| 111 | + variant: ['soft', 'ghost'], |
| 112 | + class: 'bg-secondary-foreground/5' |
| 113 | + }, |
| 114 | + { |
| 115 | + color: 'accent', |
| 116 | + variant: ['soft', 'ghost'], |
| 117 | + class: 'bg-accent-foreground/5' |
| 118 | + } |
| 119 | + ], |
| 120 | + defaultVariants: { |
| 121 | + color: 'primary', |
| 122 | + variant: 'solid', |
| 123 | + size: 'md', |
| 124 | + shape: 'auto' |
| 125 | + } |
| 126 | +}); |
| 127 | + |
| 128 | +type BadgeVariants = VariantProps<typeof badgeVariants>; |
| 129 | + |
| 130 | +export type BadgeVariant = NonNullable<BadgeVariants['variant']>; |
| 131 | + |
| 132 | +export type BadgeShape = NonNullable<BadgeVariants['shape']>; |
0 commit comments