-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.js
More file actions
144 lines (138 loc) · 2.72 KB
/
Card.js
File metadata and controls
144 lines (138 loc) · 2.72 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import React from 'react';
import {View, StyleSheet, Platform} from 'react-native';
import PropTypes from 'prop-types';
import {useThemeContext} from '../util/ThemeProvider';
const getContainerStyle = ({
row,
horizontal,
align,
vertical,
theme,
space,
shadow,
outline,
wrap,
}) => {
const cardStyle = [
styles.container,
{
padding: theme.layoutSpace[space],
},
];
if (shadow) {
cardStyle.push(styles.shadow);
}
if (row) {
cardStyle.push({
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
});
}
if (wrap) {
cardStyle.push({flexWrap: 'wrap'});
}
if (outline) {
cardStyle.push({
elevation: 0,
borderWidth: StyleSheet.hairlineWidth,
borderColor: '#333',
});
}
if (align === 'center') {
cardStyle.push({
alignItems: 'center',
});
}
if (align === 'left') {
cardStyle.push({
alignItems: 'flex-start',
});
}
if (align === 'right') {
cardStyle.push({
alignItems: 'flex-end',
});
}
if (horizontal) {
cardStyle.push({
paddingVertical: 0,
});
}
if (vertical) {
cardStyle.push({
paddingHorizontal: 0,
});
}
return cardStyle;
};
const Card = (props) => {
const theme = useThemeContext();
return (
<View
{...props}
style={StyleSheet.flatten([
getContainerStyle({...props, theme}),
props.style,
])}>
{props.children}
</View>
);
};
Card.propTypes = {
row: PropTypes.bool,
wrap: PropTypes.bool,
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
space: PropTypes.oneOf([
'none',
'xxsmall',
'xsmall',
'small',
'medium',
'large',
'xlarge',
'xxlarge',
]),
children: PropTypes.oneOfType([PropTypes.array, PropTypes.element])
.isRequired,
horizontal: PropTypes.bool,
vertical: PropTypes.bool,
align: PropTypes.oneOf(['center', 'left', 'right']),
shadow: PropTypes.bool,
outline: PropTypes.bool,
};
Card.defaultProps = {
space: 'medium',
shadow: false,
outline: false,
};
const styles = StyleSheet.create({
container: {
width: '100%',
alignItems: 'stretch',
backgroundColor: '#fff',
justifyContent: 'center',
borderRadius: 3,
},
shadow: {
...Platform.select({
android: {
elevation: 1,
},
ios: {
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 3,
},
shadowOpacity: 0.25,
shadowRadius: 3,
},
web: {
// boxShadow: `${offsetWidth}px ${offsetHeight}px ${radius}px ${rgba}`
boxShadow: '0 3px 5px rgba(0,0,0,0.10), 1px 2px 5px rgba(0,0,0,0.10)',
},
}),
},
});
export default Card;