ferns-ui 0.23.2 → 0.24.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/ActionSheet.d.ts +7 -5
- package/dist/ActionSheet.js +7 -4
- package/dist/ActionSheet.js.map +1 -1
- package/dist/Avatar.js +2 -2
- package/dist/Avatar.js.map +1 -1
- package/dist/Box.d.ts +0 -1
- package/dist/Box.js +3 -9
- package/dist/Box.js.map +1 -1
- package/dist/Button.d.ts +2 -1
- package/dist/Button.js +3 -3
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +35 -49
- package/dist/Common.js.map +1 -1
- package/dist/DateTimeActionSheet.js.map +1 -1
- package/dist/DecimalRangeActionSheet.js.map +1 -1
- package/dist/ErrorBoundary.d.ts +1 -1
- package/dist/HeightActionSheet.js.map +1 -1
- package/dist/Image.d.ts +1 -1
- package/dist/NumberPickerActionSheet.js.map +1 -1
- package/dist/PickerSelect.js.map +1 -1
- package/dist/SelectList.d.ts +1 -1
- package/dist/SplitPage.js.map +1 -1
- package/dist/TapToEdit.js +2 -2
- package/dist/TapToEdit.js.map +1 -1
- package/dist/Text.d.ts +17 -9
- package/dist/Text.js +59 -49
- package/dist/Text.js.map +1 -1
- package/dist/TextField.js.map +1 -1
- package/dist/TextFieldNumberActionSheet.js.map +1 -1
- package/dist/Tooltip.js +6 -2
- package/dist/Tooltip.js.map +1 -1
- package/dist/Unifier.d.ts +3 -3
- package/dist/Unifier.js +52 -44
- package/dist/Unifier.js.map +1 -1
- package/dist/Utilities.d.ts +2 -2
- package/dist/index.d.ts +1 -1
- package/package.json +67 -60
- package/src/ActionSheet.tsx +9 -11
- package/src/Avatar.tsx +2 -2
- package/src/Box.tsx +7 -13
- package/src/Button.tsx +10 -9
- package/src/Common.ts +2 -19
- package/src/TapToEdit.tsx +1 -1
- package/src/Text.tsx +102 -62
- package/src/Tooltip.tsx +4 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ferns-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"scripts": {
|
|
@@ -112,96 +112,103 @@
|
|
|
112
112
|
"jest-watch-typeahead/testname"
|
|
113
113
|
]
|
|
114
114
|
},
|
|
115
|
-
"resolutions": {
|
|
116
|
-
"update-input-width": "1.1.1",
|
|
117
|
-
"@types/react": "17.0.44"
|
|
118
|
-
},
|
|
119
115
|
"dependencies": {
|
|
120
|
-
"expo-image-picker": "^13.3.1",
|
|
121
116
|
"tsc-watch": "^5.0.3"
|
|
122
117
|
},
|
|
123
118
|
"devDependencies": {
|
|
124
119
|
"@expo/vector-icons": "^13.0.0",
|
|
125
|
-
"@react-native-async-storage/async-storage": "
|
|
126
|
-
"@react-native-community/blur": "^4.
|
|
127
|
-
"@react-native-community/datetimepicker": "
|
|
128
|
-
"@react-native-picker/picker": "2.4.
|
|
129
|
-
"@types/lodash": "^4.14.184",
|
|
120
|
+
"@react-native-async-storage/async-storage": "1.17.11",
|
|
121
|
+
"@react-native-community/blur": "^4.3.0",
|
|
122
|
+
"@react-native-community/datetimepicker": "6.7.3",
|
|
123
|
+
"@react-native-picker/picker": "2.4.8",
|
|
130
124
|
"@types/mdurl": "^1.0.2",
|
|
131
125
|
"@types/react-datetime-picker": "^3.4.1",
|
|
132
|
-
"@types/react-
|
|
133
|
-
"@types/react-time-picker": "^4.0.2",
|
|
126
|
+
"@types/react-time-picker": "^4.0.3",
|
|
134
127
|
"@typescript-eslint/eslint-plugin": "^5.34.0",
|
|
135
128
|
"@typescript-eslint/parser": "^5.34.0",
|
|
136
|
-
"eslint": "^8.
|
|
129
|
+
"eslint": "^8.35.0",
|
|
137
130
|
"eslint-config-ferns": "^0.4.0",
|
|
138
|
-
"eslint-config-prettier": "^8.
|
|
139
|
-
"eslint-plugin-import": "^2.
|
|
131
|
+
"eslint-config-prettier": "^8.7.0",
|
|
132
|
+
"eslint-plugin-import": "^2.27.5",
|
|
140
133
|
"eslint-plugin-lodash": "^7.1.0",
|
|
141
134
|
"eslint-plugin-prettier": "^4.0.0",
|
|
142
|
-
"eslint-plugin-react": "^7.
|
|
135
|
+
"eslint-plugin-react": "^7.32.2",
|
|
143
136
|
"eslint-plugin-react-hooks": "^4.5.0",
|
|
144
137
|
"eslint-plugin-react-native": "^4.0.0",
|
|
145
|
-
"eslint-plugin-simple-import-sort": "^
|
|
138
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
146
139
|
"eslint-plugin-unused-imports": "2.0.0",
|
|
147
|
-
"expo-font": "
|
|
148
|
-
"expo-haptics": "~
|
|
149
|
-
"expo-image-manipulator": "
|
|
150
|
-
"expo-image-picker": "
|
|
151
|
-
"libphonenumber-js": "^1.10.
|
|
140
|
+
"expo-font": "~11.1.1",
|
|
141
|
+
"expo-haptics": "~12.2.1",
|
|
142
|
+
"expo-image-manipulator": "~11.1.1",
|
|
143
|
+
"expo-image-picker": "~14.1.1",
|
|
144
|
+
"libphonenumber-js": "^1.10.21",
|
|
152
145
|
"lodash": "^4.17.21",
|
|
153
|
-
"
|
|
154
|
-
"moment-timezone": "^0.5.
|
|
155
|
-
"prettier": "^2.
|
|
156
|
-
"react": "
|
|
146
|
+
"mdurl": "^1.0.1",
|
|
147
|
+
"moment-timezone": "^0.5.41",
|
|
148
|
+
"prettier": "^2.8.4",
|
|
149
|
+
"react": "18.2.0",
|
|
157
150
|
"react-app-polyfill": "^3.0.0",
|
|
158
|
-
"react-date-picker": "^9.
|
|
159
|
-
"react-datetime-picker": "^4.0
|
|
151
|
+
"react-date-picker": "^9.2.0",
|
|
152
|
+
"react-datetime-picker": "^4.2.0",
|
|
160
153
|
"react-dev-utils": "^12.0.1",
|
|
161
154
|
"react-dom": "18.2.0",
|
|
162
|
-
"react-native": "0.
|
|
163
|
-
"react-native-calendars": "^1.
|
|
164
|
-
"react-native-gesture-handler": "
|
|
155
|
+
"react-native": "0.71.3",
|
|
156
|
+
"react-native-calendars": "^1.1293.0",
|
|
157
|
+
"react-native-gesture-handler": "~2.9.0",
|
|
165
158
|
"react-native-modalize": "^2.1.1",
|
|
166
|
-
"react-native-permissions": "^3.
|
|
167
|
-
"react-native-picker-select": "^8.0.
|
|
159
|
+
"react-native-permissions": "^3.7.3",
|
|
160
|
+
"react-native-picker-select": "^8.0.4",
|
|
168
161
|
"react-native-portalize": "^1.0.7",
|
|
169
|
-
"react-native-svg": "^13.
|
|
162
|
+
"react-native-svg": "^13.4.0",
|
|
170
163
|
"react-native-toast-notifications": "^3.3.1",
|
|
171
|
-
"react-router": "^6.
|
|
172
|
-
"react-router-dom": "^6.
|
|
173
|
-
"react-time-picker": "^5.
|
|
174
|
-
"typescript": "4.
|
|
164
|
+
"react-router": "^6.8.2",
|
|
165
|
+
"react-router-dom": "^6.8.2",
|
|
166
|
+
"react-time-picker": "^5.2.0",
|
|
167
|
+
"typescript": "^4.9.4"
|
|
175
168
|
},
|
|
176
169
|
"peerDependencies": {
|
|
177
170
|
"@expo/vector-icons": "^13.0.0",
|
|
178
|
-
"@react-native-async-storage/async-storage": "
|
|
179
|
-
"@react-native-community/blur": "^4.
|
|
180
|
-
"@react-native-community/datetimepicker": "
|
|
181
|
-
"@react-native-picker/picker": "2.4.
|
|
182
|
-
"
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
"
|
|
171
|
+
"@react-native-async-storage/async-storage": "1.17.11",
|
|
172
|
+
"@react-native-community/blur": "^4.3.0",
|
|
173
|
+
"@react-native-community/datetimepicker": "6.7.3",
|
|
174
|
+
"@react-native-picker/picker": "2.4.8",
|
|
175
|
+
"@typescript-eslint/eslint-plugin": "^5.34.0",
|
|
176
|
+
"@typescript-eslint/parser": "^5.34.0",
|
|
177
|
+
"eslint": "^8.35.0",
|
|
178
|
+
"eslint-config-ferns": "^0.4.0",
|
|
179
|
+
"eslint-config-prettier": "^8.7.0",
|
|
180
|
+
"eslint-plugin-import": "^2.27.5",
|
|
181
|
+
"eslint-plugin-lodash": "^7.1.0",
|
|
182
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
183
|
+
"eslint-plugin-react": "^7.32.2",
|
|
184
|
+
"eslint-plugin-react-hooks": "^4.5.0",
|
|
185
|
+
"eslint-plugin-react-native": "^4.0.0",
|
|
186
|
+
"eslint-plugin-simple-import-sort": "^10.0.0",
|
|
187
|
+
"eslint-plugin-unused-imports": "2.0.0",
|
|
188
|
+
"expo-font": "~11.1.1",
|
|
189
|
+
"expo-haptics": "~12.2.1",
|
|
190
|
+
"expo-image-manipulator": "~11.1.1",
|
|
191
|
+
"expo-image-picker": "~14.1.1",
|
|
192
|
+
"libphonenumber-js": "^1.10.21",
|
|
186
193
|
"lodash": "^4.17.21",
|
|
187
|
-
"
|
|
188
|
-
"
|
|
189
|
-
"react": "^18.2.0",
|
|
194
|
+
"moment-timezone": "^0.5.41",
|
|
195
|
+
"react": "18.2.0",
|
|
190
196
|
"react-app-polyfill": "^3.0.0",
|
|
191
|
-
"react-
|
|
197
|
+
"react-date-picker": "^9.2.0",
|
|
198
|
+
"react-datetime-picker": "^4.2.0",
|
|
192
199
|
"react-dev-utils": "^12.0.1",
|
|
193
200
|
"react-dom": "18.2.0",
|
|
194
|
-
"react-native": "0.
|
|
195
|
-
"react-native-calendars": "^1.
|
|
196
|
-
"react-native-gesture-handler": "
|
|
201
|
+
"react-native": "0.71.3",
|
|
202
|
+
"react-native-calendars": "^1.1293.0",
|
|
203
|
+
"react-native-gesture-handler": "~2.9.0",
|
|
197
204
|
"react-native-modalize": "^2.1.1",
|
|
198
|
-
"react-native-permissions": "^3.
|
|
199
|
-
"react-native-picker-select": "^8.0.
|
|
205
|
+
"react-native-permissions": "^3.7.3",
|
|
206
|
+
"react-native-picker-select": "^8.0.4",
|
|
200
207
|
"react-native-portalize": "^1.0.7",
|
|
201
|
-
"react-native-svg": "^13.
|
|
208
|
+
"react-native-svg": "^13.4.0",
|
|
202
209
|
"react-native-toast-notifications": "^3.3.1",
|
|
203
|
-
"react-router": "^6.
|
|
204
|
-
"react-router-dom": "^6.
|
|
205
|
-
"react-time-picker": "^5.
|
|
210
|
+
"react-router": "^6.8.2",
|
|
211
|
+
"react-router-dom": "^6.8.2",
|
|
212
|
+
"react-time-picker": "^5.2.0"
|
|
206
213
|
}
|
|
207
214
|
}
|
package/src/ActionSheet.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import React, {Component, createRef} from "react";
|
|
|
4
4
|
import {
|
|
5
5
|
Animated,
|
|
6
6
|
Dimensions,
|
|
7
|
+
EmitterSubscription,
|
|
7
8
|
findNodeHandle,
|
|
8
9
|
FlatList,
|
|
9
10
|
Keyboard,
|
|
@@ -491,6 +492,10 @@ export class ActionSheet extends Component<Props, State, any> {
|
|
|
491
492
|
|
|
492
493
|
actionSheetHeight = 0;
|
|
493
494
|
|
|
495
|
+
keyboardDidShowListener: EmitterSubscription | null = null;
|
|
496
|
+
|
|
497
|
+
keyboardDidHideListener: EmitterSubscription | null = null;
|
|
498
|
+
|
|
494
499
|
prevScroll = 0;
|
|
495
500
|
|
|
496
501
|
timeout: any | null = null;
|
|
@@ -910,12 +915,12 @@ export class ActionSheet extends Component<Props, State, any> {
|
|
|
910
915
|
};
|
|
911
916
|
|
|
912
917
|
componentDidMount() {
|
|
913
|
-
Keyboard.addListener(
|
|
918
|
+
this.keyboardDidShowListener = Keyboard.addListener(
|
|
914
919
|
Platform.OS === "android" ? "keyboardDidShow" : "keyboardWillShow",
|
|
915
920
|
this._onKeyboardShow
|
|
916
921
|
);
|
|
917
922
|
|
|
918
|
-
Keyboard.addListener(
|
|
923
|
+
this.keyboardDidHideListener = Keyboard.addListener(
|
|
919
924
|
Platform.OS === "android" ? "keyboardDidHide" : "keyboardWillHide",
|
|
920
925
|
this._onKeyboardHide
|
|
921
926
|
);
|
|
@@ -1010,15 +1015,8 @@ export class ActionSheet extends Component<Props, State, any> {
|
|
|
1010
1015
|
};
|
|
1011
1016
|
|
|
1012
1017
|
componentWillUnmount() {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
this._onKeyboardShow
|
|
1016
|
-
);
|
|
1017
|
-
|
|
1018
|
-
Keyboard.removeListener(
|
|
1019
|
-
Platform.OS === "android" ? "keyboardDidHide" : "keyboardWillHide",
|
|
1020
|
-
this._onKeyboardHide
|
|
1021
|
-
);
|
|
1018
|
+
this.keyboardDidShowListener?.remove();
|
|
1019
|
+
this.keyboardDidHideListener?.remove();
|
|
1022
1020
|
}
|
|
1023
1021
|
|
|
1024
1022
|
_onDeviceLayout = async (_event: any) => {
|
package/src/Avatar.tsx
CHANGED
|
@@ -118,8 +118,8 @@ export const Avatar = (props: AvatarProps): React.ReactElement => {
|
|
|
118
118
|
base64: true,
|
|
119
119
|
});
|
|
120
120
|
|
|
121
|
-
if (!result.
|
|
122
|
-
const resizedImage = await resizeImage(result.uri);
|
|
121
|
+
if (!result.canceled && result.assets) {
|
|
122
|
+
const resizedImage = await resizeImage(result.assets[0].uri);
|
|
123
123
|
setSrc(resizedImage.uri);
|
|
124
124
|
if (onChange) {
|
|
125
125
|
onChange({avatarImageFormat, ...resizedImage});
|
package/src/Box.tsx
CHANGED
|
@@ -120,10 +120,8 @@ export class Box extends React.Component<BoxProps, {}> {
|
|
|
120
120
|
overflow: (value) => {
|
|
121
121
|
if (value === "scrollY" || value === "scroll") {
|
|
122
122
|
return {overflow: "scroll"};
|
|
123
|
-
} else if (value === "scrollX") {
|
|
124
|
-
return {overflow: "scrollX"};
|
|
125
123
|
}
|
|
126
|
-
return {};
|
|
124
|
+
return {overflow: value};
|
|
127
125
|
},
|
|
128
126
|
width: (value) => {
|
|
129
127
|
if (this.props.border && !isNaN(Number(value))) {
|
|
@@ -236,14 +234,6 @@ export class Box extends React.Component<BoxProps, {}> {
|
|
|
236
234
|
return style;
|
|
237
235
|
}
|
|
238
236
|
|
|
239
|
-
renderBox() {
|
|
240
|
-
return (
|
|
241
|
-
<View style={!this.props.scroll && !this.props.overflow && this.propsToStyle()}>
|
|
242
|
-
{this.props.children}
|
|
243
|
-
</View>
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
237
|
render() {
|
|
248
238
|
let box;
|
|
249
239
|
|
|
@@ -251,6 +241,7 @@ export class Box extends React.Component<BoxProps, {}> {
|
|
|
251
241
|
box = (
|
|
252
242
|
<TouchableOpacity
|
|
253
243
|
style={this.propsToStyle()}
|
|
244
|
+
testID={this.props.testID ? `${this.props.testID}-clickable` : undefined}
|
|
254
245
|
// TODO: refactor this better..
|
|
255
246
|
onLayout={this.props.onLayout}
|
|
256
247
|
onPress={() => {
|
|
@@ -259,11 +250,14 @@ export class Box extends React.Component<BoxProps, {}> {
|
|
|
259
250
|
}}
|
|
260
251
|
>
|
|
261
252
|
{this.props.children}
|
|
262
|
-
{/* <View pointerEvents="none">{box}</View> */}
|
|
263
253
|
</TouchableOpacity>
|
|
264
254
|
);
|
|
265
255
|
} else {
|
|
266
|
-
box =
|
|
256
|
+
box = (
|
|
257
|
+
<View style={this.propsToStyle()} testID={this.props.testID}>
|
|
258
|
+
{this.props.children}
|
|
259
|
+
</View>
|
|
260
|
+
);
|
|
267
261
|
}
|
|
268
262
|
|
|
269
263
|
if (this.props.scroll) {
|
package/src/Button.tsx
CHANGED
|
@@ -18,9 +18,7 @@ export interface ButtonProps {
|
|
|
18
18
|
disabled?: boolean; // default false
|
|
19
19
|
inline?: boolean; // default false
|
|
20
20
|
size?: "sm" | "md" | "lg"; // default md
|
|
21
|
-
|
|
22
|
-
// Pattern Addition
|
|
23
|
-
type?: "solid" | "ghost" | "outline";
|
|
21
|
+
type?: "solid" | "ghost" | "outline"; // default solid
|
|
24
22
|
loading?: boolean;
|
|
25
23
|
onClick: any;
|
|
26
24
|
icon?: IconName;
|
|
@@ -30,6 +28,7 @@ export interface ButtonProps {
|
|
|
30
28
|
confirmationText?: string;
|
|
31
29
|
confirmationHeading?: string;
|
|
32
30
|
shape?: "rounded" | "pill";
|
|
31
|
+
testID?: string;
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
const buttonTextColor: {[buttonColor: string]: "white" | "darkGray"} = {
|
|
@@ -54,21 +53,22 @@ const HEIGHTS = {
|
|
|
54
53
|
};
|
|
55
54
|
|
|
56
55
|
export function Button({
|
|
57
|
-
disabled,
|
|
58
|
-
type,
|
|
56
|
+
disabled = false,
|
|
57
|
+
type = "solid",
|
|
59
58
|
loading: propsLoading,
|
|
60
59
|
children,
|
|
61
60
|
text,
|
|
62
|
-
inline,
|
|
61
|
+
inline = false,
|
|
63
62
|
icon,
|
|
64
63
|
iconPrefix,
|
|
65
|
-
size,
|
|
64
|
+
size = "md",
|
|
66
65
|
onClick,
|
|
67
|
-
color = "
|
|
66
|
+
color = "gray",
|
|
68
67
|
withConfirmation = false,
|
|
69
68
|
confirmationText = "Are you sure you want to continue?",
|
|
70
69
|
confirmationHeading = "Confirm",
|
|
71
70
|
shape = "rounded",
|
|
71
|
+
testID,
|
|
72
72
|
}: ButtonProps) {
|
|
73
73
|
const [loading, setLoading] = useState(propsLoading);
|
|
74
74
|
const [showConfirmation, setShowConfirmation] = useState(false);
|
|
@@ -143,8 +143,9 @@ export function Button({
|
|
|
143
143
|
borderWidth: type === "outline" ? 2 : 0,
|
|
144
144
|
opacity: disabled ? 0.4 : 1,
|
|
145
145
|
flexDirection: "row",
|
|
146
|
-
paddingHorizontal:
|
|
146
|
+
paddingHorizontal: 8 * 2,
|
|
147
147
|
}}
|
|
148
|
+
testID={testID}
|
|
148
149
|
onPress={debounce(
|
|
149
150
|
async () => {
|
|
150
151
|
Unifier.utils.haptic();
|
package/src/Common.ts
CHANGED
|
@@ -1817,24 +1817,6 @@ export type IconPrefix = "far" | "fas";
|
|
|
1817
1817
|
// | "simple-line"
|
|
1818
1818
|
// | "feather";
|
|
1819
1819
|
|
|
1820
|
-
export interface TextProps {
|
|
1821
|
-
align?: "left" | "right" | "center" | "justify"; // default "left"
|
|
1822
|
-
children?: React.ReactNode;
|
|
1823
|
-
color?: AllColors;
|
|
1824
|
-
|
|
1825
|
-
inline?: boolean; // default false
|
|
1826
|
-
italic?: boolean; // default false
|
|
1827
|
-
overflow?: "normal" | "breakWord"; // default "breakWord"
|
|
1828
|
-
size?: TextSize; // default "md"
|
|
1829
|
-
truncate?: boolean; // default false
|
|
1830
|
-
font?: Font;
|
|
1831
|
-
underline?: boolean;
|
|
1832
|
-
|
|
1833
|
-
numberOfLines?: number;
|
|
1834
|
-
skipLinking?: boolean;
|
|
1835
|
-
weight?: "bold" | "normal";
|
|
1836
|
-
}
|
|
1837
|
-
|
|
1838
1820
|
export interface ActionBannerProps {
|
|
1839
1821
|
/** The text to show in the banner. */
|
|
1840
1822
|
text: string;
|
|
@@ -1967,6 +1949,7 @@ export interface BoxProps {
|
|
|
1967
1949
|
scrollRef?: any;
|
|
1968
1950
|
onScroll?: (offsetY: number) => void;
|
|
1969
1951
|
onLayout?: (event: any) => void;
|
|
1952
|
+
testID?: string;
|
|
1970
1953
|
}
|
|
1971
1954
|
|
|
1972
1955
|
export type BoxColor = AllColors | "transparent";
|
|
@@ -2642,7 +2625,7 @@ export interface PickerProps {
|
|
|
2642
2625
|
onValueChange?: (itemValue: any, itemPosition: number) => void;
|
|
2643
2626
|
selectedValue?: any;
|
|
2644
2627
|
style?: StyleProp;
|
|
2645
|
-
|
|
2628
|
+
testID?: string;
|
|
2646
2629
|
itemStyle?: StyleProp;
|
|
2647
2630
|
enabled?: boolean;
|
|
2648
2631
|
mode?: "dialog" | "dropdown";
|
package/src/TapToEdit.tsx
CHANGED
|
@@ -147,7 +147,7 @@ export const TapToEdit = ({
|
|
|
147
147
|
</Box>
|
|
148
148
|
<Box direction="row">
|
|
149
149
|
<Box>
|
|
150
|
-
<Text
|
|
150
|
+
<Text>{displayValue}</Text>
|
|
151
151
|
</Box>
|
|
152
152
|
{editable && (
|
|
153
153
|
<Box marginLeft={2} onClick={(): void => setEditing(true)}>
|
package/src/Text.tsx
CHANGED
|
@@ -1,91 +1,131 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import {Text as NativeText} from "react-native";
|
|
2
|
+
import {Text as NativeText, TextStyle} from "react-native";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {AllColors, Font, TextSize} from "./Common";
|
|
5
5
|
import {Hyperlink} from "./Hyperlink";
|
|
6
6
|
import {Unifier} from "./Unifier";
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
export interface TextProps {
|
|
9
|
+
align?: "left" | "right" | "center" | "justify"; // default "left"
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
color?: AllColors;
|
|
12
|
+
inline?: boolean; // default false
|
|
13
|
+
italic?: boolean; // default false
|
|
14
|
+
overflow?: "normal" | "breakWord"; // deprecated
|
|
15
|
+
size?: TextSize; // default "md"
|
|
16
|
+
truncate?: boolean; // default false
|
|
17
|
+
font?: Font;
|
|
18
|
+
underline?: boolean;
|
|
19
|
+
numberOfLines?: number;
|
|
20
|
+
skipLinking?: boolean;
|
|
21
|
+
weight?: "bold" | "normal";
|
|
22
|
+
testID?: string;
|
|
23
|
+
}
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
const fontSizes = {
|
|
26
|
+
sm: 12,
|
|
27
|
+
md: 14,
|
|
28
|
+
lg: 16,
|
|
29
|
+
};
|
|
17
30
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
export function Text({
|
|
32
|
+
align = "left",
|
|
33
|
+
children,
|
|
34
|
+
color,
|
|
35
|
+
inline = false,
|
|
36
|
+
italic = false,
|
|
37
|
+
overflow,
|
|
38
|
+
size = "md",
|
|
39
|
+
truncate = false,
|
|
40
|
+
font,
|
|
41
|
+
underline,
|
|
42
|
+
numberOfLines,
|
|
43
|
+
skipLinking,
|
|
44
|
+
testID,
|
|
45
|
+
weight = "normal",
|
|
46
|
+
}: TextProps): React.ReactElement {
|
|
47
|
+
function propsToStyle(): any {
|
|
48
|
+
const style: TextStyle = {};
|
|
49
|
+
if (overflow) {
|
|
50
|
+
console.warn(
|
|
51
|
+
"Text overflow is deprecated. Use `truncate` to cut off the text and add ellipse, otherwise breakWord is the default."
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
let computedFont = "primary";
|
|
55
|
+
if (font === "primary" || !font) {
|
|
56
|
+
if (weight === "bold") {
|
|
57
|
+
computedFont = "primaryBoldFont";
|
|
30
58
|
} else {
|
|
31
|
-
|
|
59
|
+
computedFont = "primaryFont";
|
|
32
60
|
}
|
|
33
|
-
} else if (
|
|
34
|
-
if (
|
|
35
|
-
|
|
61
|
+
} else if (font === "secondary") {
|
|
62
|
+
if (weight === "bold") {
|
|
63
|
+
computedFont = "secondaryBoldFont";
|
|
36
64
|
} else {
|
|
37
|
-
|
|
65
|
+
computedFont = "secondaryFont";
|
|
38
66
|
}
|
|
39
|
-
} else if (
|
|
40
|
-
|
|
41
|
-
} else if (
|
|
42
|
-
|
|
43
|
-
} else if (
|
|
44
|
-
if (
|
|
45
|
-
|
|
67
|
+
} else if (font === "button") {
|
|
68
|
+
computedFont = "buttonFont";
|
|
69
|
+
} else if (font === "title") {
|
|
70
|
+
computedFont = "titleFont";
|
|
71
|
+
} else if (font === "accent") {
|
|
72
|
+
if (weight === "bold") {
|
|
73
|
+
computedFont = "accentBoldFont";
|
|
46
74
|
} else {
|
|
47
|
-
|
|
75
|
+
computedFont = "accentFont";
|
|
48
76
|
}
|
|
49
77
|
}
|
|
78
|
+
if (weight === "bold") {
|
|
79
|
+
style.fontWeight = "bold";
|
|
80
|
+
}
|
|
50
81
|
|
|
51
|
-
style.fontFamily = Unifier.theme[
|
|
82
|
+
style.fontFamily = Unifier.theme[computedFont];
|
|
52
83
|
|
|
53
|
-
style.fontSize =
|
|
54
|
-
if (
|
|
55
|
-
style.textAlign =
|
|
84
|
+
style.fontSize = fontSizes[size || "md"];
|
|
85
|
+
if (align) {
|
|
86
|
+
style.textAlign = align;
|
|
56
87
|
}
|
|
57
|
-
if (
|
|
58
|
-
style.color = Unifier.theme[
|
|
88
|
+
if (color) {
|
|
89
|
+
style.color = Unifier.theme[color];
|
|
59
90
|
} else {
|
|
60
91
|
style.color = Unifier.theme.darkGray;
|
|
61
92
|
}
|
|
93
|
+
|
|
94
|
+
if (italic) {
|
|
95
|
+
style.fontStyle = "italic";
|
|
96
|
+
}
|
|
97
|
+
if (underline) {
|
|
98
|
+
style.textDecorationLine = "underline";
|
|
99
|
+
}
|
|
62
100
|
// TODO: might be useful for wrapping/truncating
|
|
63
|
-
// if (
|
|
101
|
+
// if (numberOfLines !== 1 && !inline) {
|
|
64
102
|
// style.flexWrap = "wrap";
|
|
65
103
|
// }
|
|
104
|
+
|
|
66
105
|
return style;
|
|
67
106
|
}
|
|
68
107
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
108
|
+
let lines = 0;
|
|
109
|
+
if (numberOfLines && truncate && numberOfLines > 1) {
|
|
110
|
+
console.error(`Cannot truncate Text and have ${numberOfLines} lines`);
|
|
111
|
+
}
|
|
112
|
+
if (numberOfLines) {
|
|
113
|
+
lines = numberOfLines;
|
|
114
|
+
} else if (inline || truncate) {
|
|
115
|
+
lines = 1;
|
|
116
|
+
}
|
|
117
|
+
const inner = (
|
|
118
|
+
<NativeText numberOfLines={lines} style={propsToStyle()} testID={testID}>
|
|
119
|
+
{children}
|
|
120
|
+
</NativeText>
|
|
121
|
+
);
|
|
122
|
+
if (skipLinking) {
|
|
123
|
+
return inner;
|
|
124
|
+
} else {
|
|
125
|
+
return (
|
|
126
|
+
<Hyperlink linkDefault linkStyle={{textDecorationLine: "underline"}}>
|
|
127
|
+
{inner}
|
|
128
|
+
</Hyperlink>
|
|
80
129
|
);
|
|
81
|
-
if (this.props.skipLinking) {
|
|
82
|
-
return inner;
|
|
83
|
-
} else {
|
|
84
|
-
return (
|
|
85
|
-
<Hyperlink linkDefault linkStyle={{textDecorationLine: "underline"}}>
|
|
86
|
-
{inner}
|
|
87
|
-
</Hyperlink>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
130
|
}
|
|
91
131
|
}
|
package/src/Tooltip.tsx
CHANGED
|
@@ -157,6 +157,10 @@ export const Tooltip = forwardRef((props: TooltipProps, _ref: any) => {
|
|
|
157
157
|
}, []);
|
|
158
158
|
|
|
159
159
|
const handleOnLayout = ({nativeEvent: {layout}}: LayoutChangeEvent) => {
|
|
160
|
+
if (childrenWrapperRef?.current && !childrenWrapperRef?.current?.measure) {
|
|
161
|
+
console.error("Tooltip: childrenWrapperRef does not have a measure method.");
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
160
164
|
childrenWrapperRef?.current?.measure((_x, _y, width, height, pageX, pageY) => {
|
|
161
165
|
setMeasurement({
|
|
162
166
|
children: {pageX, pageY, height, width},
|