@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,243 +0,0 @@
1
- import React, {
2
- ComponentProps,
3
- ForwardedRef,
4
- forwardRef,
5
- FunctionComponent,
6
- RefObject,
7
- useImperativeHandle,
8
- useMemo,
9
- useState,
10
- } from "react";
11
- import Input from "../Input";
12
- import Button from "../Button";
13
- import Loader from "../Loader";
14
- import EmailInput from "../EmailInput";
15
- import AdaptiveButton from "../AdaptiveButton";
16
-
17
- export type BaseForm = { [k: string]: string | number | any };
18
- export type FormForm = { [k: string]: string | number };
19
-
20
- export type FieldTypes = "email" | "text" | "textarea" | "select" | "number";
21
-
22
- export type FieldDefinition<
23
- M extends BaseForm,
24
- F extends keyof M,
25
- T extends FieldTypes
26
- > = {
27
- validator: (v: M[F] | undefined, f: Partial<M>) => string | true;
28
- placeholder?: string;
29
- } & (T extends "select"
30
- ? {
31
- type: "select";
32
- choices: ComponentProps<typeof import("../Select")["default"]>["items"];
33
- }
34
- : T extends "email"
35
- ? { type: "email"; messages: ComponentProps<typeof EmailInput>["messages"] }
36
- : T extends "textarea"
37
- ? {
38
- type: "textarea";
39
- lines: number;
40
- }
41
- : {
42
- type: "text" | "number";
43
- inputProps?: ComponentProps<typeof Input>;
44
- });
45
-
46
- export type ClassName = string;
47
-
48
- function AdvancedAction({
49
- config,
50
- submited,
51
- submitting,
52
- isValid,
53
- onClick,
54
- btnProps,
55
- }: Pick<FirebaseFormProps<{}>, "submited" | "submitting"> & {
56
- config: Exclude<FirebaseFormProps<{}>["submitBtn"], string>;
57
- isValid: boolean;
58
- onClick: () => void;
59
- btnProps: ComponentProps<typeof Button>;
60
- }) {
61
- const [key, Element, className] =
62
- submited === false
63
- ? ["error", ...config.error]
64
- : submited === true
65
- ? ["success", ...config.success]
66
- : submitting
67
- ? ["loading", ...config.loading]
68
- : ["default", ...config.label];
69
-
70
- const salt = useMemo(() => Date.now(), [key]);
71
-
72
- return (
73
- <AdaptiveButton
74
- variant="filled"
75
- className={className}
76
- disabled={!isValid}
77
- onClick={onClick}
78
- {...btnProps}
79
- >
80
- <Element key={key + salt} />
81
- </AdaptiveButton>
82
- );
83
- }
84
-
85
- export type FormInterface = {
86
- clear: () => void;
87
- };
88
-
89
- export type FirebaseFormProps<M extends FormForm> = {
90
- ref?: RefObject<FormInterface>;
91
- submitting: boolean;
92
- onSubmit: (data: M) => void;
93
- submited?: boolean;
94
- config: { [k in keyof M]: FieldDefinition<M, k, FieldTypes> };
95
- submitBtn:
96
- | string
97
- | {
98
- label: [FunctionComponent] | [FunctionComponent, ClassName];
99
- loading: [FunctionComponent] | [FunctionComponent, ClassName];
100
- error: [FunctionComponent] | [FunctionComponent, ClassName];
101
- success: [FunctionComponent] | [FunctionComponent, ClassName];
102
- };
103
- btnProps?: ComponentProps<typeof Button>;
104
- };
105
- function _FirebaseForm<M extends BaseForm>(
106
- {
107
- submitting,
108
- onSubmit,
109
- submited,
110
- config,
111
- submitBtn,
112
- btnProps = {},
113
- }: FirebaseFormProps<M>,
114
- ref: ForwardedRef<FormInterface>
115
- ) {
116
- const [form, setform] = useState<Partial<M>>({});
117
- const isValid = useMemo(
118
- () =>
119
- !Object.keys(config).some(
120
- (a) => typeof config[a].validator(form[a], form) === "string"
121
- ),
122
- [form]
123
- );
124
-
125
- async function sendContact(_form: typeof form) {
126
- onSubmit(_form as M);
127
- }
128
-
129
- useImperativeHandle(
130
- ref,
131
- () => ({
132
- clear: () => setform({}),
133
- }),
134
- [ref]
135
- );
136
-
137
- return (
138
- <>
139
- {Object.keys(config).map((c) => {
140
- const fieldConfig = config[c];
141
- const invalidMessage = fieldConfig.validator(form[c], form);
142
- switch (fieldConfig.type) {
143
- case "select":
144
- return null;
145
- case "text":
146
- case "number":
147
- const isNumber = fieldConfig.type === "number";
148
- return (
149
- <Input
150
- {...fieldConfig.inputProps}
151
- key={c}
152
- name={c}
153
- error={
154
- form[c] && invalidMessage !== true
155
- ? invalidMessage
156
- : undefined
157
- }
158
- placeholder={config[c].placeholder}
159
- value={!isNumber ? form[c] || "" : undefined}
160
- hideError={"onfocus"}
161
- onChange={({ target: { value } }: any) => {
162
- let _value = isNumber ? Number(value) : value;
163
- if (isNumber && Number.isNaN(_value)) {
164
- _value = undefined;
165
- }
166
- setform({
167
- ...form,
168
- [c]: _value,
169
- });
170
- }}
171
- />
172
- );
173
- case "email":
174
- return (
175
- <EmailInput
176
- key={c}
177
- {...fieldConfig}
178
- name={c}
179
- hideError={"onfocus"}
180
- error={
181
- form[c] && invalidMessage !== true
182
- ? invalidMessage
183
- : undefined
184
- }
185
- placeholder={config[c].placeholder}
186
- value={(form[c] as string) || ""}
187
- onChange={(email) =>
188
- setform({
189
- ...form,
190
- [c]: email,
191
- })
192
- }
193
- />
194
- );
195
- case "textarea":
196
- return (
197
- <Input
198
- key={c}
199
- name={c}
200
- hideError={"onfocus"}
201
- error={
202
- form[c] && invalidMessage !== true
203
- ? invalidMessage
204
- : undefined
205
- }
206
- placeholder={config[c].placeholder}
207
- value={form[c] || ""}
208
- onChange={({ target: { value } }: any) =>
209
- setform({
210
- ...form,
211
- [c]: value,
212
- })
213
- }
214
- multiline={fieldConfig.lines}
215
- />
216
- );
217
- }
218
- })}
219
- {typeof submitBtn === "string" ? (
220
- <Button
221
- variant="filled"
222
- disabled={submitting || !isValid || submited !== undefined}
223
- onClick={() => sendContact(form as any)}
224
- {...btnProps}
225
- >
226
- {submitBtn}&nbsp;
227
- {submitting && <Loader />}
228
- </Button>
229
- ) : (
230
- <AdvancedAction
231
- config={submitBtn}
232
- isValid={isValid}
233
- onClick={() => sendContact(form as any)}
234
- submitting={submitting}
235
- submited={submited}
236
- btnProps={btnProps}
237
- />
238
- )}
239
- </>
240
- );
241
- }
242
- const FirebaseForm = forwardRef(_FirebaseForm);
243
- export default FirebaseForm;
@@ -1,2 +0,0 @@
1
- export { default } from "./Form";
2
- export * from "./Form";
@@ -1,341 +0,0 @@
1
- import { useLayoutEffect, useMemo, useState } from "react";
2
- import {
3
- OneUIContextSpecs,
4
- useOneUIConfig,
5
- } from "../../../context/OneUIProvider";
6
- import {
7
- AnswerAction,
8
- AnswerByField,
9
- FormField,
10
- FormFieldTypes,
11
- FormFieldView,
12
- FormMode,
13
- } from "./FormField/FormField.types";
14
- import { AnswersMap } from "./Form.types";
15
- import { UploadTask, UploadTaskSnapshot } from "firebase/storage";
16
-
17
- export function useFormAnswers<A extends AnswersMap<any> = AnswersMap>(
18
- defaultAnswers: A,
19
- mode: FormMode
20
- ) {
21
- const [answers, setAnswers] = useState<A>(() => {
22
- const clone = {
23
- ...defaultAnswers,
24
- };
25
- if (mode === FormMode.READ_ONLY) return clone;
26
- return clone;
27
- });
28
- return {
29
- answers,
30
- setAnswers,
31
- };
32
- }
33
- export function useFormState(
34
- currentQuestions: FormFieldView[],
35
- { answers, setAnswers }: ReturnType<typeof useFormAnswers>
36
- ) {
37
- const formConfig = useOneUIConfig("component.form");
38
-
39
- const { isValid: isQuestionsAnswered } = useMemo(() => {
40
- return areAllQuestionsAnswered(
41
- currentQuestions,
42
- answers,
43
- formConfig.requiredLabel,
44
- formConfig.extensions
45
- );
46
- }, [answers, currentQuestions]);
47
-
48
- const onAnswerAction = <T extends FormFieldTypes>(
49
- questionType: T,
50
- id: string,
51
- answer:
52
- | AnswerAction<{
53
- type: T;
54
- }>
55
- | undefined
56
- ) => {
57
- switch (questionType) {
58
- case "file":
59
- const { onFileUpload } = formConfig;
60
- setAnswers((prev: any) => {
61
- const file = answer as File | undefined;
62
- if (file)
63
- return {
64
- ...prev,
65
- [id]: onFileUpload(id, file),
66
- };
67
- delete prev[id];
68
- return { ...prev };
69
- });
70
- break;
71
- default:
72
- setAnswers((prev) => ({
73
- ...prev,
74
- [id]: answer as string,
75
- }));
76
- }
77
- };
78
-
79
- const isFilesUploaded = useFileUploads(currentQuestions, answers);
80
-
81
- return {
82
- answers,
83
- isQuestionsAnswered,
84
- isFilesUploaded,
85
- onAnswerAction,
86
- questions: currentQuestions,
87
- };
88
- }
89
-
90
- export function useForm(
91
- currentQuestions: FormFieldView[],
92
- defaultAnswers: AnswersMap,
93
- mode: FormMode
94
- ) {
95
- const answers = useFormAnswers(defaultAnswers, mode);
96
- return useFormState(currentQuestions, answers);
97
- }
98
-
99
- function useFileUploads(questions: FormField[], answers: AnswersMap) {
100
- const fileUploadQuestions = useMemo(
101
- () => questions.filter((a) => a.type === "file"),
102
- [questions]
103
- );
104
- const [fileUploadStatus, setFileUploadStatus] = useState<{
105
- [questionID: string]: UploadTaskSnapshot["state"];
106
- }>({});
107
- useLayoutEffect(() => {
108
- const unsubs: ReturnType<UploadTask["on"]>[] = [];
109
- for (let fileQuestion of fileUploadQuestions) {
110
- const uploadTask = answers[fileQuestion.id] as
111
- | AnswerByField<{
112
- type: "file";
113
- }>
114
- | undefined;
115
-
116
- if (!uploadTask)
117
- setFileUploadStatus((prev) => ({
118
- ...prev,
119
- [fileQuestion.id]: "running",
120
- }));
121
- else if (typeof uploadTask === "boolean") {
122
- setFileUploadStatus((prev) => ({
123
- ...prev,
124
- [fileQuestion.id]: "success",
125
- }));
126
- } else
127
- unsubs.push(
128
- uploadTask.on("state_changed", (r) => {
129
- setFileUploadStatus((prev) => ({
130
- ...prev,
131
- [fileQuestion.id]:
132
- r.totalBytes === r.bytesTransferred ? "success" : "running",
133
- }));
134
- })
135
- );
136
- }
137
-
138
- return () => {
139
- unsubs.forEach((unsub) => unsub());
140
- };
141
- }, [answers, fileUploadQuestions]);
142
-
143
- const areAllFileUploaded = useMemo(() => {
144
- return fileUploadQuestions.reduce((r, question) => {
145
- const uploadStatus = fileUploadStatus[question.id];
146
- return r && uploadStatus === "success";
147
- }, true);
148
- }, [fileUploadStatus, fileUploadQuestions]);
149
-
150
- return areAllFileUploaded;
151
- }
152
-
153
- export function useFieldErrors<
154
- Q extends Readonly<
155
- Pick<FormField, "type" | "id" | "optional" | "validator">[]
156
- >
157
- >(currentQuestions: Q, answers: AnswersMap, showAllErrors: boolean) {
158
- const { requiredLabel, extensions } = useOneUIConfig("component.form");
159
- const errorMap = useMemo(() => {
160
- const ans = <T extends FormFieldView["type"]>(
161
- question: Pick<FormField, "id"> & {
162
- type: T;
163
- }
164
- ) =>
165
- answers[question.id] as AnswerByField<{
166
- type: T;
167
- }>;
168
- const errorsMap: {
169
- [questionId: string]: string | undefined;
170
- } = {};
171
- for (let question of currentQuestions) {
172
- const _isValidated = () => {
173
- return isValidated(
174
- ans(question),
175
- !!question.optional,
176
- question.validator,
177
- requiredLabel
178
- );
179
- };
180
- const updateDefaultError = () => {
181
- const validation = _isValidated();
182
- errorsMap[question.id] = validation.error;
183
- };
184
- switch (question.type) {
185
- case "check":
186
- case "rawcheck":
187
- updateDefaultError();
188
- if (question.validator)
189
- errorsMap[question.id] = question.validator(
190
- ans(question) as any
191
- ) as string;
192
- break;
193
- case "number":
194
- case "text":
195
- case "select":
196
- case "radio":
197
- case "file":
198
- updateDefaultError();
199
- const validationResult = _isValidated();
200
- if (validationResult.error)
201
- errorsMap[question.id] = validationResult.error;
202
- break;
203
- default:
204
- const extendedSupport =
205
- extensions?.[
206
- question.type as OnepercentUtility.UIElements.FormExtension["fields"]["type"]
207
- ];
208
- if (extendedSupport) {
209
- const validationResultExtend = extendedSupport.validator(
210
- ans(question) as any,
211
- question as any
212
- );
213
- if (validationResultExtend.error)
214
- errorsMap[question.id] = validationResultExtend.error;
215
- } else {
216
- updateDefaultError();
217
- }
218
- }
219
- }
220
-
221
- return errorsMap;
222
- }, [currentQuestions, answers]);
223
-
224
- const currentErrors = useMemo(() => {
225
- return Object.entries(errorMap).reduce(
226
- (r, [k, v]) => ({
227
- ...r,
228
- [k]: showAllErrors ? v : v !== requiredLabel ? v : undefined,
229
- }),
230
- {}
231
- );
232
- }, [showAllErrors, errorMap]);
233
-
234
- return currentErrors as { [k in Q[number]["id"]]: string };
235
- }
236
-
237
- export function areAllQuestionsAnswered(
238
- currentQuestions: FormField[],
239
- answers: AnswersMap,
240
- requiredLabel: string,
241
- extensions: OneUIContextSpecs["component"]["form"]["extensions"]
242
- ) {
243
- const isValid = currentQuestions.reduce((answeredAll, question) => {
244
- const ans = <T extends FormFieldView["type"]>(
245
- question: FormField & {
246
- type: T;
247
- }
248
- ) =>
249
- answers[question.id] as unknown as AnswerByField<{
250
- type: T;
251
- }>;
252
-
253
- const result =
254
- answeredAll &&
255
- (() => {
256
- switch (question.type) {
257
- case "accept":
258
- const checks = ans(question) || [];
259
- return question.accept.reduce(
260
- (r, { optional }, idx) => r && (optional ? true : checks[idx]),
261
- true
262
- );
263
- case "check":
264
- case "rawcheck":
265
- if (question.optional) return true;
266
- if (question.validator)
267
- return question.validator(ans(question) as any) as boolean;
268
- const checkmarks = ans(question) || [];
269
- return checkmarks.includes(true);
270
- case "number":
271
- case "text":
272
- case "select":
273
- case "radio":
274
- case "file":
275
- if (!answers[question.id]) return !!question.optional;
276
- const validationResult = isValidated(
277
- ans(question),
278
- !!question.optional,
279
- question.validator,
280
- requiredLabel
281
- );
282
- return validationResult.isValid && answeredAll;
283
- default:
284
- const extendedSupport =
285
- extensions?.[
286
- question.type as OnepercentUtility.UIElements.FormExtension["fields"]["type"]
287
- ];
288
- if (extendedSupport) {
289
- const validationResultExtend = extendedSupport.validator(
290
- ans(question) as any,
291
- question as any
292
- );
293
- return validationResultExtend.isValid;
294
- } else
295
- return question.validator
296
- ? !!question.validator(ans(question) as any)
297
- : !!ans(question);
298
- }
299
- })();
300
- return result;
301
- }, true);
302
-
303
- return { isValid: !!isValid };
304
- }
305
-
306
- export const isValidated = (
307
- _answer: AnswerByField<{ type: FormFieldTypes }>,
308
- isOptional: boolean,
309
- validator: ((val: any) => string | boolean) | undefined,
310
- requiredFieldLabel: string
311
- ) => {
312
- const answer = Array.isArray(_answer) ? _answer[0] : _answer;
313
- if (!answer && !isOptional)
314
- return {
315
- isValid: false,
316
- error: requiredFieldLabel,
317
- };
318
- if (!validator)
319
- if (Array.isArray(_answer)) {
320
- const [_, isValid, error] = _answer;
321
- return {
322
- isValid,
323
- error,
324
- };
325
- } else {
326
- return {
327
- isValid: true,
328
- error: "",
329
- };
330
- }
331
- const validationResult = validator(answer);
332
- if (typeof validationResult === "string")
333
- return {
334
- isValid: false,
335
- error: validationResult,
336
- };
337
- return {
338
- isValid: validationResult,
339
- error: "",
340
- };
341
- };
File without changes
@@ -1,78 +0,0 @@
1
- import React, {
2
- ForwardedRef,
3
- forwardRef,
4
- useEffect,
5
- useImperativeHandle,
6
- } from "react";
7
- import { BaseQuestion, FormMode, FormViewProps } from "./Form.types";
8
- import { useFieldErrors, useForm } from "./Form.hook";
9
- import FormField from "./FormField";
10
- import { AnswerByField, FormFieldView } from "./FormField/FormField.types";
11
-
12
- export type FormRef<Q extends FormFieldView[]> = {
13
- setAnswer<I extends Q[number]["id"]>(
14
- questionId: I,
15
- ans: AnswerByField<Q[number] & { id: I }>
16
- ): void;
17
- };
18
-
19
- function Form<Q extends FormFieldView[]>(
20
- { questions, initialAnswers = {}, ...props }: FormViewProps<Q>,
21
- ref: ForwardedRef<FormRef<Q>>
22
- ) {
23
- const { mode = FormMode.WRITE } = props;
24
- const { showAllErrors = false } = props as FormViewProps<Q> & {
25
- mode: FormMode.WRITE;
26
- };
27
- const { answers, onAnswerAction, isQuestionsAnswered, isFilesUploaded } =
28
- useForm(questions, initialAnswers, mode);
29
- const errors = useFieldErrors(questions, answers, showAllErrors);
30
-
31
- useEffect(() => {
32
- if (props.mode !== FormMode.READ_ONLY)
33
- props.onFormUpdate(
34
- answers as any,
35
- isQuestionsAnswered && isFilesUploaded
36
- );
37
- }, [answers, isQuestionsAnswered, isFilesUploaded]);
38
-
39
- useImperativeHandle(
40
- ref,
41
- () => ({
42
- setAnswer(id, val) {
43
- onAnswerAction(
44
- questions.find((q) => q.id === id)!.type,
45
- id,
46
- val as any
47
- );
48
- },
49
- }),
50
- []
51
- );
52
-
53
- return (
54
- <>
55
- {questions.map((q) => (
56
- <FormField
57
- key={q.id}
58
- config={q}
59
- onAnswer={onAnswerAction}
60
- value={answers[q.id] as any}
61
- error={(errors as any)[q.id]}
62
- mode={mode}
63
- />
64
- ))}
65
- </>
66
- );
67
- }
68
-
69
- /**
70
- * Brainstorm:
71
- * The answers must be externalized in some way because those answers will be manipulated
72
- * There must be a way to disable non validation related errors
73
- */
74
-
75
- /**
76
- * A new and improved version of the one-ui design form
77
- **/
78
- export default forwardRef(Form);