@onepercentio/one-ui 0.28.7 → 0.28.9
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.
- package/package.json +8 -5
- package/src/assets/img/svg/checkbox.svg +3 -0
- package/src/assets/styles/index.scss +2 -0
- package/src/assets/styles/mixins.scss +12 -0
- package/src/assets/styles/variables.scss +49 -0
- package/src/components/AdaptiveButton/AdaptiveButton.module.scss +7 -0
- package/src/components/AdaptiveButton/AdaptiveButton.tsx +26 -0
- package/src/components/AdaptiveButton/index.tsx +1 -0
- package/src/components/AdaptiveContainer/AdaptiveContainer.module.scss +53 -0
- package/src/components/AdaptiveContainer/AdaptiveContainer.tsx +200 -0
- package/src/components/AdaptiveContainer/index.tsx +1 -0
- package/src/components/AdaptiveDialog/AdaptiveDialog.module.scss +147 -0
- package/src/components/AdaptiveDialog/AdaptiveDialog.tsx +97 -0
- package/src/components/AdaptiveDialog/index.tsx +1 -0
- package/src/components/AdaptiveSidebar/AdaptiveSidebar.module.scss +49 -0
- package/src/components/AdaptiveSidebar/AdaptiveSidebar.sample.tsx +10 -0
- package/src/components/AdaptiveSidebar/AdaptiveSidebar.tsx +123 -0
- package/src/components/AdaptiveSidebar/index.tsx +1 -0
- package/src/components/AnchoredTooltip/AnchoredTooltip.module.scss +64 -0
- package/src/components/AnchoredTooltip/AnchoredTooltip.tsx +250 -0
- package/src/components/AnchoredTooltip/index.tsx +1 -0
- package/src/components/AnimatedEntrance/AnimatedEntrance.module.scss +108 -0
- package/src/components/AnimatedEntrance/AnimatedEntrance.tsx +227 -0
- package/src/components/AnimatedEntrance/index.tsx +5 -0
- package/src/components/AsyncWrapper/AsyncWrapper.tsx +38 -0
- package/src/components/AsyncWrapper/index.tsx +1 -0
- package/src/components/Avatar/Avatar.module.scss +22 -0
- package/src/components/Avatar/Avatar.tsx +31 -0
- package/src/components/Avatar/index.tsx +1 -0
- package/src/components/BucketFill/BucketFill.module.scss +36 -0
- package/src/components/BucketFill/BucketFill.tsx +65 -0
- package/src/components/BucketFill/index.tsx +1 -0
- package/src/components/Button/Button.module.scss +45 -0
- package/src/components/Button/Button.tsx +40 -0
- package/src/components/Button/index.tsx +1 -0
- package/src/components/Card/Card.module.scss +12 -0
- package/src/components/Card/Card.tsx +9 -0
- package/src/components/Card/index.tsx +1 -0
- package/src/components/Chart/Chart.e2e.ts +4 -0
- package/src/components/Chart/Chart.logic.tsx +8 -0
- package/src/components/Chart/Chart.module.scss +58 -0
- package/src/components/Chart/Chart.types.ts +35 -0
- package/src/components/Chart/Chart.view.tsx +240 -0
- package/src/components/Chart/index.tsx +1 -0
- package/src/components/CheckBox/CheckBox.module.scss +36 -0
- package/src/components/CheckBox/CheckBox.tsx +63 -0
- package/src/components/CheckBox/index.tsx +1 -0
- package/src/components/CodeInput/CodeInput.module.scss +5 -0
- package/src/components/CodeInput/CodeInput.tsx +84 -0
- package/src/components/CodeInput/index.tsx +1 -0
- package/src/components/Collapsable/Collapsable.module.scss +42 -0
- package/src/components/Collapsable/Collapsable.tsx +253 -0
- package/src/components/Collapsable/index.tsx +1 -0
- package/src/components/Countdown/Countdown.tsx +130 -0
- package/src/components/Countdown/index.tsx +1 -0
- package/src/components/CurrencyInput/CurrencyInput.hook.ts +37 -0
- package/src/components/CurrencyInput/CurrencyInput.tsx +25 -0
- package/src/components/CurrencyInput/index.tsx +1 -0
- package/src/components/Divider/Divider.module.scss +7 -0
- package/src/components/Divider/Divider.tsx +13 -0
- package/src/components/Divider/index.tsx +1 -0
- package/src/components/EmailInput/EmailInput.module.scss +0 -0
- package/src/components/EmailInput/EmailInput.tsx +51 -0
- package/src/components/EmailInput/index.tsx +1 -0
- package/src/components/FadeIn/FadeIn.module.scss +9 -0
- package/src/components/FadeIn/FadeIn.tsx +77 -0
- package/src/components/FadeIn/index.tsx +1 -0
- package/src/components/FileInput/FileInput.module.scss +6 -0
- package/src/components/FileInput/FileInput.tsx +75 -0
- package/src/components/FileInput/View/BigFactory/BigFactory.module.scss +20 -0
- package/src/components/FileInput/View/BigFactory/BigFactory.tsx +48 -0
- package/src/components/FileInput/View/BigFactory/index.tsx +1 -0
- package/src/components/FileInput/View/Compact/Compact.module.scss +68 -0
- package/src/components/FileInput/View/Compact/Compact.tsx +151 -0
- package/src/components/FileInput/View/Compact/index.tsx +1 -0
- package/src/components/FileInput/View/View.types.ts +12 -0
- package/src/components/FileInput/index.tsx +1 -0
- package/src/components/FlowController/FlowController.module.scss +47 -0
- package/src/components/FlowController/FlowController.tsx +93 -0
- package/src/components/FlowController/index.tsx +1 -0
- package/src/components/Form/Form.tsx +243 -0
- package/src/components/Form/index.ts +1 -0
- package/src/components/Form/v2/Form.hook.ts +341 -0
- package/src/components/Form/v2/Form.module.scss +0 -0
- package/src/components/Form/v2/Form.tsx +78 -0
- package/src/components/Form/v2/Form.types.ts +118 -0
- package/src/components/Form/v2/FormField/Extensions/DateField/DateField.module.scss +0 -0
- package/src/components/Form/v2/FormField/Extensions/DateField/DateField.tsx +73 -0
- package/src/components/Form/v2/FormField/Extensions/DateField/index.tsx +1 -0
- package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.module.scss +0 -0
- package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.tsx +91 -0
- package/src/components/Form/v2/FormField/Extensions/PhoneField/index.tsx +1 -0
- package/src/components/Form/v2/FormField/FormField.module.scss +0 -0
- package/src/components/Form/v2/FormField/FormField.tsx +378 -0
- package/src/components/Form/v2/FormField/FormField.types.ts +129 -0
- package/src/components/Form/v2/FormField/index.tsx +1 -0
- package/src/components/Form/v2/index.tsx +1 -0
- package/src/components/Freeze/Freeze.tsx +9 -0
- package/src/components/Freeze/index.tsx +1 -0
- package/src/components/HSForms/HSForms.tsx +57 -0
- package/src/components/HSForms/index.tsx +1 -0
- package/src/components/Header/Header.module.scss +119 -0
- package/src/components/Header/Header.tsx +138 -0
- package/src/components/Header/index.tsx +1 -0
- package/src/components/HeaderCloseBtn/HeaderCloseBtn.module.scss +44 -0
- package/src/components/HeaderCloseBtn/HeaderCloseBtn.tsx +28 -0
- package/src/components/HeaderCloseBtn/index.tsx +1 -0
- package/src/components/InfinityScroll/InfinityScroll.module.scss +30 -0
- package/src/components/InfinityScroll/InfinityScroll.tsx +187 -0
- package/src/components/InfinityScroll/index.tsx +1 -0
- package/src/components/Input/Input.module.scss +71 -0
- package/src/components/Input/Input.tsx +134 -0
- package/src/components/Input/index.tsx +1 -0
- package/src/components/InstantCounter/InstantCounter.tsx +77 -0
- package/src/components/InstantCounter/index.tsx +1 -0
- package/src/components/LavaLamp/LavaLamp.data.tsx +114 -0
- package/src/components/LavaLamp/LavaLamp.module.scss +26 -0
- package/src/components/LavaLamp/LavaLamp.tsx +131 -0
- package/src/components/LavaLamp/index.tsx +1 -0
- package/src/components/LavaLamp/v2/LavaLamp.module.scss +23 -0
- package/src/components/LavaLamp/v2/LavaLamp.tsx +197 -0
- package/src/components/LinkToId/LinkToId.module.scss +4 -0
- package/src/components/LinkToId/LinkToId.tsx +51 -0
- package/src/components/LinkToId/index.tsx +1 -0
- package/src/components/Loader/Loader.module.scss +40 -0
- package/src/components/Loader/Loader.tsx +18 -0
- package/src/components/Loader/index.tsx +1 -0
- package/src/components/LoaderDotsIndicator/LoaderDotsIndicator.tsx +34 -0
- package/src/components/LoaderDotsIndicator/index.tsx +1 -0
- package/src/components/LoopableVideo/LoopableVideo.tsx +37 -0
- package/src/components/LoopableVideo/index.tsx +1 -0
- package/src/components/MainGrid/MainGrid.module.scss +28 -0
- package/src/components/MainGrid/MainGrid.tsx +68 -0
- package/src/components/MainGrid/index.tsx +1 -0
- package/src/components/MutableHamburgerButton/MutableHamburgerButton.module.scss +220 -0
- package/src/components/MutableHamburgerButton/MutableHamburgerButton.tsx +38 -0
- package/src/components/MutableHamburgerButton/index.tsx +1 -0
- package/src/components/Notification/Notification.module.scss +25 -0
- package/src/components/Notification/Notification.tsx +13 -0
- package/src/components/Notification/index.tsx +1 -0
- package/src/components/OrderableList/OrderableList.module.scss +98 -0
- package/src/components/OrderableList/OrderableList.tsx +564 -0
- package/src/components/OrderableList/index.tsx +1 -0
- package/src/components/PaginationIndicator/PaginationIndicator.tsx +365 -0
- package/src/components/PaginationIndicator/index.tsx +1 -0
- package/src/components/Parallax/Parallax.module.scss +28 -0
- package/src/components/Parallax/Parallax.tsx +248 -0
- package/src/components/Parallax/index.tsx +1 -0
- package/src/components/Parallax/math/helpers.ts +289 -0
- package/src/components/PasswordInput/PasswordInput.module.scss +17 -0
- package/src/components/PasswordInput/PasswordInput.tsx +154 -0
- package/src/components/PasswordInput/index.tsx +1 -0
- package/src/components/PingPongText/PingPongText.module.scss +4 -0
- package/src/components/PingPongText/PingPongText.tsx +83 -0
- package/src/components/PingPongText/index.tsx +1 -0
- package/src/components/PixelatedScan/PixelatedScan.module.scss +86 -0
- package/src/components/PixelatedScan/PixelatedScan.tsx +175 -0
- package/src/components/PixelatedScan/index.tsx +1 -0
- package/src/components/Portal/Portal.module.scss +3 -0
- package/src/components/Portal/Portal.tsx +68 -0
- package/src/components/Portal/index.tsx +1 -0
- package/src/components/ProgressBar/ProgressBar.module.scss +44 -0
- package/src/components/ProgressBar/ProgressBar.tsx +124 -0
- package/src/components/ProgressBar/index.tsx +1 -0
- package/src/components/ProgressTexts/ProgressTexts.module.scss +37 -0
- package/src/components/ProgressTexts/ProgressTexts.tsx +85 -0
- package/src/components/ProgressTexts/index.tsx +1 -0
- package/src/components/Radio/Radio.module.scss +36 -0
- package/src/components/Radio/Radio.tsx +53 -0
- package/src/components/Radio/index.tsx +1 -0
- package/src/components/SectionContainer/SectionContainer.module.scss +30 -0
- package/src/components/SectionContainer/SectionContainer.tsx +49 -0
- package/src/components/SectionContainer/index.tsx +1 -0
- package/src/components/Select/Select.module.scss +58 -0
- package/src/components/Select/Select.tsx +192 -0
- package/src/components/Select/index.tsx +1 -0
- package/src/components/Skeleton/Skeleton.module.scss +21 -0
- package/src/components/Skeleton/Skeleton.tsx +29 -0
- package/src/components/Skeleton/index.tsx +1 -0
- package/src/components/Spacing/Spacing.module.scss +13 -0
- package/src/components/Spacing/Spacing.tsx +24 -0
- package/src/components/Spacing/index.tsx +1 -0
- package/src/components/StaticScroller/StaticScroller.module.scss +14 -0
- package/src/components/StaticScroller/StaticScroller.tsx +83 -0
- package/src/components/StaticScroller/index.tsx +1 -0
- package/src/components/Switch/Switch.module.scss +43 -0
- package/src/components/Switch/Switch.tsx +41 -0
- package/src/components/Switch/index.tsx +1 -0
- package/src/components/Table/Table.module.scss +76 -0
- package/src/components/Table/Table.tsx +152 -0
- package/src/components/Table/index.tsx +1 -0
- package/src/components/Tabs/Tabs.module.scss +40 -0
- package/src/components/Tabs/Tabs.tsx +104 -0
- package/src/components/Tabs/index.tsx +1 -0
- package/src/components/Text/Text.module.scss +81 -0
- package/src/components/Text/Text.tsx +42 -0
- package/src/components/Text/index.tsx +1 -0
- package/src/components/Transition/MasksFactory/DiagonalReveal.tsx +47 -0
- package/src/components/Transition/MasksFactory/DiagonalSquareToBalls.tsx +78 -0
- package/src/components/Transition/MasksFactory/PhysicsSquares.tsx +106 -0
- package/src/components/Transition/MasksFactory/SquareToBalls.tsx +66 -0
- package/src/components/Transition/MasksFactory/utils.ts +35 -0
- package/src/components/Transition/Transition.module.scss +211 -0
- package/src/components/Transition/Transition.tsx +495 -0
- package/src/components/Transition/index.tsx +1 -0
- package/src/components/UncontrolledTransition/UncontrolledTransition.ai.md +9 -0
- package/src/components/UncontrolledTransition/UncontrolledTransition.sample.tsx +34 -0
- package/src/components/UncontrolledTransition/UncontrolledTransition.tsx +143 -0
- package/src/components/UncontrolledTransition/index.tsx +2 -0
- package/src/components/WalletConnectionWrapper/WalletConnectionWrapper.tsx +212 -0
- package/src/components/WalletConnectionWrapper/index.tsx +1 -0
- package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.module.scss +5 -0
- package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.tsx +52 -0
- package/src/components/utilitary/ScrollAndFocusLock/index.tsx +1 -0
- package/src/context/AsyncProcess.tsx +107 -0
- package/src/context/ContextAsyncControl.tsx +89 -0
- package/src/context/CustomBrowserRouter.tsx +55 -0
- package/src/context/OneUIProvider.tsx +308 -0
- package/src/hooks/logs/useDependencyChangeDetection.ts +25 -0
- package/src/hooks/logs/useIsMounting.ts +7 -0
- package/src/hooks/persistence/useLocalStorage.ts +45 -0
- package/src/hooks/shims/ObjectWatchShim.ts +56 -0
- package/src/hooks/ui/useAdaptiveImage.tsx +36 -0
- package/src/hooks/ui/useAlternating.tsx +22 -0
- package/src/hooks/ui/useBreakpoint.tsx +21 -0
- package/src/hooks/ui/useCustomScrollbar.module.scss +20 -0
- package/src/hooks/ui/useCustomScrollbar.tsx +22 -0
- package/src/hooks/ui/useEffectIf.ts +11 -0
- package/src/hooks/ui/useMouseHover.tsx +26 -0
- package/src/hooks/ui/usePaginationControls.module.scss +16 -0
- package/src/hooks/ui/usePaginationControls.tsx +176 -0
- package/src/hooks/ui/useSnapToViewport.module.scss +6 -0
- package/src/hooks/ui/useSnapToViewport.ts +28 -0
- package/src/hooks/ui/useTilt.tsx +219 -0
- package/src/hooks/ui/useZoomable.module.scss +34 -0
- package/src/hooks/ui/useZoomable.tsx +144 -0
- package/src/hooks/useAsyncControl.ai.md +25 -0
- package/src/hooks/useAsyncControl.ts +101 -0
- package/src/hooks/useContainedRepositioning.ts +110 -0
- package/src/hooks/useCustomHistory.ts +14 -0
- package/src/hooks/useElementFit.ts +82 -0
- package/src/hooks/useFirestoreWatch.ts +54 -0
- package/src/hooks/useForm.ts +49 -0
- package/src/hooks/useFreeze.ts +12 -0
- package/src/hooks/useHero.module.scss +41 -0
- package/src/hooks/useHero.ts +512 -0
- package/src/hooks/useIntersection.ts +32 -0
- package/src/hooks/useMergeRefs.ts +29 -0
- package/src/hooks/useObserve.ts +24 -0
- package/src/hooks/usePagination.ts +228 -0
- package/src/hooks/usePooledOperation.ts +54 -0
- package/src/hooks/usePooling.ts +46 -0
- package/src/hooks/useRebound.ts +23 -0
- package/src/hooks/useShortIntl.ai.md +5 -0
- package/src/hooks/useShortIntl.ts +97 -0
- package/src/hooks/utility/useAsyncMemo.ts +43 -0
- package/src/hooks/utility/useDepChange.ts +11 -0
- package/src/hooks/utility/useEvents.ts +33 -0
- package/src/hooks/utility/useImmediate.ts +8 -0
- package/src/hooks/utility/useManualInit.ts +24 -0
- package/src/hooks/utility/useModule.ts +15 -0
- package/src/hooks/utility/useQuery.ts +15 -0
- package/src/hooks/utility/useUniqueEffect.ts +22 -0
- package/src/index.ts +3 -0
- package/src/models/DebugLogger.ts +7 -0
- package/src/models/GenericContract.ts +169 -0
- package/src/models/Orbs.ts +97 -0
- package/src/reac-app-env.d.ts +6 -0
- package/src/storybook/assets/video/txt-reversed.mp4 +0 -0
- package/src/storybookUtils/index.tsx +53 -0
- package/src/type-utils.ts +49 -0
- package/src/utility.d.ts +70 -0
- package/src/utils/blockchain.ts +43 -0
- package/src/utils/flatten.ts +17 -0
- package/src/utils/formatters.ts +36 -0
- package/src/utils/html.utils.ts +3 -0
- package/src/utils/ownEvent.ts +8 -0
- package/src/utils/test.ts +19 -0
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './DateField';
|
|
File without changes
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './PhoneField';
|
|
File without changes
|
|
@@ -0,0 +1,378 @@
|
|
|
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
|
+
}
|