ferns-ui 0.41.1 → 0.42.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 (163) hide show
  1. package/dist/Avatar.js +1 -0
  2. package/dist/Avatar.js.map +1 -1
  3. package/dist/Badge.d.ts +1 -1
  4. package/dist/Badge.js +2 -2
  5. package/dist/Badge.js.map +1 -1
  6. package/dist/Body.d.ts +1 -1
  7. package/dist/Body.js +2 -2
  8. package/dist/Body.js.map +1 -1
  9. package/dist/Button.d.ts +1 -1
  10. package/dist/Button.js +4 -4
  11. package/dist/Button.js.map +1 -1
  12. package/dist/Card.d.ts +1 -1
  13. package/dist/Card.js +2 -2
  14. package/dist/Card.js.map +1 -1
  15. package/dist/CheckBox.d.ts +1 -1
  16. package/dist/CheckBox.js +2 -2
  17. package/dist/CheckBox.js.map +1 -1
  18. package/dist/Common.d.ts +18 -0
  19. package/dist/CustomSelect.js +1 -0
  20. package/dist/CustomSelect.js.map +1 -1
  21. package/dist/DateTimeActionSheet.d.ts +1 -1
  22. package/dist/DateTimeActionSheet.js +8 -7
  23. package/dist/DateTimeActionSheet.js.map +1 -1
  24. package/dist/FernsProvider.d.ts +2 -2
  25. package/dist/FernsProvider.js +2 -2
  26. package/dist/FernsProvider.js.map +1 -1
  27. package/dist/Hyperlink.d.ts +1 -1
  28. package/dist/Hyperlink.js +3 -3
  29. package/dist/Hyperlink.js.map +1 -1
  30. package/dist/Icon.d.ts +1 -1
  31. package/dist/Icon.js +2 -2
  32. package/dist/Icon.js.map +1 -1
  33. package/dist/InfoTooltipButton.d.ts +1 -1
  34. package/dist/InfoTooltipButton.js +2 -2
  35. package/dist/InfoTooltipButton.js.map +1 -1
  36. package/dist/Link.d.ts +1 -1
  37. package/dist/Link.js +2 -2
  38. package/dist/Link.js.map +1 -1
  39. package/dist/Mask.d.ts +1 -1
  40. package/dist/Mask.js +2 -2
  41. package/dist/Mask.js.map +1 -1
  42. package/dist/MobileAddressAutoComplete.js +1 -0
  43. package/dist/MobileAddressAutoComplete.js.map +1 -1
  44. package/dist/ModalSheet.js +1 -0
  45. package/dist/ModalSheet.js.map +1 -1
  46. package/dist/OpenAPIContext.d.ts +1 -1
  47. package/dist/OpenAPIContext.js +4 -3
  48. package/dist/OpenAPIContext.js.map +1 -1
  49. package/dist/PickerSelect.js +1 -0
  50. package/dist/PickerSelect.js.map +1 -1
  51. package/dist/Pill.d.ts +1 -1
  52. package/dist/Pill.js +2 -2
  53. package/dist/Pill.js.map +1 -1
  54. package/dist/Pog.d.ts +1 -1
  55. package/dist/Pog.js +2 -2
  56. package/dist/Pog.js.map +1 -1
  57. package/dist/ProgressBar.d.ts +1 -1
  58. package/dist/ProgressBar.js +2 -2
  59. package/dist/ProgressBar.js.map +1 -1
  60. package/dist/SelectList.d.ts +1 -1
  61. package/dist/SelectList.js +2 -2
  62. package/dist/SelectList.js.map +1 -1
  63. package/dist/Signature.d.ts +1 -1
  64. package/dist/Signature.js +2 -2
  65. package/dist/Signature.js.map +1 -1
  66. package/dist/Signature.native.js +1 -1
  67. package/dist/Signature.native.js.map +1 -1
  68. package/dist/Spinner.d.ts +1 -1
  69. package/dist/Spinner.js +2 -2
  70. package/dist/Spinner.js.map +1 -1
  71. package/dist/SplitPage.js +1 -0
  72. package/dist/SplitPage.js.map +1 -1
  73. package/dist/SplitPage.native.js +1 -0
  74. package/dist/SplitPage.native.js.map +1 -1
  75. package/dist/Switch.d.ts +1 -1
  76. package/dist/Switch.js +2 -2
  77. package/dist/Switch.js.map +1 -1
  78. package/dist/Table.d.ts +2 -2
  79. package/dist/Table.js +2 -2
  80. package/dist/Table.js.map +1 -1
  81. package/dist/TableHeader.d.ts +1 -1
  82. package/dist/TableHeader.js +2 -2
  83. package/dist/TableHeader.js.map +1 -1
  84. package/dist/TableHeaderCell.d.ts +1 -1
  85. package/dist/TableHeaderCell.js +2 -2
  86. package/dist/TableHeaderCell.js.map +1 -1
  87. package/dist/TableRow.d.ts +1 -1
  88. package/dist/TableRow.js +2 -2
  89. package/dist/TableRow.js.map +1 -1
  90. package/dist/TapToEdit.js +1 -1
  91. package/dist/TapToEdit.js.map +1 -1
  92. package/dist/Text.d.ts +1 -1
  93. package/dist/Text.js +2 -2
  94. package/dist/Text.js.map +1 -1
  95. package/dist/TextArea.d.ts +1 -1
  96. package/dist/TextArea.js +2 -2
  97. package/dist/TextArea.js.map +1 -1
  98. package/dist/TextField.d.ts +1 -1
  99. package/dist/TextField.js +2 -2
  100. package/dist/TextField.js.map +1 -1
  101. package/dist/Toast.d.ts +8 -2
  102. package/dist/Toast.js +30 -8
  103. package/dist/Toast.js.map +1 -1
  104. package/dist/Tooltip.js +1 -0
  105. package/dist/Tooltip.js.map +1 -1
  106. package/dist/Unifier.js +5 -5
  107. package/dist/Unifier.js.map +1 -1
  108. package/dist/Utilities.d.ts +3 -1
  109. package/dist/Utilities.js +12 -0
  110. package/dist/Utilities.js.map +1 -1
  111. package/dist/WebAddressAutocomplete.js +1 -0
  112. package/dist/WebAddressAutocomplete.js.map +1 -1
  113. package/dist/WithLabel.d.ts +1 -1
  114. package/dist/WithLabel.js +2 -2
  115. package/dist/WithLabel.js.map +1 -1
  116. package/dist/tableContext.d.ts +1 -1
  117. package/dist/tableContext.js +2 -2
  118. package/dist/tableContext.js.map +1 -1
  119. package/package.json +7 -22
  120. package/src/Avatar.tsx +1 -0
  121. package/src/Badge.tsx +3 -3
  122. package/src/Body.tsx +3 -3
  123. package/src/Button.tsx +5 -5
  124. package/src/Card.tsx +2 -2
  125. package/src/CheckBox.tsx +3 -3
  126. package/src/Common.ts +17 -0
  127. package/src/CustomSelect.tsx +1 -0
  128. package/src/DateTimeActionSheet.tsx +10 -9
  129. package/src/FernsProvider.tsx +2 -2
  130. package/src/Hyperlink.tsx +3 -3
  131. package/src/Icon.tsx +2 -2
  132. package/src/InfoTooltipButton.tsx +2 -2
  133. package/src/Link.tsx +2 -2
  134. package/src/Mask.tsx +2 -2
  135. package/src/MobileAddressAutoComplete.tsx +1 -0
  136. package/src/ModalSheet.tsx +1 -0
  137. package/src/OpenAPIContext.tsx +4 -3
  138. package/src/PickerSelect.tsx +1 -0
  139. package/src/Pill.tsx +2 -2
  140. package/src/Pog.tsx +2 -2
  141. package/src/ProgressBar.tsx +2 -2
  142. package/src/SelectList.tsx +3 -3
  143. package/src/Signature.native.tsx +1 -0
  144. package/src/Signature.tsx +2 -2
  145. package/src/Spinner.tsx +2 -2
  146. package/src/SplitPage.native.tsx +1 -0
  147. package/src/SplitPage.tsx +1 -0
  148. package/src/Switch.tsx +7 -2
  149. package/src/Table.tsx +3 -3
  150. package/src/TableHeader.tsx +3 -3
  151. package/src/TableHeaderCell.tsx +3 -3
  152. package/src/TableRow.tsx +3 -3
  153. package/src/TapToEdit.tsx +1 -1
  154. package/src/Text.tsx +3 -3
  155. package/src/TextArea.tsx +2 -2
  156. package/src/TextField.tsx +3 -3
  157. package/src/Toast.tsx +35 -18
  158. package/src/Tooltip.tsx +1 -0
  159. package/src/Unifier.ts +5 -5
  160. package/src/Utilities.tsx +13 -1
  161. package/src/WebAddressAutocomplete.tsx +1 -0
  162. package/src/WithLabel.tsx +3 -3
  163. package/src/tableContext.tsx +3 -3
@@ -8,12 +8,12 @@ import {useTableContext} from "./tableContext";
8
8
  /**
9
9
  * Use TableHeaderCell to define a header cell in Table.
10
10
  */
11
- export function TableHeaderCell({
11
+ export const TableHeaderCell = ({
12
12
  children,
13
13
  index,
14
14
  sortable,
15
15
  onSortChange,
16
- }: TableHeaderCellProps): ReactElement {
16
+ }: TableHeaderCellProps): ReactElement => {
17
17
  const {columns, setSortColumn, sortColumn} = useTableContext();
18
18
  const width = columns[index];
19
19
  if (!width) {
@@ -69,4 +69,4 @@ export function TableHeaderCell({
69
69
  </Box>
70
70
  );
71
71
  }
72
- }
72
+ };
package/src/TableRow.tsx CHANGED
@@ -8,13 +8,13 @@ import {useTableContext} from "./tableContext";
8
8
  /**
9
9
  * Use TableRow to define a row in Table.
10
10
  */
11
- export function TableRow({
11
+ export const TableRow = ({
12
12
  children,
13
13
  headerRow = false,
14
14
  expanded,
15
15
  drawerContents,
16
16
  color = "white",
17
- }: TableRowProps): React.ReactElement {
17
+ }: TableRowProps): React.ReactElement => {
18
18
  const [isExpanded, setIsExpanded] = React.useState(expanded || false);
19
19
  const {columns, hasDrawerContents} = useTableContext();
20
20
  const rowRef = useRef<typeof Box>(null);
@@ -61,4 +61,4 @@ export function TableRow({
61
61
  )}
62
62
  </Box>
63
63
  );
64
- }
64
+ };
package/src/TapToEdit.tsx CHANGED
@@ -160,7 +160,7 @@ export const TapToEdit = ({
160
160
  try {
161
161
  const url = new URL(value);
162
162
  displayValue = url?.hostname ?? value;
163
- } catch (e) {
163
+ } catch (error) {
164
164
  // Don't print an error message for empty values.
165
165
  if (value) {
166
166
  console.debug(`Invalid URL: ${value}`);
package/src/Text.tsx CHANGED
@@ -12,7 +12,7 @@ const fontSizes = {
12
12
  lg: 16,
13
13
  };
14
14
 
15
- export function Text({
15
+ export const Text = ({
16
16
  align = "left",
17
17
  children,
18
18
  color,
@@ -28,7 +28,7 @@ export function Text({
28
28
  skipLinking,
29
29
  testID,
30
30
  weight = "normal",
31
- }: TextProps): React.ReactElement {
31
+ }: TextProps): React.ReactElement => {
32
32
  const {theme} = useContext(ThemeContext);
33
33
 
34
34
  function propsToStyle(): any {
@@ -115,4 +115,4 @@ export function Text({
115
115
  </Hyperlink>
116
116
  );
117
117
  }
118
- }
118
+ };
package/src/TextArea.tsx CHANGED
@@ -3,6 +3,6 @@ import React from "react";
3
3
  import {TextAreaProps} from "./Common";
4
4
  import {TextField} from "./TextField";
5
5
 
6
- export function TextArea({height, ...rest}: TextAreaProps): React.ReactElement {
6
+ export const TextArea = ({height, ...rest}: TextAreaProps): React.ReactElement => {
7
7
  return <TextField {...rest} height={height ?? 100} multiline />;
8
- }
8
+ };
package/src/TextField.tsx CHANGED
@@ -59,7 +59,7 @@ const textContentMap: {
59
59
  username: "username",
60
60
  };
61
61
 
62
- export function TextField({
62
+ export const TextField = ({
63
63
  blurOnSubmit = true,
64
64
  value,
65
65
  height: propsHeight,
@@ -86,7 +86,7 @@ export function TextField({
86
86
  onEnter,
87
87
  onSubmitEditing,
88
88
  testID,
89
- }: TextFieldProps): ReactElement {
89
+ }: TextFieldProps): ReactElement => {
90
90
  const {theme} = useContext(ThemeContext);
91
91
 
92
92
  const dateActionSheetRef: React.RefObject<any> = React.createRef();
@@ -404,4 +404,4 @@ export function TextField({
404
404
  )}
405
405
  </>
406
406
  );
407
- }
407
+ };
package/src/Toast.tsx CHANGED
@@ -8,33 +8,50 @@ import {AllColors, ToastProps} from "./Common";
8
8
  import {Icon} from "./Icon";
9
9
  import {IconButton} from "./IconButton";
10
10
  import {Text} from "./Text";
11
+ import {isAPIError, printAPIError} from "./Utilities";
11
12
 
12
13
  const TOAST_DURATION_MS = 3 * 1000;
13
14
 
14
- export function useToast(): any {
15
+ export function useToast(): {
16
+ warn: (text: string, options?: Omit<ToastProps["data"], "variant">) => string;
17
+ hide: (id: string) => void;
18
+ show: (text: string, options?: ToastProps["data"]) => string;
19
+ catch: (error: any, message?: string, options?: Omit<ToastProps["data"], "variant">) => void;
20
+ error: (text: string, options?: Omit<ToastProps["data"], "variant">) => string;
21
+ } {
15
22
  const toast = useRNToast();
23
+ const show = (text: string, options?: ToastProps["data"]): string => {
24
+ return toast.show(text, {
25
+ data: options,
26
+ // a duration of 0 keeps the toast up infinitely until hidden
27
+ duration: options?.persistent ? 0 : TOAST_DURATION_MS,
28
+ });
29
+ };
16
30
  return {
17
- show: (
18
- text: string,
19
- options?: {
20
- variant?: "default" | "warning" | "error";
21
- buttonText?: string;
22
- buttonOnClick: () => void | Promise<void>;
23
- persistent?: boolean;
24
- onDismiss?: () => void | Promise<void>;
25
- }
26
- ): string => {
27
- return toast.show(text, {
28
- data: options,
29
- // a duration of 0 keeps the toast up infinitely until hidden
30
- duration: options?.persistent ? 0 : TOAST_DURATION_MS,
31
- });
31
+ show,
32
+ warn: (text: string, options?: Omit<ToastProps["data"], "variant">): string => {
33
+ return show(text, {...options, variant: "warning"});
34
+ },
35
+ error: (text: string, options?: Omit<ToastProps["data"], "variant">): string => {
36
+ return show(text, {...options, variant: "error"});
32
37
  },
33
38
  hide: (id: string) => toast.hide(id),
39
+ catch: (error: any, message?: string, options?: Omit<ToastProps["data"], "variant">): void => {
40
+ let exceptionMsg;
41
+ if (isAPIError(error)) {
42
+ // Get the error without details.
43
+ exceptionMsg = `${message}: ${printAPIError(error)}`;
44
+ console.error(exceptionMsg);
45
+ } else {
46
+ exceptionMsg = error?.message ?? error?.error ?? String(error);
47
+ console.error(`${message}: ${exceptionMsg}`);
48
+ }
49
+ show(exceptionMsg, {...options, variant: "error"});
50
+ },
34
51
  };
35
52
  }
36
53
 
37
- export function Toast({message, data}: ToastProps): React.ReactElement {
54
+ export const Toast = ({message, data}: ToastProps): React.ReactElement => {
38
55
  // margin 8 on either side, times the standard 4px we multiply by.
39
56
  const width = Math.min(Dimensions.get("window").width - 16 * 4, 712);
40
57
  const {variant, buttonText, buttonOnClick, persistent, onDismiss} = data ?? {};
@@ -89,4 +106,4 @@ export function Toast({message, data}: ToastProps): React.ReactElement {
89
106
  )}
90
107
  </Box>
91
108
  );
92
- }
109
+ };
package/src/Tooltip.tsx CHANGED
@@ -138,6 +138,7 @@ export const Tooltip = (props: TooltipProps) => {
138
138
 
139
139
  const isWeb = Platform.OS === "web";
140
140
 
141
+ // If the tooltip is visible, and the user clicks outside of the tooltip, hide it.
141
142
  React.useEffect(() => {
142
143
  return () => {
143
144
  if (showTooltipTimer.current) {
package/src/Unifier.ts CHANGED
@@ -151,8 +151,8 @@ class UnifierClass {
151
151
  } else {
152
152
  return null;
153
153
  }
154
- } catch (e) {
155
- console.error(`[storage] Error reading ${key}`, e);
154
+ } catch (error) {
155
+ console.error(`[storage] Error reading ${key}`, error);
156
156
  return defaultValue || null;
157
157
  }
158
158
  },
@@ -160,9 +160,9 @@ class UnifierClass {
160
160
  try {
161
161
  const jsonValue = JSON.stringify(item);
162
162
  await AsyncStorage.setItem(key, jsonValue);
163
- } catch (e) {
164
- console.error(`[storage] Error storing ${key}`, item, e);
165
- throw new Error(e as any);
163
+ } catch (error) {
164
+ console.error(`[storage] Error storing ${key}`, item, error);
165
+ throw new Error(error as any);
166
166
  }
167
167
  },
168
168
  };
package/src/Utilities.tsx CHANGED
@@ -3,7 +3,7 @@
3
3
  import get from "lodash/get";
4
4
  import {Platform} from "react-native";
5
5
 
6
- import {BaseProfile, IconSize} from "./Common";
6
+ import {APIError, BaseProfile, IconSize} from "./Common";
7
7
  import {COUNTY_AND_COUNTY_EQUIVALENT_ENTITIES} from "./Constants";
8
8
 
9
9
  export function mergeInlineStyles(inlineStyle?: any, newStyle?: any) {
@@ -308,3 +308,15 @@ export function formattedCountyCode(state: string, countyName: string): string {
308
308
 
309
309
  return `${countyData.stateFP}${countyData.countyFP}`;
310
310
  }
311
+
312
+ export function isAPIError(error: any): error is APIError {
313
+ return error && error.data?.title;
314
+ }
315
+
316
+ export function printAPIError(error: APIError, details = true): string {
317
+ let message = error.data?.title;
318
+ if (error.data?.detail && details) {
319
+ message = `${message}: ${error.data?.detail}`;
320
+ }
321
+ return message;
322
+ }
@@ -34,6 +34,7 @@ export const WebAddressAutocomplete = ({
34
34
  const [scriptLoaded, setScriptLoaded] = useState(true);
35
35
  const autocompleteInputRef = useRef(null);
36
36
 
37
+ // Load the Google Maps script and initialize the autocomplete.
37
38
  useEffect(() => {
38
39
  const callbackName = "initAutocomplete";
39
40
  if (!googleMapsApiKey) {
package/src/WithLabel.tsx CHANGED
@@ -4,7 +4,7 @@ import {Box} from "./Box";
4
4
  import {WithLabelProps} from "./Common";
5
5
  import {Text} from "./Text";
6
6
 
7
- export function WithLabel({
7
+ export const WithLabel = ({
8
8
  label,
9
9
  labelInline,
10
10
  labelJustifyContent,
@@ -14,7 +14,7 @@ export function WithLabel({
14
14
  labelColor,
15
15
  show,
16
16
  children,
17
- }: WithLabelProps): React.ReactElement | null {
17
+ }: WithLabelProps): React.ReactElement | null => {
18
18
  if (!children) {
19
19
  return null;
20
20
  }
@@ -42,4 +42,4 @@ export function WithLabel({
42
42
  )}
43
43
  </Box>
44
44
  );
45
- }
45
+ };
@@ -31,7 +31,7 @@ const TableContext: Context<TableContextType> = createContext<TableContextType>(
31
31
 
32
32
  export const {Provider} = TableContext;
33
33
 
34
- export function TableContextProvider({
34
+ export const TableContextProvider = ({
35
35
  children,
36
36
  columns,
37
37
  hasDrawerContents,
@@ -40,7 +40,7 @@ export function TableContextProvider({
40
40
  stickyHeader,
41
41
  borderStyle,
42
42
  alternateRowBackground,
43
- }: Props): React.ReactElement<typeof Provider> {
43
+ }: Props): React.ReactElement<typeof Provider> => {
44
44
  return (
45
45
  <Provider
46
46
  value={{
@@ -56,7 +56,7 @@ export function TableContextProvider({
56
56
  {children}
57
57
  </Provider>
58
58
  );
59
- }
59
+ };
60
60
 
61
61
  export function useTableContext(): TableContextType {
62
62
  const {