-
Notifications
You must be signed in to change notification settings - Fork 31
/
Spacer.js
99 lines (95 loc) · 1.72 KB
/
Spacer.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
import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {useThemeContext} from '../util/ThemeProvider';
import {spaces} from '../util/prop-types';
const getContainerStyle = ({
theme,
m,
mv,
mh,
mt,
mb,
ml,
mr,
p,
pv,
ph,
pt,
pb,
pl,
pr,
}) => {
const style = {};
if (m) {
style.margin = theme.space[m];
}
if (mv) {
style.marginVertical = theme.space[mv];
}
if (mh) {
style.marginHorizontal = theme.space[mh];
}
if (mt) {
style.marginTop = theme.space[mt];
}
if (mb) {
style.marginBottom = theme.space[mb];
}
if (ml) {
style.marginLeft = theme.space[ml];
}
if (mr) {
style.marginRight = theme.space[mr];
}
if (p) {
style.padding = theme.space[p];
}
if (pv) {
style.paddingVertical = theme.space[pv];
}
if (ph) {
style.paddingHorizontal = theme.space[ph];
}
if (pt) {
style.paddingTop = theme.space[pt];
}
if (pb) {
style.paddingBottom = theme.space[pb];
}
if (pl) {
style.paddingLeft = theme.space[pl];
}
if (pr) {
style.paddingRight = theme.space[pr];
}
return style;
};
const Spacer = ({style, children, ...props}) => {
const theme = useThemeContext();
return (
<View style={[getContainerStyle({theme, ...props}), style]}>
{children}
</View>
);
};
Spacer.propTypes = {
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
m: spaces,
mv: spaces,
mh: spaces,
mt: spaces,
mb: spaces,
ml: spaces,
mr: spaces,
p: spaces,
pv: spaces,
ph: spaces,
pt: spaces,
pb: spaces,
pl: spaces,
pr: spaces,
children: PropTypes.oneOfType([PropTypes.array, PropTypes.element])
.isRequired,
};
export default Spacer;