@draftbit/core 44.1.13-9a8dff.0 → 44.1.13-c10e64.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.
Files changed (57) hide show
  1. package/lib/commonjs/components/CircularProgress.js.map +1 -1
  2. package/lib/commonjs/components/DatePicker/DatePickerComponent.web.js.map +1 -1
  3. package/lib/commonjs/components/DeprecatedButton.js +4 -19
  4. package/lib/commonjs/components/DeprecatedButton.js.map +1 -1
  5. package/lib/commonjs/components/Picker/Picker.js +27 -266
  6. package/lib/commonjs/components/Picker/Picker.js.map +1 -1
  7. package/lib/commonjs/components/Picker/PickerComponent.android.js +120 -19
  8. package/lib/commonjs/components/Picker/PickerComponent.android.js.map +1 -1
  9. package/lib/commonjs/components/Picker/PickerComponent.ios.js +146 -35
  10. package/lib/commonjs/components/Picker/PickerComponent.ios.js.map +1 -1
  11. package/lib/commonjs/components/Picker/PickerComponent.web.js +121 -19
  12. package/lib/commonjs/components/Picker/PickerComponent.web.js.map +1 -1
  13. package/lib/commonjs/components/Picker/PickerTypes.js +6 -0
  14. package/lib/commonjs/components/Picker/PickerTypes.js.map +1 -0
  15. package/lib/commonjs/mappings/Picker.js +1 -7
  16. package/lib/commonjs/mappings/Picker.js.map +1 -1
  17. package/lib/commonjs/utilities.js +0 -19
  18. package/lib/commonjs/utilities.js.map +1 -1
  19. package/lib/module/components/Carousel.js +5 -20
  20. package/lib/module/components/Carousel.js.map +1 -1
  21. package/lib/module/components/Picker/Picker.js +28 -260
  22. package/lib/module/components/Picker/Picker.js.map +1 -1
  23. package/lib/module/components/Picker/PickerComponent.android.js +109 -18
  24. package/lib/module/components/Picker/PickerComponent.android.js.map +1 -1
  25. package/lib/module/components/Picker/PickerComponent.ios.js +132 -35
  26. package/lib/module/components/Picker/PickerComponent.ios.js.map +1 -1
  27. package/lib/module/components/Picker/PickerComponent.web.js +110 -18
  28. package/lib/module/components/Picker/PickerComponent.web.js.map +1 -1
  29. package/lib/module/components/Picker/PickerTypes.js +2 -0
  30. package/lib/module/components/Picker/PickerTypes.js.map +1 -0
  31. package/lib/module/mappings/CheckboxRow.js.map +1 -1
  32. package/lib/module/mappings/Picker.js +2 -8
  33. package/lib/module/mappings/Picker.js.map +1 -1
  34. package/lib/module/utilities.js +1 -12
  35. package/lib/module/utilities.js.map +1 -1
  36. package/lib/typescript/src/components/Picker/Picker.d.ts +4 -28
  37. package/lib/typescript/src/components/Picker/PickerComponent.android.d.ts +5 -12
  38. package/lib/typescript/src/components/Picker/PickerComponent.ios.d.ts +5 -11
  39. package/lib/typescript/src/components/Picker/PickerComponent.web.d.ts +5 -12
  40. package/lib/typescript/src/components/Picker/PickerTypes.d.ts +18 -0
  41. package/lib/typescript/src/mappings/Picker.d.ts +0 -21
  42. package/lib/typescript/src/utilities.d.ts +0 -7
  43. package/package.json +2 -2
  44. package/src/components/Picker/Picker.js +17 -229
  45. package/src/components/Picker/Picker.tsx +34 -434
  46. package/src/components/Picker/PickerComponent.android.js +66 -16
  47. package/src/components/Picker/PickerComponent.android.tsx +107 -28
  48. package/src/components/Picker/PickerComponent.ios.js +76 -32
  49. package/src/components/Picker/PickerComponent.ios.tsx +137 -49
  50. package/src/components/Picker/PickerComponent.web.js +67 -16
  51. package/src/components/Picker/PickerComponent.web.tsx +108 -28
  52. package/src/components/Picker/PickerTypes.js +1 -0
  53. package/src/components/Picker/PickerTypes.ts +18 -0
  54. package/src/mappings/Picker.js +1 -3
  55. package/src/mappings/Picker.ts +0 -4
  56. package/src/utilities.js +1 -49
  57. package/src/utilities.ts +1 -65
@@ -1,79 +1,31 @@
1
1
  import * as React from "react";
2
- import {
3
- View,
4
- StyleSheet,
5
- Text,
6
- // Platform,
7
- ViewStyle,
8
- StyleProp,
9
- Dimensions,
10
- } from "react-native";
11
- import { omit, pickBy, identity, isObject } from "lodash";
12
- // import { SafeAreaView } from "react-native-safe-area-context";
13
- // import { Picker as NativePicker } from "@react-native-picker/picker";
14
-
15
2
  import { withTheme } from "../../theming";
16
- // import Portal from "../Portal/Portal";
17
- // import Button from "../DeprecatedButton";
18
- import Touchable from "../Touchable";
19
- import type { Theme } from "../../styles/DefaultTheme";
20
- import type { IconSlot } from "../../interfaces/Icon";
21
- import {
22
- extractStyles,
23
- extractBorderAndMarginStyles,
24
- borderStyleNames,
25
- marginStyleNames,
26
- } from "../../utilities";
27
- // @ts-expect-error
28
- import { PickerComponent } from "./PickerComponent";
29
-
30
- export interface PickerOption {
31
- value: string;
32
- label: string;
33
- }
3
+ //@ts-ignore
4
+ import PickerComponent from "./PickerComponent"; //unable to find file due to using .android/.web/.ios
5
+ import { PickerComponentProps, PickerOption } from "./PickerTypes";
34
6
 
35
- export type PickerProps = {
36
- error?: any;
7
+ type Props = PickerComponentProps & {
37
8
  placeholder?: string;
38
- disabled?: boolean;
39
- style?: StyleProp<ViewStyle> & { height?: number };
40
9
  value?: string;
41
10
  options: PickerOption[] | string[];
42
- onValueChange: (value: string, index: number) => void;
43
- defaultValue?: string;
44
- assistiveText?: string;
45
- label?: string;
46
- iconColor?: string;
47
- iconSize?: number;
48
- leftIconMode?: "inset" | "outset";
49
- leftIconName?: string;
50
- placeholderTextColor?: string;
51
- rightIconName?: string;
52
- type?: "solid" | "underline";
53
- theme: Theme;
54
- Icon: IconSlot["Icon"];
55
11
  };
56
12
 
57
- function normalizeOptions(options: PickerProps["options"]): PickerOption[] {
13
+ function normalizeOptions(options: Props["options"]): PickerOption[] {
58
14
  if (options.length === 0) {
59
15
  return [];
60
16
  }
61
17
 
62
- if (typeof options[0] === ("string" || "number")) {
18
+ if (typeof options[0] === "string") {
63
19
  return (options as string[]).map((option) => ({
64
- label: String(option),
20
+ label: option,
65
21
  value: String(option),
66
22
  }));
67
23
  }
68
24
 
69
- if (
70
- isObject(options[0]) &&
71
- options[0].value !== null &&
72
- options[0].label !== null
73
- ) {
74
- return (options as PickerOption[]).map((option) => {
25
+ if (options[0].label && options[0].value) {
26
+ return options.map((option) => {
75
27
  return {
76
- label: String(option.label),
28
+ label: option.label,
77
29
  value: String(option.value),
78
30
  };
79
31
  });
@@ -84,45 +36,18 @@ function normalizeOptions(options: PickerProps["options"]): PickerOption[] {
84
36
  );
85
37
  }
86
38
 
87
- const { width: deviceWidth, height: deviceHeight } = Dimensions.get("screen");
88
- // const isIos = Platform.OS === "ios";
89
- const unstyledColor = "rgba(165, 173, 183, 1)";
90
- const disabledColor = "rgb(240, 240, 240)";
91
- const errorColor = "rgba(255, 69, 100, 1)";
92
-
93
- const Picker: React.FC<PickerProps> = ({
94
- error,
39
+ const Picker: React.FC<Props> = ({
95
40
  options = [],
96
- onValueChange,
97
- defaultValue,
98
- Icon,
99
- style,
100
41
  placeholder,
42
+ onValueChange: onValueChangeOverride,
101
43
  value,
102
- disabled = false,
103
- // theme,
104
- assistiveText,
105
- label,
106
- iconColor = unstyledColor,
107
- iconSize = 24,
108
- leftIconMode = "inset",
109
- leftIconName,
110
- placeholderTextColor = unstyledColor,
111
- rightIconName,
112
- type = "solid",
44
+ defaultValue,
45
+ ...props
113
46
  }) => {
114
- const androidPickerRef = React.useRef<any | undefined>(undefined);
115
-
116
47
  const [internalValue, setInternalValue] = React.useState<string | undefined>(
117
48
  value || defaultValue
118
49
  );
119
50
 
120
- const [pickerVisible, setPickerVisible] = React.useState(false);
121
-
122
- const togglePickerVisible = () => {
123
- setPickerVisible(!pickerVisible);
124
- };
125
-
126
51
  React.useEffect(() => {
127
52
  if (value != null) {
128
53
  setInternalValue(value);
@@ -135,11 +60,16 @@ const Picker: React.FC<PickerProps> = ({
135
60
  }
136
61
  }, [defaultValue]);
137
62
 
138
- React.useEffect(() => {
139
- if (pickerVisible && androidPickerRef.current) {
140
- androidPickerRef?.current?.focus();
141
- }
142
- }, [pickerVisible, androidPickerRef]);
63
+ const onValueChange = React.useCallback(
64
+ (itemValue: string, itemIndex: number) => {
65
+ if (placeholder && itemIndex === 0) {
66
+ return;
67
+ }
68
+ onValueChangeOverride &&
69
+ onValueChangeOverride(String(itemValue), itemIndex);
70
+ },
71
+ [placeholder, onValueChangeOverride]
72
+ );
143
73
 
144
74
  const normalizedOptions = normalizeOptions(options);
145
75
 
@@ -147,352 +77,22 @@ const Picker: React.FC<PickerProps> = ({
147
77
  ? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
148
78
  : normalizedOptions;
149
79
 
150
- // const { colors } = theme;
151
-
152
- const { viewStyles, textStyles } = extractStyles(style);
153
-
154
- const additionalBorderStyles = ["backgroundColor"];
155
-
156
- const additionalMarginStyles = [
157
- "bottom",
158
- "height",
159
- "left",
160
- "maxHeight",
161
- "maxWidth",
162
- "minHeight",
163
- "minWidth",
164
- "overflow",
165
- "position",
166
- "right",
167
- "top",
168
- "width",
169
- "zIndex",
170
- ];
171
-
172
- const {
173
- borderStyles: extractedBorderStyles,
174
- marginStyles: extractedMarginStyles,
175
- } = extractBorderAndMarginStyles(
176
- viewStyles,
177
- additionalBorderStyles,
178
- additionalMarginStyles
179
- );
180
-
181
- const borderStyles = {
182
- ...{
183
- ...(type === "solid"
184
- ? {
185
- borderTopLeftRadius: 5,
186
- borderTopRightRadius: 5,
187
- borderBottomRightRadius: 5,
188
- borderBottomLeftRadius: 5,
189
- borderTopWidth: 1,
190
- borderRightWidth: 1,
191
- borderLeftWidth: 1,
192
- }
193
- : {}),
194
- borderBottomWidth: 1,
195
- borderColor: unstyledColor,
196
- borderStyle: "solid",
197
- },
198
- ...extractedBorderStyles,
199
- ...(error ? { borderColor: errorColor } : {}),
200
- ...(disabled
201
- ? { borderColor: "transparent", backgroundColor: disabledColor }
202
- : {}),
203
- };
204
-
205
- const marginStyles = {
206
- height: 60,
207
- ...extractedMarginStyles,
208
- };
209
-
210
- const stylesWithoutBordersAndMargins = omit(viewStyles, [
211
- ...borderStyleNames,
212
- ...marginStyleNames,
213
- ...additionalBorderStyles,
214
- ...additionalMarginStyles,
215
- ]);
216
-
217
- const selectedLabel =
218
- internalValue &&
219
- ((pickerOptions as unknown as PickerOption[]).find(
220
- (option) => option.value === internalValue
221
- )?.label ??
222
- internalValue);
223
-
224
- const labelText = label ? (
225
- <Text
226
- style={{
227
- textAlign: textStyles.textAlign,
228
- color: unstyledColor,
229
- fontSize: 12,
230
- paddingBottom: 4,
231
- }}
232
- >
233
- {label}
234
- </Text>
235
- ) : null;
236
-
237
- const leftIconOutset = leftIconMode === "outset";
238
-
239
- const leftIcon = leftIconName ? (
240
- <Icon
241
- name={leftIconName}
242
- color={disabled ? unstyledColor : iconColor}
243
- size={iconSize}
244
- style={{
245
- marginRight: 4,
246
- marginLeft: 4,
247
- }}
248
- />
249
- ) : null;
250
-
251
- const rightIcon = rightIconName ? (
252
- <Icon
253
- name={rightIconName}
254
- color={disabled ? unstyledColor : iconColor}
255
- size={iconSize}
256
- style={{
257
- marginRight: -10,
258
- marginLeft: 8,
259
- }}
260
- />
261
- ) : null;
262
-
263
- const textAlign = textStyles?.textAlign;
264
-
265
- const calculateLeftPadding = () => {
266
- if (leftIconOutset) {
267
- if (textAlign === "center") {
268
- return iconSize - Math.abs(8 - iconSize);
269
- }
270
-
271
- return iconSize + 8;
272
- }
273
-
274
- return 0;
275
- };
276
-
277
- const assistiveTextLabel = assistiveText ? (
278
- <Text
279
- style={{
280
- textAlign,
281
- width: "100%",
282
- paddingLeft: calculateLeftPadding(),
283
- color: unstyledColor,
284
- fontSize: 12,
285
- paddingTop: 4,
286
- }}
287
- >
288
- {assistiveText}
289
- </Text>
290
- ) : null;
291
-
292
- const primaryTextStyle = {
293
- color: unstyledColor,
294
- fontSize: 14,
295
- ...pickBy(textStyles, identity),
296
- ...(placeholder === internalValue ? { color: placeholderTextColor } : {}),
297
- ...(disabled ? { color: unstyledColor } : {}),
298
- };
299
-
300
80
  const handleValueChange = (newValue: string, itemIndex: number) => {
301
- if (!placeholder || itemIndex > 0) {
302
- onValueChange?.(newValue, itemIndex);
303
- }
304
81
  setInternalValue(newValue);
82
+ if (onValueChange) {
83
+ onValueChange(newValue, itemIndex);
84
+ }
305
85
  };
306
86
 
307
87
  return (
308
- /* marginsContainer */
309
- <View style={[styles.marginsContainer, marginStyles]}>
310
- {/* touchableContainer */}
311
- <Touchable
312
- disabled={disabled}
313
- onPress={togglePickerVisible}
314
- style={styles.touchableContainer}
315
- >
316
- {/* outsetContainer */}
317
- <View
318
- pointerEvents="none"
319
- style={[
320
- styles.outsetContainer,
321
- stylesWithoutBordersAndMargins,
322
- !leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
323
- ]}
324
- >
325
- {leftIcon}
326
-
327
- {/* insetContainer */}
328
- <View
329
- style={[
330
- styles.insetContainer,
331
- leftIconOutset ? (borderStyles as PickerProps["style"]) : {},
332
- ]}
333
- >
334
- {/* primaryTextContainer */}
335
- <View style={styles.primaryTextContainer}>
336
- {labelText}
337
-
338
- <Text style={primaryTextStyle}>
339
- {String(selectedLabel ?? placeholder)}
340
- </Text>
341
- </View>
342
-
343
- {rightIcon}
344
- </View>
345
- </View>
346
- {assistiveTextLabel}
347
- </Touchable>
348
-
349
- <View>
350
- {pickerVisible ? (
351
- <PickerComponent
352
- {...{
353
- Icon,
354
- androidPickerRef,
355
- togglePickerVisible,
356
- pickerOptions,
357
- internalValue,
358
- handleValueChange,
359
- }}
360
- />
361
- ) : null}
362
- </View>
363
-
364
- {/* iosPicker */}
365
- {/* isIos && pickerVisible ? (
366
- <Portal>
367
- <View
368
- style={[
369
- styles.iosPicker,
370
- {
371
- backgroundColor: colors.divider,
372
- },
373
- ]}
374
- >
375
- <SafeAreaView style={styles.iosSafeArea}>
376
- <Button
377
- Icon={Icon}
378
- type="text"
379
- onPress={togglePickerVisible}
380
- style={styles.iosButton}
381
- >
382
- {"Close"}
383
- </Button>
384
-
385
- <NativePicker
386
- style={styles.iosNativePicker}
387
- selectedValue={internalValue}
388
- onValueChange={handleValueChange}
389
- >
390
- {(pickerOptions as unknown as PickerOption[]).map((option) => (
391
- <NativePicker.Item
392
- label={option.label}
393
- value={option.value}
394
- key={option.value}
395
- />
396
- ))}
397
- </NativePicker>
398
- </SafeAreaView>
399
- </View>
400
- </Portal>
401
- ) : null */}
402
-
403
- {/* nonIosPicker */}
404
- {/* !isIos && pickerVisible ? (
405
- <NativePicker
406
- enabled={pickerVisible}
407
- selectedValue={internalValue}
408
- onValueChange={handleValueChange}
409
- style={styles.nonIosPicker}
410
- ref={androidPickerRef}
411
- onBlur={() => setPickerVisible(false)}
412
- >
413
- {(pickerOptions as unknown as PickerOption[]).map((option) => (
414
- <NativePicker.Item
415
- label={option.label}
416
- value={option.value}
417
- key={option.value}
418
- />
419
- ))}
420
- </NativePicker>
421
- ) : null */}
422
- </View>
88
+ <PickerComponent
89
+ {...props}
90
+ selectedValue={String(internalValue)}
91
+ placeholder={placeholder}
92
+ options={pickerOptions}
93
+ onValueChange={handleValueChange}
94
+ />
423
95
  );
424
96
  };
425
97
 
426
98
  export default withTheme(Picker);
427
-
428
- const styles = StyleSheet.create({
429
- marginsContainer: {
430
- alignSelf: "stretch",
431
- alignItems: "center",
432
- width: "100%",
433
- maxWidth: deviceWidth,
434
- },
435
- touchableContainer: {
436
- flex: 1,
437
- height: "100%",
438
- width: "100%",
439
- alignSelf: "stretch",
440
- alignItems: "center",
441
- backgroundColor: "pink", // TODO
442
- },
443
- outsetContainer: {
444
- flex: 1,
445
- height: "100%",
446
- width: "100%",
447
- flexDirection: "row",
448
- alignItems: "center",
449
- justifyContent: "space-between",
450
- },
451
- insetContainer: {
452
- flex: 1,
453
- height: "100%",
454
- width: "100%",
455
- flexDirection: "row",
456
- alignItems: "center",
457
- justifyContent: "space-between",
458
- paddingLeft: 12,
459
- paddingRight: 12,
460
- },
461
- primaryTextContainer: {
462
- flex: 1,
463
- },
464
- iosPicker: {
465
- position: "absolute",
466
- bottom: 0,
467
- left: 0,
468
- right: 0,
469
- flexDirection: "row",
470
- justifyContent: "center",
471
- width: "100%",
472
- maxWidth: deviceWidth,
473
- maxHeight: deviceHeight,
474
- },
475
- iosSafeArea: {
476
- backgroundColor: "white",
477
- flexDirection: "column",
478
- width: "100%",
479
- maxWidth: deviceWidth,
480
- },
481
- iosButton: {
482
- alignSelf: "flex-end",
483
- },
484
- iosNativePicker: {
485
- backgroundColor: "white",
486
- },
487
- nonIosPicker: {
488
- opacity: 0,
489
- position: "absolute",
490
- top: 0,
491
- left: 0,
492
- right: 0,
493
- bottom: 0,
494
- width: "100%",
495
- maxWidth: deviceWidth,
496
- maxHeight: deviceHeight,
497
- },
498
- });
@@ -1,18 +1,68 @@
1
1
  import * as React from "react";
2
- import { /* StyleSheet, Dimensions, View, */ Text } from "react-native";
3
- export const PickerComponent = () => {
4
- return React.createElement(Text, null, "android");
2
+ import { View, StyleSheet } from "react-native";
3
+ import omit from "lodash.omit";
4
+ import { withTheme } from "../../theming";
5
+ import { Picker as NativePicker } from "@react-native-picker/picker";
6
+ import { extractStyles } from "../../utilities";
7
+ import TextField from "../TextField";
8
+ import Touchable from "../Touchable";
9
+ const Picker = ({ style, options, placeholder, selectedValue, disabled = false, onValueChange: onValueChangeOverride = () => { }, ...props }) => {
10
+ const { viewStyles: { borderRadius, // eslint-disable-line @typescript-eslint/no-unused-vars
11
+ borderWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
12
+ borderTopWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
13
+ borderRightWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
14
+ borderBottomWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
15
+ borderLeftWidth, // eslint-disable-line @typescript-eslint/no-unused-vars
16
+ borderColor, // eslint-disable-line @typescript-eslint/no-unused-vars
17
+ backgroundColor, // eslint-disable-line @typescript-eslint/no-unused-vars
18
+ padding, // eslint-disable-line @typescript-eslint/no-unused-vars
19
+ paddingTop, // eslint-disable-line @typescript-eslint/no-unused-vars
20
+ paddingRight, // eslint-disable-line @typescript-eslint/no-unused-vars
21
+ paddingBottom, // eslint-disable-line @typescript-eslint/no-unused-vars
22
+ paddingLeft, // eslint-disable-line @typescript-eslint/no-unused-vars
23
+ ...viewStyles }, } = extractStyles(style);
24
+ const textField = React.useRef(undefined);
25
+ const onValueChange = (itemValue, itemIndex) => {
26
+ toggleFocus();
27
+ onValueChangeOverride(itemValue, itemIndex);
28
+ };
29
+ const toggleFocus = () => {
30
+ if (!disabled) {
31
+ // @ts-ignore
32
+ textField.current.toggleFocus(); // cannot determine if method exists due to component being wrapped in a withTheme()
33
+ }
34
+ };
35
+ const stylesWithoutMargin = style &&
36
+ omit(StyleSheet.flatten(style), [
37
+ "margin",
38
+ "marginTop",
39
+ "marginRight",
40
+ "marginBottom",
41
+ "marginLeft",
42
+ ]);
43
+ const selectedLabel = selectedValue &&
44
+ (options.find((o) => o.value === selectedValue)?.label ?? selectedValue);
45
+ return (React.createElement(Touchable, { disabled: disabled, onPress: toggleFocus, style: [styles.container, viewStyles] },
46
+ React.createElement(View, null,
47
+ React.createElement(NativePicker, { enabled: !disabled, selectedValue: selectedValue, onValueChange: onValueChange, style: {
48
+ opacity: 0,
49
+ position: "absolute",
50
+ top: 0,
51
+ left: 0,
52
+ right: 0,
53
+ bottom: 0,
54
+ width: "100%",
55
+ } }, options.map((o) => (React.createElement(NativePicker.Item, { label: o.label, value: o.value, key: o.value })))),
56
+ React.createElement(View, { pointerEvents: "none" },
57
+ React.createElement(TextField, { ...props, value: selectedLabel, placeholder: placeholder,
58
+ // @ts-ignore
59
+ ref: textField, disabled: disabled,
60
+ // @ts-expect-error
61
+ style: stylesWithoutMargin })))));
5
62
  };
6
- // const styles = StyleSheet.create({
7
- // nonIosPicker: {
8
- // opacity: 0,
9
- // position: "absolute",
10
- // top: 0,
11
- // left: 0,
12
- // right: 0,
13
- // bottom: 0,
14
- // width: "100%",
15
- // maxWidth: deviceWidth,
16
- // maxHeight: deviceHeight,
17
- // },
18
- // });
63
+ const styles = StyleSheet.create({
64
+ container: {
65
+ alignSelf: "stretch",
66
+ },
67
+ });
68
+ export default withTheme(Picker);