@onepercentio/one-ui 0.28.8 → 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 +4 -1
- 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,495 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
AnimationEvent,
|
|
3
|
+
createRef,
|
|
4
|
+
CSSProperties,
|
|
5
|
+
DetailedHTMLProps,
|
|
6
|
+
ForwardedRef,
|
|
7
|
+
forwardRef,
|
|
8
|
+
Key,
|
|
9
|
+
MutableRefObject,
|
|
10
|
+
ReactElement,
|
|
11
|
+
useEffect,
|
|
12
|
+
useMemo,
|
|
13
|
+
useRef,
|
|
14
|
+
useState,
|
|
15
|
+
} from "react";
|
|
16
|
+
import Styles from "./Transition.module.scss";
|
|
17
|
+
|
|
18
|
+
export type TransitionTypeDefinitions =
|
|
19
|
+
| {
|
|
20
|
+
transitionType?:
|
|
21
|
+
| TransitionAnimationTypes.SLIDE
|
|
22
|
+
| TransitionAnimationTypes.POP_FROM_CLICK_ORIGIN
|
|
23
|
+
| TransitionAnimationTypes.FADE
|
|
24
|
+
| TransitionAnimationTypes.COIN_FLIP;
|
|
25
|
+
}
|
|
26
|
+
| {
|
|
27
|
+
transitionType?: TransitionAnimationTypes.POP_FROM_ELEMENT_ID;
|
|
28
|
+
elementId: string;
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
transitionType?: TransitionAnimationTypes.MASK;
|
|
32
|
+
/**
|
|
33
|
+
* It provides the transition container so you can create a dynamic svg to mask with
|
|
34
|
+
*/
|
|
35
|
+
maskFactory: (container: HTMLDivElement) => string;
|
|
36
|
+
}
|
|
37
|
+
| {
|
|
38
|
+
transitionType?: TransitionAnimationTypes.CUSTOM;
|
|
39
|
+
config: ReturnType<typeof TransitionClasses>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type TransitionProps = {
|
|
43
|
+
step: number;
|
|
44
|
+
className?: string;
|
|
45
|
+
contentStyle?: React.CSSProperties;
|
|
46
|
+
contentClassName?: string;
|
|
47
|
+
children: (React.ReactElement | undefined)[];
|
|
48
|
+
onDiscardStep?: (discardedKey: React.Key, startedAnimationAt: number) => void;
|
|
49
|
+
lockTransitionWidth?: boolean;
|
|
50
|
+
lockTransitionHeight?: boolean;
|
|
51
|
+
} & TransitionTypeDefinitions &
|
|
52
|
+
Omit<
|
|
53
|
+
DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, any>,
|
|
54
|
+
"className" | "children"
|
|
55
|
+
>;
|
|
56
|
+
|
|
57
|
+
function TransitionClasses(
|
|
58
|
+
type: NonNullable<
|
|
59
|
+
Exclude<TransitionProps["transitionType"], TransitionAnimationTypes.CUSTOM>
|
|
60
|
+
>
|
|
61
|
+
): {
|
|
62
|
+
/**
|
|
63
|
+
* Applied to the element that was not visible and is now entering the screen
|
|
64
|
+
*/
|
|
65
|
+
backward: {
|
|
66
|
+
elementEntering: string;
|
|
67
|
+
elementExiting: string;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Applied to the element that was visible and now is exiting the screen
|
|
71
|
+
*/
|
|
72
|
+
forward: {
|
|
73
|
+
elementEntering: string;
|
|
74
|
+
elementExiting: string;
|
|
75
|
+
};
|
|
76
|
+
} {
|
|
77
|
+
switch (type) {
|
|
78
|
+
case TransitionAnimationTypes.COIN_FLIP:
|
|
79
|
+
return {
|
|
80
|
+
backward: {
|
|
81
|
+
elementExiting: Styles.flipBottomUpOut,
|
|
82
|
+
elementEntering: Styles.flipBottomUpIn,
|
|
83
|
+
},
|
|
84
|
+
forward: {
|
|
85
|
+
elementExiting: Styles.flipBottomUpOut,
|
|
86
|
+
elementEntering: Styles.flipBottomUpIn,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
case TransitionAnimationTypes.FADE:
|
|
90
|
+
return {
|
|
91
|
+
backward: {
|
|
92
|
+
elementExiting: Styles.fadeOutAbsolute,
|
|
93
|
+
elementEntering: Styles.fadeInDelayed,
|
|
94
|
+
},
|
|
95
|
+
forward: {
|
|
96
|
+
elementExiting: Styles.fadeOutAbsolute,
|
|
97
|
+
elementEntering: Styles.fadeInDelayed,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
case TransitionAnimationTypes.SLIDE:
|
|
101
|
+
return {
|
|
102
|
+
backward: {
|
|
103
|
+
elementEntering: Styles.entranceLeft,
|
|
104
|
+
elementExiting: "",
|
|
105
|
+
},
|
|
106
|
+
forward: {
|
|
107
|
+
elementEntering: "",
|
|
108
|
+
elementExiting: Styles.exitLeft,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
case TransitionAnimationTypes.POP_FROM_CLICK_ORIGIN:
|
|
112
|
+
case TransitionAnimationTypes.POP_FROM_ELEMENT_ID:
|
|
113
|
+
return {
|
|
114
|
+
backward: {
|
|
115
|
+
elementEntering: Styles.fadeIn,
|
|
116
|
+
elementExiting: Styles.scaleOut,
|
|
117
|
+
},
|
|
118
|
+
forward: {
|
|
119
|
+
elementEntering: Styles.scaleIn,
|
|
120
|
+
elementExiting: Styles.fadeOut,
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
case TransitionAnimationTypes.MASK:
|
|
124
|
+
return {
|
|
125
|
+
backward: {
|
|
126
|
+
elementEntering: Styles.stubEntering,
|
|
127
|
+
elementExiting: Styles.stub,
|
|
128
|
+
},
|
|
129
|
+
forward: {
|
|
130
|
+
elementEntering: Styles.stubEntering,
|
|
131
|
+
elementExiting: Styles.stub,
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
type ChildrenWrapper = ((props: {
|
|
138
|
+
children: TransitionProps["children"][number];
|
|
139
|
+
}) => ReactElement) & {
|
|
140
|
+
createdAt: number;
|
|
141
|
+
associatedKey: Key;
|
|
142
|
+
toRemoveKeys?: Key[];
|
|
143
|
+
externalProps: { [k: string]: any };
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
function ChildrenWrapperFactory(
|
|
147
|
+
func: (p: { children: TransitionProps["children"] }) => ReactElement,
|
|
148
|
+
key: Key,
|
|
149
|
+
externalPropsContainer: { [k: string]: any },
|
|
150
|
+
/** This is used to prevent newer "duplicated" keys from being removed after the new element finished animation */
|
|
151
|
+
timestamp: number,
|
|
152
|
+
toRemoveKeys?: Key[]
|
|
153
|
+
): ChildrenWrapper {
|
|
154
|
+
(func as any).createdAt = timestamp;
|
|
155
|
+
(func as any).associatedKey = key;
|
|
156
|
+
(func as any).toRemoveKeys = toRemoveKeys;
|
|
157
|
+
(func as any).externalProps = externalPropsContainer;
|
|
158
|
+
return func as unknown as ChildrenWrapper;
|
|
159
|
+
}
|
|
160
|
+
function _Transition(
|
|
161
|
+
{
|
|
162
|
+
step,
|
|
163
|
+
contentStyle,
|
|
164
|
+
contentClassName = "",
|
|
165
|
+
children,
|
|
166
|
+
className,
|
|
167
|
+
onDiscardStep,
|
|
168
|
+
lockTransitionWidth = false,
|
|
169
|
+
lockTransitionHeight = false,
|
|
170
|
+
...props
|
|
171
|
+
}: TransitionProps,
|
|
172
|
+
_containerRef: ForwardedRef<HTMLDivElement | null>
|
|
173
|
+
) {
|
|
174
|
+
const containerRef = useMemo(
|
|
175
|
+
() =>
|
|
176
|
+
(_containerRef as MutableRefObject<HTMLDivElement | null>) || createRef(),
|
|
177
|
+
[_containerRef]
|
|
178
|
+
);
|
|
179
|
+
const preTransitionDetails = useRef<CSSProperties>({
|
|
180
|
+
transformOrigin: "initial",
|
|
181
|
+
});
|
|
182
|
+
const [childrenWrappers, setChildrenWrappers] = useState<
|
|
183
|
+
(ChildrenWrapper | undefined)[]
|
|
184
|
+
>(() => {
|
|
185
|
+
const externalProps = {
|
|
186
|
+
"data-testid": "transition-container",
|
|
187
|
+
key: String(children[step]?.key || step),
|
|
188
|
+
style: contentStyle,
|
|
189
|
+
className: contentClassName,
|
|
190
|
+
};
|
|
191
|
+
const func = ChildrenWrapperFactory(
|
|
192
|
+
({ children }) => <div {...externalProps}>{children}</div>,
|
|
193
|
+
children[step]!.key || step,
|
|
194
|
+
externalProps,
|
|
195
|
+
Date.now(),
|
|
196
|
+
[]
|
|
197
|
+
);
|
|
198
|
+
return [func];
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const prevStep = useRef(step);
|
|
202
|
+
const prevChild = useRef(children[step]);
|
|
203
|
+
|
|
204
|
+
useEffect(() => () => {
|
|
205
|
+
prevChild.current = children[step];
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
useEffect(() => {
|
|
209
|
+
containerRef.current!.style.overflow = "hidden";
|
|
210
|
+
const transitionClasses =
|
|
211
|
+
props.transitionType === TransitionAnimationTypes.CUSTOM
|
|
212
|
+
? props.config
|
|
213
|
+
: TransitionClasses(
|
|
214
|
+
props.transitionType || TransitionAnimationTypes.SLIDE
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
if (
|
|
218
|
+
prevChild.current !== null &&
|
|
219
|
+
children[step]?.key === prevChild.current?.key // I'm rendering the same screen
|
|
220
|
+
) {
|
|
221
|
+
return () => {
|
|
222
|
+
prevStep.current = step;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const key = children[step]?.key || step;
|
|
227
|
+
|
|
228
|
+
if (prevStep.current !== step && lockTransitionWidth)
|
|
229
|
+
containerRef.current!.style.width = `${
|
|
230
|
+
containerRef.current!.clientWidth
|
|
231
|
+
}px`;
|
|
232
|
+
|
|
233
|
+
if (prevStep.current !== step && lockTransitionHeight)
|
|
234
|
+
containerRef.current!.style.height = `${
|
|
235
|
+
containerRef.current!.clientHeight
|
|
236
|
+
}px`;
|
|
237
|
+
const transitionMask =
|
|
238
|
+
props.transitionType === TransitionAnimationTypes.MASK
|
|
239
|
+
? props.maskFactory(containerRef.current!)
|
|
240
|
+
: "";
|
|
241
|
+
const insertedAt = Date.now();
|
|
242
|
+
|
|
243
|
+
/** This runs on backwards */
|
|
244
|
+
if (prevStep.current > step) {
|
|
245
|
+
const stepToRemove = prevStep.current;
|
|
246
|
+
const prevKeyToRemove = prevChild.current?.key || stepToRemove;
|
|
247
|
+
setChildrenWrappers((screensBeforeChangingStep) => {
|
|
248
|
+
const enteringScreenRef = createRef<HTMLDivElement>();
|
|
249
|
+
const [FirstNextScreen, ...restOfScreens] =
|
|
250
|
+
screensBeforeChangingStep.filter(
|
|
251
|
+
(a) => a?.associatedKey !== String(key)
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
if (FirstNextScreen) {
|
|
255
|
+
Object.assign(FirstNextScreen.externalProps, {
|
|
256
|
+
"data-testid": "transition-container",
|
|
257
|
+
style: { ...contentStyle, WebkitMaskImage: transitionMask },
|
|
258
|
+
className: `${transitionClasses.backward.elementExiting}`,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function animationEndListener(event: AnimationEvent<HTMLDivElement>) {
|
|
262
|
+
if (event.target !== event.currentTarget) return;
|
|
263
|
+
|
|
264
|
+
const isAnimationFromExpectedState =
|
|
265
|
+
enteringScreenRef.current?.classList.contains(
|
|
266
|
+
transitionClasses.backward.elementEntering
|
|
267
|
+
);
|
|
268
|
+
enteringScreenRef.current?.classList.remove(
|
|
269
|
+
transitionClasses.backward.elementEntering
|
|
270
|
+
);
|
|
271
|
+
setChildrenWrappers((screensAfterTheCurrentStepEntered) => {
|
|
272
|
+
if (onDiscardStep) {
|
|
273
|
+
if (isAnimationFromExpectedState)
|
|
274
|
+
onDiscardStep(prevKeyToRemove, insertedAt);
|
|
275
|
+
if (FirstNextScreen && FirstNextScreen.toRemoveKeys)
|
|
276
|
+
FirstNextScreen.toRemoveKeys.forEach(onDiscardStep);
|
|
277
|
+
}
|
|
278
|
+
return screensAfterTheCurrentStepEntered.filter((s) => {
|
|
279
|
+
const shouldKeep =
|
|
280
|
+
(s?.associatedKey !== String(prevKeyToRemove) &&
|
|
281
|
+
!FirstNextScreen?.toRemoveKeys?.some(
|
|
282
|
+
(k) => String(k) === String(s?.associatedKey)
|
|
283
|
+
)) ||
|
|
284
|
+
s!.createdAt! > insertedAt;
|
|
285
|
+
return shouldKeep;
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
event.currentTarget.removeEventListener(
|
|
289
|
+
"animationend",
|
|
290
|
+
animationEndListener as any
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
const propsContainer = {
|
|
294
|
+
ref: enteringScreenRef,
|
|
295
|
+
"data-testid": "transition-container",
|
|
296
|
+
key,
|
|
297
|
+
className: `${transitionClasses.backward.elementEntering} ${contentClassName}`,
|
|
298
|
+
style: {
|
|
299
|
+
...contentStyle,
|
|
300
|
+
},
|
|
301
|
+
onAnimationEnd: animationEndListener,
|
|
302
|
+
};
|
|
303
|
+
const newWrapper = ChildrenWrapperFactory(
|
|
304
|
+
({ children }) => {
|
|
305
|
+
return <div {...propsContainer}>{children}</div>;
|
|
306
|
+
},
|
|
307
|
+
key,
|
|
308
|
+
propsContainer,
|
|
309
|
+
insertedAt,
|
|
310
|
+
[prevKeyToRemove, ...(FirstNextScreen?.toRemoveKeys || [])]
|
|
311
|
+
);
|
|
312
|
+
if (FirstNextScreen)
|
|
313
|
+
return [
|
|
314
|
+
newWrapper,
|
|
315
|
+
FirstNextScreen ||
|
|
316
|
+
ChildrenWrapperFactory(
|
|
317
|
+
() => <React.Fragment />,
|
|
318
|
+
"",
|
|
319
|
+
{},
|
|
320
|
+
insertedAt
|
|
321
|
+
),
|
|
322
|
+
...restOfScreens,
|
|
323
|
+
];
|
|
324
|
+
else return [newWrapper];
|
|
325
|
+
});
|
|
326
|
+
} else if (prevStep.current < step) {
|
|
327
|
+
const stepToDelete = prevStep.current;
|
|
328
|
+
const prevKeyToRemove = String(prevChild.current?.key || stepToDelete);
|
|
329
|
+
setChildrenWrappers((screensBeforeChangingStep) => {
|
|
330
|
+
const lastIndex = screensBeforeChangingStep.length - 1;
|
|
331
|
+
const lastWrapper = screensBeforeChangingStep[lastIndex];
|
|
332
|
+
const nextScreenRef = createRef<HTMLDivElement>();
|
|
333
|
+
if (lastWrapper) {
|
|
334
|
+
Object.assign(lastWrapper.externalProps, {
|
|
335
|
+
"data-testid": "transition-container",
|
|
336
|
+
style: { ...contentStyle, WebkitMaskImage: transitionMask },
|
|
337
|
+
className: `${contentClassName} ${transitionClasses.forward.elementExiting}`,
|
|
338
|
+
onAnimationEnd: (e: AnimationEvent) => {
|
|
339
|
+
if (e.target !== e.currentTarget) return;
|
|
340
|
+
if (transitionClasses.forward.elementEntering)
|
|
341
|
+
nextScreenRef.current?.classList.remove(
|
|
342
|
+
transitionClasses.forward.elementEntering
|
|
343
|
+
);
|
|
344
|
+
if (onDiscardStep) onDiscardStep(prevKeyToRemove, insertedAt);
|
|
345
|
+
setChildrenWrappers((screensAfterTheCurrentStepEntered) => {
|
|
346
|
+
const nextState = screensAfterTheCurrentStepEntered.filter(
|
|
347
|
+
(s) => {
|
|
348
|
+
const shouldMantain =
|
|
349
|
+
s?.associatedKey !== String(prevKeyToRemove) ||
|
|
350
|
+
s.createdAt > insertedAt;
|
|
351
|
+
return shouldMantain;
|
|
352
|
+
}
|
|
353
|
+
);
|
|
354
|
+
return nextState;
|
|
355
|
+
});
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
const propsContainer = {
|
|
360
|
+
ref: nextScreenRef,
|
|
361
|
+
"data-testid": "transition-container",
|
|
362
|
+
key,
|
|
363
|
+
style: {
|
|
364
|
+
...contentStyle,
|
|
365
|
+
},
|
|
366
|
+
className: `${contentClassName} ${transitionClasses.forward.elementEntering}`,
|
|
367
|
+
};
|
|
368
|
+
const newWrapper = ChildrenWrapperFactory(
|
|
369
|
+
({ children }) => {
|
|
370
|
+
return <div {...propsContainer}>{children}</div>;
|
|
371
|
+
},
|
|
372
|
+
key,
|
|
373
|
+
propsContainer,
|
|
374
|
+
insertedAt
|
|
375
|
+
);
|
|
376
|
+
return [
|
|
377
|
+
...screensBeforeChangingStep.slice(0, lastIndex),
|
|
378
|
+
lastWrapper ||
|
|
379
|
+
ChildrenWrapperFactory(
|
|
380
|
+
() => <React.Fragment />,
|
|
381
|
+
"fallback",
|
|
382
|
+
{},
|
|
383
|
+
insertedAt
|
|
384
|
+
),
|
|
385
|
+
newWrapper,
|
|
386
|
+
];
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
return () => {
|
|
390
|
+
prevStep.current = step;
|
|
391
|
+
};
|
|
392
|
+
}, [step]);
|
|
393
|
+
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
if (childrenWrappers.length === 1 && lockTransitionWidth)
|
|
396
|
+
containerRef.current!.style.width = "";
|
|
397
|
+
if (childrenWrappers.length === 1 && lockTransitionHeight)
|
|
398
|
+
containerRef.current!.style.height = "";
|
|
399
|
+
}, [childrenWrappers.length !== 1]);
|
|
400
|
+
|
|
401
|
+
useEffect(() => {
|
|
402
|
+
if (
|
|
403
|
+
props.transitionType === TransitionAnimationTypes.POP_FROM_ELEMENT_ID &&
|
|
404
|
+
"elementId" in props
|
|
405
|
+
) {
|
|
406
|
+
const element = document.querySelector(
|
|
407
|
+
`#${props.elementId}`
|
|
408
|
+
) as HTMLDivElement;
|
|
409
|
+
|
|
410
|
+
if (element) {
|
|
411
|
+
const { clientWidth, clientHeight } = containerRef.current!;
|
|
412
|
+
|
|
413
|
+
const offsetX =
|
|
414
|
+
element.clientLeft + element.offsetLeft + element.clientWidth / 2;
|
|
415
|
+
const offsetY =
|
|
416
|
+
element.clientTop + element.offsetTop + element.clientHeight / 2;
|
|
417
|
+
const percentX = (offsetX * 100) / clientWidth;
|
|
418
|
+
const percentY = (offsetY * 100) / clientHeight;
|
|
419
|
+
preTransitionDetails.current.transformOrigin = `${percentX}% ${percentY}%`;
|
|
420
|
+
|
|
421
|
+
Object.assign(containerRef.current!.style, {
|
|
422
|
+
transformOrigin: `${percentX}% ${percentY}%`,
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
} else {
|
|
426
|
+
Object.assign(containerRef.current!.style, preTransitionDetails.current);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (childrenWrappers.length === 1) {
|
|
430
|
+
containerRef.current!.style.overflow = "";
|
|
431
|
+
}
|
|
432
|
+
}, [childrenWrappers.length]);
|
|
433
|
+
|
|
434
|
+
const propsToSpread = { ...props } as any;
|
|
435
|
+
delete propsToSpread.transitionType;
|
|
436
|
+
delete propsToSpread.config;
|
|
437
|
+
|
|
438
|
+
return (
|
|
439
|
+
<>
|
|
440
|
+
<section
|
|
441
|
+
{...propsToSpread}
|
|
442
|
+
onClick={(e) => {
|
|
443
|
+
const {
|
|
444
|
+
currentTarget: { offsetTop, offsetLeft, clientWidth, clientHeight },
|
|
445
|
+
clientX,
|
|
446
|
+
clientY,
|
|
447
|
+
} = e;
|
|
448
|
+
const offsetX = clientX - offsetLeft;
|
|
449
|
+
const offsetY = clientY - offsetTop;
|
|
450
|
+
const percentX = (offsetX * 100) / clientWidth;
|
|
451
|
+
const percentY = (offsetY * 100) / clientHeight;
|
|
452
|
+
|
|
453
|
+
if (
|
|
454
|
+
props.transitionType ===
|
|
455
|
+
TransitionAnimationTypes.POP_FROM_ELEMENT_ID ||
|
|
456
|
+
props.transitionType ===
|
|
457
|
+
TransitionAnimationTypes.POP_FROM_CLICK_ORIGIN
|
|
458
|
+
)
|
|
459
|
+
preTransitionDetails.current.transformOrigin = `${percentX}% ${percentY}%`;
|
|
460
|
+
if (props.onClick) props.onClick(e as any);
|
|
461
|
+
}}
|
|
462
|
+
data-testid="transition-controller"
|
|
463
|
+
ref={containerRef}
|
|
464
|
+
className={`${Styles.section} ${className}`}
|
|
465
|
+
>
|
|
466
|
+
{(childrenWrappers as ChildrenWrapper[]).map((Wrapper) => {
|
|
467
|
+
const childToRender = children.find(
|
|
468
|
+
(a, i) => (a?.key || i) === Wrapper?.associatedKey
|
|
469
|
+
);
|
|
470
|
+
return (
|
|
471
|
+
<Wrapper key={`${Wrapper!.associatedKey} ${Wrapper.createdAt}`}>
|
|
472
|
+
<>{childToRender}</>
|
|
473
|
+
</Wrapper>
|
|
474
|
+
);
|
|
475
|
+
})}
|
|
476
|
+
</section>
|
|
477
|
+
</>
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
export enum TransitionAnimationTypes {
|
|
482
|
+
SLIDE,
|
|
483
|
+
POP_FROM_CLICK_ORIGIN,
|
|
484
|
+
POP_FROM_ELEMENT_ID,
|
|
485
|
+
FADE,
|
|
486
|
+
COIN_FLIP,
|
|
487
|
+
MASK,
|
|
488
|
+
CUSTOM,
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Handles the transition between multiple children and recycling of elements
|
|
493
|
+
**/
|
|
494
|
+
const Transition = forwardRef(_Transition);
|
|
495
|
+
export default Transition;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, TransitionAnimationTypes } from "./Transition";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import UncontrolledTransition from "../UncontrolledTransition";
|
|
4
|
+
import Button from "../Button";
|
|
5
|
+
|
|
6
|
+
function colorGen() {
|
|
7
|
+
return [255 * Math.random(), 255 * Math.random(), 255 * Math.random()];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function Example() {
|
|
11
|
+
const [color, setColor] = useState(colorGen);
|
|
12
|
+
const rgb = `rgb(${color.join(",")})`;
|
|
13
|
+
return (
|
|
14
|
+
<UncontrolledTransition>
|
|
15
|
+
<div
|
|
16
|
+
key={color.join("")}
|
|
17
|
+
style={{
|
|
18
|
+
width: "100vw",
|
|
19
|
+
height: "100vh",
|
|
20
|
+
backgroundColor: rgb,
|
|
21
|
+
textAlign: "center",
|
|
22
|
+
}}
|
|
23
|
+
>
|
|
24
|
+
<Button variant="filled" onClick={() => setColor(colorGen())}>
|
|
25
|
+
Click to transition
|
|
26
|
+
</Button>
|
|
27
|
+
<h2>RGB</h2>
|
|
28
|
+
<p>{color[0].toFixed(0)}</p>
|
|
29
|
+
<p>{color[1].toFixed(0)}</p>
|
|
30
|
+
<p>{color[2].toFixed(0)}</p>
|
|
31
|
+
</div>
|
|
32
|
+
</UncontrolledTransition>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
DetailedHTMLProps,
|
|
3
|
+
ForwardedRef,
|
|
4
|
+
forwardRef,
|
|
5
|
+
Key,
|
|
6
|
+
RefObject,
|
|
7
|
+
useEffect,
|
|
8
|
+
useImperativeHandle,
|
|
9
|
+
useLayoutEffect,
|
|
10
|
+
useRef,
|
|
11
|
+
useState,
|
|
12
|
+
} from "react";
|
|
13
|
+
import Transition from "../Transition";
|
|
14
|
+
import {
|
|
15
|
+
TransitionProps,
|
|
16
|
+
TransitionTypeDefinitions,
|
|
17
|
+
} from "../Transition/Transition";
|
|
18
|
+
|
|
19
|
+
function _UncontrolledTransition(
|
|
20
|
+
{
|
|
21
|
+
className = "",
|
|
22
|
+
contentClassName,
|
|
23
|
+
children = <React.Fragment key="default"></React.Fragment>,
|
|
24
|
+
lockTransitionWidth = true,
|
|
25
|
+
lockTransitionHeight = false,
|
|
26
|
+
contentStyle,
|
|
27
|
+
onDiscardStep,
|
|
28
|
+
...props
|
|
29
|
+
}: {
|
|
30
|
+
className?: string;
|
|
31
|
+
contentClassName?: string;
|
|
32
|
+
children?: React.ReactElement;
|
|
33
|
+
lockTransitionWidth?: boolean;
|
|
34
|
+
lockTransitionHeight?: boolean;
|
|
35
|
+
onDiscardStep?: (key: Key) => void;
|
|
36
|
+
} & Pick<TransitionProps, "contentStyle"> &
|
|
37
|
+
TransitionTypeDefinitions &
|
|
38
|
+
Omit<
|
|
39
|
+
DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, any>,
|
|
40
|
+
"className" | "children" | "ref"
|
|
41
|
+
>,
|
|
42
|
+
ref: ForwardedRef<{
|
|
43
|
+
setOrientation: (orientation: "forward" | "backward") => void;
|
|
44
|
+
sectionRef: RefObject<HTMLDivElement | null>;
|
|
45
|
+
}>
|
|
46
|
+
) {
|
|
47
|
+
const sectionRef = useRef<HTMLDivElement>(null);
|
|
48
|
+
const [{ childStack, offset }, setChildStack] = useState<{
|
|
49
|
+
childStack: (React.ReactElement & { createdAt: number })[];
|
|
50
|
+
offset: number;
|
|
51
|
+
}>(() => ({
|
|
52
|
+
childStack: [{ ...children, createdAt: Date.now() }],
|
|
53
|
+
offset: 1,
|
|
54
|
+
}));
|
|
55
|
+
const orientation = useRef<"forward" | "backward">("forward");
|
|
56
|
+
function setOrientation(a: typeof orientation.current) {
|
|
57
|
+
orientation.current = a;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
useImperativeHandle(
|
|
61
|
+
ref,
|
|
62
|
+
() => ({
|
|
63
|
+
setOrientation,
|
|
64
|
+
sectionRef,
|
|
65
|
+
}),
|
|
66
|
+
[]
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
useLayoutEffect(() => {
|
|
70
|
+
if (process.env.NODE_ENV !== "production" && !children.key)
|
|
71
|
+
throw new Error(
|
|
72
|
+
"The provided child should have a key property, please provide it"
|
|
73
|
+
);
|
|
74
|
+
if (childStack.length === 1 && childStack[0].key === children.key) return;
|
|
75
|
+
if (orientation.current === "forward")
|
|
76
|
+
setChildStack((p) => ({
|
|
77
|
+
...p,
|
|
78
|
+
childStack: [...p.childStack, { ...children, createdAt: Date.now() }],
|
|
79
|
+
}));
|
|
80
|
+
else
|
|
81
|
+
setChildStack((p) => ({
|
|
82
|
+
...p,
|
|
83
|
+
childStack: [{ ...children, createdAt: Date.now() }, ...p.childStack],
|
|
84
|
+
}));
|
|
85
|
+
}, [children.key]);
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (orientation.current === "backward") {
|
|
89
|
+
setChildStack((prev) => {
|
|
90
|
+
return {
|
|
91
|
+
...prev,
|
|
92
|
+
offset: prev.childStack.length,
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}, [childStack.length]);
|
|
97
|
+
|
|
98
|
+
childStack.forEach((a, i, arr) => {
|
|
99
|
+
if (a.key === children.key)
|
|
100
|
+
arr[i] = { ...children, createdAt: a.createdAt };
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
const predictedStep = childStack.length - offset;
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<>
|
|
107
|
+
{childStack.length ? (
|
|
108
|
+
<Transition
|
|
109
|
+
ref={sectionRef}
|
|
110
|
+
contentStyle={contentStyle}
|
|
111
|
+
className={className}
|
|
112
|
+
step={predictedStep}
|
|
113
|
+
onDiscardStep={(discardedKey, animatedAt) => {
|
|
114
|
+
setTimeout(() => {
|
|
115
|
+
if (onDiscardStep) onDiscardStep(discardedKey);
|
|
116
|
+
orientation.current = "forward";
|
|
117
|
+
setChildStack((prev) => {
|
|
118
|
+
return {
|
|
119
|
+
childStack: prev.childStack.filter((a) => {
|
|
120
|
+
return a.key !== discardedKey || a.createdAt > animatedAt;
|
|
121
|
+
}),
|
|
122
|
+
offset: prev.offset === 1 ? 1 : prev.offset - 1,
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
}, 0)
|
|
126
|
+
}}
|
|
127
|
+
lockTransitionWidth={lockTransitionWidth}
|
|
128
|
+
lockTransitionHeight={lockTransitionHeight}
|
|
129
|
+
contentClassName={contentClassName}
|
|
130
|
+
{...props}
|
|
131
|
+
>
|
|
132
|
+
{childStack}
|
|
133
|
+
</Transition>
|
|
134
|
+
) : null}
|
|
135
|
+
</>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* This component receives child with key and applies a transition when the key changes, allowing to swap elements with a fine transition.
|
|
141
|
+
**/
|
|
142
|
+
export const UncontrolledTransition = forwardRef(_UncontrolledTransition);
|
|
143
|
+
export default UncontrolledTransition;
|