forked from Mobilecn-UI/nativecn-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Badge.tsx
59 lines (54 loc) · 1.33 KB
/
Badge.tsx
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
import { type VariantProps, cva } from 'class-variance-authority';
import { Text, View } from 'react-native';
import { cn } from '../lib/utils';
const badgeVariants = cva(
'flex flex-row items-center rounded-full px-2 py-1 text-xs font-semibold',
{
variants: {
variant: {
default: 'bg-primary',
secondary: 'bg-secondary',
destructive: 'bg-destructive',
success: 'bg-green-500 dark:bg-green-700',
},
},
defaultVariants: {
variant: 'default',
},
}
);
const badgeTextVariants = cva('font-medium text-center text-xs', {
variants: {
variant: {
default: 'text-primary-foreground',
secondary: 'text-secondary-foreground',
destructive: 'text-destructive-foreground',
success: 'text-green-100',
},
},
defaultVariants: {
variant: 'default',
},
});
export interface BadgeProps
extends React.ComponentPropsWithoutRef<typeof View>,
VariantProps<typeof badgeVariants> {
label: string;
labelClasses?: string;
}
function Badge({
label,
labelClasses,
className,
variant,
...props
}: BadgeProps) {
return (
<View className={cn(badgeVariants({ variant }), className)} {...props}>
<Text className={cn(badgeTextVariants({ variant }), labelClasses)}>
{label}
</Text>
</View>
);
}
export { Badge, badgeVariants };