@onepercentio/one-ui 0.29.4 → 0.29.5

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 (286) hide show
  1. package/dist/components/Switch/Switch.d.ts +1 -1
  2. package/dist/components/Switch/Switch.js +1 -1
  3. package/dist-ts/components/Switch/Switch.d.ts +1 -1
  4. package/package.json +1 -1
  5. package/src/assets/img/svg/checkbox.svg +0 -3
  6. package/src/assets/styles/index.scss +0 -2
  7. package/src/assets/styles/mixins.scss +0 -12
  8. package/src/assets/styles/variables.scss +0 -49
  9. package/src/components/AdaptiveButton/AdaptiveButton.module.scss +0 -7
  10. package/src/components/AdaptiveButton/AdaptiveButton.tsx +0 -26
  11. package/src/components/AdaptiveButton/index.tsx +0 -2
  12. package/src/components/AdaptiveContainer/AdaptiveContainer.module.scss +0 -53
  13. package/src/components/AdaptiveContainer/AdaptiveContainer.tsx +0 -200
  14. package/src/components/AdaptiveContainer/index.tsx +0 -2
  15. package/src/components/AdaptiveDialog/AdaptiveDialog.module.scss +0 -147
  16. package/src/components/AdaptiveDialog/AdaptiveDialog.tsx +0 -97
  17. package/src/components/AdaptiveDialog/index.tsx +0 -2
  18. package/src/components/AdaptiveSidebar/AdaptiveSidebar.module.scss +0 -49
  19. package/src/components/AdaptiveSidebar/AdaptiveSidebar.sample.tsx +0 -10
  20. package/src/components/AdaptiveSidebar/AdaptiveSidebar.tsx +0 -123
  21. package/src/components/AdaptiveSidebar/index.tsx +0 -2
  22. package/src/components/AnchoredTooltip/AnchoredTooltip.module.scss +0 -64
  23. package/src/components/AnchoredTooltip/AnchoredTooltip.tsx +0 -250
  24. package/src/components/AnchoredTooltip/index.tsx +0 -2
  25. package/src/components/AnimatedEntrance/AnimatedEntrance.module.scss +0 -108
  26. package/src/components/AnimatedEntrance/AnimatedEntrance.tsx +0 -227
  27. package/src/components/AnimatedEntrance/index.tsx +0 -2
  28. package/src/components/AsyncWrapper/AsyncWrapper.tsx +0 -38
  29. package/src/components/AsyncWrapper/index.tsx +0 -2
  30. package/src/components/Avatar/Avatar.module.scss +0 -22
  31. package/src/components/Avatar/Avatar.tsx +0 -31
  32. package/src/components/Avatar/index.tsx +0 -2
  33. package/src/components/BucketFill/BucketFill.module.scss +0 -36
  34. package/src/components/BucketFill/BucketFill.tsx +0 -65
  35. package/src/components/BucketFill/index.tsx +0 -2
  36. package/src/components/Button/Button.module.scss +0 -45
  37. package/src/components/Button/Button.tsx +0 -40
  38. package/src/components/Button/index.tsx +0 -2
  39. package/src/components/Card/Card.module.scss +0 -12
  40. package/src/components/Card/Card.tsx +0 -9
  41. package/src/components/Card/index.tsx +0 -2
  42. package/src/components/Chart/Chart.e2e.ts +0 -4
  43. package/src/components/Chart/Chart.logic.tsx +0 -8
  44. package/src/components/Chart/Chart.module.scss +0 -58
  45. package/src/components/Chart/Chart.tsx +0 -2
  46. package/src/components/Chart/Chart.types.ts +0 -35
  47. package/src/components/Chart/Chart.view.tsx +0 -241
  48. package/src/components/Chart/index.tsx +0 -2
  49. package/src/components/CheckBox/CheckBox.module.scss +0 -36
  50. package/src/components/CheckBox/CheckBox.tsx +0 -63
  51. package/src/components/CheckBox/index.tsx +0 -2
  52. package/src/components/CodeInput/CodeInput.module.scss +0 -5
  53. package/src/components/CodeInput/CodeInput.tsx +0 -84
  54. package/src/components/CodeInput/index.tsx +0 -2
  55. package/src/components/Collapsable/Collapsable.module.scss +0 -42
  56. package/src/components/Collapsable/Collapsable.tsx +0 -253
  57. package/src/components/Collapsable/index.tsx +0 -2
  58. package/src/components/Countdown/Countdown.tsx +0 -130
  59. package/src/components/Countdown/index.tsx +0 -2
  60. package/src/components/CurrencyInput/CurrencyInput.hook.ts +0 -37
  61. package/src/components/CurrencyInput/CurrencyInput.tsx +0 -25
  62. package/src/components/CurrencyInput/index.tsx +0 -2
  63. package/src/components/Divider/Divider.module.scss +0 -7
  64. package/src/components/Divider/Divider.tsx +0 -13
  65. package/src/components/Divider/index.tsx +0 -2
  66. package/src/components/EmailInput/EmailInput.module.scss +0 -0
  67. package/src/components/EmailInput/EmailInput.tsx +0 -51
  68. package/src/components/EmailInput/index.tsx +0 -2
  69. package/src/components/FadeIn/FadeIn.module.scss +0 -9
  70. package/src/components/FadeIn/FadeIn.tsx +0 -77
  71. package/src/components/FadeIn/index.tsx +0 -2
  72. package/src/components/FileInput/FileInput.module.scss +0 -6
  73. package/src/components/FileInput/FileInput.tsx +0 -75
  74. package/src/components/FileInput/View/BigFactory/BigFactory.module.scss +0 -20
  75. package/src/components/FileInput/View/BigFactory/BigFactory.tsx +0 -48
  76. package/src/components/FileInput/View/BigFactory/index.tsx +0 -2
  77. package/src/components/FileInput/View/Compact/Compact.module.scss +0 -68
  78. package/src/components/FileInput/View/Compact/Compact.tsx +0 -151
  79. package/src/components/FileInput/View/Compact/index.tsx +0 -2
  80. package/src/components/FileInput/View/View.types.ts +0 -12
  81. package/src/components/FileInput/index.tsx +0 -2
  82. package/src/components/FlowController/FlowController.module.scss +0 -47
  83. package/src/components/FlowController/FlowController.tsx +0 -93
  84. package/src/components/FlowController/index.tsx +0 -2
  85. package/src/components/Form/Form.tsx +0 -243
  86. package/src/components/Form/index.ts +0 -2
  87. package/src/components/Form/v2/Form.hook.ts +0 -341
  88. package/src/components/Form/v2/Form.module.scss +0 -0
  89. package/src/components/Form/v2/Form.tsx +0 -78
  90. package/src/components/Form/v2/Form.types.ts +0 -118
  91. package/src/components/Form/v2/FormField/Extensions/DateField/DateField.module.scss +0 -0
  92. package/src/components/Form/v2/FormField/Extensions/DateField/DateField.tsx +0 -73
  93. package/src/components/Form/v2/FormField/Extensions/DateField/index.tsx +0 -2
  94. package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.module.scss +0 -0
  95. package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.tsx +0 -91
  96. package/src/components/Form/v2/FormField/Extensions/PhoneField/index.tsx +0 -2
  97. package/src/components/Form/v2/FormField/FormField.module.scss +0 -0
  98. package/src/components/Form/v2/FormField/FormField.tsx +0 -378
  99. package/src/components/Form/v2/FormField/FormField.types.ts +0 -129
  100. package/src/components/Form/v2/FormField/index.tsx +0 -2
  101. package/src/components/Form/v2/index.tsx +0 -2
  102. package/src/components/Freeze/Freeze.tsx +0 -9
  103. package/src/components/Freeze/index.tsx +0 -2
  104. package/src/components/HSForms/HSForms.tsx +0 -57
  105. package/src/components/HSForms/index.tsx +0 -2
  106. package/src/components/Header/Header.module.scss +0 -119
  107. package/src/components/Header/Header.tsx +0 -138
  108. package/src/components/Header/index.tsx +0 -2
  109. package/src/components/HeaderCloseBtn/HeaderCloseBtn.module.scss +0 -44
  110. package/src/components/HeaderCloseBtn/HeaderCloseBtn.tsx +0 -28
  111. package/src/components/HeaderCloseBtn/index.tsx +0 -2
  112. package/src/components/InfinityScroll/InfinityScroll.module.scss +0 -30
  113. package/src/components/InfinityScroll/InfinityScroll.tsx +0 -187
  114. package/src/components/InfinityScroll/index.tsx +0 -2
  115. package/src/components/Input/Input.module.scss +0 -71
  116. package/src/components/Input/Input.tsx +0 -134
  117. package/src/components/Input/index.tsx +0 -2
  118. package/src/components/InstantCounter/InstantCounter.tsx +0 -77
  119. package/src/components/InstantCounter/index.tsx +0 -2
  120. package/src/components/LavaLamp/LavaLamp.data.tsx +0 -114
  121. package/src/components/LavaLamp/LavaLamp.module.scss +0 -26
  122. package/src/components/LavaLamp/LavaLamp.tsx +0 -131
  123. package/src/components/LavaLamp/index.tsx +0 -2
  124. package/src/components/LavaLamp/v2/LavaLamp.module.scss +0 -23
  125. package/src/components/LavaLamp/v2/LavaLamp.tsx +0 -197
  126. package/src/components/LinkToId/LinkToId.module.scss +0 -4
  127. package/src/components/LinkToId/LinkToId.tsx +0 -51
  128. package/src/components/LinkToId/index.tsx +0 -2
  129. package/src/components/Loader/Loader.module.scss +0 -40
  130. package/src/components/Loader/Loader.tsx +0 -18
  131. package/src/components/Loader/index.tsx +0 -2
  132. package/src/components/LoaderDotsIndicator/LoaderDotsIndicator.tsx +0 -34
  133. package/src/components/LoaderDotsIndicator/index.tsx +0 -2
  134. package/src/components/LoopableVideo/LoopableVideo.tsx +0 -37
  135. package/src/components/LoopableVideo/index.tsx +0 -2
  136. package/src/components/MainGrid/MainGrid.module.scss +0 -28
  137. package/src/components/MainGrid/MainGrid.tsx +0 -68
  138. package/src/components/MainGrid/index.tsx +0 -2
  139. package/src/components/MutableHamburgerButton/MutableHamburgerButton.module.scss +0 -220
  140. package/src/components/MutableHamburgerButton/MutableHamburgerButton.tsx +0 -38
  141. package/src/components/MutableHamburgerButton/index.tsx +0 -2
  142. package/src/components/Notification/Notification.module.scss +0 -25
  143. package/src/components/Notification/Notification.tsx +0 -13
  144. package/src/components/Notification/index.tsx +0 -2
  145. package/src/components/OrderableList/OrderableList.module.scss +0 -98
  146. package/src/components/OrderableList/OrderableList.tsx +0 -564
  147. package/src/components/OrderableList/index.tsx +0 -2
  148. package/src/components/PaginationIndicator/PaginationIndicator.tsx +0 -365
  149. package/src/components/PaginationIndicator/index.tsx +0 -2
  150. package/src/components/Parallax/Parallax.module.scss +0 -28
  151. package/src/components/Parallax/Parallax.tsx +0 -225
  152. package/src/components/Parallax/index.tsx +0 -2
  153. package/src/components/Parallax/math/helpers.ts +0 -289
  154. package/src/components/PasswordInput/PasswordInput.module.scss +0 -17
  155. package/src/components/PasswordInput/PasswordInput.tsx +0 -154
  156. package/src/components/PasswordInput/index.tsx +0 -2
  157. package/src/components/PingPongText/PingPongText.module.scss +0 -4
  158. package/src/components/PingPongText/PingPongText.tsx +0 -83
  159. package/src/components/PingPongText/index.tsx +0 -2
  160. package/src/components/PixelatedScan/PixelatedScan.module.scss +0 -86
  161. package/src/components/PixelatedScan/PixelatedScan.tsx +0 -175
  162. package/src/components/PixelatedScan/index.tsx +0 -2
  163. package/src/components/Portal/Portal.module.scss +0 -3
  164. package/src/components/Portal/Portal.tsx +0 -68
  165. package/src/components/Portal/index.tsx +0 -2
  166. package/src/components/ProgressBar/ProgressBar.module.scss +0 -44
  167. package/src/components/ProgressBar/ProgressBar.tsx +0 -124
  168. package/src/components/ProgressBar/index.tsx +0 -2
  169. package/src/components/ProgressTexts/ProgressTexts.module.scss +0 -37
  170. package/src/components/ProgressTexts/ProgressTexts.tsx +0 -85
  171. package/src/components/ProgressTexts/index.tsx +0 -2
  172. package/src/components/Radio/Radio.module.scss +0 -36
  173. package/src/components/Radio/Radio.tsx +0 -53
  174. package/src/components/Radio/index.tsx +0 -2
  175. package/src/components/SectionContainer/SectionContainer.module.scss +0 -30
  176. package/src/components/SectionContainer/SectionContainer.tsx +0 -49
  177. package/src/components/SectionContainer/index.tsx +0 -2
  178. package/src/components/Select/Select.module.scss +0 -58
  179. package/src/components/Select/Select.tsx +0 -192
  180. package/src/components/Select/index.tsx +0 -2
  181. package/src/components/Skeleton/Skeleton.module.scss +0 -21
  182. package/src/components/Skeleton/Skeleton.tsx +0 -29
  183. package/src/components/Skeleton/index.tsx +0 -2
  184. package/src/components/Spacing/Spacing.module.scss +0 -13
  185. package/src/components/Spacing/Spacing.tsx +0 -24
  186. package/src/components/Spacing/index.tsx +0 -2
  187. package/src/components/StaticScroller/StaticScroller.module.scss +0 -14
  188. package/src/components/StaticScroller/StaticScroller.tsx +0 -83
  189. package/src/components/StaticScroller/index.tsx +0 -2
  190. package/src/components/Switch/Switch.module.scss +0 -43
  191. package/src/components/Switch/Switch.tsx +0 -41
  192. package/src/components/Switch/index.tsx +0 -2
  193. package/src/components/Table/Table.module.scss +0 -76
  194. package/src/components/Table/Table.tsx +0 -152
  195. package/src/components/Table/index.tsx +0 -2
  196. package/src/components/Tabs/Tabs.module.scss +0 -40
  197. package/src/components/Tabs/Tabs.tsx +0 -104
  198. package/src/components/Tabs/index.tsx +0 -2
  199. package/src/components/Text/Text.module.scss +0 -81
  200. package/src/components/Text/Text.tsx +0 -42
  201. package/src/components/Text/index.tsx +0 -2
  202. package/src/components/Transition/MasksFactory/DiagonalReveal.tsx +0 -47
  203. package/src/components/Transition/MasksFactory/DiagonalSquareToBalls.tsx +0 -78
  204. package/src/components/Transition/MasksFactory/PhysicsSquares.tsx +0 -106
  205. package/src/components/Transition/MasksFactory/SquareToBalls.tsx +0 -66
  206. package/src/components/Transition/MasksFactory/utils.ts +0 -35
  207. package/src/components/Transition/Transition.module.scss +0 -211
  208. package/src/components/Transition/Transition.tsx +0 -495
  209. package/src/components/Transition/index.tsx +0 -2
  210. package/src/components/UncontrolledTransition/UncontrolledTransition.ai.md +0 -9
  211. package/src/components/UncontrolledTransition/UncontrolledTransition.sample.tsx +0 -34
  212. package/src/components/UncontrolledTransition/UncontrolledTransition.tsx +0 -143
  213. package/src/components/UncontrolledTransition/index.tsx +0 -2
  214. package/src/components/WalletConnectionWrapper/WalletConnectionWrapper.tsx +0 -212
  215. package/src/components/WalletConnectionWrapper/index.tsx +0 -2
  216. package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.module.scss +0 -5
  217. package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.tsx +0 -52
  218. package/src/components/utilitary/ScrollAndFocusLock/index.tsx +0 -2
  219. package/src/context/AsyncProcess.tsx +0 -107
  220. package/src/context/ContextAsyncControl.tsx +0 -89
  221. package/src/context/CustomBrowserRouter.tsx +0 -55
  222. package/src/context/OneUIProvider.tsx +0 -308
  223. package/src/hooks/logs/useDependencyChangeDetection.ts +0 -25
  224. package/src/hooks/logs/useIsMounting.ts +0 -7
  225. package/src/hooks/persistence/useLocalStorage.ts +0 -45
  226. package/src/hooks/shims/ObjectWatchShim.ts +0 -56
  227. package/src/hooks/ui/useAdaptiveImage.tsx +0 -36
  228. package/src/hooks/ui/useAlternating.tsx +0 -22
  229. package/src/hooks/ui/useBreakpoint.tsx +0 -21
  230. package/src/hooks/ui/useCustomScrollbar.module.scss +0 -20
  231. package/src/hooks/ui/useCustomScrollbar.tsx +0 -22
  232. package/src/hooks/ui/useEffectIf.ts +0 -11
  233. package/src/hooks/ui/useMouseHover.tsx +0 -26
  234. package/src/hooks/ui/usePaginationControls.module.scss +0 -16
  235. package/src/hooks/ui/usePaginationControls.tsx +0 -176
  236. package/src/hooks/ui/useSnapToViewport.module.scss +0 -6
  237. package/src/hooks/ui/useSnapToViewport.ts +0 -28
  238. package/src/hooks/ui/useTilt.tsx +0 -219
  239. package/src/hooks/ui/useZoomable.module.scss +0 -34
  240. package/src/hooks/ui/useZoomable.tsx +0 -144
  241. package/src/hooks/useAsyncControl.ai.md +0 -25
  242. package/src/hooks/useAsyncControl.ts +0 -101
  243. package/src/hooks/useContainedRepositioning.ts +0 -110
  244. package/src/hooks/useCustomHistory.ts +0 -14
  245. package/src/hooks/useElementFit.ts +0 -82
  246. package/src/hooks/useFirestoreWatch.ts +0 -54
  247. package/src/hooks/useForm.ts +0 -49
  248. package/src/hooks/useFreeze.ts +0 -12
  249. package/src/hooks/useHero.module.scss +0 -41
  250. package/src/hooks/useHero.ts +0 -514
  251. package/src/hooks/useIntersection.ts +0 -32
  252. package/src/hooks/useMergeRefs.ts +0 -29
  253. package/src/hooks/useObserve.ts +0 -24
  254. package/src/hooks/usePagination.ts +0 -228
  255. package/src/hooks/usePooledOperation.ts +0 -54
  256. package/src/hooks/usePooling.ts +0 -46
  257. package/src/hooks/useRebound.ts +0 -23
  258. package/src/hooks/useShortIntl.ai.md +0 -5
  259. package/src/hooks/useShortIntl.ts +0 -97
  260. package/src/hooks/utility/useAsyncMemo.ts +0 -43
  261. package/src/hooks/utility/useDepChange.ts +0 -11
  262. package/src/hooks/utility/useEvents.ts +0 -33
  263. package/src/hooks/utility/useImmediate.ts +0 -8
  264. package/src/hooks/utility/useManualInit.ts +0 -24
  265. package/src/hooks/utility/useModule.ts +0 -15
  266. package/src/hooks/utility/useQuery.ts +0 -15
  267. package/src/hooks/utility/useUniqueEffect.ts +0 -22
  268. package/src/index.preprocess.ts +0 -82
  269. package/src/index.ts +0 -229
  270. package/src/models/DebugLogger.ts +0 -7
  271. package/src/models/GenericContract.ts +0 -169
  272. package/src/models/Orbs.ts +0 -97
  273. package/src/reac-app-env.d.ts +0 -6
  274. package/src/storybook/assets/video/txt-reversed.mp4 +0 -0
  275. package/src/storybookUtils/index.tsx +0 -53
  276. package/src/test.tsx +0 -0
  277. package/src/type-utils.ts +0 -49
  278. package/src/types.ts +0 -199
  279. package/src/utility.d.ts +0 -70
  280. package/src/utils/blockchain.ts +0 -43
  281. package/src/utils/e2e.ts +0 -55
  282. package/src/utils/flatten.ts +0 -17
  283. package/src/utils/formatters.ts +0 -36
  284. package/src/utils/html.utils.ts +0 -3
  285. package/src/utils/ownEvent.ts +0 -8
  286. package/src/utils/test.ts +0 -20
@@ -1,118 +0,0 @@
1
- import { SelectItem } from "../../Select/Select";
2
- import { UploadTask } from "firebase/storage";
3
- import { ReactElement } from "react";
4
-
5
- import {
6
- AnswerAction,
7
- AnswerByField,
8
- FormField,
9
- } from "./FormField/FormField.types";
10
-
11
- export type BaseQuestion = { id: string; type: FormField["type"] };
12
- export type FormState<Q extends BaseQuestion[] = []> = [
13
- answers: AnswersMap<Q>,
14
- isValid: boolean
15
- ];
16
-
17
- export enum DataStatus {
18
- /** Form is empty */
19
- PENDING,
20
- /** Form is partially filled */
21
- INCOMPLETE,
22
- /** Form is completed */
23
- COMPLETE,
24
- /** Form has error */
25
- ERROR,
26
- }
27
-
28
- export enum StepStatus {
29
- /** When the data is empty and needs to be filled */
30
- INCOMPLETE,
31
- /** When data has already been filled */
32
- COMPLETED,
33
- /** When the step is the current selected */
34
- CURRENT,
35
- /** When the step has error */
36
- ERROR,
37
- }
38
-
39
- export enum FormStep {
40
- PERSONAL_DATA,
41
- ADDITIONAL_DATA,
42
- DOCUMENTS,
43
- INVEST_PROFILE,
44
- CONTRACTS,
45
- }
46
-
47
- export enum FormMode {
48
- READ_ONLY,
49
- WRITE,
50
- }
51
-
52
- export type FormFieldView = FormField & {
53
- title: string;
54
- };
55
-
56
- export type FormProps = {
57
- onFormSubmitted: () => void;
58
- savedAnswers: Partial<{
59
- [questionId: string]: AnswerByField<FormField>;
60
- }>;
61
- startAt: FormStep;
62
- onGoBack: () => void;
63
- };
64
- export type StepFormProps = Pick<FormProps, "savedAnswers"> & {
65
- step: FormStep;
66
- } & ModeProps;
67
-
68
- export type ModeProps =
69
- | {
70
- mode: FormMode.READ_ONLY;
71
- }
72
- | {
73
- mode: FormMode.WRITE;
74
- onFinish: () => void;
75
- onCancel: () => void;
76
- };
77
- export type FormViewProps<Q extends BaseQuestion[]> = {
78
- questions: Q;
79
- } & (
80
- | {
81
- mode?: FormMode.WRITE;
82
- initialAnswers?: AnswersMap;
83
- onFormUpdate: (...args: FormState<Q>) => void;
84
- /** When provided (true) show all current errors that are blocking the completion of the form */
85
- showAllErrors?: boolean;
86
- }
87
- | {
88
- initialAnswers: AnswersMap;
89
- mode: FormMode.READ_ONLY;
90
- }
91
- );
92
-
93
- export type AnswersMap<
94
- Q extends Readonly<BaseQuestion[]> = [
95
- { type: BaseQuestion["type"]; id: string }
96
- ]
97
- > = Partial<
98
- {
99
- [questionId in Q[number]["id"]]: AnswerByField<
100
- Q[number] & { id: questionId }
101
- >;
102
- }
103
- >;
104
-
105
- export enum INVESTOR_PROFILE {
106
- /**
107
- * User can only spend up to 20k
108
- */
109
- RESTRICTED,
110
- /**
111
- * User can only spend up to 10% of it's income
112
- */
113
- LIMITED,
114
- /**
115
- * User doesn't have restrictions
116
- */
117
- UNLIMITED,
118
- }
@@ -1,73 +0,0 @@
1
- import React, { ReactNode } from "react";
2
- import InputMask from "react-input-mask";
3
- import Styles from "./DateField.module.scss";
4
- import Text from "../../../../../Text";
5
- import { useOneUIConfig } from "../../../../../../context/OneUIProvider";
6
- import { AnswerByField, GenericFormFieldProps } from "../../FormField.types";
7
- import Input from "../../../../../Input";
8
- import { isValidated } from "../../../Form.hook";
9
-
10
- /**
11
- * Allows inputing a date
12
- **/
13
- export default function dateFieldFactory(dateFormat: string) {
14
- return function DateField({
15
- onAnswer,
16
- question,
17
- value,
18
- error,
19
- }: GenericFormFieldProps<"date">) {
20
- const { titleVariant } = useOneUIConfig("component.form");
21
- return (
22
- <>
23
- <Text type={titleVariant}>{question.title}</Text>
24
- <InputMask
25
- mask={dateFormat}
26
- value={value}
27
- onChange={({ target: { value } }: any) => {
28
- onAnswer("date", question.id, value as string);
29
- }}
30
- >
31
- {
32
- ((inputProps: any) => (
33
- <Input
34
- {...inputProps}
35
- placeholder={question.title}
36
- error={error}
37
- />
38
- )) as unknown as ReactNode
39
- }
40
- </InputMask>
41
- </>
42
- );
43
- };
44
- }
45
-
46
- const parseDate = (formattedDate: string) => {
47
- const providedDate = formattedDate;
48
- const dateParts = providedDate.split("/").map(Number);
49
- if (dateParts.length < 2) return false;
50
- const [day, month, year] = dateParts;
51
- const parsedDate = new Date(year, month - 1, day);
52
-
53
- return parsedDate;
54
- };
55
-
56
- export const dateFieldValidatorFactory =
57
- (invalidDateLabel: string, requiredFieldLabel: string) =>
58
- (answer: AnswerByField<{ type: "date" }>) => {
59
- const providedDate = answer || "";
60
- const parsedDate = parseDate(providedDate);
61
- if (!parsedDate)
62
- return {
63
- isValid: false,
64
- error: invalidDateLabel,
65
- };
66
- const dateValidation = isValidated(
67
- providedDate,
68
- false,
69
- undefined,
70
- requiredFieldLabel
71
- );
72
- return dateValidation;
73
- };
@@ -1,2 +0,0 @@
1
- export { default } from "./DateField";
2
- export * from "./DateField";
@@ -1,91 +0,0 @@
1
- import React, { useEffect, useMemo } from "react";
2
- import Styles from "./PhoneField.module.scss";
3
- import {
4
- AnswerByField,
5
- FormFieldProps,
6
- FormFieldView,
7
- GenericFormFieldProps,
8
- } from "../../FormField.types";
9
- import useModule from "../../../../../../hooks/utility/useModule";
10
- import Text from "../../../../../Text";
11
- import Input from "../../../../../Input";
12
- import { useOneUIConfig } from "../../../../../../context/OneUIProvider";
13
-
14
- /**
15
- * An extra form field that enables the user to input a phone number
16
- **/
17
- export default function phoneFieldFactory(invalidPhoneLabel: string) {
18
- return function ({
19
- value,
20
- question,
21
- onAnswer,
22
- error,
23
- }: GenericFormFieldProps<"phone">) {
24
- const { country } = question;
25
- const { titleVariant } = useOneUIConfig("component.form");
26
- const [phone] = value || ["", false];
27
- const phoneFormatter = useModule(() =>
28
- import("google-libphonenumber").then((mod) => {
29
- return mod.PhoneNumberUtil.getInstance();
30
- })
31
- );
32
- const {
33
- phoneFormat,
34
- valid,
35
- error: phoneError,
36
- } = useMemo(() => {
37
- if (!phoneFormatter)
38
- return {
39
- phoneFormat: phone,
40
- valid: false,
41
- error: "",
42
- };
43
- try {
44
- const phoneInstance = phoneFormatter.parseAndKeepRawInput(
45
- phone,
46
- country
47
- );
48
- const isPhoneValid = phoneFormatter.isValidNumber(phoneInstance);
49
- return {
50
- phoneFormat: phoneFormatter.format(phoneInstance, 2),
51
- valid: isPhoneValid,
52
- error: isPhoneValid ? "" : invalidPhoneLabel,
53
- };
54
- } catch (e) {
55
- return {
56
- phoneFormat: phone,
57
- valid: false,
58
- error: invalidPhoneLabel,
59
- };
60
- }
61
- }, [phone, phoneFormatter]);
62
-
63
- useEffect(() => {
64
- onAnswer("phone", question.id, [phoneFormat, valid, phoneError]);
65
- }, [phoneFormat, valid]);
66
-
67
- return (
68
- <>
69
- <Text type={titleVariant}>{question.title}</Text>
70
- <Input
71
- placeholder={question.title}
72
- value={phoneFormat}
73
- onChange={({ target: { value } }) => {
74
- onAnswer("phone", question.id, [value, false, phoneError]);
75
- }}
76
- error={error as string}
77
- />
78
- </>
79
- );
80
- };
81
- }
82
-
83
- export const phoneFieldValidator = (
84
- answer: AnswerByField<{ type: "phone" }>
85
- ) => {
86
- const isValid = !!answer && !!answer[1];
87
- return {
88
- isValid,
89
- error: answer[2],
90
- };
91
- };
@@ -1,2 +0,0 @@
1
- export { default } from "./PhoneField";
2
- export * from "./PhoneField";
@@ -1,378 +0,0 @@
1
- import { ReactNode, useEffect, useState } from "react";
2
- import debounce from "lodash/debounce";
3
- import Styles from "./FormField.module.scss";
4
- import {
5
- AnswerAction,
6
- AnswerByField,
7
- FormFieldProps,
8
- FormFieldView,
9
- FormMode,
10
- } from "./FormField.types";
11
- import Select from "../../../Select/Select";
12
- import Input from "../../../Input";
13
- import OneText from "../../../Text";
14
- import Button from "../../../Button";
15
- import Radio from "../../../Radio";
16
- import { AnchoredTooltipAlignment } from "../../../AnchoredTooltip/AnchoredTooltip";
17
- import FileInput from "../../../FileInput/FileInput";
18
- import CheckBox from "../../../CheckBox/CheckBox";
19
- import Spacing from "../../../Spacing";
20
- import { useOneUIConfig } from "../../../../context/OneUIProvider";
21
- // import InputMask from "react-input-mask";
22
-
23
- /**
24
- * The logic for a field of the form
25
- **/
26
- export default function FormField<Q extends FormFieldView>({
27
- config: c,
28
- value,
29
- ...props
30
- }: FormFieldProps<Q>) {
31
- const val = <T extends FormFieldView["type"]>() =>
32
- value as unknown as
33
- | AnswerByField<{
34
- type: T;
35
- }>
36
- | undefined;
37
- const ans = <T extends FormFieldView["type"]>(
38
- answer:
39
- | AnswerAction<{
40
- type: T;
41
- }>
42
- | undefined
43
- ) =>
44
- answer as unknown as AnswerAction<{
45
- type: T;
46
- }>;
47
- const type = c.type;
48
- const { titleVariant, labelVariant, optionalLabel, extensions } =
49
- useOneUIConfig("component.form");
50
- if (props.mode === FormMode.READ_ONLY) {
51
- switch (type) {
52
- case "check":
53
- const checks = val<typeof type>()! || [];
54
- return (
55
- <>
56
- <OneText type={titleVariant}>{c.title}</OneText>
57
- {checks.includes(true) ? (
58
- checks.map((checked, i) =>
59
- checked ? (
60
- <OneText type={labelVariant}>{c.options[i].value}</OneText>
61
- ) : null
62
- )
63
- ) : (
64
- <OneText type={labelVariant}>-</OneText>
65
- )}
66
- <Spacing size="small" />
67
- </>
68
- );
69
- case "file":
70
- const file = val<typeof type>()!;
71
- return (
72
- <>
73
- <FileInput
74
- states={{
75
- fileProvided: {
76
- title: c.title,
77
- description: c.fileUsageDescription,
78
- },
79
- waitingFile: {
80
- title: c.title,
81
- description: c.fileUsageDescription,
82
- },
83
- }}
84
- footer={c.footer}
85
- onFile={() => {}}
86
- file={file === true ? ({} as File) : undefined}
87
- progress={file === true ? 100 : undefined}
88
- disabled={true}
89
- />
90
- <Spacing size="small" />
91
- {file === true && (
92
- <Button
93
- variant="link"
94
- color="primary"
95
- onClick={c.openFile!.action}
96
- >
97
- {c.openFile!.label}
98
- </Button>
99
- )}
100
- <Spacing size="large" />
101
- </>
102
- );
103
- default:
104
- const answer = val<typeof type>() as ReactNode;
105
- return (
106
- <>
107
- <OneText type={titleVariant}>{c.title}</OneText>
108
- <OneText type={labelVariant}>{answer || "-"}</OneText>
109
- <Spacing size="small" />
110
- </>
111
- );
112
- }
113
- }
114
- const { onAnswer, error } = props;
115
- switch (type) {
116
- case "accept":
117
- const checks = val<typeof type>() || [];
118
- return (
119
- <>
120
- <div className={Styles.acceptInput}>
121
- <div>
122
- <OneText type={titleVariant}>{c.title}</OneText>
123
- <br />
124
- <Button
125
- variant="link"
126
- color="primary"
127
- onClick={c.contract.action}
128
- >
129
- {c.contract.label}
130
- </Button>
131
- </div>
132
- {error && (
133
- <div>
134
- <OneText type="caption" color="error">
135
- {error}
136
- </OneText>
137
- <br />
138
- </div>
139
- )}
140
- <div>
141
- {c.accept.map((a, i) => (
142
- <OneText type={labelVariant}>
143
- <CheckBox
144
- label={
145
- <span>
146
- <>
147
- {a.label}
148
- {a.optional ? (
149
- <>
150
- <br />
151
- <OneText type="caption">{optionalLabel}</OneText>
152
- </>
153
- ) : (
154
- ""
155
- )}
156
- </>
157
- </span>
158
- }
159
- checked={checks[i]}
160
- onToggle={(checked) => {
161
- const clone = [...checks];
162
- clone[i] = checked;
163
- onAnswer(type, c.id, ans<typeof type>(clone));
164
- }}
165
- groupId={c.id}
166
- value={a.label}
167
- />
168
- </OneText>
169
- ))}
170
- </div>
171
- </div>
172
- <Spacing size="small" />
173
- </>
174
- );
175
- case "file":
176
- const upload = val<typeof type>();
177
- const [progress, setProgress] = useState<number | undefined>(() => {
178
- if (!upload) return undefined;
179
- if (upload === true) return 100;
180
- const s = upload.snapshot;
181
- return (s.bytesTransferred * 100) / s.totalBytes;
182
- });
183
- useEffect(() => {
184
- if (!upload) return setProgress(undefined);
185
- if (upload === true) {
186
- setProgress(100);
187
- return;
188
- }
189
- const throttleSetProgress = debounce(setProgress, 250);
190
- const unsubscribe = upload.on("state_changed", (s) => {
191
- const progress = (s.bytesTransferred * 100) / s.totalBytes;
192
- throttleSetProgress(progress);
193
- });
194
-
195
- return () => {
196
- unsubscribe();
197
- };
198
- }, [upload]);
199
- return (
200
- <>
201
- <FileInput
202
- states={{
203
- fileProvided: {
204
- title: c.title,
205
- description: c.fileUsageDescription,
206
- },
207
- waitingFile: {
208
- title: c.title,
209
- description: c.fileUsageDescription,
210
- },
211
- }}
212
- footer={c.footer}
213
- onFile={(file) => {
214
- onAnswer(type, c.id, ans<typeof type>(file));
215
- }}
216
- file={upload as unknown as File}
217
- progress={upload ? progress || 0 : undefined}
218
- accept={c.extensions.map((x) => `.${x}`).join(",")}
219
- />
220
- {error ? (
221
- <OneText type="caption" color="error">
222
- {error}
223
- </OneText>
224
- ) : null}
225
- <Spacing size="large" />
226
- </>
227
- );
228
- case "radio":
229
- const selected = val<typeof type>();
230
- return (
231
- <>
232
- <OneText type={titleVariant}>{c.title}</OneText>
233
- {error && (
234
- <OneText type="caption" color="error">
235
- {error}
236
- </OneText>
237
- )}
238
- <br />
239
- {c.options.map((el) => (
240
- <>
241
- <OneText type={labelVariant}>
242
- <Radio
243
- checked={selected === el.value}
244
- label={el.label}
245
- onToggle={() => onAnswer(type, c.id, el.value)}
246
- groupId={c.id}
247
- value={el.value}
248
- />
249
- </OneText>
250
- <br />
251
- </>
252
- ))}
253
- </>
254
- );
255
- case "check":
256
- const checkError =
257
- typeof error === "string" ? c.options.map(() => error) : error;
258
- const checkmarks = val<typeof type>() || [];
259
- return (
260
- <>
261
- <OneText type={titleVariant}>{c.title}</OneText>
262
- <br />
263
- {c.options.map((el, i) => (
264
- <>
265
- <OneText type={labelVariant}>
266
- <CheckBox
267
- checked={checkmarks[i]}
268
- label={
269
- <>
270
- {el.label}
271
- {checkError?.[i] ? (
272
- <OneText type="caption" color="error">
273
- {checkError[i]}
274
- </OneText>
275
- ) : null}
276
- </>
277
- }
278
- onToggle={(checked) => {
279
- const clone = [...checkmarks];
280
- clone[i] = checked;
281
- onAnswer(type, c.id, clone);
282
- }}
283
- groupId={c.id}
284
- value={el.value}
285
- />
286
- </OneText>
287
- <br />
288
- </>
289
- ))}
290
- </>
291
- );
292
- case "rawcheck":
293
- const rawCheckmarks = val<typeof type>() || [];
294
- return (
295
- <>
296
- {error && (
297
- <>
298
- <OneText type="caption" color="error">
299
- {error}
300
- </OneText>
301
- <br />
302
- </>
303
- )}
304
- {c.options.map((el, i) => (
305
- <>
306
- <OneText type={labelVariant}>
307
- <CheckBox
308
- checked={rawCheckmarks[i]}
309
- label={el.label}
310
- onToggle={(checked) => {
311
- const clone = [...rawCheckmarks];
312
- clone[i] = checked;
313
- onAnswer(type, c.id, clone);
314
- }}
315
- groupId={c.id}
316
- value={el.value}
317
- />
318
- </OneText>
319
- <br />
320
- </>
321
- ))}
322
- </>
323
- );
324
- case "select":
325
- return (
326
- <>
327
- <OneText type={titleVariant}>{c.title}</OneText>
328
- <Select
329
- data-testid={`cvm88-${c.id}`}
330
- alignTo={AnchoredTooltipAlignment.LEFT}
331
- items={c.options}
332
- selected={val<typeof type>()!}
333
- onClick={(i) => {
334
- onAnswer(type, c.id, i.value);
335
- }}
336
- filter={c.filter}
337
- error={error as string}
338
- />
339
- </>
340
- );
341
- case "text":
342
- case "number":
343
- const filter =
344
- type === "number"
345
- ? (val: string) => val.replace(/[^0-9]+/g, "")
346
- : (val: string) => val;
347
- return (
348
- <>
349
- <OneText type={titleVariant}>{c.title}</OneText>
350
- <Input
351
- multiline={"multiline" in c ? c.multiline : undefined}
352
- placeholder={c.title}
353
- value={val<typeof type>()}
354
- error={error as string}
355
- onChange={({ target: { value } }) => {
356
- onAnswer(type, c.id, filter(value));
357
- }}
358
- />
359
- </>
360
- );
361
- default:
362
- const registeredExtension = extensions?.[type] as any;
363
- if (registeredExtension) {
364
- const { Input } = registeredExtension;
365
- return (
366
- <Input
367
- onAnswer={onAnswer}
368
- question={c as any}
369
- value={value as any}
370
- error={error as any}
371
- />
372
- );
373
- }
374
- throw new Error(
375
- `The form field "${type}" is not implemented yet. Please provide it using OneUIProvider config options for form extensions`
376
- );
377
- }
378
- }