-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathutils.tsx
110 lines (94 loc) · 2.02 KB
/
utils.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
import type { ViewStyle } from 'react-native';
import color from 'color';
import { black, white } from '../../styles/themes/v2/colors';
import type { InternalTheme } from '../../types';
type CardMode = 'elevated' | 'outlined' | 'contained';
type BorderRadiusStyles = Pick<
ViewStyle,
Extract<keyof ViewStyle, `border${string}Radius`>
>;
export const getCardCoverStyle = ({
theme,
index,
total,
borderRadiusStyles,
}: {
theme: InternalTheme;
borderRadiusStyles: BorderRadiusStyles;
index?: number;
total?: number;
}) => {
const { isV3, roundness } = theme;
if (Object.keys(borderRadiusStyles).length > 0) {
return {
borderRadius: 3 * roundness,
...borderRadiusStyles,
};
}
if (isV3) {
return {
borderRadius: 3 * roundness,
};
}
if (index === 0) {
if (total === 1) {
return {
borderRadius: roundness,
};
}
return {
borderTopLeftRadius: roundness,
borderTopRightRadius: roundness,
};
}
if (typeof total === 'number' && index === total - 1) {
return {
borderBottomLeftRadius: roundness,
};
}
return undefined;
};
const getBorderColor = ({ theme }: { theme: InternalTheme }) => {
if (theme.isV3) {
return theme.colors.outline;
}
if (theme.dark) {
return color(white).alpha(0.12).rgb().string();
}
return color(black).alpha(0.12).rgb().string();
};
const getBackgroundColor = ({
theme,
isMode,
}: {
theme: InternalTheme;
isMode: (mode: CardMode) => boolean;
}) => {
if (theme.isV3) {
if (isMode('contained')) {
return theme.colors.surfaceVariant;
}
if (isMode('outlined')) {
return theme.colors.surface;
}
}
return undefined;
};
export const getCardColors = ({
theme,
mode,
}: {
theme: InternalTheme;
mode: CardMode;
}) => {
const isMode = (modeToCompare: CardMode) => {
return mode === modeToCompare;
};
return {
backgroundColor: getBackgroundColor({
theme,
isMode,
}),
borderColor: getBorderColor({ theme }),
};
};