-
Notifications
You must be signed in to change notification settings - Fork 36
/
CardTitle.js
125 lines (122 loc) · 3.08 KB
/
CardTitle.js
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 React from 'react';
import {
StyleSheet,
Text,
View,
Image,
} from 'react-native';
const CardTitle = (props) => {
const newStyle = props.style || {};
const newTitleStyle = props.titleStyle || {};
const newSubtitleStyle = props.subtitleStyle || {};
const newAvatarStyle = props.avatarStyle || {};
let titleStyle = [styles.titleText, newTitleStyle];
let subtitleStyle = [styles.subtitleText, newSubtitleStyle];
// eslint-disable-next-line max-len
if (props.title !== undefined && props.subtitle !== undefined && props.avatarSource === undefined) {
if (props.subtitleAbove) {
subtitleStyle = [...subtitleStyle, { marginBottom: 12 }];
} else {
titleStyle = [...titleStyle, { marginBottom: 12 }];
}
}
if (props.isDark) {
subtitleStyle = [...subtitleStyle, styles.lightText];
titleStyle = [...titleStyle, styles.lightText];
} else {
titleStyle = [...titleStyle, styles.darkText];
}
if (!props.subtitleAbove) {
return (
<View style={[styles.cardTitle, newStyle]}>
{props.avatarSource !== undefined && (
<Image
source={props.avatarSource}
resizeMode="stretch"
style={[styles.avatarStyle, newAvatarStyle]}
/>
)}
<View style={styles.cardTitleTextContainer}>
{props.title !== undefined && (
<Text
style={props.avatarSource === undefined
? titleStyle
: [titleStyle, { fontSize: 14 }]
}
>
{props.title}
</Text>
)}
{props.subtitle !== undefined && (
<Text style={subtitleStyle}>
{props.subtitle}
</Text>
)}
</View>
</View>
);
}
return (
<View style={[styles.cardTitle, newStyle]}>
{props.avatarSource !== undefined && (
<Image
source={props.avatarSource}
resizeMode="stretch"
style={[styles.avatarStyle, newAvatarStyle]}
/>
)}
<View style={styles.cardTitleTextContainer}>
{props.subtitle !== undefined && (
<Text style={subtitleStyle}>
{props.subtitle}
</Text>
)}
{props.title !== undefined && (
<Text
style={props.avatarSource === undefined
? titleStyle
: [titleStyle, { fontSize: 14 }]
}
>
{props.title}
</Text>
)}
</View>
</View>
);
};
const styles = StyleSheet.create({
darkText: {
color: 'rgba(0 ,0 ,0 , 0.87)',
},
lightText: {
color: 'rgba(255 ,255 ,255 , 0.87)',
},
cardTitle: {
flex: 1,
flexDirection: 'row',
alignItems: 'flex-start',
paddingRight: 16,
paddingLeft: 16,
paddingBottom: 16,
paddingTop: 16,
},
cardTitleTextContainer: {
flex: 1,
flexDirection: 'column',
},
titleText: {
fontSize: 24,
},
subtitleText: {
fontSize: 14,
color: 'rgba(0 ,0 ,0 , 0.38)',
},
avatarStyle: {
width: 40,
height: 40,
borderRadius: 20,
marginRight: 16,
},
});
export default CardTitle;