@onepercentio/one-ui 0.29.4 → 0.29.6

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 (294) hide show
  1. package/dist/components/Portal/Portal.d.ts +5 -0
  2. package/dist/components/Portal/Portal.js +6 -1
  3. package/dist/components/Switch/Switch.d.ts +1 -1
  4. package/dist/components/Switch/Switch.js +1 -1
  5. package/dist/utils/e2e.d.ts +1 -1
  6. package/dist/utils/e2e.js +1 -1
  7. package/dist-ts/components/Portal/Portal.d.ts +5 -0
  8. package/dist-ts/components/Portal/Portal.js +5 -0
  9. package/dist-ts/components/Portal/Portal.js.map +1 -1
  10. package/dist-ts/components/Switch/Switch.d.ts +1 -1
  11. package/dist-ts/utils/e2e.d.ts +1 -1
  12. package/package.json +1 -1
  13. package/src/assets/img/svg/checkbox.svg +0 -3
  14. package/src/assets/styles/index.scss +0 -2
  15. package/src/assets/styles/mixins.scss +0 -12
  16. package/src/assets/styles/variables.scss +0 -49
  17. package/src/components/AdaptiveButton/AdaptiveButton.module.scss +0 -7
  18. package/src/components/AdaptiveButton/AdaptiveButton.tsx +0 -26
  19. package/src/components/AdaptiveButton/index.tsx +0 -2
  20. package/src/components/AdaptiveContainer/AdaptiveContainer.module.scss +0 -53
  21. package/src/components/AdaptiveContainer/AdaptiveContainer.tsx +0 -200
  22. package/src/components/AdaptiveContainer/index.tsx +0 -2
  23. package/src/components/AdaptiveDialog/AdaptiveDialog.module.scss +0 -147
  24. package/src/components/AdaptiveDialog/AdaptiveDialog.tsx +0 -97
  25. package/src/components/AdaptiveDialog/index.tsx +0 -2
  26. package/src/components/AdaptiveSidebar/AdaptiveSidebar.module.scss +0 -49
  27. package/src/components/AdaptiveSidebar/AdaptiveSidebar.sample.tsx +0 -10
  28. package/src/components/AdaptiveSidebar/AdaptiveSidebar.tsx +0 -123
  29. package/src/components/AdaptiveSidebar/index.tsx +0 -2
  30. package/src/components/AnchoredTooltip/AnchoredTooltip.module.scss +0 -64
  31. package/src/components/AnchoredTooltip/AnchoredTooltip.tsx +0 -250
  32. package/src/components/AnchoredTooltip/index.tsx +0 -2
  33. package/src/components/AnimatedEntrance/AnimatedEntrance.module.scss +0 -108
  34. package/src/components/AnimatedEntrance/AnimatedEntrance.tsx +0 -227
  35. package/src/components/AnimatedEntrance/index.tsx +0 -2
  36. package/src/components/AsyncWrapper/AsyncWrapper.tsx +0 -38
  37. package/src/components/AsyncWrapper/index.tsx +0 -2
  38. package/src/components/Avatar/Avatar.module.scss +0 -22
  39. package/src/components/Avatar/Avatar.tsx +0 -31
  40. package/src/components/Avatar/index.tsx +0 -2
  41. package/src/components/BucketFill/BucketFill.module.scss +0 -36
  42. package/src/components/BucketFill/BucketFill.tsx +0 -65
  43. package/src/components/BucketFill/index.tsx +0 -2
  44. package/src/components/Button/Button.module.scss +0 -45
  45. package/src/components/Button/Button.tsx +0 -40
  46. package/src/components/Button/index.tsx +0 -2
  47. package/src/components/Card/Card.module.scss +0 -12
  48. package/src/components/Card/Card.tsx +0 -9
  49. package/src/components/Card/index.tsx +0 -2
  50. package/src/components/Chart/Chart.e2e.ts +0 -4
  51. package/src/components/Chart/Chart.logic.tsx +0 -8
  52. package/src/components/Chart/Chart.module.scss +0 -58
  53. package/src/components/Chart/Chart.tsx +0 -2
  54. package/src/components/Chart/Chart.types.ts +0 -35
  55. package/src/components/Chart/Chart.view.tsx +0 -241
  56. package/src/components/Chart/index.tsx +0 -2
  57. package/src/components/CheckBox/CheckBox.module.scss +0 -36
  58. package/src/components/CheckBox/CheckBox.tsx +0 -63
  59. package/src/components/CheckBox/index.tsx +0 -2
  60. package/src/components/CodeInput/CodeInput.module.scss +0 -5
  61. package/src/components/CodeInput/CodeInput.tsx +0 -84
  62. package/src/components/CodeInput/index.tsx +0 -2
  63. package/src/components/Collapsable/Collapsable.module.scss +0 -42
  64. package/src/components/Collapsable/Collapsable.tsx +0 -253
  65. package/src/components/Collapsable/index.tsx +0 -2
  66. package/src/components/Countdown/Countdown.tsx +0 -130
  67. package/src/components/Countdown/index.tsx +0 -2
  68. package/src/components/CurrencyInput/CurrencyInput.hook.ts +0 -37
  69. package/src/components/CurrencyInput/CurrencyInput.tsx +0 -25
  70. package/src/components/CurrencyInput/index.tsx +0 -2
  71. package/src/components/Divider/Divider.module.scss +0 -7
  72. package/src/components/Divider/Divider.tsx +0 -13
  73. package/src/components/Divider/index.tsx +0 -2
  74. package/src/components/EmailInput/EmailInput.module.scss +0 -0
  75. package/src/components/EmailInput/EmailInput.tsx +0 -51
  76. package/src/components/EmailInput/index.tsx +0 -2
  77. package/src/components/FadeIn/FadeIn.module.scss +0 -9
  78. package/src/components/FadeIn/FadeIn.tsx +0 -77
  79. package/src/components/FadeIn/index.tsx +0 -2
  80. package/src/components/FileInput/FileInput.module.scss +0 -6
  81. package/src/components/FileInput/FileInput.tsx +0 -75
  82. package/src/components/FileInput/View/BigFactory/BigFactory.module.scss +0 -20
  83. package/src/components/FileInput/View/BigFactory/BigFactory.tsx +0 -48
  84. package/src/components/FileInput/View/BigFactory/index.tsx +0 -2
  85. package/src/components/FileInput/View/Compact/Compact.module.scss +0 -68
  86. package/src/components/FileInput/View/Compact/Compact.tsx +0 -151
  87. package/src/components/FileInput/View/Compact/index.tsx +0 -2
  88. package/src/components/FileInput/View/View.types.ts +0 -12
  89. package/src/components/FileInput/index.tsx +0 -2
  90. package/src/components/FlowController/FlowController.module.scss +0 -47
  91. package/src/components/FlowController/FlowController.tsx +0 -93
  92. package/src/components/FlowController/index.tsx +0 -2
  93. package/src/components/Form/Form.tsx +0 -243
  94. package/src/components/Form/index.ts +0 -2
  95. package/src/components/Form/v2/Form.hook.ts +0 -341
  96. package/src/components/Form/v2/Form.module.scss +0 -0
  97. package/src/components/Form/v2/Form.tsx +0 -78
  98. package/src/components/Form/v2/Form.types.ts +0 -118
  99. package/src/components/Form/v2/FormField/Extensions/DateField/DateField.module.scss +0 -0
  100. package/src/components/Form/v2/FormField/Extensions/DateField/DateField.tsx +0 -73
  101. package/src/components/Form/v2/FormField/Extensions/DateField/index.tsx +0 -2
  102. package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.module.scss +0 -0
  103. package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.tsx +0 -91
  104. package/src/components/Form/v2/FormField/Extensions/PhoneField/index.tsx +0 -2
  105. package/src/components/Form/v2/FormField/FormField.module.scss +0 -0
  106. package/src/components/Form/v2/FormField/FormField.tsx +0 -378
  107. package/src/components/Form/v2/FormField/FormField.types.ts +0 -129
  108. package/src/components/Form/v2/FormField/index.tsx +0 -2
  109. package/src/components/Form/v2/index.tsx +0 -2
  110. package/src/components/Freeze/Freeze.tsx +0 -9
  111. package/src/components/Freeze/index.tsx +0 -2
  112. package/src/components/HSForms/HSForms.tsx +0 -57
  113. package/src/components/HSForms/index.tsx +0 -2
  114. package/src/components/Header/Header.module.scss +0 -119
  115. package/src/components/Header/Header.tsx +0 -138
  116. package/src/components/Header/index.tsx +0 -2
  117. package/src/components/HeaderCloseBtn/HeaderCloseBtn.module.scss +0 -44
  118. package/src/components/HeaderCloseBtn/HeaderCloseBtn.tsx +0 -28
  119. package/src/components/HeaderCloseBtn/index.tsx +0 -2
  120. package/src/components/InfinityScroll/InfinityScroll.module.scss +0 -30
  121. package/src/components/InfinityScroll/InfinityScroll.tsx +0 -187
  122. package/src/components/InfinityScroll/index.tsx +0 -2
  123. package/src/components/Input/Input.module.scss +0 -71
  124. package/src/components/Input/Input.tsx +0 -134
  125. package/src/components/Input/index.tsx +0 -2
  126. package/src/components/InstantCounter/InstantCounter.tsx +0 -77
  127. package/src/components/InstantCounter/index.tsx +0 -2
  128. package/src/components/LavaLamp/LavaLamp.data.tsx +0 -114
  129. package/src/components/LavaLamp/LavaLamp.module.scss +0 -26
  130. package/src/components/LavaLamp/LavaLamp.tsx +0 -131
  131. package/src/components/LavaLamp/index.tsx +0 -2
  132. package/src/components/LavaLamp/v2/LavaLamp.module.scss +0 -23
  133. package/src/components/LavaLamp/v2/LavaLamp.tsx +0 -197
  134. package/src/components/LinkToId/LinkToId.module.scss +0 -4
  135. package/src/components/LinkToId/LinkToId.tsx +0 -51
  136. package/src/components/LinkToId/index.tsx +0 -2
  137. package/src/components/Loader/Loader.module.scss +0 -40
  138. package/src/components/Loader/Loader.tsx +0 -18
  139. package/src/components/Loader/index.tsx +0 -2
  140. package/src/components/LoaderDotsIndicator/LoaderDotsIndicator.tsx +0 -34
  141. package/src/components/LoaderDotsIndicator/index.tsx +0 -2
  142. package/src/components/LoopableVideo/LoopableVideo.tsx +0 -37
  143. package/src/components/LoopableVideo/index.tsx +0 -2
  144. package/src/components/MainGrid/MainGrid.module.scss +0 -28
  145. package/src/components/MainGrid/MainGrid.tsx +0 -68
  146. package/src/components/MainGrid/index.tsx +0 -2
  147. package/src/components/MutableHamburgerButton/MutableHamburgerButton.module.scss +0 -220
  148. package/src/components/MutableHamburgerButton/MutableHamburgerButton.tsx +0 -38
  149. package/src/components/MutableHamburgerButton/index.tsx +0 -2
  150. package/src/components/Notification/Notification.module.scss +0 -25
  151. package/src/components/Notification/Notification.tsx +0 -13
  152. package/src/components/Notification/index.tsx +0 -2
  153. package/src/components/OrderableList/OrderableList.module.scss +0 -98
  154. package/src/components/OrderableList/OrderableList.tsx +0 -564
  155. package/src/components/OrderableList/index.tsx +0 -2
  156. package/src/components/PaginationIndicator/PaginationIndicator.tsx +0 -365
  157. package/src/components/PaginationIndicator/index.tsx +0 -2
  158. package/src/components/Parallax/Parallax.module.scss +0 -28
  159. package/src/components/Parallax/Parallax.tsx +0 -225
  160. package/src/components/Parallax/index.tsx +0 -2
  161. package/src/components/Parallax/math/helpers.ts +0 -289
  162. package/src/components/PasswordInput/PasswordInput.module.scss +0 -17
  163. package/src/components/PasswordInput/PasswordInput.tsx +0 -154
  164. package/src/components/PasswordInput/index.tsx +0 -2
  165. package/src/components/PingPongText/PingPongText.module.scss +0 -4
  166. package/src/components/PingPongText/PingPongText.tsx +0 -83
  167. package/src/components/PingPongText/index.tsx +0 -2
  168. package/src/components/PixelatedScan/PixelatedScan.module.scss +0 -86
  169. package/src/components/PixelatedScan/PixelatedScan.tsx +0 -175
  170. package/src/components/PixelatedScan/index.tsx +0 -2
  171. package/src/components/Portal/Portal.module.scss +0 -3
  172. package/src/components/Portal/Portal.tsx +0 -68
  173. package/src/components/Portal/index.tsx +0 -2
  174. package/src/components/ProgressBar/ProgressBar.module.scss +0 -44
  175. package/src/components/ProgressBar/ProgressBar.tsx +0 -124
  176. package/src/components/ProgressBar/index.tsx +0 -2
  177. package/src/components/ProgressTexts/ProgressTexts.module.scss +0 -37
  178. package/src/components/ProgressTexts/ProgressTexts.tsx +0 -85
  179. package/src/components/ProgressTexts/index.tsx +0 -2
  180. package/src/components/Radio/Radio.module.scss +0 -36
  181. package/src/components/Radio/Radio.tsx +0 -53
  182. package/src/components/Radio/index.tsx +0 -2
  183. package/src/components/SectionContainer/SectionContainer.module.scss +0 -30
  184. package/src/components/SectionContainer/SectionContainer.tsx +0 -49
  185. package/src/components/SectionContainer/index.tsx +0 -2
  186. package/src/components/Select/Select.module.scss +0 -58
  187. package/src/components/Select/Select.tsx +0 -192
  188. package/src/components/Select/index.tsx +0 -2
  189. package/src/components/Skeleton/Skeleton.module.scss +0 -21
  190. package/src/components/Skeleton/Skeleton.tsx +0 -29
  191. package/src/components/Skeleton/index.tsx +0 -2
  192. package/src/components/Spacing/Spacing.module.scss +0 -13
  193. package/src/components/Spacing/Spacing.tsx +0 -24
  194. package/src/components/Spacing/index.tsx +0 -2
  195. package/src/components/StaticScroller/StaticScroller.module.scss +0 -14
  196. package/src/components/StaticScroller/StaticScroller.tsx +0 -83
  197. package/src/components/StaticScroller/index.tsx +0 -2
  198. package/src/components/Switch/Switch.module.scss +0 -43
  199. package/src/components/Switch/Switch.tsx +0 -41
  200. package/src/components/Switch/index.tsx +0 -2
  201. package/src/components/Table/Table.module.scss +0 -76
  202. package/src/components/Table/Table.tsx +0 -152
  203. package/src/components/Table/index.tsx +0 -2
  204. package/src/components/Tabs/Tabs.module.scss +0 -40
  205. package/src/components/Tabs/Tabs.tsx +0 -104
  206. package/src/components/Tabs/index.tsx +0 -2
  207. package/src/components/Text/Text.module.scss +0 -81
  208. package/src/components/Text/Text.tsx +0 -42
  209. package/src/components/Text/index.tsx +0 -2
  210. package/src/components/Transition/MasksFactory/DiagonalReveal.tsx +0 -47
  211. package/src/components/Transition/MasksFactory/DiagonalSquareToBalls.tsx +0 -78
  212. package/src/components/Transition/MasksFactory/PhysicsSquares.tsx +0 -106
  213. package/src/components/Transition/MasksFactory/SquareToBalls.tsx +0 -66
  214. package/src/components/Transition/MasksFactory/utils.ts +0 -35
  215. package/src/components/Transition/Transition.module.scss +0 -211
  216. package/src/components/Transition/Transition.tsx +0 -495
  217. package/src/components/Transition/index.tsx +0 -2
  218. package/src/components/UncontrolledTransition/UncontrolledTransition.ai.md +0 -9
  219. package/src/components/UncontrolledTransition/UncontrolledTransition.sample.tsx +0 -34
  220. package/src/components/UncontrolledTransition/UncontrolledTransition.tsx +0 -143
  221. package/src/components/UncontrolledTransition/index.tsx +0 -2
  222. package/src/components/WalletConnectionWrapper/WalletConnectionWrapper.tsx +0 -212
  223. package/src/components/WalletConnectionWrapper/index.tsx +0 -2
  224. package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.module.scss +0 -5
  225. package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.tsx +0 -52
  226. package/src/components/utilitary/ScrollAndFocusLock/index.tsx +0 -2
  227. package/src/context/AsyncProcess.tsx +0 -107
  228. package/src/context/ContextAsyncControl.tsx +0 -89
  229. package/src/context/CustomBrowserRouter.tsx +0 -55
  230. package/src/context/OneUIProvider.tsx +0 -308
  231. package/src/hooks/logs/useDependencyChangeDetection.ts +0 -25
  232. package/src/hooks/logs/useIsMounting.ts +0 -7
  233. package/src/hooks/persistence/useLocalStorage.ts +0 -45
  234. package/src/hooks/shims/ObjectWatchShim.ts +0 -56
  235. package/src/hooks/ui/useAdaptiveImage.tsx +0 -36
  236. package/src/hooks/ui/useAlternating.tsx +0 -22
  237. package/src/hooks/ui/useBreakpoint.tsx +0 -21
  238. package/src/hooks/ui/useCustomScrollbar.module.scss +0 -20
  239. package/src/hooks/ui/useCustomScrollbar.tsx +0 -22
  240. package/src/hooks/ui/useEffectIf.ts +0 -11
  241. package/src/hooks/ui/useMouseHover.tsx +0 -26
  242. package/src/hooks/ui/usePaginationControls.module.scss +0 -16
  243. package/src/hooks/ui/usePaginationControls.tsx +0 -176
  244. package/src/hooks/ui/useSnapToViewport.module.scss +0 -6
  245. package/src/hooks/ui/useSnapToViewport.ts +0 -28
  246. package/src/hooks/ui/useTilt.tsx +0 -219
  247. package/src/hooks/ui/useZoomable.module.scss +0 -34
  248. package/src/hooks/ui/useZoomable.tsx +0 -144
  249. package/src/hooks/useAsyncControl.ai.md +0 -25
  250. package/src/hooks/useAsyncControl.ts +0 -101
  251. package/src/hooks/useContainedRepositioning.ts +0 -110
  252. package/src/hooks/useCustomHistory.ts +0 -14
  253. package/src/hooks/useElementFit.ts +0 -82
  254. package/src/hooks/useFirestoreWatch.ts +0 -54
  255. package/src/hooks/useForm.ts +0 -49
  256. package/src/hooks/useFreeze.ts +0 -12
  257. package/src/hooks/useHero.module.scss +0 -41
  258. package/src/hooks/useHero.ts +0 -514
  259. package/src/hooks/useIntersection.ts +0 -32
  260. package/src/hooks/useMergeRefs.ts +0 -29
  261. package/src/hooks/useObserve.ts +0 -24
  262. package/src/hooks/usePagination.ts +0 -228
  263. package/src/hooks/usePooledOperation.ts +0 -54
  264. package/src/hooks/usePooling.ts +0 -46
  265. package/src/hooks/useRebound.ts +0 -23
  266. package/src/hooks/useShortIntl.ai.md +0 -5
  267. package/src/hooks/useShortIntl.ts +0 -97
  268. package/src/hooks/utility/useAsyncMemo.ts +0 -43
  269. package/src/hooks/utility/useDepChange.ts +0 -11
  270. package/src/hooks/utility/useEvents.ts +0 -33
  271. package/src/hooks/utility/useImmediate.ts +0 -8
  272. package/src/hooks/utility/useManualInit.ts +0 -24
  273. package/src/hooks/utility/useModule.ts +0 -15
  274. package/src/hooks/utility/useQuery.ts +0 -15
  275. package/src/hooks/utility/useUniqueEffect.ts +0 -22
  276. package/src/index.preprocess.ts +0 -82
  277. package/src/index.ts +0 -229
  278. package/src/models/DebugLogger.ts +0 -7
  279. package/src/models/GenericContract.ts +0 -169
  280. package/src/models/Orbs.ts +0 -97
  281. package/src/reac-app-env.d.ts +0 -6
  282. package/src/storybook/assets/video/txt-reversed.mp4 +0 -0
  283. package/src/storybookUtils/index.tsx +0 -53
  284. package/src/test.tsx +0 -0
  285. package/src/type-utils.ts +0 -49
  286. package/src/types.ts +0 -199
  287. package/src/utility.d.ts +0 -70
  288. package/src/utils/blockchain.ts +0 -43
  289. package/src/utils/e2e.ts +0 -55
  290. package/src/utils/flatten.ts +0 -17
  291. package/src/utils/formatters.ts +0 -36
  292. package/src/utils/html.utils.ts +0 -3
  293. package/src/utils/ownEvent.ts +0 -8
  294. 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
- }