forked from berty/berty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap-border.ts
126 lines (122 loc) · 3.23 KB
/
map-border.ts
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
/* eslint-disable @typescript-eslint/no-explicit-any */
import mem from 'mem'
import { StyleSheet, Platform } from 'react-native'
import { Declaration, Sizes } from './types'
import { mapSizes, mapBorderSidesSizes } from './map-sides'
import { mapColorsDeclaration } from './map-colors'
import { initialScaleSize } from './constant'
export const mapBorderRadiusSides = (
decl: Declaration,
{ scaleSize } = { scaleSize: initialScaleSize },
): any => {
return {
top: mapSizes(
decl.sides,
(radius) => ({
borderTopLeftRadius: radius,
borderTopRightRadius: radius,
}),
{ scaleSize },
),
left: mapSizes(
decl.sides,
(radius) => ({
borderTopLeftRadius: radius,
borderBottomLeftRadius: radius,
}),
{ scaleSize },
),
right: mapSizes(
decl.sides,
(radius) => ({
borderTopRightRadius: radius,
borderBottomRightRadius: radius,
}),
{ scaleSize },
),
bottom: mapSizes(
decl.sides,
(radius) => ({
borderBottomLeftRadius: radius,
borderBottomRightRadius: radius,
}),
{ scaleSize },
),
vertical: mapSizes(decl.sides, (radius) => ({ borderRadius: radius }), {
scaleSize,
}),
horizontal: mapSizes(decl.sides, (radius) => ({ borderRadius: radius }), {
scaleSize,
}),
}
}
export const mapBorderShadowIOS = (
decl: Declaration,
_defaultValues = {
shadowOpacity: 0.2,
},
): Sizes<{}> => ({
...StyleSheet.create({
tiny: { ..._defaultValues, shadowRadius: 0.5, shadowOffset: { width: 0, height: 0.25 } },
small: { ..._defaultValues, shadowRadius: 1, shadowOffset: { width: 0, height: 0.5 } },
medium: { ..._defaultValues, shadowRadius: 2, shadowOffset: { width: 0, height: 1 } },
large: { ..._defaultValues, shadowRadius: 5, shadowOffset: { width: 0, height: 2.5 } },
big: { ..._defaultValues, shadowRadius: 8, shadowOffset: { width: 0, height: 4 } },
huge: { ..._defaultValues, shadowRadius: 13, shadowOffset: { width: 0, height: 6.5 } },
}),
scale: mem(
(size: number) =>
StyleSheet.create({
scale: {
..._defaultValues,
shadowRadius: size,
shadowOffset: { width: 0, height: size / 2 },
},
}).scale,
),
})
export const mapBorderShadowAndroid = (): Sizes<{}> => ({
...StyleSheet.create({
tiny: { elevation: 1 },
medium: { elevation: 2 },
small: { elevation: 3 },
large: { elevation: 4 },
big: { elevation: 5 },
huge: { elevation: 6 },
}),
scale: mem((size: number) => StyleSheet.create({ scale: { elevation: size } }).scale),
})
export const mapBorder = (
decl: Declaration,
{ scaleSize } = { scaleSize: initialScaleSize },
): any => ({
...mapBorderSidesSizes(
{ scaleSize },
{
tiny: 0.1 * scaleSize,
small: 0.2 * scaleSize,
medium: 0.5 * scaleSize,
large: 1 * scaleSize,
big: 2 * scaleSize,
huge: 5 * scaleSize,
},
),
scale: mem((size: number) => {
return StyleSheet.create({ scale: { borderWidth: size * scaleSize } }).scale
}),
radius: {
...mapSizes(
decl.sides,
(radius) => {
return {
borderRadius: radius,
}
},
{ scaleSize },
),
...mapBorderRadiusSides(decl, { scaleSize }),
},
shadow: Platform.select({ ios: mapBorderShadowIOS(decl), android: mapBorderShadowAndroid() }),
size: StyleSheet.create({}),
color: mapColorsDeclaration(decl.colors, (v) => ({ borderColor: v })),
})