forked from mrzachnugent/react-native-reusables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
badge.tsx
62 lines (58 loc) · 1.55 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
60
61
62
import { cva, type VariantProps } from 'class-variance-authority';
import React from 'react';
import { Text, View } from 'react-native';
const badgeRootVariants = cva(
'items-center rounded-full border px-2.5 py-0.5',
{
variants: {
variant: {
default: 'border-transparent bg-primary ',
secondary: 'border-transparent bg-secondary ',
destructive: 'border-transparent bg-destructive ',
outline: 'border-border',
},
},
defaultVariants: {
variant: 'default',
},
}
);
const badgeTextVariants = cva('font-semibold', {
variants: {
variant: {
default: 'text-primary-foreground',
secondary: 'text-secondary-foreground',
destructive: 'text-destructive-foreground',
outline: 'text-foreground',
},
size: {
sm: 'text-xs native:text-sm',
md: 'text-sm native:text-base',
lg: 'text-base native:text-lg',
},
},
defaultVariants: {
variant: 'default',
size: 'md',
},
});
const Badge = React.forwardRef<
React.ElementRef<typeof View>,
React.ComponentPropsWithoutRef<typeof View> &
VariantProps<typeof badgeTextVariants> & { textClass?: string }
>(({ className, children, textClass, variant, size, ...props }, ref) => {
return (
<View
ref={ref}
className={badgeRootVariants({ variant, className })}
{...props}
>
<Text
className={badgeTextVariants({ variant, size, className: textClass })}
>
{children}
</Text>
</View>
);
});
export { Badge, badgeRootVariants, badgeTextVariants };