ferns-ui 2.0.0-beta.2 → 2.0.0-beta.4

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 (140) hide show
  1. package/dist/Accordion.js +7 -2
  2. package/dist/Accordion.js.map +1 -1
  3. package/dist/ActionSheet.js +14 -11
  4. package/dist/ActionSheet.js.map +1 -1
  5. package/dist/AddressField.js +1 -1
  6. package/dist/AddressField.js.map +1 -1
  7. package/dist/Badge.js +1 -1
  8. package/dist/Badge.js.map +1 -1
  9. package/dist/Banner.js +1 -1
  10. package/dist/Banner.js.map +1 -1
  11. package/dist/Box.js +3 -3
  12. package/dist/Box.js.map +1 -1
  13. package/dist/Button.js +0 -1
  14. package/dist/Button.js.map +1 -1
  15. package/dist/CheckBox.js.map +1 -1
  16. package/dist/Common.d.ts +13 -9
  17. package/dist/Common.js.map +1 -1
  18. package/dist/DataTable.js +1 -2
  19. package/dist/DataTable.js.map +1 -1
  20. package/dist/DateTimeField.js +22 -22
  21. package/dist/DateTimeField.js.map +1 -1
  22. package/dist/EmailField.js +17 -37
  23. package/dist/EmailField.js.map +1 -1
  24. package/dist/FernsProvider.js +1 -1
  25. package/dist/FernsProvider.js.map +1 -1
  26. package/dist/Heading.js +3 -1
  27. package/dist/Heading.js.map +1 -1
  28. package/dist/Hyperlink.js +1 -1
  29. package/dist/Hyperlink.js.map +1 -1
  30. package/dist/IconButton.js +1 -1
  31. package/dist/IconButton.js.map +1 -1
  32. package/dist/Image.js.map +1 -1
  33. package/dist/MarkdownView.d.ts +5 -0
  34. package/dist/MarkdownView.js +44 -0
  35. package/dist/MarkdownView.js.map +1 -0
  36. package/dist/MobileAddressAutoComplete.js +1 -1
  37. package/dist/MobileAddressAutoComplete.js.map +1 -1
  38. package/dist/Modal.d.ts +1 -1
  39. package/dist/Modal.js +35 -15
  40. package/dist/Modal.js.map +1 -1
  41. package/dist/NumberField.js +10 -4
  42. package/dist/NumberField.js.map +1 -1
  43. package/dist/NumberPickerActionSheet.d.ts +1 -3
  44. package/dist/NumberPickerActionSheet.js +0 -3
  45. package/dist/NumberPickerActionSheet.js.map +1 -1
  46. package/dist/Page.js +1 -1
  47. package/dist/Page.js.map +1 -1
  48. package/dist/Pagination.js +2 -2
  49. package/dist/Pagination.js.map +1 -1
  50. package/dist/Permissions.d.ts +1 -1
  51. package/dist/Permissions.js +2 -2
  52. package/dist/Permissions.js.map +1 -1
  53. package/dist/PickerSelect.js +1 -1
  54. package/dist/PickerSelect.js.map +1 -1
  55. package/dist/SectionDivider.js +1 -1
  56. package/dist/SectionDivider.js.map +1 -1
  57. package/dist/SegmentedControl.js.map +1 -1
  58. package/dist/Signature.native.js +2 -2
  59. package/dist/Signature.native.js.map +1 -1
  60. package/dist/SignatureField.js +2 -2
  61. package/dist/SignatureField.js.map +1 -1
  62. package/dist/Slider.js +3 -3
  63. package/dist/Slider.js.map +1 -1
  64. package/dist/SplitPage.js +7 -7
  65. package/dist/SplitPage.js.map +1 -1
  66. package/dist/SplitPage.native.js +4 -6
  67. package/dist/SplitPage.native.js.map +1 -1
  68. package/dist/TapToEdit.js +3 -3
  69. package/dist/TapToEdit.js.map +1 -1
  70. package/dist/Text.js +1 -1
  71. package/dist/Text.js.map +1 -1
  72. package/dist/TextFieldNumberActionSheet.d.ts +2 -4
  73. package/dist/TextFieldNumberActionSheet.js +1 -4
  74. package/dist/TextFieldNumberActionSheet.js.map +1 -1
  75. package/dist/Tooltip.js +37 -19
  76. package/dist/Tooltip.js.map +1 -1
  77. package/dist/Unifier.d.ts +0 -1
  78. package/dist/Unifier.js.map +1 -1
  79. package/dist/Utilities.d.ts +1 -1
  80. package/dist/Utilities.js +2 -3
  81. package/dist/Utilities.js.map +1 -1
  82. package/dist/WebAddressAutocomplete.js +2 -1
  83. package/dist/WebAddressAutocomplete.js.map +1 -1
  84. package/dist/index.d.ts +10 -10
  85. package/dist/index.js +10 -9
  86. package/dist/index.js.map +1 -1
  87. package/dist/table/Table.js +14 -15
  88. package/dist/table/Table.js.map +1 -1
  89. package/dist/table/TableHeaderCell.js +2 -2
  90. package/dist/table/TableHeaderCell.js.map +1 -1
  91. package/dist/useStoredState.js +4 -2
  92. package/dist/useStoredState.js.map +1 -1
  93. package/package.json +5 -64
  94. package/src/Accordion.tsx +7 -1
  95. package/src/ActionSheet.tsx +26 -22
  96. package/src/AddressField.tsx +1 -1
  97. package/src/Badge.tsx +1 -1
  98. package/src/Banner.tsx +1 -1
  99. package/src/Box.test.tsx +71 -70
  100. package/src/Box.tsx +21 -9
  101. package/src/Button.tsx +0 -1
  102. package/src/CheckBox.tsx +7 -1
  103. package/src/Common.ts +14 -21
  104. package/src/DataTable.tsx +1 -2
  105. package/src/DateTimeField.tsx +22 -22
  106. package/src/EmailField.tsx +22 -42
  107. package/src/FernsProvider.tsx +1 -4
  108. package/src/Heading.tsx +3 -1
  109. package/src/Hyperlink.tsx +1 -1
  110. package/src/IconButton.tsx +2 -2
  111. package/src/Image.tsx +1 -0
  112. package/src/MarkdownView.tsx +67 -0
  113. package/src/MobileAddressAutoComplete.tsx +1 -1
  114. package/src/Modal.tsx +58 -21
  115. package/src/NumberField.tsx +10 -4
  116. package/src/NumberPickerActionSheet.tsx +1 -5
  117. package/src/Page.tsx +1 -1
  118. package/src/Pagination.tsx +2 -11
  119. package/src/Permissions.ts +2 -2
  120. package/src/PickerSelect.tsx +1 -1
  121. package/src/SectionDivider.tsx +1 -1
  122. package/src/SegmentedControl.tsx +3 -1
  123. package/src/Signature.native.tsx +2 -2
  124. package/src/SignatureField.tsx +2 -2
  125. package/src/Slider.tsx +10 -17
  126. package/src/SplitPage.native.tsx +2 -4
  127. package/src/SplitPage.tsx +4 -4
  128. package/src/TapToEdit.tsx +3 -7
  129. package/src/Text.tsx +1 -1
  130. package/src/TextArea.test.tsx +27 -43
  131. package/src/TextField.test.tsx +3 -4
  132. package/src/TextFieldNumberActionSheet.tsx +3 -7
  133. package/src/Tooltip.tsx +41 -19
  134. package/src/Unifier.ts +1 -3
  135. package/src/Utilities.tsx +3 -4
  136. package/src/WebAddressAutocomplete.tsx +1 -1
  137. package/src/index.tsx +11 -10
  138. package/src/table/Table.tsx +34 -36
  139. package/src/table/TableHeaderCell.tsx +2 -2
  140. package/src/useStoredState.ts +13 -11
@@ -262,20 +262,20 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
262
262
  if (type === "date" || type === "datetime") {
263
263
  if (fieldIndex === 0) {
264
264
  // Month
265
- const monthNum = parseInt(fieldValue);
266
- if (isNaN(monthNum) || monthNum < 1 || monthNum > 12) {
265
+ const monthNum = parseInt(fieldValue, 10);
266
+ if (Number.isNaN(monthNum) || monthNum < 1 || monthNum > 12) {
267
267
  return "Month must be between 1 and 12";
268
268
  }
269
269
  } else if (fieldIndex === 1) {
270
270
  // Day
271
- const dayNum = parseInt(fieldValue);
272
- if (isNaN(dayNum) || dayNum < 1 || dayNum > 31) {
271
+ const dayNum = parseInt(fieldValue, 10);
272
+ if (Number.isNaN(dayNum) || dayNum < 1 || dayNum > 31) {
273
273
  return "Day must be between 1 and 31";
274
274
  }
275
275
  } else if (fieldIndex === 2) {
276
276
  // Year
277
- const yearNum = parseInt(fieldValue);
278
- if (isNaN(yearNum) || yearNum < 1900 || yearNum > 2100) {
277
+ const yearNum = parseInt(fieldValue, 10);
278
+ if (Number.isNaN(yearNum) || yearNum < 1900 || yearNum > 2100) {
279
279
  return "Year must be between 1900 and 2100";
280
280
  }
281
281
  }
@@ -284,14 +284,14 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
284
284
  if (type === "time" || type === "datetime") {
285
285
  if (fieldIndex === (type === "time" ? 0 : 3)) {
286
286
  // Hour
287
- const hourNum = parseInt(fieldValue);
288
- if (isNaN(hourNum) || hourNum < 1 || hourNum > 12) {
287
+ const hourNum = parseInt(fieldValue, 10);
288
+ if (Number.isNaN(hourNum) || hourNum < 1 || hourNum > 12) {
289
289
  return "Hour must be between 1 and 12";
290
290
  }
291
291
  } else if (fieldIndex === (type === "time" ? 1 : 4)) {
292
292
  // Minute
293
- const minuteNum = parseInt(fieldValue);
294
- if (isNaN(minuteNum) || minuteNum < 0 || minuteNum > 59) {
293
+ const minuteNum = parseInt(fieldValue, 10);
294
+ if (Number.isNaN(minuteNum) || minuteNum < 0 || minuteNum > 59) {
295
295
  return "Minute must be between 0 and 59";
296
296
  }
297
297
  }
@@ -323,7 +323,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
323
323
  if (!monthVal || !dayVal || !yearVal || !hour || !minuteVal) {
324
324
  return undefined;
325
325
  }
326
- let hourNum = parseInt(hourVal);
326
+ let hourNum = parseInt(hourVal, 10);
327
327
  if (ampPmVal === "pm" && hourNum !== 12) {
328
328
  hourNum += 12;
329
329
  } else if (ampPmVal === "am" && hourNum === 12) {
@@ -331,11 +331,11 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
331
331
  }
332
332
  date = DateTime.fromObject(
333
333
  {
334
- year: parseInt(yearVal),
335
- month: parseInt(monthVal),
336
- day: parseInt(dayVal),
334
+ year: parseInt(yearVal, 10),
335
+ month: parseInt(monthVal, 10),
336
+ day: parseInt(dayVal, 10),
337
337
  hour: hourNum,
338
- minute: parseInt(minuteVal),
338
+ minute: parseInt(minuteVal, 10),
339
339
  second: 0,
340
340
  millisecond: 0,
341
341
  },
@@ -349,9 +349,9 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
349
349
  }
350
350
  date = DateTime.fromObject(
351
351
  {
352
- year: parseInt(yearVal),
353
- month: parseInt(monthVal),
354
- day: parseInt(dayVal),
352
+ year: parseInt(yearVal, 10),
353
+ month: parseInt(monthVal, 10),
354
+ day: parseInt(dayVal, 10),
355
355
  hour: 0,
356
356
  minute: 0,
357
357
  second: 0,
@@ -365,7 +365,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
365
365
  if (!hour || !minuteVal) {
366
366
  return undefined;
367
367
  }
368
- let hourNum = parseInt(hour);
368
+ let hourNum = parseInt(hour, 10);
369
369
  if (ampPmVal === "pm" && hourNum !== 12) {
370
370
  hourNum += 12;
371
371
  } else if (ampPmVal === "am" && hourNum === 12) {
@@ -374,7 +374,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
374
374
  date = DateTime.fromObject(
375
375
  {
376
376
  hour: hourNum,
377
- minute: parseInt(minuteVal),
377
+ minute: parseInt(minuteVal, 10),
378
378
  second: 0,
379
379
  millisecond: 0,
380
380
  },
@@ -404,7 +404,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
404
404
  // so it's always a valid time and easier to edit.
405
405
  // This lets users freely edit or clear the minute field without breaking the time format.
406
406
  const finalValue = numericValue === "" ? "00" : numericValue.slice(-2);
407
- const minuteNum = parseInt(finalValue);
407
+ const minuteNum = parseInt(finalValue, 10);
408
408
 
409
409
  // Update the minute state so the UI reflects the latest input,
410
410
  // even if it's temporarily invalid
@@ -412,7 +412,7 @@ export const DateTimeField: FC<DateTimeFieldProps> = ({
412
412
  setMinute(finalValue);
413
413
 
414
414
  // Only update ref and result if it's a valid minute value
415
- if (!isNaN(minuteNum) && minuteNum >= 0 && minuteNum <= 59) {
415
+ if (!Number.isNaN(minuteNum) && minuteNum >= 0 && minuteNum <= 59) {
416
416
  pendingValueRef.current = {minute: finalValue};
417
417
  setFieldErrors((prev) => ({...prev, [index]: undefined}));
418
418
 
@@ -13,7 +13,11 @@ export const EmailField: FC<EmailFieldProps> = ({
13
13
  ...rest
14
14
  }) => {
15
15
  const [localValue, setLocalValue] = useState<string>(value || "");
16
- const [error, setError] = useState<string | undefined>(errorText);
16
+
17
+ // Sync local state with incoming prop values
18
+ useEffect(() => {
19
+ setLocalValue(value || "");
20
+ }, [value]);
17
21
 
18
22
  const validateEmail = useCallback((email: string): string | undefined => {
19
23
  if (email.trim() === "") {
@@ -26,60 +30,36 @@ export const EmailField: FC<EmailFieldProps> = ({
26
30
  return undefined;
27
31
  }, []);
28
32
 
29
- // Sync local state with incoming prop values
30
- useEffect(() => {
31
- setLocalValue(value || "");
32
- setError(errorText);
33
- }, [value, errorText]);
34
-
35
- const handleBlur = useCallback(
36
- (email: string) => {
37
- if (onBlur) {
38
- onBlur(email);
39
- }
40
- const validationError = validateEmail(email);
41
- if (validationError) {
42
- setError(validationError);
43
- } else {
44
- setError(undefined);
33
+ const localOnChange = useCallback(
34
+ (e: string) => {
35
+ setLocalValue(e);
36
+ const err = validateEmail(e);
37
+ if (!err && onChange) {
38
+ onChange(e);
45
39
  }
46
40
  },
47
- [onBlur, validateEmail]
41
+ [onChange, validateEmail, setLocalValue]
48
42
  );
49
43
 
50
- const handleChange = useCallback(
51
- (email: string) => {
52
- setLocalValue(email);
53
- const validationError = validateEmail(email);
54
- if (error && !validationError) {
55
- setError(undefined);
56
- }
57
- if (!validationError) {
58
- onChange(email);
44
+ const localOnBlur = useCallback(
45
+ (e: string) => {
46
+ setLocalValue(e);
47
+ const err = validateEmail(e);
48
+ if (!err && onBlur) {
49
+ onBlur(e);
59
50
  }
60
51
  },
61
- [onChange, error, validateEmail]
52
+ [onBlur, validateEmail]
62
53
  );
63
-
64
54
  return (
65
55
  <TextField
66
- errorText={error}
56
+ errorText={errorText || validateEmail(localValue)}
67
57
  iconName={iconName}
68
58
  placeholder={placeholder}
69
59
  type="email"
70
60
  value={localValue}
71
- onBlur={(e) => {
72
- handleBlur(e);
73
- if (onBlur) {
74
- onBlur(value || "");
75
- }
76
- }}
77
- onChange={(e) => {
78
- handleChange(e);
79
- if (onChange) {
80
- onChange;
81
- }
82
- }}
61
+ onBlur={localOnBlur}
62
+ onChange={localOnChange}
83
63
  {...rest}
84
64
  />
85
65
  );
@@ -9,10 +9,7 @@ import {Toast} from "./Toast";
9
9
  export const FernsProvider: FC<{
10
10
  children: React.ReactNode;
11
11
  openAPISpecUrl?: string;
12
- }> = ({
13
- children,
14
- openAPISpecUrl,
15
- }) => {
12
+ }> = ({children, openAPISpecUrl}) => {
16
13
  return (
17
14
  <ThemeProvider>
18
15
  <ToastProvider
package/src/Heading.tsx CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  useFonts,
5
5
  } from "@expo-google-fonts/titillium-web";
6
6
  import React from "react";
7
- import {Platform, StyleProp, Text as NativeText, TextStyle} from "react-native";
7
+ import {Text as NativeText, Platform, StyleProp, TextStyle} from "react-native";
8
8
 
9
9
  import {HeadingProps} from "./Common";
10
10
  import {useTheme} from "./Theme";
@@ -14,6 +14,7 @@ const fontSizeAndWeightWeb = {
14
14
  md: {size: 18, weight: "bold"},
15
15
  lg: {size: 24, weight: "bold"},
16
16
  xl: {size: 32, weight: "bold"},
17
+ "2xl": {size: 48, weight: "bold"},
17
18
  };
18
19
 
19
20
  const fontSizeAndWeighMobile = {
@@ -21,6 +22,7 @@ const fontSizeAndWeighMobile = {
21
22
  md: {size: 16, weight: "bold"},
22
23
  lg: {size: 20, weight: "bold"},
23
24
  xl: {size: 28, weight: "bold"},
25
+ "2xl": {size: 32, weight: "bold"},
24
26
  };
25
27
 
26
28
  const fontSizes = Platform.OS === "web" ? fontSizeAndWeightWeb : fontSizeAndWeighMobile;
package/src/Hyperlink.tsx CHANGED
@@ -111,7 +111,7 @@ class HyperlinkComponent extends React.Component<HyperlinkProps> {
111
111
  component.props.children.substring(_lastIndex, component.props.children.length)
112
112
  );
113
113
  return React.cloneElement(component, componentProps, elements);
114
- } catch (error) {
114
+ } catch (_error) {
115
115
  return component;
116
116
  }
117
117
  };
@@ -1,7 +1,7 @@
1
1
  import FontAwesome6 from "@expo/vector-icons/FontAwesome6";
2
2
  import debounce from "lodash/debounce";
3
3
  import React, {FC, useState} from "react";
4
- import {ActivityIndicator, Pressable, Text as NativeText, View} from "react-native";
4
+ import {ActivityIndicator, Text as NativeText, Pressable, View} from "react-native";
5
5
 
6
6
  import {IconButtonProps} from "./Common";
7
7
  import {isMobileDevice} from "./MediaQuery";
@@ -98,7 +98,7 @@ const IconButtonComponent: FC<IconButtonProps> = ({
98
98
  return (
99
99
  <Pressable
100
100
  accessibilityHint={
101
- accessibilityHint ?? withConfirmation
101
+ (accessibilityHint ?? withConfirmation)
102
102
  ? `Opens a confirmation dialog to confirm ${accessLabel}`
103
103
  : `Press to perform ${accessLabel} action`
104
104
  }
package/src/Image.tsx CHANGED
@@ -3,6 +3,7 @@ import {Dimensions, Image as NativeImage} from "react-native";
3
3
 
4
4
  import {Box} from "./Box";
5
5
  import {ImageProps} from "./Common";
6
+
6
7
  const {width: DEVICE_WIDTH} = Dimensions.get("window");
7
8
 
8
9
  export class Image extends React.Component<ImageProps, {}> {
@@ -0,0 +1,67 @@
1
+ import {
2
+ Nunito_400Regular,
3
+ Nunito_500Medium,
4
+ Nunito_700Bold,
5
+ useFonts as useTextFonts,
6
+ } from "@expo-google-fonts/nunito";
7
+ import {
8
+ TitilliumWeb_600SemiBold,
9
+ TitilliumWeb_700Bold,
10
+ useFonts as useHeadingFonts,
11
+ } from "@expo-google-fonts/titillium-web";
12
+ import React from "react";
13
+ import {Platform} from "react-native";
14
+ import Markdown from "react-native-markdown-display";
15
+
16
+ import {useTheme} from "./Theme";
17
+
18
+ // Takes markdown and renders it with our theme. We should open source this component.
19
+ export const MarkdownView: React.FC<{children: React.ReactNode; inverted?: boolean}> = ({
20
+ children,
21
+ inverted,
22
+ }) => {
23
+ const {theme} = useTheme();
24
+
25
+ const color = {color: inverted ? theme.text.inverted : theme.text.primary};
26
+
27
+ // Match Heading font sizes to Heading component
28
+ // Web sizes (see src/Heading.tsx): sm:16, md:18, lg:24, xl:32
29
+ // Mobile sizes: sm:14, md:16, lg:20, xl:28
30
+ const isWeb = Platform.OS === "web";
31
+ const sizes = {
32
+ sm: isWeb ? 16 : 14,
33
+ md: isWeb ? 18 : 16,
34
+ lg: isWeb ? 24 : 20,
35
+ xl: isWeb ? 32 : 28,
36
+ } as const;
37
+
38
+ // Load fonts similar to Heading/Text components so fontFamily names resolve
39
+ useHeadingFonts({
40
+ heading: TitilliumWeb_600SemiBold,
41
+ "heading-bold": TitilliumWeb_700Bold,
42
+ "heading-semibold": TitilliumWeb_600SemiBold,
43
+ });
44
+ useTextFonts({
45
+ text: Nunito_400Regular,
46
+ "text-regular": Nunito_400Regular,
47
+ "text-medium": Nunito_500Medium,
48
+ "text-bold": Nunito_700Bold,
49
+ });
50
+
51
+ return (
52
+ <Markdown
53
+ style={{
54
+ body: {fontFamily: "text", ...color},
55
+ heading1: {fontFamily: "heading-bold", fontSize: sizes.xl, ...color},
56
+ heading2: {fontFamily: "heading-bold", fontSize: sizes.lg, ...color},
57
+ heading3: {fontFamily: "heading-bold", fontSize: sizes.md, ...color},
58
+ heading4: {fontFamily: "heading-semibold", fontSize: sizes.sm, ...color},
59
+ // h5/h6 map to small as well for consistency, slightly smaller visually handled by weight
60
+ heading5: {fontFamily: "heading-semibold", fontSize: sizes.sm, ...color},
61
+ heading6: {fontFamily: "heading-semibold", fontSize: sizes.sm, ...color},
62
+ }}
63
+ >
64
+ {children}
65
+ </Markdown>
66
+ );
67
+ };
@@ -108,7 +108,7 @@ export const MobileAddressAutocomplete = ({
108
108
  handleAddressChange(event.nativeEvent.text);
109
109
  },
110
110
  }}
111
- onPress={(data, details = null) => {
111
+ onPress={(_data, details = null) => {
112
112
  const addressComponents = details?.address_components;
113
113
  const formattedAddressObject = processAddressComponents(addressComponents, {
114
114
  includeCounty,
package/src/Modal.tsx CHANGED
@@ -1,14 +1,11 @@
1
1
  import React, {FC, useEffect, useRef} from "react";
2
- import {Dimensions, DimensionValue, Modal as RNModal, Pressable, View} from "react-native";
2
+ import {Dimensions, DimensionValue, Pressable, Modal as RNModal, View} from "react-native";
3
3
  import ActionSheet, {ActionSheetRef} from "react-native-actions-sheet";
4
- import {
5
- PanGestureHandler,
6
- PanGestureHandlerStateChangeEvent,
7
- State,
8
- } from "react-native-gesture-handler";
4
+ import {Gesture, GestureDetector} from "react-native-gesture-handler";
5
+ import {runOnJS} from "react-native-reanimated";
9
6
 
10
7
  import {Button} from "./Button";
11
- import {ModalProps} from "./Common";
8
+ import type {ModalProps} from "./Common";
12
9
  import {Heading} from "./Heading";
13
10
  import {Icon} from "./Icon";
14
11
  import {isMobileDevice} from "./MediaQuery";
@@ -129,7 +126,13 @@ const ModalContent: FC<{
129
126
  </View>
130
127
  )}
131
128
  {children && (
132
- <View style={{marginTop: text ? 0 : 12, width: "100%", flex: isMobile ? undefined : 1}}>
129
+ <View
130
+ style={{
131
+ marginTop: text ? 0 : 12,
132
+ width: "100%",
133
+ flex: isMobile ? undefined : 1,
134
+ }}
135
+ >
133
136
  {children}
134
137
  </View>
135
138
  )}
@@ -163,6 +166,7 @@ const ModalContent: FC<{
163
166
 
164
167
  export const Modal: FC<ModalProps> = ({
165
168
  children,
169
+ persistOnBackgroundClick = false,
166
170
  primaryButtonDisabled = false,
167
171
  primaryButtonText,
168
172
  secondaryButtonText,
@@ -184,23 +188,28 @@ export const Modal: FC<ModalProps> = ({
184
188
  }
185
189
  };
186
190
 
187
- const handlePrimaryButtonClick = (value?: Parameters<NonNullable<ModalProps["primaryButtonOnClick"]>>[0]) => {
191
+ const handlePrimaryButtonClick = (
192
+ value?: Parameters<NonNullable<ModalProps["primaryButtonOnClick"]>>[0]
193
+ ) => {
188
194
  if (visible && primaryButtonOnClick) {
189
195
  return primaryButtonOnClick(value);
190
196
  }
191
197
  };
192
198
 
193
- const handleSecondaryButtonClick = (value?: Parameters<NonNullable<ModalProps["secondaryButtonOnClick"]>>[0]) => {
199
+ const handleSecondaryButtonClick = (
200
+ value?: Parameters<NonNullable<ModalProps["secondaryButtonOnClick"]>>[0]
201
+ ) => {
194
202
  if (visible && secondaryButtonOnClick) {
195
203
  return secondaryButtonOnClick(value);
196
204
  }
197
205
  };
198
206
 
199
- const onHandlerStateChange = ({nativeEvent}: PanGestureHandlerStateChangeEvent) => {
200
- if (nativeEvent.state === State.END && nativeEvent.translationY > 100) {
201
- handleDismiss();
207
+ const dragToClose = Gesture.Pan().onEnd((event) => {
208
+ if (event.translationY > 20) {
209
+ // Gesture callbacks run on the UI thread, runOnJS is required to safely invoke handleDismiss on the JS thread
210
+ runOnJS(handleDismiss)();
202
211
  }
203
- };
212
+ });
204
213
 
205
214
  // Open the action sheet ref when the visible prop changes.
206
215
  useEffect(() => {
@@ -213,6 +222,7 @@ export const Modal: FC<ModalProps> = ({
213
222
  const sizePx = getModalSize(size);
214
223
 
215
224
  const modalContentProps = {
225
+ persistOnBackgroundClick,
216
226
  title,
217
227
  subtitle,
218
228
  text,
@@ -229,13 +239,22 @@ export const Modal: FC<ModalProps> = ({
229
239
 
230
240
  if (isMobile) {
231
241
  return (
232
- <ActionSheet ref={actionSheetRef} onClose={handleDismiss}>
233
- <PanGestureHandler onHandlerStateChange={onHandlerStateChange}>
234
- <View>
242
+ <ActionSheet
243
+ ref={actionSheetRef}
244
+ closeOnTouchBackdrop={!persistOnBackgroundClick}
245
+ // Disable ActionSheet's built-in gestures to avoid conflicts with scrolling
246
+ gestureEnabled={false}
247
+ onClose={handleDismiss}
248
+ >
249
+ <View>
250
+ {/* Attach our own swipe-to-dismiss gesture to the top handle */}
251
+ <GestureDetector gesture={dragToClose}>
235
252
  <View
236
253
  accessibilityHint="Pull down to close the modal"
237
254
  aria-label="Pull down bar"
238
255
  aria-role="adjustable"
256
+ // add hitSlop to make the bar easier to hit since it's small
257
+ hitSlop={{top: 20, bottom: 20, left: 50, right: 50}}
239
258
  style={{
240
259
  justifyContent: "center",
241
260
  alignItems: "center",
@@ -248,15 +267,33 @@ export const Modal: FC<ModalProps> = ({
248
267
  marginTop: 10,
249
268
  }}
250
269
  />
251
- <ModalContent {...modalContentProps}>{children}</ModalContent>
252
- </View>
253
- </PanGestureHandler>
270
+ </GestureDetector>
271
+
272
+ <ModalContent {...modalContentProps}>{children}</ModalContent>
273
+ </View>
254
274
  </ActionSheet>
255
275
  );
256
276
  } else {
257
277
  return (
258
278
  <RNModal animationType="slide" transparent visible={visible} onRequestClose={handleDismiss}>
259
- <ModalContent {...modalContentProps}>{children}</ModalContent>
279
+ <Pressable
280
+ style={{
281
+ flex: 1,
282
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
283
+ justifyContent: "center",
284
+ alignItems: "center",
285
+ }}
286
+ onPress={persistOnBackgroundClick ? undefined : handleDismiss}
287
+ >
288
+ <Pressable
289
+ style={{cursor: "auto"}}
290
+ onPress={(e) => {
291
+ persistOnBackgroundClick ? null : e.stopPropagation();
292
+ }}
293
+ >
294
+ <ModalContent {...modalContentProps}>{children}</ModalContent>
295
+ </Pressable>
296
+ </Pressable>
260
297
  </RNModal>
261
298
  );
262
299
  }
@@ -24,8 +24,8 @@ export const NumberField: FC<NumberFieldProps> = ({
24
24
  if (!v) {
25
25
  return;
26
26
  }
27
- const num = type === "number" ? parseInt(v) : parseFloat(v);
28
- if (isNaN(num) || (type === "number" && v.match(/[^0-9]/) !== null)) {
27
+ const num = type === "number" ? parseInt(v, 10) : parseFloat(v);
28
+ if (Number.isNaN(num) || (type === "number" && v.match(/[^0-9]/) !== null)) {
29
29
  return "Value must be an integer";
30
30
  } else if (
31
31
  (type === "decimal" && v.match(/[^0-9.]+/) !== null) ||
@@ -47,13 +47,19 @@ export const NumberField: FC<NumberFieldProps> = ({
47
47
  // Only return the value if it is a valid number
48
48
  const localOnChange = useCallback(
49
49
  (v: string) => {
50
- setValue(v);
50
+ if (type === "decimal" && v === ".") {
51
+ // if type is decimal and dot is the first character add 0 before it
52
+ setValue("0.");
53
+ rest.onChange("0.");
54
+ return;
55
+ }
51
56
  const err = getError(v);
52
57
  if (!err) {
58
+ setValue(v);
53
59
  rest.onChange(v);
54
60
  }
55
61
  },
56
- [getError, rest]
62
+ [getError, rest, type]
57
63
  );
58
64
 
59
65
  return <TextField {...rest} errorText={error} value={value} onChange={localOnChange} />;
@@ -9,16 +9,12 @@ import {NumberPickerActionSheetProps} from "./Common";
9
9
 
10
10
  const PICKER_HEIGHT = 104;
11
11
 
12
- interface NumberPickerActionSheetState {}
12
+ type NumberPickerActionSheetState = {};
13
13
 
14
14
  export class NumberPickerActionSheet extends React.Component<
15
15
  NumberPickerActionSheetProps,
16
16
  NumberPickerActionSheetState
17
17
  > {
18
- constructor(props: NumberPickerActionSheetProps) {
19
- super(props);
20
- }
21
-
22
18
  render() {
23
19
  return (
24
20
  <ActionSheet ref={this.props.actionSheetRef} bounceOnOpen gestureEnabled>
package/src/Page.tsx CHANGED
@@ -47,7 +47,7 @@ export class Page extends React.Component<PageProps, {}> {
47
47
  <Button
48
48
  text={this.props.rightButton}
49
49
  variant="muted"
50
- onClick={() => this.props.rightButtonOnClick && this.props.rightButtonOnClick()}
50
+ onClick={() => this.props.rightButtonOnClick?.()}
51
51
  />
52
52
  </Box>
53
53
  )}
@@ -11,12 +11,7 @@ const PaginationButton: FC<{
11
11
  onClick: () => void;
12
12
  totalPages?: number;
13
13
  page?: number;
14
- }> = ({
15
- type,
16
- onClick,
17
- totalPages = 1,
18
- page = 1,
19
- }) => {
14
+ }> = ({type, onClick, totalPages = 1, page = 1}) => {
20
15
  let icon: IconName;
21
16
  let disabled = false;
22
17
 
@@ -56,11 +51,7 @@ const PaginationNumber: FC<{
56
51
  number: number | "more";
57
52
  current: boolean;
58
53
  onClick: () => void;
59
- }> = ({
60
- number,
61
- current,
62
- onClick,
63
- }) => {
54
+ }> = ({number, current, onClick}) => {
64
55
  // Shortcut to make rendering the number buttons easier.
65
56
  if (number === "more") {
66
57
  return <PaginationButton type="more" onClick={() => {}} />;
@@ -4,8 +4,8 @@
4
4
  // import Permissions from "react-native-permissions";
5
5
  import {PermissionKind, PermissionStatus} from "./Common";
6
6
 
7
- export async function requestPermissions(kind: PermissionKind): Promise<PermissionStatus> {
8
- return new Promise(async (resolve, reject) => {
7
+ export async function requestPermissions(_kind: PermissionKind): Promise<PermissionStatus> {
8
+ return new Promise((_resolve, _reject) => {
9
9
  return "denied";
10
10
  });
11
11
  // const userPropertyKey = `PermissionsFor${capitalize(kind)}`;
@@ -201,7 +201,7 @@ export function RNPickerSelect({
201
201
  Keyboard.dismiss();
202
202
  }
203
203
 
204
- setAnimationType(modalProps && modalProps?.animationType ? modalProps?.animationType : "slide");
204
+ setAnimationType(modalProps?.animationType ? modalProps?.animationType : "slide");
205
205
 
206
206
  triggerOpenCloseCallbacks();
207
207
 
@@ -1,6 +1,6 @@
1
- import {useTheme} from "./Theme";
2
1
  import React from "react";
3
2
  import {View} from "react-native";
3
+ import {useTheme} from "./Theme";
4
4
 
5
5
  export const SectionDivider: React.FC<{}> = () => {
6
6
  const {theme} = useTheme();
@@ -24,7 +24,9 @@ export const SegmentedControl: FC<SegmentedControlProps> = ({
24
24
  }, []);
25
25
 
26
26
  const handleNext = useCallback(() => {
27
- setStartIndex((prev) => Math.min(items.length - (maxItems ?? items.length), prev + (maxItems ?? 4)));
27
+ setStartIndex((prev) =>
28
+ Math.min(items.length - (maxItems ?? items.length), prev + (maxItems ?? 4))
29
+ );
28
30
  }, [items.length, maxItems]);
29
31
 
30
32
  const visibleItems = maxItems ? items.slice(startIndex, startIndex + maxItems) : items;
@@ -21,14 +21,14 @@ export const Signature: FC<Props> = ({onChange, onStart, onEnd}: Props) => {
21
21
  };
22
22
 
23
23
  const onBegin = () => {
24
- onStart && onStart();
24
+ onStart?.();
25
25
  };
26
26
 
27
27
  // Called after end of stroke. Kind of goofy if you ask me,
28
28
  // but you need this in order to trigger the 'onOK' callback that gives us the actual image.
29
29
  const handleEnd = () => {
30
30
  ref.current?.readSignature();
31
- onEnd && onEnd();
31
+ onEnd?.();
32
32
  };
33
33
 
34
34
  return (