ferns-ui 0.36.4 → 0.37.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/Banner.d.ts +6 -16
- package/dist/Banner.js +52 -43
- package/dist/Banner.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/useStoredState.d.ts +1 -0
- package/dist/useStoredState.js +33 -0
- package/dist/useStoredState.js.map +1 -0
- package/package.json +55 -56
- package/src/ActionSheet.tsx +1231 -0
- package/src/Avatar.tsx +317 -0
- package/src/Badge.tsx +65 -0
- package/src/Banner.tsx +149 -0
- package/src/BlurBox.native.tsx +40 -0
- package/src/BlurBox.tsx +31 -0
- package/src/Body.tsx +32 -0
- package/src/Box.tsx +308 -0
- package/src/Button.tsx +219 -0
- package/src/Card.tsx +23 -0
- package/src/CheckBox.tsx +118 -0
- package/src/Common.ts +2743 -0
- package/src/Constants.ts +53 -0
- package/src/CustomSelect.tsx +85 -0
- package/src/DateTimeActionSheet.tsx +409 -0
- package/src/DateTimeField.android.tsx +101 -0
- package/src/DateTimeField.ios.tsx +83 -0
- package/src/DateTimeField.tsx +69 -0
- package/src/DecimalRangeActionSheet.tsx +113 -0
- package/src/ErrorBoundary.tsx +37 -0
- package/src/ErrorPage.tsx +44 -0
- package/src/FernsProvider.tsx +21 -0
- package/src/Field.tsx +299 -0
- package/src/FieldWithLabels.tsx +36 -0
- package/src/FlatList.tsx +2 -0
- package/src/Form.tsx +182 -0
- package/src/HeaderButtons.tsx +107 -0
- package/src/Heading.tsx +53 -0
- package/src/HeightActionSheet.tsx +104 -0
- package/src/Hyperlink.tsx +181 -0
- package/src/Icon.tsx +24 -0
- package/src/IconButton.tsx +165 -0
- package/src/Image.tsx +50 -0
- package/src/ImageBackground.tsx +14 -0
- package/src/InfoTooltipButton.tsx +23 -0
- package/src/Layer.tsx +17 -0
- package/src/Link.tsx +17 -0
- package/src/Mask.tsx +21 -0
- package/src/MediaQuery.ts +46 -0
- package/src/Meta.tsx +9 -0
- package/src/Modal.tsx +248 -0
- package/src/ModalSheet.tsx +58 -0
- package/src/NumberPickerActionSheet.tsx +66 -0
- package/src/Page.tsx +133 -0
- package/src/Permissions.ts +44 -0
- package/src/PickerSelect.tsx +553 -0
- package/src/Pill.tsx +24 -0
- package/src/Pog.tsx +87 -0
- package/src/ProgressBar.tsx +55 -0
- package/src/ScrollView.tsx +2 -0
- package/src/SegmentedControl.tsx +102 -0
- package/src/SelectList.tsx +89 -0
- package/src/SideDrawer.tsx +62 -0
- package/src/Spinner.tsx +20 -0
- package/src/SplitPage.native.tsx +160 -0
- package/src/SplitPage.tsx +302 -0
- package/src/Switch.tsx +19 -0
- package/src/Table.tsx +87 -0
- package/src/TableHeader.tsx +36 -0
- package/src/TableHeaderCell.tsx +76 -0
- package/src/TableRow.tsx +87 -0
- package/src/TapToEdit.tsx +221 -0
- package/src/Text.tsx +131 -0
- package/src/TextArea.tsx +16 -0
- package/src/TextField.tsx +401 -0
- package/src/TextFieldNumberActionSheet.tsx +61 -0
- package/src/Toast.tsx +106 -0
- package/src/Tooltip.tsx +269 -0
- package/src/UnifiedScreens.ts +24 -0
- package/src/Unifier.ts +371 -0
- package/src/Utilities.tsx +159 -0
- package/src/WithLabel.tsx +57 -0
- package/src/dayjsExtended.ts +10 -0
- package/src/index.tsx +1347 -0
- package/src/polyfill.d.ts +11 -0
- package/src/tableContext.tsx +80 -0
- package/src/useStoredState.ts +39 -0
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
// MIT License
|
|
2
|
+
|
|
3
|
+
// Copyright (c) LawnStarter
|
|
4
|
+
|
|
5
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
// in the Software without restriction, including without limitation the rights
|
|
8
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
// furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
// copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
// SOFTWARE.
|
|
22
|
+
|
|
23
|
+
// Forked 2021/11/26 by Josh Gachnang <josh@nang.io> from version 8.0.3 because it conflicted
|
|
24
|
+
// with react-native-picker in Expo, then converted to TS.
|
|
25
|
+
|
|
26
|
+
import {Picker} from "@react-native-picker/picker";
|
|
27
|
+
import isEqual from "lodash/isEqual";
|
|
28
|
+
import React, {useCallback, useEffect, useMemo, useState} from "react";
|
|
29
|
+
import {
|
|
30
|
+
Keyboard,
|
|
31
|
+
Modal,
|
|
32
|
+
Platform,
|
|
33
|
+
Pressable,
|
|
34
|
+
StyleSheet,
|
|
35
|
+
Text,
|
|
36
|
+
TextInput,
|
|
37
|
+
TouchableOpacity,
|
|
38
|
+
View,
|
|
39
|
+
} from "react-native";
|
|
40
|
+
|
|
41
|
+
export const defaultStyles = StyleSheet.create({
|
|
42
|
+
viewContainer: {
|
|
43
|
+
alignSelf: "stretch",
|
|
44
|
+
},
|
|
45
|
+
iconContainer: {
|
|
46
|
+
position: "absolute",
|
|
47
|
+
right: 0,
|
|
48
|
+
},
|
|
49
|
+
modalViewTop: {
|
|
50
|
+
flex: 1,
|
|
51
|
+
},
|
|
52
|
+
modalViewMiddle: {
|
|
53
|
+
height: 45,
|
|
54
|
+
flexDirection: "row",
|
|
55
|
+
justifyContent: "space-between",
|
|
56
|
+
alignItems: "center",
|
|
57
|
+
paddingHorizontal: 10,
|
|
58
|
+
backgroundColor: "#f8f8f8",
|
|
59
|
+
borderTopWidth: 1,
|
|
60
|
+
borderTopColor: "#dedede",
|
|
61
|
+
zIndex: 2,
|
|
62
|
+
},
|
|
63
|
+
chevronContainer: {
|
|
64
|
+
flexDirection: "row",
|
|
65
|
+
},
|
|
66
|
+
chevron: {
|
|
67
|
+
width: 15,
|
|
68
|
+
height: 15,
|
|
69
|
+
backgroundColor: "transparent",
|
|
70
|
+
borderColor: "#a1a1a1",
|
|
71
|
+
borderTopWidth: 1.5,
|
|
72
|
+
borderRightWidth: 1.5,
|
|
73
|
+
},
|
|
74
|
+
chevronUp: {
|
|
75
|
+
marginLeft: 11,
|
|
76
|
+
transform: [{translateY: 4}, {rotate: "-45deg"}],
|
|
77
|
+
},
|
|
78
|
+
chevronDown: {
|
|
79
|
+
marginLeft: 22,
|
|
80
|
+
transform: [{translateY: -5}, {rotate: "135deg"}],
|
|
81
|
+
},
|
|
82
|
+
chevronActive: {
|
|
83
|
+
borderColor: "#007aff",
|
|
84
|
+
},
|
|
85
|
+
done: {
|
|
86
|
+
color: "#007aff",
|
|
87
|
+
fontWeight: "600",
|
|
88
|
+
fontSize: 17,
|
|
89
|
+
paddingTop: 1,
|
|
90
|
+
paddingRight: 11,
|
|
91
|
+
},
|
|
92
|
+
doneDepressed: {
|
|
93
|
+
fontSize: 19,
|
|
94
|
+
},
|
|
95
|
+
modalViewBottom: {
|
|
96
|
+
justifyContent: "center",
|
|
97
|
+
backgroundColor: "#d0d4da",
|
|
98
|
+
},
|
|
99
|
+
placeholder: {
|
|
100
|
+
color: "#c7c7cd",
|
|
101
|
+
},
|
|
102
|
+
headlessAndroidPicker: {
|
|
103
|
+
position: "absolute",
|
|
104
|
+
width: "100%",
|
|
105
|
+
height: "100%",
|
|
106
|
+
color: "transparent",
|
|
107
|
+
opacity: 0,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
interface RNPickerSelectProps {
|
|
112
|
+
onValueChange: (value: any, index: any) => void;
|
|
113
|
+
items: any[];
|
|
114
|
+
value?: any;
|
|
115
|
+
placeholder?: any;
|
|
116
|
+
disabled?: boolean;
|
|
117
|
+
itemKey?: string | number;
|
|
118
|
+
style?: any;
|
|
119
|
+
children?: any;
|
|
120
|
+
onOpen?: () => void;
|
|
121
|
+
useNativeAndroidPickerStyle?: boolean;
|
|
122
|
+
fixAndroidTouchableBug?: boolean;
|
|
123
|
+
|
|
124
|
+
// Custom Modal props (iOS only)
|
|
125
|
+
doneText?: string;
|
|
126
|
+
onDonePress?: () => void;
|
|
127
|
+
onUpArrow?: () => void;
|
|
128
|
+
onDownArrow?: () => void;
|
|
129
|
+
onClose?: () => void;
|
|
130
|
+
|
|
131
|
+
// Modal props (iOS only)
|
|
132
|
+
modalProps?: any;
|
|
133
|
+
|
|
134
|
+
// TextInput props
|
|
135
|
+
textInputProps?: any;
|
|
136
|
+
|
|
137
|
+
// Picker props
|
|
138
|
+
pickerProps?: any;
|
|
139
|
+
|
|
140
|
+
// Touchable Done props (iOS only)
|
|
141
|
+
touchableDoneProps?: any;
|
|
142
|
+
|
|
143
|
+
// Touchable wrapper props
|
|
144
|
+
touchableWrapperProps?: any;
|
|
145
|
+
|
|
146
|
+
// Custom Icon
|
|
147
|
+
Icon?: any;
|
|
148
|
+
InputAccessoryView?: any;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function RNPickerSelect({
|
|
152
|
+
onValueChange,
|
|
153
|
+
value,
|
|
154
|
+
items,
|
|
155
|
+
placeholder = {
|
|
156
|
+
label: "Select an item...",
|
|
157
|
+
value: null,
|
|
158
|
+
color: "#9EA0A4",
|
|
159
|
+
},
|
|
160
|
+
disabled = false,
|
|
161
|
+
itemKey,
|
|
162
|
+
style = defaultStyles,
|
|
163
|
+
children,
|
|
164
|
+
useNativeAndroidPickerStyle = true,
|
|
165
|
+
fixAndroidTouchableBug = false,
|
|
166
|
+
doneText = "Done",
|
|
167
|
+
onDonePress,
|
|
168
|
+
onUpArrow,
|
|
169
|
+
onDownArrow,
|
|
170
|
+
onOpen,
|
|
171
|
+
onClose,
|
|
172
|
+
modalProps,
|
|
173
|
+
textInputProps,
|
|
174
|
+
pickerProps,
|
|
175
|
+
touchableDoneProps,
|
|
176
|
+
touchableWrapperProps,
|
|
177
|
+
Icon,
|
|
178
|
+
InputAccessoryView,
|
|
179
|
+
}: RNPickerSelectProps) {
|
|
180
|
+
const [selectedItem, setSelectedItem] = useState<any>();
|
|
181
|
+
const [showPicker, setShowPicker] = useState<boolean>(false);
|
|
182
|
+
const [animationType, setAnimationType] = useState(undefined);
|
|
183
|
+
const [orientation, setOrientation] = useState<"portrait" | "landscape">("portrait");
|
|
184
|
+
const [doneDepressed, setDoneDepressed] = useState<boolean>(false);
|
|
185
|
+
|
|
186
|
+
const options = useMemo(() => {
|
|
187
|
+
if (isEqual(placeholder, {})) {
|
|
188
|
+
return [...items];
|
|
189
|
+
} else {
|
|
190
|
+
return [placeholder, ...items];
|
|
191
|
+
}
|
|
192
|
+
}, [items, placeholder]);
|
|
193
|
+
|
|
194
|
+
const getSelectedItem = useCallback(
|
|
195
|
+
(key: any, val: any) => {
|
|
196
|
+
let idx = options.findIndex((item: any) => {
|
|
197
|
+
if (item.key && key) {
|
|
198
|
+
return isEqual(item.key, key);
|
|
199
|
+
}
|
|
200
|
+
return isEqual(item.value, val);
|
|
201
|
+
});
|
|
202
|
+
if (idx === -1) {
|
|
203
|
+
idx = 0;
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
selectedItem: options[idx] || {},
|
|
207
|
+
idx,
|
|
208
|
+
};
|
|
209
|
+
},
|
|
210
|
+
[options]
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
const item = getSelectedItem(itemKey, value);
|
|
215
|
+
setSelectedItem(item.selectedItem);
|
|
216
|
+
}, [getSelectedItem, itemKey, value]);
|
|
217
|
+
|
|
218
|
+
const onUpArrowEvent = () => {
|
|
219
|
+
togglePicker(false, onUpArrow);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const onDownArrowEvent = () => {
|
|
223
|
+
togglePicker(false, onDownArrow);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const onValueChangeEvent = (val: any, index: any) => {
|
|
227
|
+
const item = getSelectedItem(itemKey, val);
|
|
228
|
+
onValueChange(val, index);
|
|
229
|
+
setSelectedItem(item.selectedItem);
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const onOrientationChange = ({nativeEvent}: any) => {
|
|
233
|
+
setOrientation(nativeEvent.orientation);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const getPlaceholderStyle = () => {
|
|
237
|
+
if (!isEqual(placeholder, {}) && selectedItem?.label === placeholder?.label) {
|
|
238
|
+
return {
|
|
239
|
+
...defaultStyles.placeholder,
|
|
240
|
+
...style?.placeholder,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
return {};
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const triggerOpenCloseCallbacks = () => {
|
|
247
|
+
if (!showPicker && onOpen) {
|
|
248
|
+
onOpen();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (showPicker && onClose) {
|
|
252
|
+
onClose();
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const togglePicker = (animate = false, postToggleCallback?: any) => {
|
|
257
|
+
if (disabled) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (!showPicker) {
|
|
262
|
+
Keyboard.dismiss();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
setAnimationType(modalProps && modalProps?.animationType ? modalProps?.animationType : "slide");
|
|
266
|
+
|
|
267
|
+
triggerOpenCloseCallbacks();
|
|
268
|
+
|
|
269
|
+
setAnimationType(animate ? animationType : undefined);
|
|
270
|
+
setShowPicker(!showPicker);
|
|
271
|
+
|
|
272
|
+
if (postToggleCallback) {
|
|
273
|
+
postToggleCallback();
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const renderPickerItems = () => {
|
|
278
|
+
return options?.map((item: any) => {
|
|
279
|
+
return (
|
|
280
|
+
<Picker.Item
|
|
281
|
+
key={item.key || item.label}
|
|
282
|
+
color={item.color}
|
|
283
|
+
label={item.label}
|
|
284
|
+
value={item.value}
|
|
285
|
+
/>
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const renderInputAccessoryView = () => {
|
|
291
|
+
if (InputAccessoryView) {
|
|
292
|
+
return <InputAccessoryView testID="custom_input_accessory_view" />;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return (
|
|
296
|
+
<View
|
|
297
|
+
style={[defaultStyles.modalViewMiddle, style.modalViewMiddle]}
|
|
298
|
+
testID="input_accessory_view"
|
|
299
|
+
>
|
|
300
|
+
<View style={[defaultStyles.chevronContainer, style.chevronContainer]}>
|
|
301
|
+
<TouchableOpacity
|
|
302
|
+
activeOpacity={onUpArrow ? 0.5 : 1}
|
|
303
|
+
onPress={onUpArrow ? onUpArrowEvent : undefined}
|
|
304
|
+
>
|
|
305
|
+
<View
|
|
306
|
+
style={[
|
|
307
|
+
defaultStyles.chevron,
|
|
308
|
+
style.chevron,
|
|
309
|
+
defaultStyles.chevronUp,
|
|
310
|
+
style.chevronUp,
|
|
311
|
+
onUpArrow ? [defaultStyles.chevronActive, style.chevronActive] : {},
|
|
312
|
+
]}
|
|
313
|
+
/>
|
|
314
|
+
</TouchableOpacity>
|
|
315
|
+
<TouchableOpacity
|
|
316
|
+
activeOpacity={onDownArrow ? 0.5 : 1}
|
|
317
|
+
onPress={onDownArrow ? onDownArrowEvent : undefined}
|
|
318
|
+
>
|
|
319
|
+
<View
|
|
320
|
+
style={[
|
|
321
|
+
defaultStyles.chevron,
|
|
322
|
+
style.chevron,
|
|
323
|
+
defaultStyles.chevronDown,
|
|
324
|
+
style.chevronDown,
|
|
325
|
+
onDownArrow ? [defaultStyles.chevronActive, style.chevronActive] : {},
|
|
326
|
+
]}
|
|
327
|
+
/>
|
|
328
|
+
</TouchableOpacity>
|
|
329
|
+
</View>
|
|
330
|
+
<Pressable
|
|
331
|
+
hitSlop={{top: 4, right: 4, bottom: 4, left: 4}}
|
|
332
|
+
testID="done_button"
|
|
333
|
+
onPress={() => {
|
|
334
|
+
togglePicker(true, onDonePress);
|
|
335
|
+
}}
|
|
336
|
+
onPressIn={() => {
|
|
337
|
+
setDoneDepressed(true);
|
|
338
|
+
}}
|
|
339
|
+
onPressOut={() => {
|
|
340
|
+
setDoneDepressed(false);
|
|
341
|
+
}}
|
|
342
|
+
{...touchableDoneProps}
|
|
343
|
+
>
|
|
344
|
+
<View testID="needed_for_touchable">
|
|
345
|
+
<Text
|
|
346
|
+
allowFontScaling={false}
|
|
347
|
+
style={[
|
|
348
|
+
defaultStyles.done,
|
|
349
|
+
style.done,
|
|
350
|
+
doneDepressed ? [defaultStyles.doneDepressed, style.doneDepressed] : {},
|
|
351
|
+
]}
|
|
352
|
+
testID="done_text"
|
|
353
|
+
>
|
|
354
|
+
{doneText}
|
|
355
|
+
</Text>
|
|
356
|
+
</View>
|
|
357
|
+
</Pressable>
|
|
358
|
+
</View>
|
|
359
|
+
);
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const renderIcon = () => {
|
|
363
|
+
if (!Icon) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return (
|
|
368
|
+
<View
|
|
369
|
+
pointerEvents="none"
|
|
370
|
+
style={[defaultStyles.iconContainer, style.iconContainer]}
|
|
371
|
+
testID="icon_container"
|
|
372
|
+
>
|
|
373
|
+
<Icon testID="icon" />
|
|
374
|
+
</View>
|
|
375
|
+
);
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
const renderTextInputOrChildren = () => {
|
|
379
|
+
const containerStyle =
|
|
380
|
+
Platform.OS === "ios" ? style.inputIOSContainer : style.inputAndroidContainer;
|
|
381
|
+
|
|
382
|
+
if (children) {
|
|
383
|
+
return (
|
|
384
|
+
<View pointerEvents="box-only" style={containerStyle}>
|
|
385
|
+
{children}
|
|
386
|
+
</View>
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return (
|
|
391
|
+
<View pointerEvents="box-only" style={containerStyle}>
|
|
392
|
+
<TextInput
|
|
393
|
+
editable={false}
|
|
394
|
+
style={[
|
|
395
|
+
Platform.OS === "ios" ? style.inputIOS : style.inputAndroid,
|
|
396
|
+
getPlaceholderStyle(),
|
|
397
|
+
]}
|
|
398
|
+
testID="text_input"
|
|
399
|
+
value={selectedItem?.inputLabel ? selectedItem?.inputLabel : selectedItem?.label}
|
|
400
|
+
{...textInputProps}
|
|
401
|
+
/>
|
|
402
|
+
{renderIcon()}
|
|
403
|
+
</View>
|
|
404
|
+
);
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
const renderIOS = () => {
|
|
408
|
+
return (
|
|
409
|
+
<View style={[defaultStyles.viewContainer, style.viewContainer]}>
|
|
410
|
+
<Pressable
|
|
411
|
+
activeOpacity={1}
|
|
412
|
+
style={{
|
|
413
|
+
flexDirection: "row",
|
|
414
|
+
justifyContent: "center",
|
|
415
|
+
alignItems: "center",
|
|
416
|
+
minHeight: style?.minHeight || 50,
|
|
417
|
+
width: "100%",
|
|
418
|
+
}}
|
|
419
|
+
testID="ios_touchable_wrapper"
|
|
420
|
+
onPress={() => {
|
|
421
|
+
togglePicker(true);
|
|
422
|
+
}}
|
|
423
|
+
{...touchableWrapperProps}
|
|
424
|
+
>
|
|
425
|
+
{renderTextInputOrChildren()}
|
|
426
|
+
</Pressable>
|
|
427
|
+
<Modal
|
|
428
|
+
animationType={animationType}
|
|
429
|
+
supportedOrientations={["portrait", "landscape"]}
|
|
430
|
+
testID="ios_modal"
|
|
431
|
+
transparent
|
|
432
|
+
visible={showPicker}
|
|
433
|
+
onOrientationChange={onOrientationChange}
|
|
434
|
+
{...modalProps}
|
|
435
|
+
>
|
|
436
|
+
<Pressable
|
|
437
|
+
style={[defaultStyles.modalViewTop, style.modalViewTop]}
|
|
438
|
+
testID="ios_modal_top"
|
|
439
|
+
onPress={() => {
|
|
440
|
+
togglePicker(true);
|
|
441
|
+
}}
|
|
442
|
+
/>
|
|
443
|
+
{renderInputAccessoryView()}
|
|
444
|
+
<View
|
|
445
|
+
style={[
|
|
446
|
+
defaultStyles.modalViewBottom,
|
|
447
|
+
{height: orientation === "portrait" ? 215 : 162},
|
|
448
|
+
style.modalViewBottom,
|
|
449
|
+
]}
|
|
450
|
+
>
|
|
451
|
+
<Picker
|
|
452
|
+
selectedValue={selectedItem?.value}
|
|
453
|
+
testID="ios_picker"
|
|
454
|
+
onValueChange={onValueChangeEvent}
|
|
455
|
+
{...pickerProps}
|
|
456
|
+
>
|
|
457
|
+
{renderPickerItems()}
|
|
458
|
+
</Picker>
|
|
459
|
+
</View>
|
|
460
|
+
</Modal>
|
|
461
|
+
</View>
|
|
462
|
+
);
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
const renderAndroidHeadless = () => {
|
|
466
|
+
const Component: any = fixAndroidTouchableBug ? View : Pressable;
|
|
467
|
+
return (
|
|
468
|
+
<Component
|
|
469
|
+
activeOpacity={1}
|
|
470
|
+
testID="android_touchable_wrapper"
|
|
471
|
+
onPress={onOpen}
|
|
472
|
+
{...touchableWrapperProps}
|
|
473
|
+
>
|
|
474
|
+
<View style={style.headlessAndroidContainer}>
|
|
475
|
+
{renderTextInputOrChildren()}
|
|
476
|
+
<Picker
|
|
477
|
+
enabled={!disabled}
|
|
478
|
+
selectedValue={selectedItem?.value}
|
|
479
|
+
style={[
|
|
480
|
+
Icon ? {backgroundColor: "transparent"} : {}, // to hide native icon
|
|
481
|
+
defaultStyles.headlessAndroidPicker,
|
|
482
|
+
style.headlessAndroidPicker,
|
|
483
|
+
]}
|
|
484
|
+
testID="android_picker_headless"
|
|
485
|
+
onValueChange={onValueChangeEvent}
|
|
486
|
+
{...pickerProps}
|
|
487
|
+
>
|
|
488
|
+
{renderPickerItems()}
|
|
489
|
+
</Picker>
|
|
490
|
+
</View>
|
|
491
|
+
</Component>
|
|
492
|
+
);
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const renderAndroidNativePickerStyle = () => {
|
|
496
|
+
return (
|
|
497
|
+
<View style={[defaultStyles.viewContainer, style.viewContainer]}>
|
|
498
|
+
<Picker
|
|
499
|
+
enabled={!disabled}
|
|
500
|
+
selectedValue={selectedItem?.value}
|
|
501
|
+
style={[
|
|
502
|
+
Icon ? {backgroundColor: "transparent"} : {}, // to hide native icon
|
|
503
|
+
style.inputAndroid,
|
|
504
|
+
{width: "100%"},
|
|
505
|
+
getPlaceholderStyle(),
|
|
506
|
+
]}
|
|
507
|
+
testID="android_picker"
|
|
508
|
+
onValueChange={onValueChangeEvent}
|
|
509
|
+
{...pickerProps}
|
|
510
|
+
>
|
|
511
|
+
{renderPickerItems()}
|
|
512
|
+
</Picker>
|
|
513
|
+
{renderIcon()}
|
|
514
|
+
</View>
|
|
515
|
+
);
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
const renderWeb = () => {
|
|
519
|
+
return (
|
|
520
|
+
<View style={[defaultStyles.viewContainer, style.viewContainer]}>
|
|
521
|
+
<Picker
|
|
522
|
+
enabled={!disabled}
|
|
523
|
+
selectedValue={selectedItem?.value}
|
|
524
|
+
style={[{width: "100%", height: "100%", border: "none"}, style.inputWeb]}
|
|
525
|
+
testID="web_picker"
|
|
526
|
+
onValueChange={onValueChangeEvent}
|
|
527
|
+
{...pickerProps}
|
|
528
|
+
>
|
|
529
|
+
{renderPickerItems()}
|
|
530
|
+
</Picker>
|
|
531
|
+
{renderIcon()}
|
|
532
|
+
</View>
|
|
533
|
+
);
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
const render = () => {
|
|
537
|
+
if (Platform.OS === "ios") {
|
|
538
|
+
return renderIOS();
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
if (Platform.OS === "web") {
|
|
542
|
+
return renderWeb();
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
if (children || !useNativeAndroidPickerStyle) {
|
|
546
|
+
return renderAndroidHeadless();
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
return renderAndroidNativePickerStyle();
|
|
550
|
+
};
|
|
551
|
+
|
|
552
|
+
return render();
|
|
553
|
+
}
|
package/src/Pill.tsx
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import {Box} from "./Box";
|
|
4
|
+
import {PillProps} from "./Common";
|
|
5
|
+
import {Text} from "./Text";
|
|
6
|
+
|
|
7
|
+
export class Pill extends React.Component<PillProps, {}> {
|
|
8
|
+
render() {
|
|
9
|
+
return (
|
|
10
|
+
<Box
|
|
11
|
+
border={this.props.color}
|
|
12
|
+
color={this.props.enabled ? this.props.color : "white"}
|
|
13
|
+
paddingX={4}
|
|
14
|
+
paddingY={2}
|
|
15
|
+
rounding="pill"
|
|
16
|
+
onClick={() => this.props.onClick(!this.props.enabled)}
|
|
17
|
+
>
|
|
18
|
+
<Text align="center" color={this.props.enabled ? "white" : this.props.color}>
|
|
19
|
+
{this.props.text}
|
|
20
|
+
</Text>
|
|
21
|
+
</Box>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/Pog.tsx
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
import {Box} from "./Box";
|
|
5
|
+
import {AllColors, IconName, IconPrefix, IconSize} from "./Common";
|
|
6
|
+
import {Icon} from "./Icon";
|
|
7
|
+
|
|
8
|
+
const SIZE_NAME_TO_PIXEL = {
|
|
9
|
+
xs: 24,
|
|
10
|
+
sm: 32,
|
|
11
|
+
md: 40,
|
|
12
|
+
lg: 48,
|
|
13
|
+
xl: 56,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
active?: boolean;
|
|
18
|
+
bgColor?: "transparent" | "transparentDarkGray" | "gray" | "lightGray" | "white" | "blue";
|
|
19
|
+
focused?: boolean;
|
|
20
|
+
hovered?: boolean;
|
|
21
|
+
selected?: boolean;
|
|
22
|
+
iconColor?: AllColors;
|
|
23
|
+
icon: IconName;
|
|
24
|
+
iconPrefix?: IconPrefix;
|
|
25
|
+
size?: IconSize;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const defaultIconButtonIconColors = {
|
|
29
|
+
blue: "white",
|
|
30
|
+
darkGray: "white",
|
|
31
|
+
gray: "white",
|
|
32
|
+
lightGray: "gray",
|
|
33
|
+
transparent: "gray",
|
|
34
|
+
transparentDarkGray: "white",
|
|
35
|
+
white: "gray",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default function Pog(props: Props) {
|
|
39
|
+
const {
|
|
40
|
+
bgColor = "transparent",
|
|
41
|
+
iconColor,
|
|
42
|
+
icon,
|
|
43
|
+
iconPrefix = "fas",
|
|
44
|
+
selected = false,
|
|
45
|
+
size = "md",
|
|
46
|
+
} = props;
|
|
47
|
+
|
|
48
|
+
const color =
|
|
49
|
+
(selected && "white") ||
|
|
50
|
+
iconColor ||
|
|
51
|
+
(defaultIconButtonIconColors[bgColor] as AllColors) ||
|
|
52
|
+
"white";
|
|
53
|
+
|
|
54
|
+
const inlineStyle = {
|
|
55
|
+
height: SIZE_NAME_TO_PIXEL[size],
|
|
56
|
+
width: SIZE_NAME_TO_PIXEL[size],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// const classes = classnames(styles.pog, {
|
|
60
|
+
// [styles[bgColor]]: !selected,
|
|
61
|
+
// [styles.selected]: selected,
|
|
62
|
+
// [styles.active]: active,
|
|
63
|
+
// [styles.focused]: focused,
|
|
64
|
+
// [styles.hovered]: hovered && !focused && !active,
|
|
65
|
+
// });
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div style={inlineStyle}>
|
|
69
|
+
<Box rounding="circle">
|
|
70
|
+
{/*
|
|
71
|
+
We're explicitly setting an empty string as a label on the Icon since we
|
|
72
|
+
already have an aria-label on the button container.
|
|
73
|
+
This is similar to having empty `alt` attributes:
|
|
74
|
+
https://davidwalsh.name/accessibility-tip-empty-alt-attributes
|
|
75
|
+
*/}
|
|
76
|
+
<Icon
|
|
77
|
+
// accessibilityLabel=""
|
|
78
|
+
color={color}
|
|
79
|
+
// dangerouslySetSvgPath={dangerouslySetSvgPath}
|
|
80
|
+
name={icon}
|
|
81
|
+
prefix={iconPrefix}
|
|
82
|
+
size={size}
|
|
83
|
+
/>
|
|
84
|
+
</Box>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {View} from "react-native";
|
|
3
|
+
|
|
4
|
+
import {ProgressBarProps} from "./Common";
|
|
5
|
+
import {Unifier} from "./Unifier";
|
|
6
|
+
|
|
7
|
+
interface ProgressBarState {}
|
|
8
|
+
|
|
9
|
+
export class ProgressBar extends React.Component<ProgressBarProps, ProgressBarState> {
|
|
10
|
+
constructor(props: ProgressBarProps) {
|
|
11
|
+
super(props);
|
|
12
|
+
this.state = {};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
render() {
|
|
16
|
+
// console.log("PROGRESS", Unifier.theme[this.props.color], `${this.props.completed / 100}%`);
|
|
17
|
+
return (
|
|
18
|
+
<View
|
|
19
|
+
style={{
|
|
20
|
+
width: "100%",
|
|
21
|
+
height: 6,
|
|
22
|
+
}}
|
|
23
|
+
>
|
|
24
|
+
<View
|
|
25
|
+
style={{
|
|
26
|
+
width: "100%",
|
|
27
|
+
position: "absolute",
|
|
28
|
+
top: 0,
|
|
29
|
+
left: 0,
|
|
30
|
+
height: 6,
|
|
31
|
+
borderRadius: 6,
|
|
32
|
+
borderWidth: 1,
|
|
33
|
+
borderColor: Unifier.theme[this.props.color],
|
|
34
|
+
backgroundColor: Unifier.theme[this.props.color],
|
|
35
|
+
opacity: 0.3,
|
|
36
|
+
}}
|
|
37
|
+
/>
|
|
38
|
+
<View
|
|
39
|
+
style={{
|
|
40
|
+
width: `${Math.min(this.props.completed / 100, 1) * 100}%`,
|
|
41
|
+
position: "absolute",
|
|
42
|
+
top: 0,
|
|
43
|
+
left: 0,
|
|
44
|
+
height: 6,
|
|
45
|
+
borderRadius: 6,
|
|
46
|
+
borderWidth: 1,
|
|
47
|
+
borderColor: Unifier.theme[this.props.color],
|
|
48
|
+
backgroundColor: Unifier.theme[this.props.color],
|
|
49
|
+
opacity: 1,
|
|
50
|
+
}}
|
|
51
|
+
/>
|
|
52
|
+
</View>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|