-
Notifications
You must be signed in to change notification settings - Fork 31
/
Card.js
121 lines (115 loc) · 2.31 KB
/
Card.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
import React from 'react';
import {View, StyleSheet} from 'react-native';
import PropTypes from 'prop-types';
import {useThemeContext} from '../util/ThemeProvider';
import {radii, shadows, spaces} from '../util/prop-types';
const getContainerStyle = ({
row,
horizontal,
align,
vertical,
theme,
space,
shadow,
outline,
wrap,
background,
radius,
}) => {
const cardStyle = [
styles.container,
{
padding: theme.space[space],
backgroundColor: theme.colors[background],
borderRadius: theme.radius[radius],
},
];
if (shadow) {
cardStyle.push(theme.shadow[shadow]);
}
if (row) {
cardStyle.push({
flexDirection: 'row',
justifyContent: 'flex-start',
alignItems: 'center',
});
}
if (wrap) {
cardStyle.push({flexWrap: 'wrap'});
}
if (outline) {
cardStyle.push({
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: spaces,
children: PropTypes.oneOfType([PropTypes.array, PropTypes.element])
.isRequired,
horizontal: PropTypes.bool,
vertical: PropTypes.bool,
align: PropTypes.oneOf(['center', 'left', 'right']),
shadow: shadows,
outline: PropTypes.bool,
background: PropTypes.string,
radius: radii,
};
Card.defaultProps = {
space: 'lg',
outline: false,
background: 'bg200',
shadow: 'none',
radius: 'sm',
};
const styles = StyleSheet.create({
container: {
width: '100%',
alignItems: 'stretch',
justifyContent: 'center',
},
});
export default Card;