forked from mrzachnugent/react-native-reusables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.tsx
125 lines (113 loc) · 2.9 KB
/
card.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
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
import { useColorScheme } from 'nativewind';
import React from 'react';
import { Text, View, StyleSheet, ViewStyle } from 'react-native';
import { cn } from '~/lib/utils';
const Card = React.forwardRef<
React.ElementRef<typeof View>,
Omit<React.ComponentPropsWithoutRef<typeof View>, 'style'> & {
style?: ViewStyle;
}
>(({ className, style: styleProp, ...props }, ref) => {
const { colorScheme } = useColorScheme();
const [style, setStyle] = React.useState<ViewStyle>(styleProp ?? {});
React.useEffect(() => {
setStyle(
StyleSheet.flatten([
colorScheme === 'dark' ? styles.shadowDark : styles.shadowLight,
styleProp,
])
);
}, [styleProp, colorScheme]);
return (
<View
ref={ref}
className={cn(
'rounded-lg border border-border bg-card px-0.5 py-2',
className
)}
style={style}
{...props}
/>
);
});
Card.displayName = 'Card';
const CardHeader = React.forwardRef<
React.ElementRef<typeof View>,
React.ComponentPropsWithoutRef<typeof View>
>(({ className, ...props }, ref) => (
<View ref={ref} className={cn('gap-1.5 p-6', className)} {...props} />
));
CardHeader.displayName = 'CardHeader';
const CardTitle = React.forwardRef<
React.ElementRef<typeof Text>,
React.ComponentPropsWithoutRef<typeof Text>
>(({ className, ...props }, ref) => (
<Text
ref={ref}
className={cn(
'text-2xl native:text-3xl font-semibold leading-none tracking-tight text-foreground',
className
)}
{...props}
/>
));
CardTitle.displayName = 'CardTitle';
const CardDescription = React.forwardRef<
React.ElementRef<typeof Text>,
React.ComponentPropsWithoutRef<typeof Text>
>(({ className, ...props }, ref) => (
<Text
ref={ref}
className={cn('text-sm native:text-base text-muted-foreground', className)}
{...props}
/>
));
CardDescription.displayName = 'CardDescription';
const CardContent = React.forwardRef<
React.ElementRef<typeof View>,
React.ComponentPropsWithoutRef<typeof View>
>(({ className, ...props }, ref) => (
<View ref={ref} className={cn('p-6 pt-0', className)} {...props} />
));
CardContent.displayName = 'CardContent';
const CardFooter = React.forwardRef<
React.ElementRef<typeof View>,
React.ComponentPropsWithoutRef<typeof View>
>(({ className, ...props }, ref) => (
<View
ref={ref}
className={cn('flex items-center p-6 pt-0', className)}
{...props}
/>
));
CardFooter.displayName = 'CardFooter';
export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardDescription,
CardContent,
};
const styles = StyleSheet.create({
shadowLight: {
shadowColor: '#000000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.05,
shadowRadius: 8,
elevation: 2,
},
shadowDark: {
shadowColor: '#FFFFFF',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.03,
shadowRadius: 8,
elevation: 1,
},
});