@rabbitio/ui-kit 1.0.0-beta.43 → 1.0.0-beta.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/coverage/clover.xml +5262 -821
  2. package/coverage/coverage-final.json +25 -1
  3. package/coverage/index.html +311 -26
  4. package/coverage/rabbit-ui-kit/index.html +1 -1
  5. package/coverage/rabbit-ui-kit/index.js.html +1 -1
  6. package/coverage/rabbit-ui-kit/src/common/adapters/axiosAdapter.js.html +1 -1
  7. package/coverage/rabbit-ui-kit/src/common/adapters/index.html +1 -1
  8. package/coverage/rabbit-ui-kit/src/common/amountUtils.js.html +1 -1
  9. package/coverage/rabbit-ui-kit/src/common/errorUtils.js.html +1 -1
  10. package/coverage/rabbit-ui-kit/src/common/external-apis/apiGroups.js.html +1 -1
  11. package/coverage/rabbit-ui-kit/src/common/external-apis/index.html +1 -1
  12. package/coverage/rabbit-ui-kit/src/common/external-apis/ipAddressProviders.js.html +1 -1
  13. package/coverage/rabbit-ui-kit/src/common/fiatCurrenciesService.js.html +1 -1
  14. package/coverage/rabbit-ui-kit/src/common/index.html +1 -1
  15. package/coverage/rabbit-ui-kit/src/common/models/blockchain.js.html +1 -1
  16. package/coverage/rabbit-ui-kit/src/common/models/coin.js.html +1 -1
  17. package/coverage/rabbit-ui-kit/src/common/models/index.html +1 -1
  18. package/coverage/rabbit-ui-kit/src/common/models/protocol.js.html +1 -1
  19. package/coverage/rabbit-ui-kit/src/common/utils/cache.js.html +1 -1
  20. package/coverage/rabbit-ui-kit/src/common/utils/emailAPI.js.html +1 -1
  21. package/coverage/rabbit-ui-kit/src/common/utils/index.html +1 -1
  22. package/coverage/rabbit-ui-kit/src/common/utils/logging/index.html +1 -1
  23. package/coverage/rabbit-ui-kit/src/common/utils/logging/logger.js.html +1 -1
  24. package/coverage/rabbit-ui-kit/src/common/utils/logging/logsStorage.js.html +1 -1
  25. package/coverage/rabbit-ui-kit/src/common/utils/postponeExecution.js.html +1 -1
  26. package/coverage/rabbit-ui-kit/src/common/utils/safeStringify.js.html +1 -1
  27. package/coverage/rabbit-ui-kit/src/components/atoms/AssetIcon/AssetIcon.jsx.html +1 -1
  28. package/coverage/rabbit-ui-kit/src/components/atoms/AssetIcon/index.html +1 -1
  29. package/coverage/rabbit-ui-kit/src/components/atoms/AssetSelection/AssetSelection.jsx.html +364 -0
  30. package/coverage/rabbit-ui-kit/src/components/atoms/AssetSelection/index.html +116 -0
  31. package/coverage/rabbit-ui-kit/src/components/atoms/BackgroundTitle/BackgroundTitle.jsx.html +217 -0
  32. package/coverage/rabbit-ui-kit/src/components/atoms/BackgroundTitle/index.html +116 -0
  33. package/coverage/rabbit-ui-kit/src/components/atoms/LoadingDots/LoadingDots.jsx.html +1 -1
  34. package/coverage/rabbit-ui-kit/src/components/atoms/LoadingDots/index.html +1 -1
  35. package/coverage/rabbit-ui-kit/src/components/atoms/NoticeIcon/NoticeIcon.jsx.html +298 -0
  36. package/coverage/rabbit-ui-kit/src/components/atoms/NoticeIcon/index.html +116 -0
  37. package/coverage/rabbit-ui-kit/src/components/atoms/SupportChat/SupportChat.jsx.html +1 -1
  38. package/coverage/rabbit-ui-kit/src/components/atoms/SupportChat/index.html +1 -1
  39. package/coverage/rabbit-ui-kit/src/components/atoms/TitleBox/TitleBox.jsx.html +574 -0
  40. package/coverage/rabbit-ui-kit/src/components/atoms/TitleBox/index.html +116 -0
  41. package/coverage/rabbit-ui-kit/src/components/atoms/Tooltip/Tooltip.jsx.html +370 -0
  42. package/coverage/rabbit-ui-kit/src/components/atoms/Tooltip/index.html +116 -0
  43. package/coverage/rabbit-ui-kit/src/components/atoms/Validation/Validation.jsx.html +475 -0
  44. package/coverage/rabbit-ui-kit/src/components/atoms/Validation/index.html +116 -0
  45. package/coverage/rabbit-ui-kit/src/components/atoms/buttons/Button/Button.jsx.html +1 -1
  46. package/coverage/rabbit-ui-kit/src/components/atoms/buttons/Button/index.html +1 -1
  47. package/coverage/rabbit-ui-kit/src/components/atoms/buttons/Close/Close.jsx.html +277 -0
  48. package/coverage/rabbit-ui-kit/src/components/atoms/buttons/Close/index.html +116 -0
  49. package/coverage/rabbit-ui-kit/src/components/atoms/buttons/LinkButton/LinkButton.jsx.html +448 -0
  50. package/coverage/rabbit-ui-kit/src/components/atoms/buttons/LinkButton/index.html +116 -0
  51. package/coverage/rabbit-ui-kit/src/components/hooks/index.html +1 -1
  52. package/coverage/rabbit-ui-kit/src/components/hooks/useCallHandlingErrors.js.html +1 -1
  53. package/coverage/rabbit-ui-kit/src/components/hooks/useReferredState.js.html +1 -1
  54. package/coverage/rabbit-ui-kit/src/components/molecules/AmountInput/AmountInput.jsx.html +1510 -0
  55. package/coverage/rabbit-ui-kit/src/components/molecules/AmountInput/index.html +116 -0
  56. package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/Dialog.jsx.html +1630 -0
  57. package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/DialogButtons/DialogButtons.jsx.html +451 -0
  58. package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/DialogButtons/index.html +116 -0
  59. package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/DialogStep/DialogStep.jsx.html +2077 -0
  60. package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/DialogStep/index.html +116 -0
  61. package/coverage/rabbit-ui-kit/src/components/organisms/Dialog/index.html +116 -0
  62. package/coverage/rabbit-ui-kit/src/components/organisms/SwapForm/SwapForm.jsx.html +3538 -0
  63. package/coverage/rabbit-ui-kit/src/components/organisms/SwapForm/index.html +116 -0
  64. package/coverage/rabbit-ui-kit/src/components/utils/index.html +24 -9
  65. package/coverage/rabbit-ui-kit/src/components/utils/inputValueProviders.js.html +1 -1
  66. package/coverage/rabbit-ui-kit/src/components/utils/textUtils.js.html +139 -0
  67. package/coverage/rabbit-ui-kit/src/components/utils/uiUtils.js.html +1 -1
  68. package/coverage/rabbit-ui-kit/src/components/utils/urlQueryUtils.js.html +1 -1
  69. package/coverage/rabbit-ui-kit/src/constants/organisms/dialog/DialogStep/dialogStep.js.html +88 -0
  70. package/coverage/rabbit-ui-kit/src/constants/organisms/dialog/DialogStep/index.html +116 -0
  71. package/coverage/rabbit-ui-kit/src/constants/organisms/dialog/dialog.js.html +172 -0
  72. package/coverage/rabbit-ui-kit/src/constants/organisms/dialog/index.html +116 -0
  73. package/coverage/rabbit-ui-kit/src/index.html +5 -5
  74. package/coverage/rabbit-ui-kit/src/index.js.html +65 -5
  75. package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/cacheAndConcurrentRequestsResolver.js.html +1 -1
  76. package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/cachedRobustExternalApiCallerService.js.html +1 -1
  77. package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/cancelProcessing.js.html +1 -1
  78. package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/concurrentCalculationsMetadataHolder.js.html +1 -1
  79. package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/externalApiProvider.js.html +1 -1
  80. package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/externalServicesStatsCollector.js.html +1 -1
  81. package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/index.html +1 -1
  82. package/coverage/rabbit-ui-kit/src/robustExteranlApiCallerService/robustExternalAPICallerService.js.html +1 -1
  83. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/index.html +1 -1
  84. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/swapProvider.js.html +1 -1
  85. package/coverage/rabbit-ui-kit/src/swaps-lib/external-apis/swapspaceSwapProvider.js.html +1 -1
  86. package/coverage/rabbit-ui-kit/src/swaps-lib/models/baseSwapCreationInfo.js.html +1 -1
  87. package/coverage/rabbit-ui-kit/src/swaps-lib/models/existingSwap.js.html +1 -1
  88. package/coverage/rabbit-ui-kit/src/swaps-lib/models/existingSwapWithFiatData.js.html +1 -1
  89. package/coverage/rabbit-ui-kit/src/swaps-lib/models/index.html +1 -1
  90. package/coverage/rabbit-ui-kit/src/swaps-lib/services/index.html +1 -1
  91. package/coverage/rabbit-ui-kit/src/swaps-lib/services/publicSwapService.js.html +1 -1
  92. package/coverage/rabbit-ui-kit/src/swaps-lib/utils/index.html +1 -1
  93. package/coverage/rabbit-ui-kit/src/swaps-lib/utils/swapUtils.js.html +1 -1
  94. package/coverage/rabbit-ui-kit/stories/atoms/BackgroundTitle.stories.jsx.html +202 -0
  95. package/coverage/rabbit-ui-kit/stories/atoms/LoadingDots.stories.jsx.html +1 -1
  96. package/coverage/rabbit-ui-kit/stories/atoms/Validation.stories.jsx.html +178 -0
  97. package/coverage/rabbit-ui-kit/stories/atoms/buttons/Button.stories.jsx.html +1 -1
  98. package/coverage/rabbit-ui-kit/stories/atoms/buttons/Close.stories.jsx.html +211 -0
  99. package/coverage/rabbit-ui-kit/stories/atoms/buttons/LinkButton.stories.jsx.html +298 -0
  100. package/coverage/rabbit-ui-kit/stories/atoms/buttons/index.html +35 -5
  101. package/coverage/rabbit-ui-kit/stories/atoms/index.html +35 -5
  102. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/Dialog.stories.jsx.html +574 -0
  103. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogButtons/DialogButtons.stories.jsx.html +328 -0
  104. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogButtons/index.html +116 -0
  105. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogStep/DialogStep.stories.jsx.html +352 -0
  106. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/DialogStep/index.html +116 -0
  107. package/coverage/rabbit-ui-kit/stories/organisms/Dialog/index.html +116 -0
  108. package/coverage/rabbit-ui-kit/stories/stubs/exampleContent.jsx.html +145 -0
  109. package/coverage/rabbit-ui-kit/stories/stubs/index.html +116 -0
  110. package/dist/index.cjs +3022 -231
  111. package/dist/index.cjs.map +1 -1
  112. package/dist/index.css +40976 -0
  113. package/dist/index.css.map +1 -1
  114. package/dist/index.modern.js +2568 -183
  115. package/dist/index.modern.js.map +1 -1
  116. package/dist/index.module.js +3010 -239
  117. package/dist/index.module.js.map +1 -1
  118. package/dist/index.umd.js +3019 -234
  119. package/dist/index.umd.js.map +1 -1
  120. package/package.json +7 -1
  121. package/src/assets/image/icons/arrow-darker.svg +14 -0
  122. package/src/assets/image/icons/arrow-tosca.svg +3 -0
  123. package/src/assets/image/icons/arrow-white.svg +14 -0
  124. package/src/assets/image/icons/dark-rectangle.svg +3 -0
  125. package/src/assets/image/icons/failed-validation-icon.svg +15 -0
  126. package/src/assets/image/icons/successful-validation-icon.svg +10 -0
  127. package/src/assets/image/icons/wallet-gray-small.svg +6 -0
  128. package/src/components/atoms/AssetSelection/AssetSelection.jsx +93 -0
  129. package/src/components/atoms/AssetSelection/asset-selection.module.scss +55 -0
  130. package/src/components/atoms/BackgroundTitle/BackgroundTitle.jsx +44 -0
  131. package/src/components/atoms/BackgroundTitle/background-title.module.scss +52 -0
  132. package/src/components/atoms/NoticeIcon/NoticeIcon.jsx +71 -0
  133. package/src/components/atoms/NoticeIcon/notice-icon.module.scss +14 -0
  134. package/src/components/atoms/TitleBox/TitleBox.jsx +163 -0
  135. package/src/components/atoms/TitleBox/title-box.module.scss +30 -0
  136. package/src/components/atoms/Tooltip/Tooltip.jsx +95 -0
  137. package/src/components/atoms/Tooltip/tooltip.module.scss +231 -0
  138. package/src/components/atoms/Validation/Validation.jsx +130 -0
  139. package/src/components/atoms/Validation/validation.module.scss +15 -0
  140. package/src/components/atoms/buttons/Close/Close.jsx +64 -0
  141. package/src/components/atoms/buttons/Close/close.module.scss +75 -0
  142. package/src/components/atoms/buttons/LinkButton/LinkButton.jsx +121 -0
  143. package/src/components/atoms/buttons/LinkButton/link-button.module.scss +45 -0
  144. package/src/components/molecules/AmountInput/AmountInput.jsx +475 -0
  145. package/src/components/molecules/AmountInput/amount-input.module.scss +189 -0
  146. package/src/components/organisms/Dialog/Dialog.jsx +515 -0
  147. package/src/components/organisms/Dialog/DialogButtons/DialogButtons.jsx +122 -0
  148. package/src/components/organisms/Dialog/DialogButtons/dialog-buttons.module.scss +25 -0
  149. package/src/components/organisms/Dialog/DialogStep/DialogStep.jsx +664 -0
  150. package/src/components/organisms/Dialog/DialogStep/dialog-step.module.scss +362 -0
  151. package/src/components/organisms/Dialog/dialog.module.scss +223 -0
  152. package/src/components/organisms/SwapForm/SwapForm.jsx +1151 -0
  153. package/src/components/organisms/SwapForm/swap-form.module.scss +120 -0
  154. package/src/components/utils/textUtils.js +18 -0
  155. package/src/constants/organisms/dialog/DialogStep/dialogStep.js +1 -0
  156. package/src/constants/organisms/dialog/dialog.js +29 -0
  157. package/src/index.js +21 -1
  158. package/stories/stubs/exampleContent.jsx +20 -0
  159. package/styles/fonts/NunitoSans-Bold.ttf +0 -0
  160. package/styles/fonts/NunitoSans-ExtraBold.ttf +0 -0
  161. package/styles/fonts/NunitoSans-Light.ttf +0 -0
  162. package/styles/fonts/NunitoSans-Regular.ttf +0 -0
  163. package/styles/fonts/NunitoSans-SemiBold.ttf +0 -0
  164. package/styles/index.scss +5 -3
@@ -0,0 +1,189 @@
1
+ @import "../../../../styles/index";
2
+
3
+ .amount-input-container {
4
+ padding: Padding("5");
5
+ background: SolidColor("lightsmoke");
6
+ border-radius: 8px;
7
+ display: flex;
8
+ align-items: center;
9
+ gap: 10px;
10
+ justify-content: space-between;
11
+ transition: 0.2s box-shadow ease;
12
+
13
+ &.upper-form-position {
14
+ border-bottom-left-radius: 4px;
15
+ border-bottom-right-radius: 4px;
16
+ }
17
+
18
+ &.lower-form-position {
19
+ border-top-left-radius: 4px;
20
+ border-top-right-radius: 4px;
21
+ }
22
+
23
+ &.error-encountered {
24
+ box-shadow: $shadowOutlineError !important;
25
+ }
26
+
27
+ @media (hover: hover) {
28
+ &:hover {
29
+ &:not(.focus) {
30
+ box-shadow: $shadowOutlineHover;
31
+ transition: 0.02s box-shadow ease;
32
+ }
33
+ }
34
+ }
35
+
36
+ &.focus {
37
+ box-shadow: $shadowOutlineActive;
38
+ }
39
+
40
+ &-input-wrapper {
41
+ width: 100%;
42
+
43
+ &.disabled {
44
+ opacity: 0.15;
45
+ }
46
+
47
+ &.bottom-margin {
48
+ @media (max-width: $tablet-width) {
49
+ margin-bottom: Margin("5");
50
+ }
51
+ }
52
+
53
+ .asset-balance {
54
+ display: flex;
55
+ justify-content: flex-start;
56
+ align-items: center;
57
+
58
+ svg {
59
+ margin-left: -1px;
60
+ margin-right: 4px;
61
+
62
+ path {
63
+ transition: stroke 0.2s ease;
64
+ }
65
+ }
66
+
67
+ &.red {
68
+ svg path {
69
+ stroke: SolidColor("red");
70
+ }
71
+
72
+ p {
73
+ color: SolidColor("red");
74
+ }
75
+ }
76
+
77
+ p {
78
+ color: SolidColor("grey");
79
+ transition: color 0.2s ease;
80
+
81
+ span {
82
+ opacity: 0.5;
83
+ }
84
+ }
85
+ }
86
+
87
+ .requested-amount-coin {
88
+ font-size: 20px;
89
+ font-weight: $bold;
90
+ color: SolidColor("dark");
91
+ width: 100%;
92
+ padding: 0;
93
+ display: flex;
94
+ align-items: center;
95
+ position: relative;
96
+
97
+ &::after {
98
+ content: " ";
99
+ width: 100%;
100
+ height: 100%;
101
+ position: absolute;
102
+ top: 0;
103
+ left: 0;
104
+ box-shadow: -20px 0px 10px -15px SolidColor(lightsmoke) inset;
105
+ pointer-events: none;
106
+ user-select: none;
107
+ }
108
+
109
+ &-currency,
110
+ &-input {
111
+ font-size: inherit;
112
+ font-weight: inherit;
113
+ font-family: inherit;
114
+ color: inherit;
115
+ margin: 0;
116
+ }
117
+
118
+ &-currency {
119
+ user-select: none;
120
+ padding-right: 4px;
121
+ white-space: nowrap;
122
+ }
123
+
124
+ &-input {
125
+ border: none;
126
+ background: transparent;
127
+ padding: 0;
128
+ width: 100%;
129
+ flex-grow: 1;
130
+ margin: 0;
131
+
132
+ &::placeholder {
133
+ color: rgba(SolidColor("dark"), 0.3);
134
+ }
135
+ }
136
+
137
+ &-skeleton {
138
+ height: 24px;
139
+ width: 40%;
140
+ display: flex;
141
+ align-items: center;
142
+
143
+ &-content {
144
+ @extend %skeleton-big-text;
145
+ }
146
+ }
147
+ }
148
+
149
+ .requested-amount-fiat {
150
+ color: SolidColor("grey");
151
+ display: flex;
152
+ align-items: center;
153
+ font-size: 14px;
154
+
155
+ &-currency,
156
+ &-input,
157
+ &-placeholder {
158
+ font-size: inherit;
159
+ font-weight: inherit;
160
+ font-family: inherit;
161
+ color: inherit;
162
+ }
163
+
164
+ &-currency {
165
+ user-select: none;
166
+ padding-right: 4px;
167
+ white-space: nowrap;
168
+ }
169
+
170
+ &-input {
171
+ background: none;
172
+ outline: none;
173
+ border: none;
174
+ padding: 0;
175
+ width: 100%;
176
+ flex-grow: 1;
177
+ margin: 0;
178
+
179
+ &::placeholder {
180
+ color: rgba(SolidColor("dark"), 0.3);
181
+ }
182
+ }
183
+
184
+ &-placeholder {
185
+ cursor: pointer;
186
+ }
187
+ }
188
+ }
189
+ }
@@ -0,0 +1,515 @@
1
+ import React, { useEffect, useRef, useState } from "react";
2
+ import PropTypes from "prop-types";
3
+ import { CSSTransition } from "react-transition-group";
4
+ import AnimateHeight from "react-animate-height";
5
+ import ResizeObserver from "resize-observer-polyfill";
6
+ import {
7
+ disableBodyScroll,
8
+ enableBodyScroll,
9
+ clearAllBodyScrollLocks,
10
+ } from "body-scroll-lock";
11
+ import animateScrollTo from "animated-scroll-to";
12
+
13
+ import { useReferredState } from "../../hooks/useReferredState";
14
+ import { logErrorOrOutputToConsole } from "../../../common/errorUtils";
15
+ import {
16
+ DIALOG_TRANSITION_STEP_DURATION,
17
+ DIALOG_SIZES,
18
+ } from "../../../constants/organisms/dialog/dialog";
19
+
20
+ import s from "./dialog.module.scss";
21
+ import { Close } from "../../atoms/buttons/Close/Close";
22
+ import { DialogButtons } from "./DialogButtons/DialogButtons";
23
+
24
+ /**
25
+ * Flexible modal window component with support for multiple steps. Can be used as an inline component and inserted in regular layouts. Only <DialogStep> components can be passed as children.
26
+ *
27
+ * @component
28
+ * @param {Object} props - Component props.
29
+ * @param {boolean} props.showDialog - Step name, specified on the root dialog level, used as an ID for dialog navigation.
30
+ * @param {string} props.onClose - Handler for when the dialog is closed.
31
+ * @param {string} props.initControls - State-setting function to initialize the dialog-to-step connection.
32
+ * @param {string} props.children - Content of the dialog window, supports only dialog step components.
33
+ * @param {Coin} props.width - Width in pixels, formatted as "1000px" and passed a string. Values should be used from constants.
34
+ * @param {string} props.dispatchDialogOpened - Dispatch upon the dialog closure.
35
+ * @param {string} props.dispatchDialogClosed - Dispatch upon the dialog opening.
36
+ * @param {function} props.inline - If false or not set, dialog will be opened as a modal window above the UI. If true, inline mode will be used, making the dialog a regular block, that can be placed inside a regular layout. Default: false.
37
+ * @returns {JSX.Element} React component
38
+ */
39
+ export const Dialog = ({
40
+ showDialog = false,
41
+ onClose = () => {},
42
+ initControls = null,
43
+ children = [],
44
+ width = "",
45
+ dispatchDialogOpened = () => {},
46
+ dispatchDialogClosed = () => {},
47
+ inline = false,
48
+ }) => {
49
+ const buttonsConfigurationDefault = {
50
+ primaryButtonTitle: null,
51
+ primaryButtonOnClick: null,
52
+ primaryButtonLoader: false,
53
+ primaryButtonTo: null,
54
+ primaryButtonSetClickTrigger: () => {},
55
+ secondaryButtonTitle: null,
56
+ secondaryButtonOnClick: null,
57
+ secondaryButtonTo: null,
58
+ fixedButtonsEnabled: false,
59
+ };
60
+
61
+ const [showDialogProcessed, setShowDialogProcessed] = useState(false);
62
+ const [currentStep, setCurrentStep] = useState(0);
63
+ const [steps, setSteps] = useState(null);
64
+ const [dialogConfiguration, updateDialogConfiguration] = useState({
65
+ cornerBackButtonTitle: "",
66
+ customWidth: width !== "" ? width : DIALOG_SIZES.small.width,
67
+ });
68
+ const [animationConfiguration, updateAnimationConfiguration] = useState({
69
+ animateHeightDelay: DIALOG_TRANSITION_STEP_DURATION * 2,
70
+ animateHeightTransitionSpeed: DIALOG_TRANSITION_STEP_DURATION,
71
+ animateHeightTransitionEnabled: false,
72
+ wrapperWidthAnimationEnabled: false,
73
+ currentStepAnimationEnabled: false,
74
+ cornerBackButtonAnimationEnabled: false,
75
+ triggerAnimationFinishedDispatcher: false,
76
+ dialogContainerOverflowDisabled: false,
77
+ hideMobileBottomButtonSection: false,
78
+ });
79
+ const [stepAnimationFinishedTrigger, setStepAnimationFinishedTrigger] =
80
+ useState(0);
81
+ const [dialogVerticalHeight, setDialogVerticalHeight] = useState(300);
82
+ const [currentStepRef, setCurrentStepRef] = useState({});
83
+ const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
84
+ const [buttonsConfiguration, updateButtonsConfigurationState] = useState(
85
+ buttonsConfigurationDefault
86
+ );
87
+ const [buttonControllingStep, updateButtonControllingStep] =
88
+ useReferredState("");
89
+ const [isMultiStep, setIsMultiStep] = useState(false);
90
+
91
+ const dialogWrapperRef = useRef();
92
+ const dialogRef = useRef();
93
+ const scrollableRef = useRef();
94
+ const resizeObserverRef = useRef(null);
95
+
96
+ const updateButtonsConfiguration = (newConfiguration, stepName) => {
97
+ if (
98
+ buttonControllingStep.current === stepName ||
99
+ buttonControllingStep.current === ""
100
+ )
101
+ updateButtonsConfigurationState(newConfiguration);
102
+ };
103
+
104
+ useEffect(() => {
105
+ if (showDialog) disableAnimation();
106
+ setShowDialogProcessed(showDialog);
107
+ showDialog ? dispatchDialogOpened() : dispatchDialogClosed();
108
+ // eslint-disable-next-line react-hooks/exhaustive-deps
109
+ }, [showDialog]);
110
+
111
+ const showCornerButtonForStep = (stepName, stepButtonShowParam) => {
112
+ if (stepName !== "") {
113
+ let stepNameId = steps.findIndex((step) => step.name === stepName);
114
+ return stepButtonShowParam !== null &&
115
+ typeof stepButtonShowParam === "boolean"
116
+ ? stepButtonShowParam
117
+ : stepNameId > steps.findIndex((step) => step.hidden === false);
118
+ } else {
119
+ return false;
120
+ }
121
+ };
122
+
123
+ const nextStep = (animationControlEnabled = true) => {
124
+ const nextStep = steps.find(
125
+ (step, index) => index > currentStep && step.hidden === false
126
+ );
127
+ if (nextStep) {
128
+ goToStep(nextStep.name, animationControlEnabled);
129
+ return true;
130
+ } else {
131
+ return false;
132
+ }
133
+ };
134
+
135
+ const previousStep = (animationControlEnabled = true) => {
136
+ const prevSteps = steps
137
+ .map((step, index) => {
138
+ return index < currentStep && step.hidden === false
139
+ ? step.name
140
+ : undefined;
141
+ })
142
+ .filter((item) => typeof item !== "undefined");
143
+
144
+ if (prevSteps.length > 0) {
145
+ goToStep(prevSteps[prevSteps.length - 1], animationControlEnabled);
146
+ return true;
147
+ } else {
148
+ return false;
149
+ }
150
+ };
151
+
152
+ const getStepClass = (stepName) => {
153
+ if (steps.length > 1) {
154
+ let stepNameId = steps.findIndex((step) => step.name === stepName);
155
+ let stepClass =
156
+ currentStep > stepNameId
157
+ ? "prev"
158
+ : currentStep === stepNameId
159
+ ? "current"
160
+ : "next";
161
+ return stepClass;
162
+ } else {
163
+ return "current";
164
+ }
165
+ };
166
+
167
+ const isCurrentStep = (stepName) => {
168
+ return steps[currentStep].name === stepName;
169
+ };
170
+
171
+ const toFirstStep = (animationControlEnabled = true) => {
172
+ if (animationControlEnabled) enableAnimation();
173
+ setCurrentStep(steps.findIndex((step) => step.hidden === false));
174
+ };
175
+
176
+ const goToStep = (stepName, animationControlEnabled = true) => {
177
+ if (animationControlEnabled) enableAnimation();
178
+ try {
179
+ let stepNameId = steps.findIndex((step) => step.name === stepName);
180
+ setCurrentStep(stepNameId);
181
+ } catch (e) {
182
+ logErrorOrOutputToConsole(e);
183
+ }
184
+ };
185
+
186
+ const provideCurrentStepRef = (ref) => {
187
+ setCurrentStepRef(ref);
188
+ };
189
+
190
+ const disableAnimation = (dispatch = false) => {
191
+ updateAnimationConfiguration((prev) => {
192
+ return {
193
+ ...prev,
194
+ animateHeightTransitionEnabled: false,
195
+ wrapperWidthAnimationEnabled: false,
196
+ currentStepAnimationEnabled: false,
197
+ cornerBackButtonAnimationEnabled: false,
198
+ dialogContainerOverflowDisabled: false,
199
+ hideMobileBottomButtonSection: false,
200
+ };
201
+ });
202
+ if (dispatch) {
203
+ updateAnimationConfiguration((prev) => {
204
+ return {
205
+ ...prev,
206
+ triggerAnimationFinishedDispatcher: true,
207
+ };
208
+ });
209
+ }
210
+ };
211
+
212
+ useEffect(() => {
213
+ if (animationConfiguration.triggerAnimationFinishedDispatcher) {
214
+ setStepAnimationFinishedTrigger((prev) => prev + 1);
215
+ updateAnimationConfiguration((prev) => {
216
+ return {
217
+ ...prev,
218
+ triggerAnimationFinishedDispatcher: false,
219
+ };
220
+ });
221
+ }
222
+ // eslint-disable-next-line react-hooks/exhaustive-deps
223
+ }, [animationConfiguration]);
224
+
225
+ const enableAnimation = () => {
226
+ updateAnimationConfiguration((prev) => {
227
+ return {
228
+ ...prev,
229
+ animateHeightTransitionEnabled: true,
230
+ wrapperWidthAnimationEnabled: true,
231
+ currentStepAnimationEnabled: true,
232
+ cornerBackButtonAnimationEnabled: true,
233
+ dialogContainerOverflowDisabled: true,
234
+ hideMobileBottomButtonSection: true,
235
+ };
236
+ });
237
+ };
238
+
239
+ const scrollDialogToTop = () => {
240
+ animateScrollTo(0, {
241
+ elementToScroll: dialogRef?.current,
242
+ minDuration: DIALOG_TRANSITION_STEP_DURATION,
243
+ maxDuration: DIALOG_TRANSITION_STEP_DURATION,
244
+ });
245
+ animateScrollTo(0, {
246
+ elementToScroll: scrollableRef?.current,
247
+ minDuration: DIALOG_TRANSITION_STEP_DURATION,
248
+ maxDuration: DIALOG_TRANSITION_STEP_DURATION,
249
+ });
250
+ };
251
+
252
+ const clearButtonsConfiguration = () => {
253
+ updateButtonsConfigurationState(buttonsConfigurationDefault);
254
+ };
255
+
256
+ useEffect(() => {
257
+ initControls &&
258
+ initControls((prev) => {
259
+ return {
260
+ ...prev,
261
+ stepAnimationFinishedTrigger: stepAnimationFinishedTrigger,
262
+ };
263
+ });
264
+ // eslint-disable-next-line react-hooks/exhaustive-deps
265
+ }, [stepAnimationFinishedTrigger]);
266
+
267
+ useEffect(() => {
268
+ initControls &&
269
+ initControls((prev) => {
270
+ return {
271
+ ...prev,
272
+ animationConfiguration: animationConfiguration,
273
+ };
274
+ });
275
+ // eslint-disable-next-line react-hooks/exhaustive-deps
276
+ }, [animationConfiguration]);
277
+
278
+ useEffect(() => {
279
+ if (currentStepRef.current) {
280
+ resizeObserverRef.current = new ResizeObserver((entries = []) => {
281
+ entries.forEach((entry) => {
282
+ const { width, height } = entry.contentRect;
283
+ setDimensions({ width, height });
284
+ });
285
+ });
286
+ if (currentStepRef.current)
287
+ resizeObserverRef.current.observe(currentStepRef.current);
288
+ return () => {
289
+ if (resizeObserverRef.current)
290
+ resizeObserverRef.current.disconnect();
291
+ };
292
+ }
293
+ // eslint-disable-next-line react-hooks/exhaustive-deps
294
+ }, [currentStepRef]);
295
+
296
+ useEffect(() => {
297
+ setDialogVerticalHeight((prev) =>
298
+ prev !== 0 && dimensions.height === 0 ? prev : dimensions.height
299
+ );
300
+ // eslint-disable-next-line react-hooks/exhaustive-deps
301
+ }, [dimensions]);
302
+
303
+ useEffect(() => {
304
+ const childrenFormatted = children.length > 1 ? children : [children];
305
+
306
+ let stepsArr = childrenFormatted.map((child) => {
307
+ return {
308
+ name: child.props.stepName,
309
+ hidden: !!child.props.hidden,
310
+ };
311
+ });
312
+ setSteps(stepsArr);
313
+
314
+ // eslint-disable-next-line react-hooks/exhaustive-deps
315
+ }, []);
316
+
317
+ useEffect(() => {
318
+ setIsMultiStep(typeof initControls === "function");
319
+ // eslint-disable-next-line react-hooks/exhaustive-deps
320
+ }, [initControls]);
321
+
322
+ useEffect(() => {
323
+ if (steps)
324
+ initControls &&
325
+ initControls({
326
+ nextStep: nextStep,
327
+ previousStep: previousStep,
328
+ currentStep: currentStep,
329
+ isCurrentStep: isCurrentStep,
330
+ getStepClass: getStepClass,
331
+ updateDialogConfiguration: updateDialogConfiguration,
332
+ toFirstStep: toFirstStep,
333
+ goToStep: goToStep,
334
+ provideCurrentStepRef: provideCurrentStepRef,
335
+ animationConfiguration: animationConfiguration,
336
+ disableAnimation: disableAnimation,
337
+ enableAnimation: enableAnimation,
338
+ showCornerButtonForStep: showCornerButtonForStep,
339
+ stepAnimationFinishedTrigger: stepAnimationFinishedTrigger,
340
+ scrollDialogToTop: scrollDialogToTop,
341
+ updateButtonsConfiguration: updateButtonsConfiguration,
342
+ clearButtonsConfiguration: clearButtonsConfiguration,
343
+ buttonControllingStep: buttonControllingStep.current,
344
+ updateButtonControllingStep: updateButtonControllingStep,
345
+ updateAnimationConfiguration: updateAnimationConfiguration,
346
+ inline: inline,
347
+ });
348
+ // eslint-disable-next-line react-hooks/exhaustive-deps
349
+ }, [currentStep, steps]);
350
+
351
+ useEffect(() => {
352
+ return () => {
353
+ clearAllBodyScrollLocks();
354
+ updateButtonControllingStep("");
355
+ clearButtonsConfiguration();
356
+ };
357
+ // eslint-disable-next-line react-hooks/exhaustive-deps
358
+ }, []);
359
+
360
+ return (
361
+ <CSSTransition
362
+ in={showDialogProcessed}
363
+ timeout={DIALOG_TRANSITION_STEP_DURATION}
364
+ classNames={
365
+ inline
366
+ ? undefined
367
+ : {
368
+ enter: s["dialog-transition-enter"],
369
+ enterActive: s["dialog-transition-enter-active"],
370
+ exit: s["dialog-transition-exit"],
371
+ exitActive: s["dialog-transition-exit-active"],
372
+ }
373
+ }
374
+ unmountOnExit
375
+ onExited={() => {
376
+ disableAnimation(false);
377
+ clearButtonsConfiguration();
378
+ updateButtonControllingStep("");
379
+ }}
380
+ onExiting={() => {
381
+ if (inline) return;
382
+ enableBodyScroll(scrollableRef.current);
383
+ enableBodyScroll(dialogRef.current);
384
+ }}
385
+ onEntered={() => {
386
+ if (inline) return;
387
+ disableBodyScroll(scrollableRef.current);
388
+ disableBodyScroll(dialogRef.current);
389
+ }}
390
+ >
391
+ <div
392
+ className={
393
+ s["dialog"] +
394
+ " " +
395
+ (dialogVerticalHeight > 1 || !isMultiStep
396
+ ? ""
397
+ : " " + s["hidden"]) +
398
+ (animationConfiguration.dialogContainerOverflowDisabled
399
+ ? " " + s["vertical-overflow-disabled"]
400
+ : "") +
401
+ (inline ? " " + s["inline"] : "")
402
+ }
403
+ ref={dialogRef}
404
+ >
405
+ <div
406
+ className={
407
+ s["scrollable"] + (inline ? " " + s["inline"] : "")
408
+ }
409
+ ref={scrollableRef}
410
+ >
411
+ <div
412
+ className={
413
+ s["dialog-wrapper"] +
414
+ (animationConfiguration.wrapperWidthAnimationEnabled
415
+ ? ""
416
+ : " " + s["animation-disabled"]) +
417
+ (inline ? " " + s["inline"] : "")
418
+ }
419
+ ref={dialogWrapperRef}
420
+ style={
421
+ dialogConfiguration.customWidth !== ""
422
+ ? { maxWidth: dialogConfiguration.customWidth }
423
+ : width !== ""
424
+ ? { maxWidth: width }
425
+ : null
426
+ }
427
+ >
428
+ <AnimateHeight
429
+ duration={
430
+ animationConfiguration.animateHeightTransitionEnabled
431
+ ? animationConfiguration.animateHeightTransitionSpeed
432
+ : 0
433
+ }
434
+ delay={
435
+ animationConfiguration.animateHeightTransitionEnabled
436
+ ? animationConfiguration.animateHeightDelay
437
+ : 0
438
+ }
439
+ height={isMultiStep ? dialogVerticalHeight : "auto"}
440
+ contentClassName={s["dialog-wrapper-rah-content"]}
441
+ >
442
+ {inline ? (
443
+ ""
444
+ ) : (
445
+ <div className={s["dialog-wrapper-close"]}>
446
+ <Close
447
+ color="dark"
448
+ onClick={(e) => onClose()}
449
+ large
450
+ />
451
+ </div>
452
+ )}
453
+ {children}
454
+ </AnimateHeight>
455
+ </div>
456
+ </div>
457
+ {
458
+ <CSSTransition
459
+ in={
460
+ (!!buttonsConfiguration.primaryButtonTitle ||
461
+ !!buttonsConfiguration.secondaryButtonTitle) &&
462
+ !animationConfiguration.hideMobileBottomButtonSection &&
463
+ buttonsConfiguration.fixedButtonsEnabled
464
+ }
465
+ timeout={DIALOG_TRANSITION_STEP_DURATION}
466
+ // classNames={s["fixed-buttons-container"]}
467
+ classNames={{
468
+ enter: s["fixed-buttons-container-enter"],
469
+ enterActive:
470
+ s["fixed-buttons-container-enter-active"],
471
+ enterDone: s["fixed-buttons-container-enter-done"],
472
+ exit: s["fixed-buttons-container-exit"],
473
+ exitActive:
474
+ s["fixed-buttons-container-exit-active"],
475
+ exitDone: s["fixed-buttons-container-exit-done"],
476
+ }}
477
+ unmountOnExit
478
+ >
479
+ <div className={s["fixed-buttons-container"]}>
480
+ <DialogButtons {...buttonsConfiguration} />
481
+ </div>
482
+ </CSSTransition>
483
+ }
484
+ </div>
485
+ </CSSTransition>
486
+ );
487
+ };
488
+
489
+ Dialog.propTypes = {
490
+ showDialog: PropTypes.bool,
491
+ onClose: PropTypes.func.isRequired,
492
+ initControls: PropTypes.func,
493
+ children: PropTypes.node,
494
+ width: PropTypes.oneOf([
495
+ "550px",
496
+ "600px",
497
+ "700px",
498
+ "750px",
499
+ "800px",
500
+ "1000px",
501
+ ]),
502
+ dispatchDialogOpened: PropTypes.func,
503
+ dispatchDialogClosed: PropTypes.func,
504
+ inline: PropTypes.bool,
505
+ };
506
+
507
+ Dialog.defaultProps = {
508
+ showDialog: false,
509
+ onClose: () => {},
510
+ initControls: null,
511
+ children: [],
512
+ dispatchDialogOpened: () => {},
513
+ dispatchDialogClosed: () => {},
514
+ inline: false,
515
+ };