@jobber/components-native 0.34.0 → 0.34.1-migrate-fo.12

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 (189) hide show
  1. package/dist/src/Checkbox/Checkbox.js +66 -0
  2. package/dist/src/Checkbox/Checkbox.style.js +30 -0
  3. package/dist/src/Checkbox/CheckboxGroup.js +115 -0
  4. package/dist/src/Checkbox/CheckboxGroup.style.js +14 -0
  5. package/dist/src/Checkbox/CheckboxGroupReducer.js +17 -0
  6. package/dist/src/Checkbox/index.js +2 -0
  7. package/dist/src/Checkbox/types.js +1 -0
  8. package/dist/src/Disclosure/Disclosure.js +50 -0
  9. package/dist/src/Disclosure/Disclosure.style.js +21 -0
  10. package/dist/src/Disclosure/constants.js +1 -0
  11. package/dist/src/Disclosure/index.js +1 -0
  12. package/dist/src/Form/Form.js +190 -0
  13. package/dist/src/Form/Form.style.js +33 -0
  14. package/dist/src/Form/components/FormActionBar/FormActionBar.js +21 -0
  15. package/dist/src/Form/components/FormActionBar/FormActionBar.style.js +5 -0
  16. package/dist/src/Form/components/FormActionBar/index.js +1 -0
  17. package/dist/src/Form/components/FormBody/FormBody.js +20 -0
  18. package/dist/src/Form/components/FormBody/FormBody.style.js +26 -0
  19. package/dist/src/Form/components/FormBody/index.js +1 -0
  20. package/dist/src/Form/components/FormCache/FormCache.js +34 -0
  21. package/dist/src/Form/components/FormErrorBanner/FormErrorBanner.js +21 -0
  22. package/dist/src/Form/components/FormErrorBanner/index.js +1 -0
  23. package/dist/src/Form/components/FormErrorBanner/messages.js +13 -0
  24. package/dist/src/Form/components/FormMask/FormMask.js +11 -0
  25. package/dist/src/Form/components/FormMask/FormMask.style.js +15 -0
  26. package/dist/src/Form/components/FormMask/index.js +1 -0
  27. package/dist/src/Form/components/FormMessage/FormMessage.js +48 -0
  28. package/dist/src/Form/components/FormMessage/components/InternalFormMessage/InternalFormMessage.js +28 -0
  29. package/dist/src/Form/components/FormMessage/components/InternalFormMessage/InternalFormMessage.style.js +17 -0
  30. package/dist/src/Form/components/FormMessage/components/InternalFormMessage/index.js +1 -0
  31. package/dist/src/Form/components/FormMessage/components/InternalFormMessage/messages.js +8 -0
  32. package/dist/src/Form/components/FormMessage/index.js +1 -0
  33. package/dist/src/Form/components/FormMessageBanner/FormMessageBanner.js +15 -0
  34. package/dist/src/Form/components/FormMessageBanner/index.js +1 -0
  35. package/dist/src/Form/components/FormSaveButton/FormSaveButton.js +69 -0
  36. package/dist/src/Form/components/FormSaveButton/index.js +1 -0
  37. package/dist/src/Form/components/FormSaveButton/messages.js +8 -0
  38. package/dist/src/Form/constants.js +2 -0
  39. package/dist/src/Form/context/AtlantisFormContext.js +15 -0
  40. package/dist/src/Form/context/index.js +1 -0
  41. package/dist/src/Form/context/types.js +1 -0
  42. package/dist/src/Form/hooks/useFormViewRefs.js +14 -0
  43. package/dist/src/Form/hooks/useInternalForm.js +37 -0
  44. package/dist/src/Form/hooks/useOfflineHandler.js +24 -0
  45. package/dist/src/Form/hooks/useSaveButtonPosition.js +25 -0
  46. package/dist/src/Form/hooks/useScreenInformation.js +14 -0
  47. package/dist/src/Form/hooks/useScrollToError/index.js +1 -0
  48. package/dist/src/Form/hooks/useScrollToError/useScrollToError.js +63 -0
  49. package/dist/src/Form/index.js +4 -0
  50. package/dist/src/Form/messages.js +28 -0
  51. package/dist/src/Form/types.js +10 -0
  52. package/dist/src/InputTime/InputTime.js +83 -0
  53. package/dist/src/InputTime/InputTime.style.js +7 -0
  54. package/dist/src/InputTime/index.js +2 -0
  55. package/dist/src/InputTime/messages.js +8 -0
  56. package/dist/src/InputTime/utils/index.js +16 -0
  57. package/dist/src/index.js +4 -0
  58. package/dist/tsconfig.tsbuildinfo +1 -1
  59. package/dist/types/src/Checkbox/Checkbox.d.ts +59 -0
  60. package/dist/types/src/Checkbox/Checkbox.style.d.ts +27 -0
  61. package/dist/types/src/Checkbox/CheckboxGroup.d.ts +22 -0
  62. package/dist/types/src/Checkbox/CheckboxGroup.style.d.ts +12 -0
  63. package/dist/types/src/Checkbox/CheckboxGroupReducer.d.ts +9 -0
  64. package/dist/types/src/Checkbox/index.d.ts +2 -0
  65. package/dist/types/src/Checkbox/types.d.ts +11 -0
  66. package/dist/types/src/Disclosure/Disclosure.d.ts +35 -0
  67. package/dist/types/src/Disclosure/Disclosure.style.d.ts +19 -0
  68. package/dist/types/src/Disclosure/constants.d.ts +1 -0
  69. package/dist/types/src/Disclosure/index.d.ts +1 -0
  70. package/dist/types/src/Form/Form.d.ts +4 -0
  71. package/dist/types/src/Form/Form.style.d.ts +31 -0
  72. package/dist/types/src/Form/components/FormActionBar/FormActionBar.d.ts +13 -0
  73. package/dist/types/src/Form/components/FormActionBar/FormActionBar.style.d.ts +15 -0
  74. package/dist/types/src/Form/components/FormActionBar/index.d.ts +2 -0
  75. package/dist/types/src/Form/components/FormBody/FormBody.d.ts +10 -0
  76. package/dist/types/src/Form/components/FormBody/FormBody.style.d.ts +24 -0
  77. package/dist/types/src/Form/components/FormBody/index.d.ts +1 -0
  78. package/dist/types/src/Form/components/FormCache/FormCache.d.ts +10 -0
  79. package/dist/types/src/Form/components/FormErrorBanner/FormErrorBanner.d.ts +3 -0
  80. package/dist/types/src/Form/components/FormErrorBanner/index.d.ts +1 -0
  81. package/dist/types/src/Form/components/FormErrorBanner/messages.d.ts +12 -0
  82. package/dist/types/src/Form/components/FormMask/FormMask.d.ts +2 -0
  83. package/dist/types/src/Form/components/FormMask/FormMask.style.d.ts +13 -0
  84. package/dist/types/src/Form/components/FormMask/index.d.ts +1 -0
  85. package/dist/types/src/Form/components/FormMessage/FormMessage.d.ts +19 -0
  86. package/dist/types/src/Form/components/FormMessage/components/InternalFormMessage/InternalFormMessage.d.ts +8 -0
  87. package/dist/types/src/Form/components/FormMessage/components/InternalFormMessage/InternalFormMessage.style.d.ts +20 -0
  88. package/dist/types/src/Form/components/FormMessage/components/InternalFormMessage/index.d.ts +1 -0
  89. package/dist/types/src/Form/components/FormMessage/components/InternalFormMessage/messages.d.ts +7 -0
  90. package/dist/types/src/Form/components/FormMessage/index.d.ts +1 -0
  91. package/dist/types/src/Form/components/FormMessageBanner/FormMessageBanner.d.ts +7 -0
  92. package/dist/types/src/Form/components/FormMessageBanner/index.d.ts +1 -0
  93. package/dist/types/src/Form/components/FormSaveButton/FormSaveButton.d.ts +3 -0
  94. package/dist/types/src/Form/components/FormSaveButton/index.d.ts +1 -0
  95. package/dist/types/src/Form/components/FormSaveButton/messages.d.ts +7 -0
  96. package/dist/types/src/Form/constants.d.ts +2 -0
  97. package/dist/types/src/Form/context/AtlantisFormContext.d.ts +11 -0
  98. package/dist/types/src/Form/context/index.d.ts +2 -0
  99. package/dist/types/src/Form/context/types.d.ts +25 -0
  100. package/dist/types/src/Form/hooks/useFormViewRefs.d.ts +10 -0
  101. package/dist/types/src/Form/hooks/useInternalForm.d.ts +19 -0
  102. package/dist/types/src/Form/hooks/useOfflineHandler.d.ts +1 -0
  103. package/dist/types/src/Form/hooks/useSaveButtonPosition.d.ts +12 -0
  104. package/dist/types/src/Form/hooks/useScreenInformation.d.ts +8 -0
  105. package/dist/types/src/Form/hooks/useScrollToError/index.d.ts +1 -0
  106. package/dist/types/src/Form/hooks/useScrollToError/useScrollToError.d.ts +10 -0
  107. package/dist/types/src/Form/index.d.ts +5 -0
  108. package/dist/types/src/Form/messages.d.ts +27 -0
  109. package/dist/types/src/Form/types.d.ts +199 -0
  110. package/dist/types/src/InputNumber/InputNumber.d.ts +1 -1
  111. package/dist/types/src/InputTime/InputTime.d.ts +61 -0
  112. package/dist/types/src/InputTime/InputTime.style.d.ts +6 -0
  113. package/dist/types/src/InputTime/index.d.ts +2 -0
  114. package/dist/types/src/InputTime/messages.d.ts +7 -0
  115. package/dist/types/src/InputTime/utils/index.d.ts +11 -0
  116. package/dist/types/src/index.d.ts +4 -0
  117. package/package.json +10 -3
  118. package/src/Checkbox/Checkbox.style.ts +36 -0
  119. package/src/Checkbox/Checkbox.test.tsx +104 -0
  120. package/src/Checkbox/Checkbox.tsx +192 -0
  121. package/src/Checkbox/CheckboxGroup.style.ts +15 -0
  122. package/src/Checkbox/CheckboxGroup.test.tsx +341 -0
  123. package/src/Checkbox/CheckboxGroup.tsx +228 -0
  124. package/src/Checkbox/CheckboxGroupReducer.test.ts +41 -0
  125. package/src/Checkbox/CheckboxGroupReducer.ts +32 -0
  126. package/src/Checkbox/index.ts +2 -0
  127. package/src/Checkbox/types.ts +13 -0
  128. package/src/Disclosure/Disclosure.style.ts +22 -0
  129. package/src/Disclosure/Disclosure.test.tsx +71 -0
  130. package/src/Disclosure/Disclosure.tsx +162 -0
  131. package/src/Disclosure/__snapshots__/Disclosure.test.tsx.snap +488 -0
  132. package/src/Disclosure/constants.ts +1 -0
  133. package/src/Disclosure/index.ts +1 -0
  134. package/src/Form/Form.style.ts +34 -0
  135. package/src/Form/Form.test.tsx +593 -0
  136. package/src/Form/Form.tsx +299 -0
  137. package/src/Form/components/FormActionBar/FormActionBar.style.ts +11 -0
  138. package/src/Form/components/FormActionBar/FormActionBar.tsx +63 -0
  139. package/src/Form/components/FormActionBar/index.ts +2 -0
  140. package/src/Form/components/FormBody/FormBody.style.ts +27 -0
  141. package/src/Form/components/FormBody/FormBody.tsx +62 -0
  142. package/src/Form/components/FormBody/index.ts +1 -0
  143. package/src/Form/components/FormCache/FormCache.tsx +50 -0
  144. package/src/Form/components/FormErrorBanner/FormErrorBanner.test.tsx +124 -0
  145. package/src/Form/components/FormErrorBanner/FormErrorBanner.tsx +34 -0
  146. package/src/Form/components/FormErrorBanner/index.ts +1 -0
  147. package/src/Form/components/FormErrorBanner/messages.ts +14 -0
  148. package/src/Form/components/FormMask/FormMask.style.tsx +16 -0
  149. package/src/Form/components/FormMask/FormMask.tsx +19 -0
  150. package/src/Form/components/FormMask/index.ts +1 -0
  151. package/src/Form/components/FormMessage/FormMessage.test.tsx +66 -0
  152. package/src/Form/components/FormMessage/FormMessage.tsx +63 -0
  153. package/src/Form/components/FormMessage/components/InternalFormMessage/InternalFormMessage.style.ts +18 -0
  154. package/src/Form/components/FormMessage/components/InternalFormMessage/InternalFormMessage.tsx +55 -0
  155. package/src/Form/components/FormMessage/components/InternalFormMessage/index.ts +1 -0
  156. package/src/Form/components/FormMessage/components/InternalFormMessage/messages.ts +10 -0
  157. package/src/Form/components/FormMessage/index.ts +1 -0
  158. package/src/Form/components/FormMessageBanner/FormMessageBanner.test.tsx +27 -0
  159. package/src/Form/components/FormMessageBanner/FormMessageBanner.tsx +33 -0
  160. package/src/Form/components/FormMessageBanner/index.ts +1 -0
  161. package/src/Form/components/FormSaveButton/FormSaveButton.test.tsx +153 -0
  162. package/src/Form/components/FormSaveButton/FormSaveButton.tsx +103 -0
  163. package/src/Form/components/FormSaveButton/index.ts +1 -0
  164. package/src/Form/components/FormSaveButton/messages.ts +9 -0
  165. package/src/Form/constants.ts +2 -0
  166. package/src/Form/context/AtlantisFormContext.test.tsx +44 -0
  167. package/src/Form/context/AtlantisFormContext.tsx +20 -0
  168. package/src/Form/context/index.ts +5 -0
  169. package/src/Form/context/types.ts +33 -0
  170. package/src/Form/hooks/useFormViewRefs.ts +23 -0
  171. package/src/Form/hooks/useInternalForm.ts +99 -0
  172. package/src/Form/hooks/useOfflineHandler.ts +36 -0
  173. package/src/Form/hooks/useSaveButtonPosition.ts +52 -0
  174. package/src/Form/hooks/useScreenInformation.ts +23 -0
  175. package/src/Form/hooks/useScrollToError/index.ts +1 -0
  176. package/src/Form/hooks/useScrollToError/useScrollToError.test.tsx +103 -0
  177. package/src/Form/hooks/useScrollToError/useScrollToError.ts +102 -0
  178. package/src/Form/index.ts +14 -0
  179. package/src/Form/messages.ts +32 -0
  180. package/src/Form/types.ts +255 -0
  181. package/src/InputNumber/InputNumber.tsx +1 -1
  182. package/src/InputTime/InputTime.style.ts +8 -0
  183. package/src/InputTime/InputTime.test.tsx +323 -0
  184. package/src/InputTime/InputTime.tsx +221 -0
  185. package/src/InputTime/index.tsx +2 -0
  186. package/src/InputTime/messages.ts +9 -0
  187. package/src/InputTime/utils/index.ts +26 -0
  188. package/src/InputTime/utils/utils.test.ts +47 -0
  189. package/src/index.ts +4 -0
@@ -0,0 +1,66 @@
1
+ import React from "react";
2
+ import { Pressable, View } from "react-native";
3
+ import { tokens } from "@jobber/design/foundation";
4
+ import { styles } from "./Checkbox.style";
5
+ import { Text } from "../Text";
6
+ import { Icon } from "../Icon";
7
+ import { FormField } from "../FormField";
8
+ export function Checkbox(props) {
9
+ if (props.checked !== undefined && props.onChange !== undefined) {
10
+ return React.createElement(CheckboxInternal, Object.assign({}, props));
11
+ }
12
+ else if (props.name) {
13
+ return (React.createElement(FormField, { name: props.name, defaultValue: props.defaultChecked }, field => {
14
+ return (React.createElement(CheckboxInternal, Object.assign({}, props, { checked: field.value, onChange: newValue => {
15
+ var _a;
16
+ (_a = props === null || props === void 0 ? void 0 : props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, newValue);
17
+ field.onChange(newValue);
18
+ } })));
19
+ }));
20
+ }
21
+ else {
22
+ throw new Error("Checkbox was given invalid props");
23
+ }
24
+ }
25
+ function CheckboxInternal({ label, checked, defaultChecked, indeterminate = false, disabled = false, assistiveText, onChange, accessibilityLabel, }) {
26
+ const internalValue = checked !== null && checked !== void 0 ? checked : !!defaultChecked;
27
+ const iconName = indeterminate ? "minus2" : "checkmark";
28
+ const textVariation = disabled ? "disabled" : "subdued";
29
+ const a11yStateChecked = indeterminate ? "mixed" : internalValue;
30
+ const backgroundColor = getBackgroundColor(internalValue, disabled, indeterminate);
31
+ return (React.createElement(Pressable, { accessibilityRole: "checkbox", accessibilityLabel: accessibilityLabel || label, accessibilityState: {
32
+ disabled: disabled,
33
+ checked: a11yStateChecked,
34
+ }, disabled: disabled, style: ({ pressed }) => [
35
+ {
36
+ opacity: pressed ? 0.2 : 1,
37
+ },
38
+ styles.container,
39
+ ], onPress: () => {
40
+ onChange === null || onChange === void 0 ? void 0 : onChange(!internalValue);
41
+ } },
42
+ React.createElement(View, { style: styles.checkBoxContainer },
43
+ label && (React.createElement(View, { style: styles.label },
44
+ React.createElement(Text, { variation: textVariation, align: "start" }, label))),
45
+ React.createElement(View, { style: [
46
+ styles.checkbox,
47
+ disabled && styles.disabledCheckbox,
48
+ {
49
+ backgroundColor,
50
+ },
51
+ ] }, (internalValue || indeterminate) && (React.createElement(Icon, { name: iconName, color: "white" })))),
52
+ assistiveText && (React.createElement(Text, { level: "textSupporting", align: "start", variation: textVariation }, assistiveText))));
53
+ }
54
+ function getBackgroundColor(checked, disabled, indeterminate) {
55
+ if (checked || indeterminate) {
56
+ if (disabled) {
57
+ return tokens["color-disabled"];
58
+ }
59
+ else {
60
+ return tokens["color-interactive"];
61
+ }
62
+ }
63
+ else {
64
+ return tokens["color-overlay--dimmed"];
65
+ }
66
+ }
@@ -0,0 +1,30 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+ const checkboxDimensions = tokens["space-large"] + tokens["space-smaller"];
4
+ export const styles = StyleSheet.create({
5
+ container: {
6
+ width: "100%",
7
+ },
8
+ checkBoxContainer: {
9
+ width: "100%",
10
+ justifyContent: "space-between",
11
+ flexDirection: "row",
12
+ alignItems: "center",
13
+ paddingVertical: tokens["space-small"],
14
+ },
15
+ label: {
16
+ flex: 1,
17
+ },
18
+ checkbox: {
19
+ borderRadius: tokens["radius-base"],
20
+ borderWidth: tokens["border-thick"],
21
+ justifyContent: "flex-end",
22
+ width: checkboxDimensions,
23
+ height: checkboxDimensions,
24
+ marginLeft: tokens["space-smaller"],
25
+ borderColor: tokens["color-interactive"],
26
+ },
27
+ disabledCheckbox: {
28
+ borderColor: tokens["color-disabled"],
29
+ },
30
+ });
@@ -0,0 +1,115 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React, { Fragment, useReducer } from "react";
13
+ import { View } from "react-native";
14
+ import isEmpty from "lodash/isEmpty";
15
+ import reduce from "lodash/reduce";
16
+ import { styles } from "./CheckboxGroup.style";
17
+ import { Checkbox } from "./Checkbox";
18
+ import { checkboxGroupReducer, initCheckboxGroupState, } from "./CheckboxGroupReducer";
19
+ import { FormField } from "../FormField";
20
+ import { Divider } from "../Divider";
21
+ export function CheckboxGroup(_a) {
22
+ var { children, state, onChange, name } = _a, rest = __rest(_a, ["children", "state", "onChange", "name"]);
23
+ if (state !== undefined && onChange !== undefined) {
24
+ return (React.createElement(CheckboxGroupInternal, Object.assign({ state: state, onChange: onChange, name: name }, rest), children));
25
+ }
26
+ if (name) {
27
+ return (React.createElement(FormField, { name: name }, field => {
28
+ return (React.createElement(CheckboxGroupInternal, Object.assign({ name: field.name, state: field.value, onChange: newValue => {
29
+ onChange === null || onChange === void 0 ? void 0 : onChange(newValue);
30
+ field.onChange(newValue);
31
+ } }, rest), children));
32
+ }));
33
+ }
34
+ throw new Error("CheckboxGroup passed invalid props");
35
+ }
36
+ function CheckboxGroupInternal({ label, disabled, children, state, accessibilityLabel, onChange, name: parentName, }) {
37
+ const childrenNames = React.Children.map(children, child => {
38
+ const name = throwErrorIfItHasNoName(child.props.name);
39
+ return name;
40
+ });
41
+ const isNested = !!label;
42
+ const [internalCheckedValues, dispatch] = useReducer(checkboxGroupReducer, childrenNames, initCheckboxGroupState);
43
+ const actualCheckedValues = !isEmpty(state) ? state : internalCheckedValues;
44
+ const handleChange = (data) => {
45
+ dispatch({ type: "Update", data });
46
+ onChange === null || onChange === void 0 ? void 0 : onChange(data);
47
+ };
48
+ const indeterminate = checkIndeterminateStatus(actualCheckedValues);
49
+ function cloneChildCheckbox(checkbox) {
50
+ const name = throwErrorIfItHasNoName(checkbox.props.name);
51
+ const childDisabled = disabled || checkbox.props.disabled;
52
+ const childrenHandleChange = (checked) => {
53
+ var _a, _b;
54
+ const childrenNextValue = Object.assign(Object.assign({}, actualCheckedValues.childrenChecked), { [name]: checked });
55
+ const parentNextValue = reduce(childrenNextValue, getParentChecked, true);
56
+ (_b = (_a = checkbox.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, checked);
57
+ handleChange({
58
+ childrenChecked: childrenNextValue,
59
+ parentChecked: parentNextValue,
60
+ });
61
+ };
62
+ return React.cloneElement(checkbox, {
63
+ onChange: childrenHandleChange,
64
+ checked: actualCheckedValues.childrenChecked[name],
65
+ disabled: childDisabled,
66
+ });
67
+ }
68
+ const checkboxObject = React.Children.toArray(children).reduce((childCheckboxObject, child) => {
69
+ if (!React.isValidElement(child)) {
70
+ return childCheckboxObject;
71
+ }
72
+ const name = throwErrorIfItHasNoName(child.props.name);
73
+ return Object.assign(Object.assign({}, childCheckboxObject), { [name]: cloneChildCheckbox(child) });
74
+ }, {});
75
+ function getParentChecked(acc, value, childName) {
76
+ var _a;
77
+ const currentCheckbox = checkboxObject[childName];
78
+ if ((_a = currentCheckbox === null || currentCheckbox === void 0 ? void 0 : currentCheckbox.props) === null || _a === void 0 ? void 0 : _a.disabled) {
79
+ return acc;
80
+ }
81
+ return acc && value;
82
+ }
83
+ return (React.createElement(View, null,
84
+ isNested ? (React.createElement(React.Fragment, null,
85
+ React.createElement(Checkbox, { name: parentName, label: label, accessibilityLabel: accessibilityLabel || label, indeterminate: indeterminate, checked: actualCheckedValues.parentChecked || false, onChange: value => {
86
+ const newValues = reduce(actualCheckedValues.childrenChecked, (acc, currentCheckboxValue, childName) => {
87
+ var _a;
88
+ const currentCheckbox = checkboxObject[childName];
89
+ return ((_a = currentCheckbox === null || currentCheckbox === void 0 ? void 0 : currentCheckbox.props) === null || _a === void 0 ? void 0 : _a.disabled)
90
+ ? Object.assign(Object.assign({}, acc), { [childName]: currentCheckboxValue }) : Object.assign(Object.assign({}, acc), { [childName]: value });
91
+ }, {});
92
+ const parentChecked = reduce(newValues, getParentChecked, value);
93
+ onChange({ childrenChecked: newValues, parentChecked });
94
+ }, disabled: disabled }),
95
+ React.createElement(Divider, null))) : undefined,
96
+ React.createElement(View, null),
97
+ React.createElement(View, { style: isNested ? styles.nestedCheckboxes : {} }, Object.values(checkboxObject).map((checkbox, index) => {
98
+ return (React.createElement(Fragment, { key: index },
99
+ checkbox,
100
+ index !== children.length - 1 && React.createElement(Divider, null)));
101
+ }))));
102
+ }
103
+ function throwErrorIfItHasNoName(name) {
104
+ if (!name) {
105
+ throw new Error("You must provide a name to checkboxes in a checkbox group");
106
+ }
107
+ return name;
108
+ }
109
+ function checkIndeterminateStatus(checkedValues) {
110
+ const checkedValuesAsArray = Object.values(checkedValues.childrenChecked);
111
+ if (checkedValuesAsArray.length === 1) {
112
+ return false;
113
+ }
114
+ return !checkedValuesAsArray.every((value, i, arr) => value === arr[0]);
115
+ }
@@ -0,0 +1,14 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ container: {
5
+ width: "100%",
6
+ justifyContent: "center",
7
+ alignItems: "center",
8
+ paddingHorizontal: tokens["space-base"],
9
+ paddingVertical: tokens["space-small"],
10
+ },
11
+ nestedCheckboxes: {
12
+ marginLeft: tokens["space-large"],
13
+ },
14
+ });
@@ -0,0 +1,17 @@
1
+ import deepmerge from "deepmerge";
2
+ export function initCheckboxGroupState(childNames) {
3
+ return {
4
+ parentChecked: false,
5
+ childrenChecked: childNames.reduce((acc, name) => {
6
+ return Object.assign(Object.assign({}, acc), { [name]: false });
7
+ }, {}),
8
+ };
9
+ }
10
+ export function checkboxGroupReducer(state, action) {
11
+ switch (action.type) {
12
+ case "Update":
13
+ return deepmerge(state, action.data);
14
+ default:
15
+ return state;
16
+ }
17
+ }
@@ -0,0 +1,2 @@
1
+ export { Checkbox } from "./Checkbox";
2
+ export { CheckboxGroup } from "./CheckboxGroup";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ import React, { useState } from "react";
2
+ import { ScrollView, TouchableOpacity, View, } from "react-native";
3
+ import Reanimated, { Easing, useAnimatedStyle, useSharedValue, withTiming, } from "react-native-reanimated";
4
+ import { EASE_CUBIC_IN_OUT } from "./constants";
5
+ import { styles } from "./Disclosure.style";
6
+ import { tokens } from "../utils/design";
7
+ import { Icon } from "../Icon";
8
+ const ReanimatedView = Reanimated.createAnimatedComponent(View);
9
+ const ReanimatedScrollView = Reanimated.createAnimatedComponent(ScrollView);
10
+ export function Disclosure({ content, header, open, onToggle, isEmpty, animationDuration = tokens["timing-slowest"], }) {
11
+ return (React.createElement(View, { style: styles.container },
12
+ React.createElement(DisclosureHeader, Object.assign({}, { header, onToggle, isEmpty, open, animationDuration })),
13
+ React.createElement(DisclosureContent, Object.assign({}, { content, open, animationDuration }))));
14
+ }
15
+ function DisclosureHeader({ header, onToggle, isEmpty, open, animationDuration, }) {
16
+ const rotateZ = useSharedValue(0);
17
+ rotateZ.value = withTiming(open ? 0 : -180, {
18
+ easing: Easing.bezier(...EASE_CUBIC_IN_OUT),
19
+ duration: animationDuration,
20
+ });
21
+ const animatedStyle = useAnimatedStyle(() => {
22
+ return {
23
+ transform: [{ rotateZ: `${rotateZ.value}deg` }],
24
+ };
25
+ });
26
+ return (React.createElement(TouchableOpacity, { activeOpacity: tokens["opacity-pressed"], onPress: onToggle, disabled: isEmpty },
27
+ React.createElement(View, { style: styles.headerContainer },
28
+ header,
29
+ !isEmpty && (React.createElement(ReanimatedView, { style: [animatedStyle] },
30
+ React.createElement(Icon, { name: "arrowUp", color: "grey" }))))));
31
+ }
32
+ function DisclosureContent({ content, open, animationDuration, }) {
33
+ const [maxHeight, setMaxHeight] = useState(0);
34
+ const height = useSharedValue(0);
35
+ const onContentLayoutChange = (event) => {
36
+ const newHeight = event.nativeEvent.layout.height;
37
+ setMaxHeight(newHeight);
38
+ };
39
+ height.value = withTiming(open ? maxHeight : 0, {
40
+ duration: animationDuration,
41
+ easing: Easing.bezier(...EASE_CUBIC_IN_OUT),
42
+ });
43
+ const animatedStyle = useAnimatedStyle(() => {
44
+ return {
45
+ height: height.value,
46
+ };
47
+ }, []);
48
+ return (React.createElement(ReanimatedScrollView, { scrollEnabled: false, showsHorizontalScrollIndicator: false, showsVerticalScrollIndicator: false, style: [styles.contentContainer, animatedStyle] },
49
+ React.createElement(View, { testID: "content", onLayout: onContentLayoutChange }, content)));
50
+ }
@@ -0,0 +1,21 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ container: {
5
+ width: "100%",
6
+ },
7
+ headerContainer: {
8
+ flexDirection: "row",
9
+ alignItems: "flex-start",
10
+ justifyContent: "space-between",
11
+ },
12
+ countColumn: {
13
+ paddingRight: tokens["space-base"],
14
+ },
15
+ titleContainer: {
16
+ flexDirection: "row",
17
+ },
18
+ contentContainer: {
19
+ paddingTop: tokens["space-small"],
20
+ },
21
+ });
@@ -0,0 +1 @@
1
+ export const EASE_CUBIC_IN_OUT = [0.645, 0.045, 0.355, 1.0];
@@ -0,0 +1 @@
1
+ export { Disclosure } from "./Disclosure";
@@ -0,0 +1,190 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import React, { useState } from "react";
22
+ import { FormProvider } from "react-hook-form";
23
+ import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
24
+ import { Keyboard, Platform, View, findNodeHandle, } from "react-native";
25
+ import { styles } from "./Form.style";
26
+ import { FormErrorBanner } from "./components/FormErrorBanner";
27
+ import { KEYBOARD_SAVE_BUTTON_DISTANCE } from "./constants";
28
+ import { FormMessageBanner } from "./components/FormMessageBanner";
29
+ import { FormSubmitErrorType, } from "./types";
30
+ import { FormMask } from "./components/FormMask";
31
+ import { useInternalForm } from "./hooks/useInternalForm";
32
+ import { useFormViewRefs } from "./hooks/useFormViewRefs";
33
+ import { useScreenInformation } from "./hooks/useScreenInformation";
34
+ import { FormMessage } from "./components/FormMessage";
35
+ import { FormBody, useBottomPadding } from "./components/FormBody";
36
+ import { useOfflineHandler } from "./hooks/useOfflineHandler";
37
+ import { useScrollToError } from "./hooks/useScrollToError";
38
+ import { FormSaveButton } from "./components/FormSaveButton";
39
+ import { useSaveButtonPosition } from "./hooks/useSaveButtonPosition";
40
+ import { FormCache } from "./components/FormCache/FormCache";
41
+ import { InputAccessoriesProvider } from "../InputText";
42
+ import { tokens } from "../utils/design";
43
+ import { ErrorMessageProvider } from "../ErrorMessageWrapper";
44
+ export function Form(_a) {
45
+ var { initialLoading } = _a, rest = __rest(_a, ["initialLoading"]);
46
+ const child = initialLoading ? React.createElement(FormMask, null) : React.createElement(InternalForm, Object.assign({}, rest));
47
+ return (React.createElement(InputAccessoriesProvider, null,
48
+ React.createElement(ErrorMessageProvider, null, child)));
49
+ }
50
+ // eslint-disable-next-line max-statements
51
+ function InternalForm({ children, onBeforeSubmit, onSubmit, onSubmitError, onSubmitSuccess, bannerErrors, bannerMessages, initialValues, mode = "onTouched", reValidateMode = "onChange", formRef, saveButtonLabel, renderStickySection, localCacheKey, localCacheExclude, localCacheId, secondaryActions, saveButtonOffset, showStickySaveButton = false, renderFooter, }) {
52
+ var _a;
53
+ const { scrollViewRef, bottomViewRef, scrollToTop } = useFormViewRefs();
54
+ const [saveButtonHeight, setSaveButtonHeight] = useState(0);
55
+ const [messageBannerHeight, setMessageBannerHeight] = useState(0);
56
+ const { formMethods, handleSubmit, isSubmitting, removeListenerRef, setLocalCache, } = useInternalForm({
57
+ mode,
58
+ reValidateMode,
59
+ initialValues,
60
+ formRef,
61
+ localCacheKey,
62
+ localCacheExclude,
63
+ localCacheId,
64
+ scrollViewRef,
65
+ saveButtonHeight,
66
+ messageBannerHeight,
67
+ });
68
+ const { windowHeight, headerHeight } = useScreenInformation();
69
+ const [keyboardHeight, setKeyboardHeight] = useState(0);
70
+ const [keyboardScreenY, setKeyboardScreenY] = useState(0);
71
+ const [formContentHeight, setFormContentHeight] = useState(0);
72
+ const [isBottomSheetOpen, setIsBottomSheetOpen] = useState(false);
73
+ const paddingBottom = useBottomPadding();
74
+ const { saveButtonPosition } = useSaveButtonPosition({
75
+ formContentHeight,
76
+ isBottomSheetOpen,
77
+ showStickySaveButton,
78
+ keyboardHeight,
79
+ keyboardScreenY,
80
+ });
81
+ const [isSecondaryActionLoading, setIsSecondaryActionLoading] = useState(false);
82
+ const extraViewHeight = paddingBottom + KEYBOARD_SAVE_BUTTON_DISTANCE;
83
+ const calculatedKeyboardHeight = keyboardHeight - extraViewHeight;
84
+ useScrollToError({
85
+ formState: formMethods.formState,
86
+ refNode: findNodeHandle(scrollViewRef.current),
87
+ setFocus: formMethods.setFocus,
88
+ scrollToPosition: (_a = scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollToPosition,
89
+ });
90
+ const handleOfflineSubmit = useOfflineHandler();
91
+ const keyboardProps = Platform.select({
92
+ ios: {
93
+ onKeyboardWillHide: handleKeyboardHide,
94
+ onKeyboardWillShow: handleKeyboardShow,
95
+ },
96
+ android: {
97
+ onKeyboardDidHide: handleKeyboardHide,
98
+ onKeyboardDidShow: handleKeyboardShow,
99
+ },
100
+ });
101
+ const onLayout = (event) => {
102
+ setMessageBannerHeight(event.nativeEvent.layout.height);
103
+ };
104
+ return (React.createElement(FormProvider, Object.assign({}, formMethods),
105
+ React.createElement(React.Fragment, null,
106
+ (isSubmitting || isSecondaryActionLoading) && React.createElement(FormMask, null),
107
+ React.createElement(FormCache, { localCacheKey: localCacheKey, localCacheExclude: localCacheExclude, setLocalCache: setLocalCache }),
108
+ React.createElement(FormBody, { keyboardHeight: calculateSaveButtonOffset(), submit: handleSubmit(internalSubmit), isFormSubmitting: isSubmitting, saveButtonLabel: saveButtonLabel, shouldRenderActionBar: saveButtonPosition === "sticky", renderStickySection: renderStickySection, secondaryActions: secondaryActions, setSecondaryActionLoading: setIsSecondaryActionLoading, setSaveButtonHeight: setSaveButtonHeight, saveButtonOffset: saveButtonOffset },
109
+ React.createElement(KeyboardAwareScrollView, Object.assign({ enableResetScrollToCoords: false, enableAutomaticScroll: true, keyboardOpeningTime: Platform.OS === "ios" ? tokens["timing-slowest"] : 0, keyboardShouldPersistTaps: "handled", ref: scrollViewRef }, keyboardProps, { extraHeight: headerHeight, contentContainerStyle: !keyboardHeight && styles.scrollContentContainer }),
110
+ React.createElement(View, { onLayout: ({ nativeEvent }) => {
111
+ setFormContentHeight(nativeEvent.layout.height);
112
+ } },
113
+ React.createElement(View, { onLayout: onLayout },
114
+ React.createElement(FormMessageBanner, { bannerMessages: bannerMessages }),
115
+ React.createElement(FormErrorBanner, { networkError: bannerErrors === null || bannerErrors === void 0 ? void 0 : bannerErrors.networkError, bannerError: bannerErrors === null || bannerErrors === void 0 ? void 0 : bannerErrors.bannerError })),
116
+ React.createElement(View, { style: styles.formChildContainer },
117
+ React.createElement(React.Fragment, null,
118
+ React.createElement(View, { style: styles.formContent }, children),
119
+ saveButtonPosition === "inline" && (React.createElement(View, { style: styles.fixedSaveButton }, renderStickySection ? (renderStickySection(handleSubmit(internalSubmit), saveButtonLabel, isSubmitting)) : (React.createElement(FormSaveButton, { primaryAction: handleSubmit(internalSubmit), label: saveButtonLabel, loading: isSubmitting, secondaryActions: secondaryActions, setSecondaryActionLoading: setIsSecondaryActionLoading, onOpenBottomSheet: () => setIsBottomSheetOpen(true), onCloseBottomSheet: () => setIsBottomSheetOpen(false) })))),
120
+ renderFooter))),
121
+ React.createElement(View, { style: styles.safeArea, ref: bottomViewRef })))),
122
+ React.createElement(FormMessage, null)));
123
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
+ function handleKeyboardShow(frames) {
125
+ setKeyboardScreenY(frames.endCoordinates.screenY);
126
+ setKeyboardHeight(frames.endCoordinates.height);
127
+ }
128
+ function handleKeyboardHide() {
129
+ var _a;
130
+ (_a = bottomViewRef === null || bottomViewRef === void 0 ? void 0 : bottomViewRef.current) === null || _a === void 0 ? void 0 : _a.measureInWindow(
131
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
132
+ (_x, y, _width, _height) => {
133
+ var _a;
134
+ // This fixes extra whitespace below the form if it was scrolled down while the keyboard was open
135
+ // i.e. a View below the form is higher than the bottom of the window
136
+ if (y < windowHeight) {
137
+ (_a = scrollViewRef === null || scrollViewRef === void 0 ? void 0 : scrollViewRef.current) === null || _a === void 0 ? void 0 : _a.scrollToEnd();
138
+ }
139
+ });
140
+ setKeyboardHeight(0);
141
+ setKeyboardScreenY(0);
142
+ }
143
+ function internalSubmit(data) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ let performSubmit = true;
146
+ if (onBeforeSubmit) {
147
+ performSubmit = yield onBeforeSubmit(data);
148
+ }
149
+ if (performSubmit) {
150
+ Keyboard.dismiss();
151
+ return onSubmit(data)
152
+ .then((result) => {
153
+ var _a;
154
+ (_a = removeListenerRef.current) === null || _a === void 0 ? void 0 : _a.call(removeListenerRef);
155
+ onSubmitSuccess(result);
156
+ })
157
+ .catch(handleSubmitCatch);
158
+ }
159
+ });
160
+ }
161
+ function handleSubmitCatch(error) {
162
+ // Scroll to top of form to see error
163
+ scrollToTop();
164
+ onSubmitError(error);
165
+ if ((error === null || error === void 0 ? void 0 : error.errorType) === FormSubmitErrorType.NetworkError) {
166
+ // @ts-expect-error We are making the form submission fail so that we can
167
+ // We are making the form submission fail so that we can
168
+ // prevent the isSubmitSuccess to be true
169
+ formMethods.setError("offline", "Error saving form.");
170
+ handleOfflineSubmit(handleRetry, clearFormErrors)();
171
+ }
172
+ }
173
+ function clearFormErrors() {
174
+ // @ts-expect-error We are clearing the error that we previously set
175
+ // We are clearing the error that we previously set
176
+ // when the form had no internet connection
177
+ formMethods.clearErrors("offline");
178
+ }
179
+ function handleRetry() {
180
+ clearFormErrors();
181
+ return handleSubmit(internalSubmit)();
182
+ }
183
+ function calculateSaveButtonOffset() {
184
+ if (saveButtonOffset) {
185
+ // Included the space-base because it's the padding of the FormActionBar
186
+ return calculatedKeyboardHeight - saveButtonOffset + tokens["space-base"];
187
+ }
188
+ return calculatedKeyboardHeight;
189
+ }
190
+ }
@@ -0,0 +1,33 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ container: {
5
+ flex: 1,
6
+ flexGrow: 1,
7
+ width: "100%",
8
+ },
9
+ safeArea: {
10
+ backgroundColor: tokens["color-surface"],
11
+ },
12
+ scrollContentContainer: {
13
+ flexGrow: 1,
14
+ },
15
+ scrollView: {
16
+ flexGrow: 1,
17
+ },
18
+ formChildContainer: {
19
+ flexGrow: 1,
20
+ justifyContent: "flex-start",
21
+ },
22
+ formContent: {
23
+ paddingVertical: tokens["space-small"],
24
+ },
25
+ fixedSaveButton: {
26
+ padding: tokens["space-base"],
27
+ backgroundColor: tokens["color-surface"],
28
+ },
29
+ activityIndicator: {
30
+ marginVertical: tokens["space-base"],
31
+ flex: 1,
32
+ },
33
+ });
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ import { StyleSheet, View } from "react-native";
3
+ import Reanimated from "react-native-reanimated";
4
+ import { styles } from "./FormActionBar.style";
5
+ import { FormSaveButton } from "../FormSaveButton";
6
+ const ReanimatedView = Reanimated.createAnimatedComponent(View);
7
+ export function FormActionBar({ keyboardHeight, submit, isFormSubmitting, saveButtonLabel, renderStickySection, setSaveButtonHeight, secondaryActions, setSecondaryActionLoading, }) {
8
+ const buttonStyle = StyleSheet.flatten([
9
+ styles.saveButton,
10
+ {
11
+ position: keyboardHeight > 0 ? "absolute" : "relative",
12
+ bottom: 0,
13
+ },
14
+ ]);
15
+ const onLayout = (event) => {
16
+ setSaveButtonHeight && setSaveButtonHeight(event.nativeEvent.layout.height);
17
+ };
18
+ return (
19
+ //@ts-expect-error tsc-ci
20
+ React.createElement(ReanimatedView, { style: buttonStyle, onLayout: onLayout }, renderStickySection ? (renderStickySection(submit, saveButtonLabel, isFormSubmitting)) : (React.createElement(FormSaveButton, { setSecondaryActionLoading: setSecondaryActionLoading, primaryAction: submit, loading: isFormSubmitting, label: saveButtonLabel, secondaryActions: secondaryActions }))));
21
+ }
@@ -0,0 +1,5 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../../../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ saveButton: Object.assign({ padding: tokens["space-base"], backgroundColor: tokens["color-surface"], width: "100%" }, tokens["shadow-high"]),
5
+ });
@@ -0,0 +1 @@
1
+ export { FormActionBar } from "./FormActionBar";
@@ -0,0 +1,20 @@
1
+ import React, { useMemo } from "react";
2
+ import { View } from "react-native";
3
+ import { styles } from "./FormBody.style";
4
+ import { useScreenInformation } from "../../hooks/useScreenInformation";
5
+ import { FormActionBar } from "../FormActionBar";
6
+ import { tokens } from "../../../utils/design";
7
+ export function FormBody({ isFormSubmitting, submit, keyboardHeight, children, saveButtonLabel, renderStickySection, shouldRenderActionBar = true, secondaryActions, setSecondaryActionLoading, setSaveButtonHeight, saveButtonOffset, }) {
8
+ const paddingBottom = useBottomPadding();
9
+ const fullViewPadding = useMemo(() => ({ paddingBottom }), [paddingBottom]);
10
+ return (React.createElement(React.Fragment, null,
11
+ React.createElement(View, { style: [styles.container] },
12
+ children,
13
+ shouldRenderActionBar && (React.createElement(FormActionBar, { setSecondaryActionLoading: setSecondaryActionLoading, keyboardHeight: keyboardHeight, submit: submit, isFormSubmitting: isFormSubmitting, saveButtonLabel: saveButtonLabel, renderStickySection: renderStickySection, secondaryActions: secondaryActions, setSaveButtonHeight: setSaveButtonHeight }))),
14
+ shouldRenderActionBar && !saveButtonOffset && (React.createElement(View, { style: [fullViewPadding, styles.safeArea], testID: "ATL-FormSafeArea" }))));
15
+ }
16
+ export function useBottomPadding() {
17
+ const { insets } = useScreenInformation();
18
+ const extraBottomSpace = insets.bottom - tokens["space-base"];
19
+ return extraBottomSpace >= 0 ? extraBottomSpace : 0;
20
+ }
@@ -0,0 +1,26 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { tokens } from "../../../utils/design";
3
+ export const styles = StyleSheet.create({
4
+ container: {
5
+ flex: 1,
6
+ flexGrow: 1,
7
+ width: "100%",
8
+ },
9
+ safeArea: {
10
+ backgroundColor: tokens["color-surface"],
11
+ },
12
+ scrollContentContainer: {
13
+ flexGrow: 1,
14
+ },
15
+ scrollView: {
16
+ flexGrow: 1,
17
+ },
18
+ formChildContainer: {
19
+ flexGrow: 1,
20
+ justifyContent: "flex-start",
21
+ },
22
+ activityIndicator: {
23
+ marginVertical: tokens["space-base"],
24
+ flex: 1,
25
+ },
26
+ });
@@ -0,0 +1 @@
1
+ export { FormBody, useBottomPadding } from "./FormBody";