@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,101 @@
|
|
|
1
|
+
import { SetStateAction, useCallback, useMemo, useState } from "react";
|
|
2
|
+
import { Primitive } from "type-fest";
|
|
3
|
+
|
|
4
|
+
type Arr<X> = [X, React.Dispatch<SetStateAction<X>>];
|
|
5
|
+
export type FunctionMap = {
|
|
6
|
+
[f: string]: ((...args: any[]) => Promise<any>) | Object | Primitive;
|
|
7
|
+
};
|
|
8
|
+
export type Control<E extends any = any> = {
|
|
9
|
+
error?: E;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
};
|
|
12
|
+
export function useRawAsynControl<E = any, F extends FunctionMap = {}>(
|
|
13
|
+
functionsToWrap: F | undefined,
|
|
14
|
+
[error, setError]: Arr<E | undefined>,
|
|
15
|
+
[loading, setLoading]: Arr<boolean>
|
|
16
|
+
) {
|
|
17
|
+
const _process = useCallback(async (asyncFn: (() => Promise<any>) | Promise<any>) => {
|
|
18
|
+
try {
|
|
19
|
+
setLoading(true);
|
|
20
|
+
setError(undefined);
|
|
21
|
+
if (asyncFn instanceof Promise) await asyncFn;
|
|
22
|
+
else return await asyncFn();
|
|
23
|
+
} catch (e) {
|
|
24
|
+
if (process.env.NODE_ENV === "development") console.error(e);
|
|
25
|
+
setError(e as E);
|
|
26
|
+
throw e;
|
|
27
|
+
} finally {
|
|
28
|
+
setLoading(false);
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
const { functionsToMemoize, other } = Object.entries(
|
|
33
|
+
functionsToWrap || {}
|
|
34
|
+
).reduce(
|
|
35
|
+
(r, [k, func]) => {
|
|
36
|
+
return {
|
|
37
|
+
...r,
|
|
38
|
+
...(typeof func === "function"
|
|
39
|
+
? {
|
|
40
|
+
functionsToMemoize: {
|
|
41
|
+
...r.functionsToMemoize,
|
|
42
|
+
[k]: func,
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
: {
|
|
46
|
+
other: {
|
|
47
|
+
...r.other,
|
|
48
|
+
[k]: func,
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
functionsToMemoize: {},
|
|
55
|
+
other: {},
|
|
56
|
+
} as {
|
|
57
|
+
functionsToMemoize: F;
|
|
58
|
+
other: F;
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
process: _process,
|
|
64
|
+
loading,
|
|
65
|
+
error,
|
|
66
|
+
setError,
|
|
67
|
+
setLoading,
|
|
68
|
+
...other,
|
|
69
|
+
...Object.entries(functionsToMemoize).reduce(
|
|
70
|
+
(r, [k, v]) => ({
|
|
71
|
+
...r,
|
|
72
|
+
[k]: useMemo(
|
|
73
|
+
() =>
|
|
74
|
+
(...args: any[]) =>
|
|
75
|
+
_process(() => (v as any)(...args)),
|
|
76
|
+
[v]
|
|
77
|
+
),
|
|
78
|
+
}),
|
|
79
|
+
{} as F
|
|
80
|
+
),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function useAsyncControl<
|
|
85
|
+
E = any,
|
|
86
|
+
F extends {
|
|
87
|
+
[f: string]: ((...args: any[]) => Promise<any>) | Object | Primitive;
|
|
88
|
+
} = {}
|
|
89
|
+
>(functionsToWrap?: F) {
|
|
90
|
+
const error = useState<E | Error>();
|
|
91
|
+
const loading = useState<boolean>(false);
|
|
92
|
+
|
|
93
|
+
return useRawAsynControl(functionsToWrap, error, loading);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* This hook provides a way to handle async operations storing the loading state, or the error when it fails, it does not store information returned from the functions.
|
|
98
|
+
* @param functionsToWrap The functions to wrap in control.
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
export default useAsyncControl;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import debounce from "lodash/debounce";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This hook takes an html and checks if its outside its parent
|
|
6
|
+
* If it is, it should move it so it can be totally visible inside the container
|
|
7
|
+
*/
|
|
8
|
+
export default function useContainedRepositioning(
|
|
9
|
+
focused: boolean,
|
|
10
|
+
getParent: (el: HTMLElement) => HTMLElement,
|
|
11
|
+
{
|
|
12
|
+
offset = 16,
|
|
13
|
+
scale = 1,
|
|
14
|
+
offsetLimit = Number.POSITIVE_INFINITY,
|
|
15
|
+
}: {
|
|
16
|
+
/** The offset the element will be moved by from the closest bound */
|
|
17
|
+
offset?: number;
|
|
18
|
+
|
|
19
|
+
/** The scaled element width to be considered. usefull for when the focused element will change size */
|
|
20
|
+
scale?: number;
|
|
21
|
+
|
|
22
|
+
/** Limit offset */
|
|
23
|
+
offsetLimit?: number;
|
|
24
|
+
} = {}
|
|
25
|
+
) {
|
|
26
|
+
const elementToCheck = useRef<HTMLDivElement>(null);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const el = elementToCheck.current;
|
|
29
|
+
if (!el) return;
|
|
30
|
+
|
|
31
|
+
const curr = el;
|
|
32
|
+
const relativeParent = getParent(curr);
|
|
33
|
+
|
|
34
|
+
if (process.env.NODE_ENV === "development") {
|
|
35
|
+
if (window.getComputedStyle(el).position !== "relative")
|
|
36
|
+
throw new Error(
|
|
37
|
+
"The target element MUST have position relative so it can be moved"
|
|
38
|
+
);
|
|
39
|
+
if (window.getComputedStyle(relativeParent).position !== "relative")
|
|
40
|
+
throw new Error(
|
|
41
|
+
"The relative to element MUST have position relative so it can calculate correctly the target position"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (focused) {
|
|
46
|
+
curr.style.right = `0px`;
|
|
47
|
+
const reposition = debounce(() => {
|
|
48
|
+
const alreadyRight = Number(curr.style.right.replace("px", ""));
|
|
49
|
+
const limitOffset =
|
|
50
|
+
relativeParent.scrollLeft + relativeParent.clientWidth;
|
|
51
|
+
const elWidth = curr.clientWidth * scale;
|
|
52
|
+
const offsetOfScale = (elWidth - curr.clientWidth) / 2;
|
|
53
|
+
const cardLimit =
|
|
54
|
+
curr.offsetLeft - offsetOfScale + alreadyRight + elWidth;
|
|
55
|
+
const exceedingSpace = cardLimit - limitOffset;
|
|
56
|
+
const offsetLeft =
|
|
57
|
+
curr.offsetLeft -
|
|
58
|
+
offsetOfScale +
|
|
59
|
+
alreadyRight -
|
|
60
|
+
relativeParent.scrollLeft;
|
|
61
|
+
const isOverflowedRight = exceedingSpace > 0;
|
|
62
|
+
const isOverflowedLeft = offsetLeft < 0;
|
|
63
|
+
const limit = exceedingSpace + -offsetLeft;
|
|
64
|
+
|
|
65
|
+
if (isOverflowedRight) {
|
|
66
|
+
const val = Math.min(
|
|
67
|
+
exceedingSpace - -Math.min(Math.abs(limit / 2), offset),
|
|
68
|
+
offsetLimit
|
|
69
|
+
);
|
|
70
|
+
curr.style.right = `${val}px`;
|
|
71
|
+
}
|
|
72
|
+
if (isOverflowedLeft) {
|
|
73
|
+
const val = Math.max(
|
|
74
|
+
offsetLeft - Math.min(Math.abs(limit) / 2, offset),
|
|
75
|
+
-offsetLimit
|
|
76
|
+
);
|
|
77
|
+
curr.style.right = `${val}px`;
|
|
78
|
+
}
|
|
79
|
+
if (isOverflowedLeft || isOverflowedRight) {
|
|
80
|
+
curr.style.zIndex = "1000";
|
|
81
|
+
}
|
|
82
|
+
}, 50);
|
|
83
|
+
reposition();
|
|
84
|
+
reposition.flush();
|
|
85
|
+
|
|
86
|
+
relativeParent.addEventListener("scroll", reposition, {
|
|
87
|
+
passive: true
|
|
88
|
+
});
|
|
89
|
+
return () => {
|
|
90
|
+
reposition.cancel();
|
|
91
|
+
relativeParent.removeEventListener("scroll", reposition);
|
|
92
|
+
el.style.right = `0px`;
|
|
93
|
+
const restore = ({ propertyName, currentTarget }: TransitionEvent) => {
|
|
94
|
+
const targetTransformation = window.getComputedStyle(
|
|
95
|
+
currentTarget as HTMLDivElement
|
|
96
|
+
).right;
|
|
97
|
+
if (propertyName === "right" && targetTransformation === "0px") {
|
|
98
|
+
curr.style.zIndex = "";
|
|
99
|
+
el.removeEventListener("transitionend", restore);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
el.addEventListener("transitionend", restore);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}, [focused]);
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
elementToCheck,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useHistory, useLocation } from "react-router-dom"
|
|
2
|
+
import { CustomState } from "../context/CustomBrowserRouter";
|
|
3
|
+
|
|
4
|
+
export default function useCustomHistory() {
|
|
5
|
+
const customHistory = useHistory();
|
|
6
|
+
const { state } = useLocation<CustomState | undefined>();
|
|
7
|
+
return {
|
|
8
|
+
...customHistory,
|
|
9
|
+
goBackWithFallback(fallbackRoute: string) {
|
|
10
|
+
if (state?.internalNavigation) customHistory.goBack();
|
|
11
|
+
else customHistory.push(fallbackRoute);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { RefObject, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This hook receives a base width of an element and returns how much items fit **vertically** inside the referenced html element
|
|
5
|
+
*
|
|
6
|
+
* @param baseWidth The base width of each element
|
|
7
|
+
*/
|
|
8
|
+
export default function useElementFit(
|
|
9
|
+
baseWidth: number,
|
|
10
|
+
baseHeight?: number
|
|
11
|
+
): {
|
|
12
|
+
/** The amount of items that are able to fit in the available width */
|
|
13
|
+
howManyItemsFit?: number;
|
|
14
|
+
/** The amount of items that are able to fit in the available visible space + a row more so it can be scrollable */
|
|
15
|
+
howManyItemsFitWithExtraRow?: number;
|
|
16
|
+
/** How many items would fit a single row */
|
|
17
|
+
howManyItemsByRow?: number;
|
|
18
|
+
/** How many items until it overflows width */
|
|
19
|
+
anItemMore?: number;
|
|
20
|
+
|
|
21
|
+
/** The ref to be sent to the element that will receive the items */
|
|
22
|
+
ref: RefObject<HTMLDivElement | undefined>;
|
|
23
|
+
} {
|
|
24
|
+
const ref = useRef<HTMLDivElement>(undefined);
|
|
25
|
+
function calculateDimension() {
|
|
26
|
+
function howManyItemsStackVertically() {
|
|
27
|
+
if (!ref.current || baseHeight === undefined) return 1;
|
|
28
|
+
return Math.floor(ref.current!.clientHeight / baseHeight);
|
|
29
|
+
}
|
|
30
|
+
if ((window as any).PRERENDER)
|
|
31
|
+
return {
|
|
32
|
+
howManyItemsWillBeVisible: 4,
|
|
33
|
+
byRow: 4,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const width = ref.current?.clientWidth || window.visualViewport!.width;
|
|
37
|
+
const maxItemsHorizontally = Math.floor(width / baseWidth) || 1;
|
|
38
|
+
|
|
39
|
+
if (process.env.NODE_ENV === "development")
|
|
40
|
+
require("../models/DebugLogger").default(
|
|
41
|
+
`${useElementFit.name}:clientWidth`,
|
|
42
|
+
ref.current?.clientWidth
|
|
43
|
+
);
|
|
44
|
+
return {
|
|
45
|
+
howManyItemsWillBeVisible:
|
|
46
|
+
maxItemsHorizontally * howManyItemsStackVertically(),
|
|
47
|
+
byRow: maxItemsHorizontally,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const [itemsToShow, setItemsToShow] = useState<
|
|
51
|
+
ReturnType<typeof calculateDimension> | undefined
|
|
52
|
+
>(
|
|
53
|
+
(window as any).PRERENDER
|
|
54
|
+
? {
|
|
55
|
+
byRow: 4,
|
|
56
|
+
howManyItemsWillBeVisible: 4,
|
|
57
|
+
}
|
|
58
|
+
: undefined
|
|
59
|
+
);
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
setItemsToShow(calculateDimension());
|
|
62
|
+
function onResize() {
|
|
63
|
+
setItemsToShow(calculateDimension());
|
|
64
|
+
}
|
|
65
|
+
window.addEventListener("resize", onResize);
|
|
66
|
+
return () => {
|
|
67
|
+
window.removeEventListener("resize", onResize);
|
|
68
|
+
};
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
71
|
+
return {
|
|
72
|
+
howManyItemsFit: itemsToShow?.howManyItemsWillBeVisible,
|
|
73
|
+
howManyItemsFitWithExtraRow: itemsToShow
|
|
74
|
+
? itemsToShow.howManyItemsWillBeVisible + itemsToShow.byRow
|
|
75
|
+
: undefined,
|
|
76
|
+
anItemMore: itemsToShow
|
|
77
|
+
? itemsToShow.howManyItemsWillBeVisible + 1
|
|
78
|
+
: undefined,
|
|
79
|
+
howManyItemsByRow: itemsToShow?.byRow,
|
|
80
|
+
ref,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { DocumentChangeType, Unsubscribe } from "firebase/firestore";
|
|
3
|
+
|
|
4
|
+
type SnapshotFactoryCb<D extends any> = (changes: {
|
|
5
|
+
doc: D,
|
|
6
|
+
type: DocumentChangeType
|
|
7
|
+
}[]) => void
|
|
8
|
+
|
|
9
|
+
export type SnapshotFactoryReturn<D extends { id: string }> = (cb: SnapshotFactoryCb<D>) => Unsubscribe
|
|
10
|
+
|
|
11
|
+
export default function useFirestoreWatch<D extends { id: string }, P extends any[]>(queryFactory: (...params: P) => SnapshotFactoryReturn<D>, params: P) {
|
|
12
|
+
const [docsList, updateList] = useState<D[]>();
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const unsub = queryFactory(...params)((changes) => {
|
|
16
|
+
updateList((prevList = []) => {
|
|
17
|
+
for (let docChange of changes) {
|
|
18
|
+
if (docChange.type === undefined) {
|
|
19
|
+
const existing = prevList.find((f) => f.id === docChange.doc.id);
|
|
20
|
+
if (existing) docChange.type = "modified"
|
|
21
|
+
else docChange.type = "added"
|
|
22
|
+
}
|
|
23
|
+
switch (docChange.type) {
|
|
24
|
+
case 'added':
|
|
25
|
+
if (!prevList.find((f) => f.id === docChange.doc.id)) {
|
|
26
|
+
prevList.unshift(docChange.doc)
|
|
27
|
+
}
|
|
28
|
+
break
|
|
29
|
+
case 'modified':
|
|
30
|
+
prevList = prevList!.map((item) => {
|
|
31
|
+
if (item.id === docChange.doc.id)
|
|
32
|
+
for (let key in docChange.doc) {
|
|
33
|
+
item[key] = docChange.doc[key];
|
|
34
|
+
}
|
|
35
|
+
return item
|
|
36
|
+
})
|
|
37
|
+
break
|
|
38
|
+
case 'removed':
|
|
39
|
+
prevList = prevList!.filter(
|
|
40
|
+
(item) => item.id !== docChange.doc.id
|
|
41
|
+
)
|
|
42
|
+
break
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return [...prevList]
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
})
|
|
50
|
+
return unsub;
|
|
51
|
+
}, params);
|
|
52
|
+
|
|
53
|
+
return docsList;
|
|
54
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Context, useMemo, useState } from "react"
|
|
2
|
+
import { BaseForm, FieldDefinition, FieldTypes } from "../components/Form/Form";
|
|
3
|
+
|
|
4
|
+
type Intermediary<F extends BaseForm> = {
|
|
5
|
+
form: F,
|
|
6
|
+
formValidation: {
|
|
7
|
+
[k in keyof F]: string
|
|
8
|
+
} & { isValid: string | true },
|
|
9
|
+
set: <K extends keyof F>(k: K, value: F[K]) => void
|
|
10
|
+
}
|
|
11
|
+
export type FormControls<C extends FormConfig<any>> = Intermediary<C extends FormConfig<infer F> ? F : never>
|
|
12
|
+
export type FormConfig<T extends BaseForm> = { [k in keyof T]: FieldDefinition<T, k, FieldTypes> };
|
|
13
|
+
export default function useContextForm<T extends BaseForm>(
|
|
14
|
+
config: FormConfig<T>,
|
|
15
|
+
initialState: T
|
|
16
|
+
): FormControls<FormConfig<T>> {
|
|
17
|
+
const [form, setForm] = useState<Partial<T>>(initialState);
|
|
18
|
+
const isValid = useMemo(
|
|
19
|
+
() =>
|
|
20
|
+
!Object.keys(config).some(
|
|
21
|
+
(a) => typeof config[a].validator(form[a], form) === "string"
|
|
22
|
+
),
|
|
23
|
+
[form]
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const _setFormField: <K extends keyof T>(k: K, value: T[K]) => void = (key, value) => {
|
|
27
|
+
setForm(prev => ({
|
|
28
|
+
...prev,
|
|
29
|
+
[key]: value
|
|
30
|
+
}))
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const validFormFields = useMemo(() => {
|
|
34
|
+
return Object.keys(config).reduce((result, field: keyof T) => {
|
|
35
|
+
const fieldConfig = config[field];
|
|
36
|
+
const invalidMessage = fieldConfig.validator(form[field], form);
|
|
37
|
+
return {
|
|
38
|
+
...result,
|
|
39
|
+
[field]: invalidMessage
|
|
40
|
+
}
|
|
41
|
+
}, { isValid } as { [k in keyof T]: string | true } & { isValid: boolean })
|
|
42
|
+
}, [form, isValid]);
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
form: form,
|
|
46
|
+
formValidation: validFormFields,
|
|
47
|
+
set: _setFormField
|
|
48
|
+
} as any
|
|
49
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useRef } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This hook pipes a data and when it is set to a falsy value ("", undefined, null, 0),
|
|
5
|
+
* it returns the previous valid value
|
|
6
|
+
*/
|
|
7
|
+
export default function useFreeze<T>(something: T) {
|
|
8
|
+
const currChildOrPrev = useRef<T>(undefined);
|
|
9
|
+
currChildOrPrev.current =
|
|
10
|
+
something === undefined ? currChildOrPrev.current : something;
|
|
11
|
+
return currChildOrPrev.current;
|
|
12
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
@import "../assets/styles/index.scss";
|
|
2
|
+
|
|
3
|
+
$timing: cubic-bezier(0.5, -0.45, 0.44, 1.37);
|
|
4
|
+
// $timing: cubic-bezier(0.73, -0.49, 0.16, 1.4);
|
|
5
|
+
|
|
6
|
+
.acceleration {
|
|
7
|
+
--animation--speed-fast: 1s;
|
|
8
|
+
animation-name: acceleration;
|
|
9
|
+
animation-duration: var(--animation--speed-fast);
|
|
10
|
+
animation-timing-function: $timing;
|
|
11
|
+
transition-timing-function: $timing !important;
|
|
12
|
+
transform-origin: var(--origin-1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@keyframes acceleration {
|
|
16
|
+
0% {
|
|
17
|
+
transform: rotateY(0deg);
|
|
18
|
+
}
|
|
19
|
+
10% {
|
|
20
|
+
transform-origin: var(--origin-1);
|
|
21
|
+
transform: var(--stage-1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
70% {
|
|
25
|
+
transform: var(--stage-1);
|
|
26
|
+
transform-origin: var(--origin-1);
|
|
27
|
+
}
|
|
28
|
+
85% {
|
|
29
|
+
transform-origin: var(--origin-2);
|
|
30
|
+
transform: var(--stage-2);
|
|
31
|
+
}
|
|
32
|
+
100% {
|
|
33
|
+
transform: rotateY(0deg);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.component:not([data-hero-clone]) {
|
|
38
|
+
transition: height $fast linear, opacity $fast linear, min-height $fast linear,
|
|
39
|
+
max-height $fast linear !important;
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
}
|