-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathText.js
147 lines (139 loc) · 3.23 KB
/
Text.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import React from "react";
import { Animated, StyleSheet, Text } from "react-native";
import expoTheme from "./theme";
import { mergeTheme, getMargins, getPaddings } from "./utils/index";
const Typography = ({
// fonts & sizes
h1 = false,
h2 = false,
h3 = false,
title = false,
subtitle = false,
caption = false,
small = false,
size = null,
margin = null,
padding = null,
// styling
transform = null,
regular = false,
bold = false,
semibold = false,
medium = false,
weight = false,
light = false,
center = false,
right = false,
spacing = null, // letter-spacing
height = null, // line-height
// colors
color = null,
primary = false,
secondary = false,
tertiary = false,
black = false,
white = false,
gray = false,
error = false,
warning = false,
success = false,
info = false,
animated = false,
theme = {},
style = {},
children,
marginHorizontal,
marginVertical,
marginTop,
marginBottom,
marginLeft,
marginRight,
paddingHorizontal,
paddingVertical,
paddingTop,
paddingBottom,
paddingLeft,
paddingRight,
...rest
}) => {
const { SIZES, COLORS, FONTS, WEIGHTS } = mergeTheme({ ...expoTheme }, theme);
const marginSpacing = getMargins({
margin,
marginHorizontal,
marginVertical,
marginTop,
marginBottom,
marginLeft,
marginRight,
defaultValue: SIZES.base
});
const paddingSpacing = getPaddings({
padding,
paddingHorizontal,
paddingVertical,
paddingTop,
paddingBottom,
paddingLeft,
paddingRight,
defaultValue: SIZES.base
});
const textStyles = StyleSheet.flatten([
{
fontWeight: WEIGHTS.regular,
fontSize: SIZES.font,
color: COLORS.font
},
h1 && FONTS.h1,
h2 && FONTS.h2,
h3 && FONTS.h3,
title && FONTS.title,
subtitle && FONTS.subtitle,
caption && FONTS.caption,
small && FONTS.small,
size && { fontSize: size },
marginSpacing,
paddingSpacing,
transform && { textTransform: transform },
height && { lineHeight: height },
spacing && { letterSpacing: spacing },
weight && { fontWeight: weight },
regular && { fontWeight: WEIGHTS.regular },
bold && { fontWeight: WEIGHTS.bold },
semibold && { fontWeight: WEIGHTS.semibold },
medium && { fontWeight: WEIGHTS.medium },
light && { fontWeight: WEIGHTS.light },
center && styles.center,
right && styles.right,
// color shortcuts
primary && { color: COLORS.primary },
secondary && { color: COLORS.secondary },
tertiary && { color: COLORS.tertiary },
black && { color: COLORS.black },
white && { color: COLORS.white },
gray && { color: COLORS.gray },
error && { color: COLORS.error },
warning && { color: COLORS.warning },
success && { color: COLORS.success },
info && { color: COLORS.info },
color && { color },
style // rewrite predefined styles
]);
if (animated) {
return (
<Animated.Text {...rest} style={textStyles}>
{children}
</Animated.Text>
);
}
return (
<Text {...rest} style={textStyles}>
{children}
</Text>
);
};
export default Typography;
const styles = StyleSheet.create({
// positioning
center: { textAlign: "center" },
right: { textAlign: "right" }
});