-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathshorthandStyles.js
38 lines (34 loc) · 1015 Bytes
/
shorthandStyles.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
const shorthandStyles = (margin, padding) => Object.assign(
getSpacing('margin', margin),
getSpacing('padding', padding)
)
function getSpacing(type, spacing) {
const s = {}
if (typeof spacing === "number") { s[type] = spacing }
else if (Array.isArray(spacing)){
switch (spacing.length) {
case 1:
s[`${type}Vertical`] = spacing[0]
break
case 2:
s[`${type}Vertical`] = spacing[0]
s[`${type}Horizontal`] = spacing[1]
break
case 3:
s[`${type}Top`] = spacing[0]
s[`${type}Horizontal`] = spacing[1]
s[`${type}Bottom`] = spacing[2]
break
case 4:
s[`${type}Top`] = spacing[0]
s[`${type}Right`] = spacing[1]
s[`${type}Bottom`] = spacing[2]
s[`${type}Left`] = spacing[3]
break
default:
break
}
}
return s
}
export default shorthandStyles