@jobber/components-native 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/Divider/Divider.style.js +6 -7
- package/dist/src/Typography/Typography.js +98 -0
- package/dist/src/Typography/Typography.style.js +280 -0
- package/dist/src/Typography/TypographyGestureDetector.js +10 -0
- package/dist/src/Typography/index.js +3 -0
- package/dist/src/index.js +1 -0
- package/dist/src/utils/design/index.js +6 -0
- package/dist/src/utils/intl/capitalize.js +6 -0
- package/dist/src/utils/intl/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/src/Typography/Typography.d.ts +101 -0
- package/dist/types/src/Typography/Typography.style.d.ts +20 -0
- package/dist/types/src/Typography/TypographyGestureDetector.d.ts +7 -0
- package/dist/types/src/Typography/index.d.ts +4 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/utils/design/index.d.ts +2 -0
- package/dist/types/src/utils/intl/capitalize.d.ts +1 -0
- package/dist/types/src/utils/intl/index.d.ts +1 -0
- package/package.json +4 -3
- package/src/Divider/Divider.style.ts +6 -7
- package/src/Typography/Typography.style.ts +364 -0
- package/src/Typography/Typography.tsx +368 -0
- package/src/Typography/TypographyGestureDetector.tsx +13 -0
- package/src/Typography/index.ts +22 -0
- package/src/index.ts +1 -0
- package/src/utils/design/index.ts +8 -0
- package/src/utils/intl/capitalize.ts +6 -0
- package/src/utils/intl/index.ts +1 -0
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { StyleSheet } from "react-native";
|
|
2
|
-
|
|
3
|
-
import { JobberStyle } from "@jobber/design/foundation";
|
|
2
|
+
import { tokens } from "../utils/design";
|
|
4
3
|
export const styles = StyleSheet.create({
|
|
5
4
|
base: {
|
|
6
|
-
height:
|
|
5
|
+
height: tokens["space-minuscule"],
|
|
7
6
|
margin: 0,
|
|
8
|
-
borderBottomWidth:
|
|
9
|
-
borderBottomColor:
|
|
7
|
+
borderBottomWidth: tokens["border-base"],
|
|
8
|
+
borderBottomColor: tokens["color-border"],
|
|
10
9
|
},
|
|
11
10
|
large: {
|
|
12
|
-
borderBottomWidth:
|
|
11
|
+
borderBottomWidth: tokens["border-thick"],
|
|
13
12
|
opacity: 0.875,
|
|
14
13
|
},
|
|
15
14
|
largest: {
|
|
16
|
-
borderBottomWidth:
|
|
15
|
+
borderBottomWidth: tokens["space-small"],
|
|
17
16
|
opacity: 0.375,
|
|
18
17
|
},
|
|
19
18
|
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { I18nManager, StyleSheet,
|
|
3
|
+
// eslint-disable-next-line no-restricted-imports
|
|
4
|
+
Text, } from "react-native";
|
|
5
|
+
import { TypographyGestureDetector } from "./TypographyGestureDetector";
|
|
6
|
+
import { typographyStyles as styles } from "./Typography.style";
|
|
7
|
+
import { tokens } from "../utils/design";
|
|
8
|
+
import { capitalize } from "../utils/intl";
|
|
9
|
+
const maxNumberOfLines = {
|
|
10
|
+
single: 1,
|
|
11
|
+
small: 2,
|
|
12
|
+
base: 4,
|
|
13
|
+
large: 8,
|
|
14
|
+
extraLarge: 16,
|
|
15
|
+
unlimited: undefined,
|
|
16
|
+
};
|
|
17
|
+
export const Typography = React.memo(InternalTypography);
|
|
18
|
+
function InternalTypography({ fontFamily, fontStyle, fontWeight, transform, color, align, size = "default", children, maxLines = "unlimited", allowFontScaling = true, maxFontScaleSize, adjustsFontSizeToFit = false, lineHeight, letterSpacing, reverseTheme = false, hideFromScreenReader = false, accessibilityRole = "text", strikeThrough = false, selectable = true, }) {
|
|
19
|
+
const sizeAndHeight = getSizeAndHeightStyle(size, lineHeight);
|
|
20
|
+
const style = [
|
|
21
|
+
getFontStyle(fontFamily, fontStyle, fontWeight),
|
|
22
|
+
getColorStyle(color, reverseTheme),
|
|
23
|
+
getAlignStyle(align),
|
|
24
|
+
sizeAndHeight,
|
|
25
|
+
getLetterSpacingStyle(letterSpacing),
|
|
26
|
+
];
|
|
27
|
+
if (strikeThrough) {
|
|
28
|
+
style.push(styles.strikeThrough);
|
|
29
|
+
}
|
|
30
|
+
const numberOfLinesForNativeText = maxNumberOfLines[maxLines];
|
|
31
|
+
const text = getTransformedText(children, transform);
|
|
32
|
+
const accessibilityProps = hideFromScreenReader
|
|
33
|
+
? {
|
|
34
|
+
accessibilityRole: "none",
|
|
35
|
+
accessible: false,
|
|
36
|
+
importantForAccessibility: "no-hide-descendants",
|
|
37
|
+
}
|
|
38
|
+
: { accessibilityRole };
|
|
39
|
+
return (React.createElement(TypographyGestureDetector, null,
|
|
40
|
+
React.createElement(Text, Object.assign({}, {
|
|
41
|
+
allowFontScaling,
|
|
42
|
+
adjustsFontSizeToFit,
|
|
43
|
+
style,
|
|
44
|
+
numberOfLines: numberOfLinesForNativeText,
|
|
45
|
+
}, accessibilityProps, { maxFontSizeMultiplier: getScaleMultiplier(maxFontScaleSize, sizeAndHeight.fontSize), selectable: selectable, selectionColor: tokens["color-brand--highlight"] }), text)));
|
|
46
|
+
}
|
|
47
|
+
function getScaleMultiplier(maxFontScaleSize = 0, size = 1) {
|
|
48
|
+
if (maxFontScaleSize === 0)
|
|
49
|
+
return undefined;
|
|
50
|
+
return maxFontScaleSize / size;
|
|
51
|
+
}
|
|
52
|
+
function getFontStyle(fontFamily = "base", fontStyle = "regular", fontWeight = "regular") {
|
|
53
|
+
const defaultBaseFontStyling = styles.baseRegularRegular;
|
|
54
|
+
const defaultDisplayFontStyling = styles.displayRegularBold;
|
|
55
|
+
const styleKey = `${fontFamily}${capitalize(fontStyle)}${capitalize(fontWeight)}`;
|
|
56
|
+
const fontStyling = styles[styleKey];
|
|
57
|
+
if (fontStyling) {
|
|
58
|
+
return fontStyling;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return fontFamily === "display"
|
|
62
|
+
? defaultDisplayFontStyling
|
|
63
|
+
: defaultBaseFontStyling;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function getTransformedText(text, transform) {
|
|
67
|
+
switch (transform) {
|
|
68
|
+
case "lowercase":
|
|
69
|
+
return text === null || text === void 0 ? void 0 : text.toLocaleLowerCase();
|
|
70
|
+
case "uppercase":
|
|
71
|
+
return text === null || text === void 0 ? void 0 : text.toLocaleUpperCase();
|
|
72
|
+
case "capitalize":
|
|
73
|
+
return capitalize(text || "");
|
|
74
|
+
default:
|
|
75
|
+
return text;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
function getColorStyle(color, reverseTheme) {
|
|
79
|
+
if (color === "default" || !color) {
|
|
80
|
+
return styles.greyBlue;
|
|
81
|
+
}
|
|
82
|
+
const colorStyleKey = `${color}${reverseTheme ? "Reverse" : ""}`;
|
|
83
|
+
return styles[`${colorStyleKey}`];
|
|
84
|
+
}
|
|
85
|
+
function getAlignStyle(alignStyle = I18nManager.isRTL ? "end" : "start") {
|
|
86
|
+
return styles[`${alignStyle}Align`];
|
|
87
|
+
}
|
|
88
|
+
function getSizeAndHeightStyle(textSize, lineHeightOverwrite) {
|
|
89
|
+
const fontSize = styles[`${textSize}Size`];
|
|
90
|
+
if (lineHeightOverwrite) {
|
|
91
|
+
const lineHeight = styles[`${lineHeightOverwrite}LineHeight`];
|
|
92
|
+
return StyleSheet.flatten([fontSize, lineHeight]);
|
|
93
|
+
}
|
|
94
|
+
return fontSize;
|
|
95
|
+
}
|
|
96
|
+
function getLetterSpacingStyle(letterSpacing = "base") {
|
|
97
|
+
return styles[`${letterSpacing}LetterSpacing`];
|
|
98
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { StyleSheet } from "react-native";
|
|
2
|
+
import { tokens } from "../utils/design";
|
|
3
|
+
const extravagantLineHeight = tokens["typography--lineHeight-extravagant"];
|
|
4
|
+
const jumboLineHeight = tokens["typography--lineHeight-jumbo"];
|
|
5
|
+
const largestLineHeight = tokens["typography--lineHeight-largest"];
|
|
6
|
+
const largerLineHeight = tokens["typography--lineHeight-larger"];
|
|
7
|
+
const largeLineHeight = tokens["typography--lineHeight-large"];
|
|
8
|
+
const baseLineHeight = tokens["typography--lineHeight-base"];
|
|
9
|
+
const tightLineHeight = tokens["typography--lineHeight-tight"];
|
|
10
|
+
const minisculeLineHeight = tokens["typography--lineHeight-miniscule"];
|
|
11
|
+
/**
|
|
12
|
+
* `StyleSheet` for Typography.tsx.
|
|
13
|
+
*
|
|
14
|
+
* If you find yourself needing to use what's inside this object on files other
|
|
15
|
+
* than `<Typography />`, please import from `@jobber/components-native` instead.
|
|
16
|
+
*
|
|
17
|
+
* ```
|
|
18
|
+
* import { typographyStyles } from "@jobber/components-native"
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Reusable typography tokens to ensure consistency for any client facing texts.
|
|
23
|
+
*/
|
|
24
|
+
export const typographyTokens = {
|
|
25
|
+
// This follows a pattern of
|
|
26
|
+
// { fontFamily }{ fontStyle }{ fontWeight }
|
|
27
|
+
baseRegularRegular: {
|
|
28
|
+
fontFamily: "inter-regular",
|
|
29
|
+
},
|
|
30
|
+
baseRegularMedium: {
|
|
31
|
+
fontFamily: "inter-medium",
|
|
32
|
+
},
|
|
33
|
+
baseRegularBold: {
|
|
34
|
+
fontFamily: "inter-bold",
|
|
35
|
+
},
|
|
36
|
+
baseRegularSemiBold: {
|
|
37
|
+
fontFamily: "inter-semibold",
|
|
38
|
+
},
|
|
39
|
+
baseRegularExtraBold: {
|
|
40
|
+
fontFamily: "inter-extrabold",
|
|
41
|
+
},
|
|
42
|
+
displayRegularBold: {
|
|
43
|
+
fontFamily: "jobberpro-bd",
|
|
44
|
+
},
|
|
45
|
+
displayRegularExtraBold: {
|
|
46
|
+
fontFamily: "jobberpro-xbd",
|
|
47
|
+
},
|
|
48
|
+
displayRegularBlack: {
|
|
49
|
+
fontFamily: "jobberpro-blk",
|
|
50
|
+
},
|
|
51
|
+
startAlign: {
|
|
52
|
+
textAlign: "left",
|
|
53
|
+
},
|
|
54
|
+
endAlign: {
|
|
55
|
+
textAlign: "right",
|
|
56
|
+
},
|
|
57
|
+
centerAlign: {
|
|
58
|
+
textAlign: "center",
|
|
59
|
+
},
|
|
60
|
+
justifyAlign: {
|
|
61
|
+
textAlign: "justify",
|
|
62
|
+
},
|
|
63
|
+
blue: {
|
|
64
|
+
color: tokens["color-heading"],
|
|
65
|
+
},
|
|
66
|
+
blueDark: {
|
|
67
|
+
color: tokens["color-blue--dark"],
|
|
68
|
+
},
|
|
69
|
+
white: {
|
|
70
|
+
color: tokens["color-white"],
|
|
71
|
+
},
|
|
72
|
+
green: {
|
|
73
|
+
color: tokens["color-green"],
|
|
74
|
+
},
|
|
75
|
+
greenDark: {
|
|
76
|
+
color: tokens["color-green--dark"],
|
|
77
|
+
},
|
|
78
|
+
grey: {
|
|
79
|
+
color: tokens["color-grey"],
|
|
80
|
+
},
|
|
81
|
+
greyDark: {
|
|
82
|
+
color: tokens["color-grey--dark"],
|
|
83
|
+
},
|
|
84
|
+
greyBlue: {
|
|
85
|
+
color: tokens["color-greyBlue"],
|
|
86
|
+
},
|
|
87
|
+
greyBlueDark: {
|
|
88
|
+
color: tokens["color-greyBlue--dark"],
|
|
89
|
+
},
|
|
90
|
+
lightBlue: {
|
|
91
|
+
color: tokens["color-lightBlue"],
|
|
92
|
+
},
|
|
93
|
+
lightBlueDark: {
|
|
94
|
+
color: tokens["color-lightBlue--dark"],
|
|
95
|
+
},
|
|
96
|
+
red: {
|
|
97
|
+
color: tokens["color-red"],
|
|
98
|
+
},
|
|
99
|
+
redDark: {
|
|
100
|
+
color: tokens["color-red--dark"],
|
|
101
|
+
},
|
|
102
|
+
yellow: {
|
|
103
|
+
color: tokens["color-yellow"],
|
|
104
|
+
},
|
|
105
|
+
yellowDark: {
|
|
106
|
+
color: tokens["color-yellow--dark"],
|
|
107
|
+
},
|
|
108
|
+
yellowGreenDark: {
|
|
109
|
+
color: tokens["color-yellowGreen--dark"],
|
|
110
|
+
},
|
|
111
|
+
orangeDark: {
|
|
112
|
+
color: tokens["color-orange--dark"],
|
|
113
|
+
},
|
|
114
|
+
navyDark: {
|
|
115
|
+
color: tokens["color-navy--dark"],
|
|
116
|
+
},
|
|
117
|
+
limeDark: {
|
|
118
|
+
color: tokens["color-lime--dark"],
|
|
119
|
+
},
|
|
120
|
+
purpleDark: {
|
|
121
|
+
color: tokens["color-purple--dark"],
|
|
122
|
+
},
|
|
123
|
+
pinkDark: {
|
|
124
|
+
color: tokens["color-pink--dark"],
|
|
125
|
+
},
|
|
126
|
+
tealDark: {
|
|
127
|
+
color: tokens["color-teal--dark"],
|
|
128
|
+
},
|
|
129
|
+
indigoDark: {
|
|
130
|
+
color: tokens["color-indigo--dark"],
|
|
131
|
+
},
|
|
132
|
+
navy: {
|
|
133
|
+
color: tokens["color-navy"],
|
|
134
|
+
},
|
|
135
|
+
heading: {
|
|
136
|
+
color: tokens["color-heading"],
|
|
137
|
+
},
|
|
138
|
+
headingReverse: {
|
|
139
|
+
color: tokens["color-text--reverse"],
|
|
140
|
+
},
|
|
141
|
+
text: {
|
|
142
|
+
color: tokens["color-text"],
|
|
143
|
+
},
|
|
144
|
+
textSecondary: {
|
|
145
|
+
color: tokens["color-text--secondary"],
|
|
146
|
+
},
|
|
147
|
+
textReverse: {
|
|
148
|
+
color: tokens["color-text--reverse"],
|
|
149
|
+
},
|
|
150
|
+
textReverseSecondary: {
|
|
151
|
+
color: tokens["color-text--reverse--secondary"],
|
|
152
|
+
},
|
|
153
|
+
success: {
|
|
154
|
+
color: tokens["color-success--onSurface"],
|
|
155
|
+
},
|
|
156
|
+
error: {
|
|
157
|
+
color: tokens["color-critical"],
|
|
158
|
+
},
|
|
159
|
+
base: {
|
|
160
|
+
color: tokens["color-text"],
|
|
161
|
+
},
|
|
162
|
+
subdued: {
|
|
163
|
+
color: tokens["color-text--secondary"],
|
|
164
|
+
},
|
|
165
|
+
warn: {
|
|
166
|
+
color: tokens["color-warning--onSurface"],
|
|
167
|
+
},
|
|
168
|
+
info: {
|
|
169
|
+
color: tokens["color-informative--onSurface"],
|
|
170
|
+
},
|
|
171
|
+
critical: {
|
|
172
|
+
color: tokens["color-critical"],
|
|
173
|
+
},
|
|
174
|
+
successReverse: {
|
|
175
|
+
color: tokens["color-success"],
|
|
176
|
+
},
|
|
177
|
+
errorReverse: {
|
|
178
|
+
color: tokens["color-critical"],
|
|
179
|
+
},
|
|
180
|
+
baseReverse: {
|
|
181
|
+
color: tokens["color-text--reverse"],
|
|
182
|
+
},
|
|
183
|
+
subduedReverse: {
|
|
184
|
+
color: tokens["color-text--reverse--secondary"],
|
|
185
|
+
},
|
|
186
|
+
warnReverse: {
|
|
187
|
+
color: tokens["color-warning"],
|
|
188
|
+
},
|
|
189
|
+
infoReverse: {
|
|
190
|
+
color: tokens["color-informative"],
|
|
191
|
+
},
|
|
192
|
+
criticalReverse: {
|
|
193
|
+
color: tokens["color-critical"],
|
|
194
|
+
},
|
|
195
|
+
interactive: {
|
|
196
|
+
color: tokens["color-interactive"],
|
|
197
|
+
},
|
|
198
|
+
destructive: {
|
|
199
|
+
color: tokens["color-destructive"],
|
|
200
|
+
},
|
|
201
|
+
learning: {
|
|
202
|
+
color: tokens["color-informative"],
|
|
203
|
+
},
|
|
204
|
+
subtle: {
|
|
205
|
+
color: tokens["color-interactive--subtle"],
|
|
206
|
+
},
|
|
207
|
+
onPrimary: {
|
|
208
|
+
color: tokens["color-surface"],
|
|
209
|
+
},
|
|
210
|
+
disabled: {
|
|
211
|
+
color: tokens["color-disabled"],
|
|
212
|
+
},
|
|
213
|
+
smallestSize: {
|
|
214
|
+
fontSize: tokens["typography--fontSize-smallest"],
|
|
215
|
+
lineHeight: minisculeLineHeight,
|
|
216
|
+
},
|
|
217
|
+
smallerSize: {
|
|
218
|
+
fontSize: tokens["typography--fontSize-smaller"],
|
|
219
|
+
lineHeight: tightLineHeight,
|
|
220
|
+
},
|
|
221
|
+
smallSize: {
|
|
222
|
+
fontSize: tokens["typography--fontSize-small"],
|
|
223
|
+
lineHeight: tightLineHeight,
|
|
224
|
+
},
|
|
225
|
+
defaultSize: {
|
|
226
|
+
fontSize: tokens["typography--fontSize-base"],
|
|
227
|
+
lineHeight: baseLineHeight,
|
|
228
|
+
},
|
|
229
|
+
largeSize: {
|
|
230
|
+
fontSize: tokens["typography--fontSize-large"],
|
|
231
|
+
lineHeight: largeLineHeight,
|
|
232
|
+
},
|
|
233
|
+
largerSize: {
|
|
234
|
+
fontSize: tokens["typography--fontSize-larger"],
|
|
235
|
+
lineHeight: largeLineHeight,
|
|
236
|
+
},
|
|
237
|
+
largestSize: {
|
|
238
|
+
fontSize: tokens["typography--fontSize-largest"],
|
|
239
|
+
lineHeight: largerLineHeight,
|
|
240
|
+
},
|
|
241
|
+
jumboSize: {
|
|
242
|
+
fontSize: tokens["typography--fontSize-jumbo"],
|
|
243
|
+
lineHeight: jumboLineHeight,
|
|
244
|
+
},
|
|
245
|
+
extravagantSize: {
|
|
246
|
+
fontSize: tokens["typography--fontSize-extravagant"],
|
|
247
|
+
lineHeight: extravagantLineHeight,
|
|
248
|
+
},
|
|
249
|
+
extravagantLineHeight: {
|
|
250
|
+
lineHeight: extravagantLineHeight,
|
|
251
|
+
},
|
|
252
|
+
jumboLineHeight: {
|
|
253
|
+
lineHeight: jumboLineHeight,
|
|
254
|
+
},
|
|
255
|
+
largestLineHeight: {
|
|
256
|
+
lineHeight: largestLineHeight,
|
|
257
|
+
},
|
|
258
|
+
largerLineHeight: {
|
|
259
|
+
lineHeight: largerLineHeight,
|
|
260
|
+
},
|
|
261
|
+
largeLineHeight: {
|
|
262
|
+
lineHeight: largeLineHeight,
|
|
263
|
+
},
|
|
264
|
+
baseLineHeight: {
|
|
265
|
+
lineHeight: baseLineHeight,
|
|
266
|
+
},
|
|
267
|
+
tightLineHeight: {
|
|
268
|
+
lineHeight: tightLineHeight,
|
|
269
|
+
},
|
|
270
|
+
baseLetterSpacing: {
|
|
271
|
+
letterSpacing: tokens["typography--letterSpacing-base"],
|
|
272
|
+
},
|
|
273
|
+
looseLetterSpacing: {
|
|
274
|
+
letterSpacing: tokens["typography--letterSpacing-loose"],
|
|
275
|
+
},
|
|
276
|
+
strikeThrough: {
|
|
277
|
+
textDecorationLine: "line-through",
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
export const typographyStyles = StyleSheet.create(typographyTokens);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
|
3
|
+
/**
|
|
4
|
+
* This is a workaround suggested by react-native-gesture-handler to prevent
|
|
5
|
+
* accidental highlighting of text in Android devices
|
|
6
|
+
* https://github.com/software-mansion/react-native-gesture-handler/issues/1372
|
|
7
|
+
*/
|
|
8
|
+
export function TypographyGestureDetector(props) {
|
|
9
|
+
return React.createElement(GestureDetector, Object.assign({}, props, { gesture: Gesture.Native() }));
|
|
10
|
+
}
|
package/dist/src/index.js
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
export const tokens = Platform.select({
|
|
3
|
+
ios: () => require("@jobber/design/foundation.ios").JobberStyle,
|
|
4
|
+
android: () => require("@jobber/design/foundation.android").JobberStyle,
|
|
5
|
+
default: () => require("@jobber/design/foundation.native").JobberStyle,
|
|
6
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { capitalize } from "./capitalize";
|