@onepercentio/one-ui 0.29.2 → 0.29.5

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 (289) hide show
  1. package/dist/components/Switch/Switch.d.ts +1 -1
  2. package/dist/components/Switch/Switch.js +1 -1
  3. package/dist/hooks/useHero.js +3 -2
  4. package/dist-ts/components/Switch/Switch.d.ts +1 -1
  5. package/dist-ts/hooks/useHero.js +5 -4
  6. package/dist-ts/hooks/useHero.js.map +1 -1
  7. package/package.json +5 -1
  8. package/src/assets/img/svg/checkbox.svg +0 -3
  9. package/src/assets/styles/index.scss +0 -2
  10. package/src/assets/styles/mixins.scss +0 -12
  11. package/src/assets/styles/variables.scss +0 -49
  12. package/src/components/AdaptiveButton/AdaptiveButton.module.scss +0 -7
  13. package/src/components/AdaptiveButton/AdaptiveButton.tsx +0 -26
  14. package/src/components/AdaptiveButton/index.tsx +0 -2
  15. package/src/components/AdaptiveContainer/AdaptiveContainer.module.scss +0 -53
  16. package/src/components/AdaptiveContainer/AdaptiveContainer.tsx +0 -200
  17. package/src/components/AdaptiveContainer/index.tsx +0 -2
  18. package/src/components/AdaptiveDialog/AdaptiveDialog.module.scss +0 -147
  19. package/src/components/AdaptiveDialog/AdaptiveDialog.tsx +0 -97
  20. package/src/components/AdaptiveDialog/index.tsx +0 -2
  21. package/src/components/AdaptiveSidebar/AdaptiveSidebar.module.scss +0 -49
  22. package/src/components/AdaptiveSidebar/AdaptiveSidebar.sample.tsx +0 -10
  23. package/src/components/AdaptiveSidebar/AdaptiveSidebar.tsx +0 -123
  24. package/src/components/AdaptiveSidebar/index.tsx +0 -2
  25. package/src/components/AnchoredTooltip/AnchoredTooltip.module.scss +0 -64
  26. package/src/components/AnchoredTooltip/AnchoredTooltip.tsx +0 -250
  27. package/src/components/AnchoredTooltip/index.tsx +0 -2
  28. package/src/components/AnimatedEntrance/AnimatedEntrance.module.scss +0 -108
  29. package/src/components/AnimatedEntrance/AnimatedEntrance.tsx +0 -227
  30. package/src/components/AnimatedEntrance/index.tsx +0 -2
  31. package/src/components/AsyncWrapper/AsyncWrapper.tsx +0 -38
  32. package/src/components/AsyncWrapper/index.tsx +0 -2
  33. package/src/components/Avatar/Avatar.module.scss +0 -22
  34. package/src/components/Avatar/Avatar.tsx +0 -31
  35. package/src/components/Avatar/index.tsx +0 -2
  36. package/src/components/BucketFill/BucketFill.module.scss +0 -36
  37. package/src/components/BucketFill/BucketFill.tsx +0 -65
  38. package/src/components/BucketFill/index.tsx +0 -2
  39. package/src/components/Button/Button.module.scss +0 -45
  40. package/src/components/Button/Button.tsx +0 -40
  41. package/src/components/Button/index.tsx +0 -2
  42. package/src/components/Card/Card.module.scss +0 -12
  43. package/src/components/Card/Card.tsx +0 -9
  44. package/src/components/Card/index.tsx +0 -2
  45. package/src/components/Chart/Chart.e2e.ts +0 -4
  46. package/src/components/Chart/Chart.logic.tsx +0 -8
  47. package/src/components/Chart/Chart.module.scss +0 -58
  48. package/src/components/Chart/Chart.tsx +0 -2
  49. package/src/components/Chart/Chart.types.ts +0 -35
  50. package/src/components/Chart/Chart.view.tsx +0 -241
  51. package/src/components/Chart/index.tsx +0 -2
  52. package/src/components/CheckBox/CheckBox.module.scss +0 -36
  53. package/src/components/CheckBox/CheckBox.tsx +0 -63
  54. package/src/components/CheckBox/index.tsx +0 -2
  55. package/src/components/CodeInput/CodeInput.module.scss +0 -5
  56. package/src/components/CodeInput/CodeInput.tsx +0 -84
  57. package/src/components/CodeInput/index.tsx +0 -2
  58. package/src/components/Collapsable/Collapsable.module.scss +0 -42
  59. package/src/components/Collapsable/Collapsable.tsx +0 -253
  60. package/src/components/Collapsable/index.tsx +0 -2
  61. package/src/components/Countdown/Countdown.tsx +0 -130
  62. package/src/components/Countdown/index.tsx +0 -2
  63. package/src/components/CurrencyInput/CurrencyInput.hook.ts +0 -37
  64. package/src/components/CurrencyInput/CurrencyInput.tsx +0 -25
  65. package/src/components/CurrencyInput/index.tsx +0 -2
  66. package/src/components/Divider/Divider.module.scss +0 -7
  67. package/src/components/Divider/Divider.tsx +0 -13
  68. package/src/components/Divider/index.tsx +0 -2
  69. package/src/components/EmailInput/EmailInput.module.scss +0 -0
  70. package/src/components/EmailInput/EmailInput.tsx +0 -51
  71. package/src/components/EmailInput/index.tsx +0 -2
  72. package/src/components/FadeIn/FadeIn.module.scss +0 -9
  73. package/src/components/FadeIn/FadeIn.tsx +0 -77
  74. package/src/components/FadeIn/index.tsx +0 -2
  75. package/src/components/FileInput/FileInput.module.scss +0 -6
  76. package/src/components/FileInput/FileInput.tsx +0 -75
  77. package/src/components/FileInput/View/BigFactory/BigFactory.module.scss +0 -20
  78. package/src/components/FileInput/View/BigFactory/BigFactory.tsx +0 -48
  79. package/src/components/FileInput/View/BigFactory/index.tsx +0 -2
  80. package/src/components/FileInput/View/Compact/Compact.module.scss +0 -68
  81. package/src/components/FileInput/View/Compact/Compact.tsx +0 -151
  82. package/src/components/FileInput/View/Compact/index.tsx +0 -2
  83. package/src/components/FileInput/View/View.types.ts +0 -12
  84. package/src/components/FileInput/index.tsx +0 -2
  85. package/src/components/FlowController/FlowController.module.scss +0 -47
  86. package/src/components/FlowController/FlowController.tsx +0 -93
  87. package/src/components/FlowController/index.tsx +0 -2
  88. package/src/components/Form/Form.tsx +0 -243
  89. package/src/components/Form/index.ts +0 -2
  90. package/src/components/Form/v2/Form.hook.ts +0 -341
  91. package/src/components/Form/v2/Form.module.scss +0 -0
  92. package/src/components/Form/v2/Form.tsx +0 -78
  93. package/src/components/Form/v2/Form.types.ts +0 -118
  94. package/src/components/Form/v2/FormField/Extensions/DateField/DateField.module.scss +0 -0
  95. package/src/components/Form/v2/FormField/Extensions/DateField/DateField.tsx +0 -73
  96. package/src/components/Form/v2/FormField/Extensions/DateField/index.tsx +0 -2
  97. package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.module.scss +0 -0
  98. package/src/components/Form/v2/FormField/Extensions/PhoneField/PhoneField.tsx +0 -91
  99. package/src/components/Form/v2/FormField/Extensions/PhoneField/index.tsx +0 -2
  100. package/src/components/Form/v2/FormField/FormField.module.scss +0 -0
  101. package/src/components/Form/v2/FormField/FormField.tsx +0 -378
  102. package/src/components/Form/v2/FormField/FormField.types.ts +0 -129
  103. package/src/components/Form/v2/FormField/index.tsx +0 -2
  104. package/src/components/Form/v2/index.tsx +0 -2
  105. package/src/components/Freeze/Freeze.tsx +0 -9
  106. package/src/components/Freeze/index.tsx +0 -2
  107. package/src/components/HSForms/HSForms.tsx +0 -57
  108. package/src/components/HSForms/index.tsx +0 -2
  109. package/src/components/Header/Header.module.scss +0 -119
  110. package/src/components/Header/Header.tsx +0 -138
  111. package/src/components/Header/index.tsx +0 -2
  112. package/src/components/HeaderCloseBtn/HeaderCloseBtn.module.scss +0 -44
  113. package/src/components/HeaderCloseBtn/HeaderCloseBtn.tsx +0 -28
  114. package/src/components/HeaderCloseBtn/index.tsx +0 -2
  115. package/src/components/InfinityScroll/InfinityScroll.module.scss +0 -30
  116. package/src/components/InfinityScroll/InfinityScroll.tsx +0 -187
  117. package/src/components/InfinityScroll/index.tsx +0 -2
  118. package/src/components/Input/Input.module.scss +0 -71
  119. package/src/components/Input/Input.tsx +0 -134
  120. package/src/components/Input/index.tsx +0 -2
  121. package/src/components/InstantCounter/InstantCounter.tsx +0 -77
  122. package/src/components/InstantCounter/index.tsx +0 -2
  123. package/src/components/LavaLamp/LavaLamp.data.tsx +0 -114
  124. package/src/components/LavaLamp/LavaLamp.module.scss +0 -26
  125. package/src/components/LavaLamp/LavaLamp.tsx +0 -131
  126. package/src/components/LavaLamp/index.tsx +0 -2
  127. package/src/components/LavaLamp/v2/LavaLamp.module.scss +0 -23
  128. package/src/components/LavaLamp/v2/LavaLamp.tsx +0 -197
  129. package/src/components/LinkToId/LinkToId.module.scss +0 -4
  130. package/src/components/LinkToId/LinkToId.tsx +0 -51
  131. package/src/components/LinkToId/index.tsx +0 -2
  132. package/src/components/Loader/Loader.module.scss +0 -40
  133. package/src/components/Loader/Loader.tsx +0 -18
  134. package/src/components/Loader/index.tsx +0 -2
  135. package/src/components/LoaderDotsIndicator/LoaderDotsIndicator.tsx +0 -34
  136. package/src/components/LoaderDotsIndicator/index.tsx +0 -2
  137. package/src/components/LoopableVideo/LoopableVideo.tsx +0 -37
  138. package/src/components/LoopableVideo/index.tsx +0 -2
  139. package/src/components/MainGrid/MainGrid.module.scss +0 -28
  140. package/src/components/MainGrid/MainGrid.tsx +0 -68
  141. package/src/components/MainGrid/index.tsx +0 -2
  142. package/src/components/MutableHamburgerButton/MutableHamburgerButton.module.scss +0 -220
  143. package/src/components/MutableHamburgerButton/MutableHamburgerButton.tsx +0 -38
  144. package/src/components/MutableHamburgerButton/index.tsx +0 -2
  145. package/src/components/Notification/Notification.module.scss +0 -25
  146. package/src/components/Notification/Notification.tsx +0 -13
  147. package/src/components/Notification/index.tsx +0 -2
  148. package/src/components/OrderableList/OrderableList.module.scss +0 -98
  149. package/src/components/OrderableList/OrderableList.tsx +0 -564
  150. package/src/components/OrderableList/index.tsx +0 -2
  151. package/src/components/PaginationIndicator/PaginationIndicator.tsx +0 -365
  152. package/src/components/PaginationIndicator/index.tsx +0 -2
  153. package/src/components/Parallax/Parallax.module.scss +0 -28
  154. package/src/components/Parallax/Parallax.tsx +0 -225
  155. package/src/components/Parallax/index.tsx +0 -2
  156. package/src/components/Parallax/math/helpers.ts +0 -289
  157. package/src/components/PasswordInput/PasswordInput.module.scss +0 -17
  158. package/src/components/PasswordInput/PasswordInput.tsx +0 -154
  159. package/src/components/PasswordInput/index.tsx +0 -2
  160. package/src/components/PingPongText/PingPongText.module.scss +0 -4
  161. package/src/components/PingPongText/PingPongText.tsx +0 -83
  162. package/src/components/PingPongText/index.tsx +0 -2
  163. package/src/components/PixelatedScan/PixelatedScan.module.scss +0 -86
  164. package/src/components/PixelatedScan/PixelatedScan.tsx +0 -175
  165. package/src/components/PixelatedScan/index.tsx +0 -2
  166. package/src/components/Portal/Portal.module.scss +0 -3
  167. package/src/components/Portal/Portal.tsx +0 -68
  168. package/src/components/Portal/index.tsx +0 -2
  169. package/src/components/ProgressBar/ProgressBar.module.scss +0 -44
  170. package/src/components/ProgressBar/ProgressBar.tsx +0 -124
  171. package/src/components/ProgressBar/index.tsx +0 -2
  172. package/src/components/ProgressTexts/ProgressTexts.module.scss +0 -37
  173. package/src/components/ProgressTexts/ProgressTexts.tsx +0 -85
  174. package/src/components/ProgressTexts/index.tsx +0 -2
  175. package/src/components/Radio/Radio.module.scss +0 -36
  176. package/src/components/Radio/Radio.tsx +0 -53
  177. package/src/components/Radio/index.tsx +0 -2
  178. package/src/components/SectionContainer/SectionContainer.module.scss +0 -30
  179. package/src/components/SectionContainer/SectionContainer.tsx +0 -49
  180. package/src/components/SectionContainer/index.tsx +0 -2
  181. package/src/components/Select/Select.module.scss +0 -58
  182. package/src/components/Select/Select.tsx +0 -192
  183. package/src/components/Select/index.tsx +0 -2
  184. package/src/components/Skeleton/Skeleton.module.scss +0 -21
  185. package/src/components/Skeleton/Skeleton.tsx +0 -29
  186. package/src/components/Skeleton/index.tsx +0 -2
  187. package/src/components/Spacing/Spacing.module.scss +0 -13
  188. package/src/components/Spacing/Spacing.tsx +0 -24
  189. package/src/components/Spacing/index.tsx +0 -2
  190. package/src/components/StaticScroller/StaticScroller.module.scss +0 -14
  191. package/src/components/StaticScroller/StaticScroller.tsx +0 -83
  192. package/src/components/StaticScroller/index.tsx +0 -2
  193. package/src/components/Switch/Switch.module.scss +0 -43
  194. package/src/components/Switch/Switch.tsx +0 -41
  195. package/src/components/Switch/index.tsx +0 -2
  196. package/src/components/Table/Table.module.scss +0 -76
  197. package/src/components/Table/Table.tsx +0 -152
  198. package/src/components/Table/index.tsx +0 -2
  199. package/src/components/Tabs/Tabs.module.scss +0 -40
  200. package/src/components/Tabs/Tabs.tsx +0 -104
  201. package/src/components/Tabs/index.tsx +0 -2
  202. package/src/components/Text/Text.module.scss +0 -81
  203. package/src/components/Text/Text.tsx +0 -42
  204. package/src/components/Text/index.tsx +0 -2
  205. package/src/components/Transition/MasksFactory/DiagonalReveal.tsx +0 -47
  206. package/src/components/Transition/MasksFactory/DiagonalSquareToBalls.tsx +0 -78
  207. package/src/components/Transition/MasksFactory/PhysicsSquares.tsx +0 -106
  208. package/src/components/Transition/MasksFactory/SquareToBalls.tsx +0 -66
  209. package/src/components/Transition/MasksFactory/utils.ts +0 -35
  210. package/src/components/Transition/Transition.module.scss +0 -211
  211. package/src/components/Transition/Transition.tsx +0 -495
  212. package/src/components/Transition/index.tsx +0 -2
  213. package/src/components/UncontrolledTransition/UncontrolledTransition.ai.md +0 -9
  214. package/src/components/UncontrolledTransition/UncontrolledTransition.sample.tsx +0 -34
  215. package/src/components/UncontrolledTransition/UncontrolledTransition.tsx +0 -143
  216. package/src/components/UncontrolledTransition/index.tsx +0 -2
  217. package/src/components/WalletConnectionWrapper/WalletConnectionWrapper.tsx +0 -212
  218. package/src/components/WalletConnectionWrapper/index.tsx +0 -2
  219. package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.module.scss +0 -5
  220. package/src/components/utilitary/ScrollAndFocusLock/ScrollAndFocusLock.tsx +0 -52
  221. package/src/components/utilitary/ScrollAndFocusLock/index.tsx +0 -2
  222. package/src/context/AsyncProcess.tsx +0 -107
  223. package/src/context/ContextAsyncControl.tsx +0 -89
  224. package/src/context/CustomBrowserRouter.tsx +0 -55
  225. package/src/context/OneUIProvider.tsx +0 -308
  226. package/src/hooks/logs/useDependencyChangeDetection.ts +0 -25
  227. package/src/hooks/logs/useIsMounting.ts +0 -7
  228. package/src/hooks/persistence/useLocalStorage.ts +0 -45
  229. package/src/hooks/shims/ObjectWatchShim.ts +0 -56
  230. package/src/hooks/ui/useAdaptiveImage.tsx +0 -36
  231. package/src/hooks/ui/useAlternating.tsx +0 -22
  232. package/src/hooks/ui/useBreakpoint.tsx +0 -21
  233. package/src/hooks/ui/useCustomScrollbar.module.scss +0 -20
  234. package/src/hooks/ui/useCustomScrollbar.tsx +0 -22
  235. package/src/hooks/ui/useEffectIf.ts +0 -11
  236. package/src/hooks/ui/useMouseHover.tsx +0 -26
  237. package/src/hooks/ui/usePaginationControls.module.scss +0 -16
  238. package/src/hooks/ui/usePaginationControls.tsx +0 -176
  239. package/src/hooks/ui/useSnapToViewport.module.scss +0 -6
  240. package/src/hooks/ui/useSnapToViewport.ts +0 -28
  241. package/src/hooks/ui/useTilt.tsx +0 -219
  242. package/src/hooks/ui/useZoomable.module.scss +0 -34
  243. package/src/hooks/ui/useZoomable.tsx +0 -144
  244. package/src/hooks/useAsyncControl.ai.md +0 -25
  245. package/src/hooks/useAsyncControl.ts +0 -101
  246. package/src/hooks/useContainedRepositioning.ts +0 -110
  247. package/src/hooks/useCustomHistory.ts +0 -14
  248. package/src/hooks/useElementFit.ts +0 -82
  249. package/src/hooks/useFirestoreWatch.ts +0 -54
  250. package/src/hooks/useForm.ts +0 -49
  251. package/src/hooks/useFreeze.ts +0 -12
  252. package/src/hooks/useHero.module.scss +0 -41
  253. package/src/hooks/useHero.ts +0 -512
  254. package/src/hooks/useIntersection.ts +0 -32
  255. package/src/hooks/useMergeRefs.ts +0 -29
  256. package/src/hooks/useObserve.ts +0 -24
  257. package/src/hooks/usePagination.ts +0 -228
  258. package/src/hooks/usePooledOperation.ts +0 -54
  259. package/src/hooks/usePooling.ts +0 -46
  260. package/src/hooks/useRebound.ts +0 -23
  261. package/src/hooks/useShortIntl.ai.md +0 -5
  262. package/src/hooks/useShortIntl.ts +0 -97
  263. package/src/hooks/utility/useAsyncMemo.ts +0 -43
  264. package/src/hooks/utility/useDepChange.ts +0 -11
  265. package/src/hooks/utility/useEvents.ts +0 -33
  266. package/src/hooks/utility/useImmediate.ts +0 -8
  267. package/src/hooks/utility/useManualInit.ts +0 -24
  268. package/src/hooks/utility/useModule.ts +0 -15
  269. package/src/hooks/utility/useQuery.ts +0 -15
  270. package/src/hooks/utility/useUniqueEffect.ts +0 -22
  271. package/src/index.preprocess.ts +0 -82
  272. package/src/index.ts +0 -229
  273. package/src/models/DebugLogger.ts +0 -7
  274. package/src/models/GenericContract.ts +0 -169
  275. package/src/models/Orbs.ts +0 -97
  276. package/src/reac-app-env.d.ts +0 -6
  277. package/src/storybook/assets/video/txt-reversed.mp4 +0 -0
  278. package/src/storybookUtils/index.tsx +0 -53
  279. package/src/test.tsx +0 -0
  280. package/src/type-utils.ts +0 -49
  281. package/src/types.ts +0 -199
  282. package/src/utility.d.ts +0 -70
  283. package/src/utils/blockchain.ts +0 -43
  284. package/src/utils/e2e.ts +0 -55
  285. package/src/utils/flatten.ts +0 -17
  286. package/src/utils/formatters.ts +0 -36
  287. package/src/utils/html.utils.ts +0 -3
  288. package/src/utils/ownEvent.ts +0 -8
  289. package/src/utils/test.ts +0 -20
@@ -1,176 +0,0 @@
1
- import throttle from "lodash/throttle";
2
- import React, { RefObject, useEffect, useState } from "react";
3
- import Fade from "../../components/FadeIn";
4
- import { useOneUIConfig } from "../../context/OneUIProvider";
5
- import Styles from "./usePaginationControls.module.scss";
6
- import { isSameTarget } from "../../utils/html.utils";
7
-
8
- /**
9
- * This hook handles the display of pagination controls for the user to move to another page
10
- */
11
- export default function usePaginationControls(
12
- containerRef: RefObject<HTMLDivElement>,
13
- {
14
- snapToPage,
15
- baseWidth,
16
- snapToCutElement: _snapToCutElement,
17
- ...props
18
- }: {
19
- snapToPage?: boolean;
20
- baseWidth?: number;
21
- /** This will scroll only until the partially visible element is at the border, instead of scrolling all the container */
22
- snapToCutElement?: boolean;
23
- "data-testid"?: [left: string, right: string];
24
- } = {}
25
- ) {
26
- const [controlsState, setControls] = useState<
27
- [leftControl: boolean, rightControl: boolean]
28
- >([false, false]);
29
- const [leftControl, rightControl] = controlsState;
30
- const LeftControl = useOneUIConfig(
31
- "hook.ui.usePaginationControls.LeftControl"
32
- );
33
- const RightControl = useOneUIConfig(
34
- "hook.ui.usePaginationControls.RightControl"
35
- );
36
- const className = useOneUIConfig(
37
- "hook.ui.usePaginationControls.className",
38
- ""
39
- );
40
- function move(direction: "l" | "r", snapToCutElement = _snapToCutElement) {
41
- return () => {
42
- if (snapToCutElement ?? false) {
43
- const childBaseWidth =
44
- baseWidth! || containerRef.current!.firstElementChild!.clientWidth;
45
- const howMuchDoesTheScrollAddsUpTo =
46
- containerRef.current!.scrollLeft / childBaseWidth -
47
- Math.floor(
48
- (containerRef.current!.scrollLeft + (direction === "l" ? -1 : 0)) /
49
- childBaseWidth
50
- );
51
- const howMuchElementsFitOnAPage =
52
- containerRef.current!.clientWidth / childBaseWidth;
53
-
54
- const howMuchElementsFullyFitOnAPage =
55
- Math.floor(howMuchElementsFitOnAPage) || 1;
56
-
57
- const directionScale =
58
- direction === "l"
59
- ? 1 - howMuchDoesTheScrollAddsUpTo
60
- : howMuchDoesTheScrollAddsUpTo;
61
-
62
- const howMuchOfTheRemainingElementIsShown =
63
- howMuchElementsFitOnAPage +
64
- directionScale -
65
- howMuchElementsFullyFitOnAPage;
66
-
67
- const howMuchToScroll =
68
- (containerRef.current!.clientWidth -
69
- childBaseWidth * howMuchOfTheRemainingElementIsShown) *
70
- (direction === "l" ? -1 : 1);
71
-
72
- containerRef.current!.scrollBy({
73
- left: howMuchToScroll,
74
- behavior: "smooth",
75
- });
76
- } else {
77
- const rest =
78
- Math.round(containerRef.current!.scrollLeft) %
79
- containerRef.current!.clientWidth;
80
- const snapOffset = snapToPage
81
- ? direction === "l"
82
- ? rest
83
- ? containerRef.current!.clientWidth - rest
84
- : 0
85
- : rest
86
- : 0;
87
- containerRef.current!.scrollBy({
88
- left:
89
- (containerRef.current!.clientWidth - snapOffset) *
90
- (direction === "l" ? -1 : 1),
91
- behavior: "smooth",
92
- });
93
- }
94
- };
95
- }
96
-
97
- function checkControlsRequirement() {
98
- const updateFunc =
99
- (next: typeof controlsState) => (prev: typeof controlsState) => {
100
- if (prev[0] !== next[0] || prev[1] !== next[1]) return next;
101
- return prev;
102
- };
103
- const el = containerRef.current;
104
- if (!el) return;
105
- const shouldHaveAnyControl = el.scrollWidth > el.clientWidth;
106
- if (!shouldHaveAnyControl) setControls(updateFunc([false, false]));
107
- else {
108
- const shouldHaveRightControl =
109
- el.scrollLeft < el.scrollWidth - el.clientWidth;
110
- const shouldHaveLeftControl = el.scrollLeft > 0;
111
-
112
- setControls(updateFunc([shouldHaveLeftControl, shouldHaveRightControl]));
113
- }
114
- }
115
- useEffect(() => {
116
- const el = containerRef.current!;
117
- const throttledCheck = throttle(checkControlsRequirement, 1000 / 4);
118
- checkControlsRequirement();
119
- let startingX: number | undefined;
120
- let lastX: number | undefined;
121
-
122
- const onTouchStart = ({ touches, ...e }: TouchEvent) => {
123
- if (!isSameTarget(e)) return;
124
- const { pageX } = touches.item(0)!;
125
- startingX = pageX;
126
- };
127
- const onTouchMove = ({ touches, ...e }: TouchEvent) => {
128
- if (!isSameTarget(e)) return;
129
- const touch = touches.item(0);
130
-
131
- lastX = touch!.pageX;
132
- };
133
- const onTouchEnd = (e: Event) => {
134
- if (!lastX) return;
135
- const dir = lastX > startingX! ? "l" : "r";
136
- move(dir, true)();
137
- startingX = undefined;
138
- };
139
- el.addEventListener("scroll", throttledCheck, {
140
- passive: true,
141
- });
142
- el.addEventListener("touchstart", onTouchStart);
143
- el.addEventListener("touchend", onTouchEnd);
144
- el.addEventListener("touchmove", onTouchMove);
145
- return () => {
146
- el.removeEventListener("scroll", throttledCheck);
147
- el.removeEventListener("touchstart", onTouchStart);
148
- el.removeEventListener("touchend", onTouchEnd);
149
- el.removeEventListener("touchend", onTouchEnd);
150
- };
151
- }, []);
152
-
153
- return {
154
- controls: [
155
- <Fade
156
- key={"l"}
157
- active={leftControl}
158
- className={`${Styles.left} ${Styles.control} ${className}`}
159
- data-testid={props["data-testid"]?.[0]}
160
- onClick={move("l")}
161
- >
162
- {leftControl && <LeftControl />}
163
- </Fade>,
164
- <Fade
165
- key={"r"}
166
- active={rightControl}
167
- className={`${Styles.right} ${Styles.control} ${className}`}
168
- data-testid={props["data-testid"]?.[1]}
169
- onClick={move("r")}
170
- >
171
- {rightControl && <RightControl />}
172
- </Fade>,
173
- ],
174
- checkControlsRequirement,
175
- };
176
- }
@@ -1,6 +0,0 @@
1
- .applySpacings {
2
- padding-left: var(--overflow-padding, var(--default-padding));
3
- padding-right: var(--overflow-padding, var(--default-padding));
4
- margin-left: var(--overflow-margin, var(--default-margin));
5
- margin-right: var(--overflow-margin, var(--default-margin));
6
- }
@@ -1,28 +0,0 @@
1
- import { useLayoutEffect, useRef } from "react";
2
- import Styles from "./useSnapToViewport.module.scss";
3
- /**
4
- * This takes a container and applies padding and margin so the content overflow container and goes until it hits the viewport border
5
- */
6
- export default function useSnapToViewport(defaultPadding: number) {
7
- const elRef = useRef<HTMLDivElement>(null);
8
-
9
- useLayoutEffect(() => {
10
- const diff = window.visualViewport!.width - elRef.current!.clientWidth;
11
-
12
- const margin = diff / 2;
13
-
14
- elRef.current!.style.setProperty("--overflow-padding", `${margin}px`);
15
- elRef.current!.style.setProperty("--overflow-margin", `${-margin}px`);
16
- elRef.current!.style.setProperty(
17
- "--default-padding",
18
- `${defaultPadding}px`
19
- );
20
- elRef.current!.style.setProperty(
21
- "--default-margin",
22
- `${-defaultPadding}px`
23
- );
24
- elRef.current!.classList.add(Styles.applySpacings);
25
- }, []);
26
-
27
- return elRef;
28
- }
@@ -1,219 +0,0 @@
1
- import throttle from "lodash/throttle";
2
- import { RefObject, useEffect, useRef, useState } from "react";
3
- import {
4
- flattenMatrix,
5
- generateMatrixFromOperations,
6
- IDENTITY_MATRIX,
7
- invertMatrix,
8
- } from "../../components/Parallax/math/helpers";
9
-
10
- const MAX_TILT = {
11
- x: 100,
12
- y: 100,
13
- };
14
-
15
- type Options = {
16
- round?: boolean;
17
- gyroEnabled?: boolean;
18
- };
19
-
20
- export function useTiltUpdates(
21
- active: boolean,
22
- relativeToEl: RefObject<HTMLDivElement | null>,
23
- onTilt: (p: { x: number; y: number }) => void,
24
- onInverseMatrix?: (updateFunc: (matrix: number[]) => number[]) => void,
25
- sensorScale: number = 1,
26
- tiltLimit: { x: number; y: number } = MAX_TILT,
27
- options?: Options
28
- ) {
29
- useEffect(() => {
30
- if (active) {
31
- const updatePositions = (relativeToX: number, relativeToY: number) => {
32
- const el = relativeToEl.current!;
33
- const rect = el.getBoundingClientRect();
34
- const {
35
- width: [x0, xW],
36
- height: [y0, yH],
37
- } = {
38
- width: [rect.left, el.clientWidth],
39
- height: [rect.top, el.clientHeight],
40
- };
41
- const distanceOffRight = calculateDistanceRelativeToBounds(
42
- relativeToX,
43
- x0,
44
- xW,
45
- options?.round ?? true
46
- );
47
- const distanceOffBottom = calculateDistanceRelativeToBounds(
48
- relativeToY,
49
- y0,
50
- yH,
51
- options?.round ?? true
52
- );
53
- const howMuchToRotateY = givenTheRelativePositionHowMuchToRotate(
54
- distanceOffRight,
55
- tiltLimit.y
56
- );
57
- const howMuchToRotateX = givenTheRelativePositionHowMuchToRotate(
58
- distanceOffBottom,
59
- tiltLimit.x
60
- );
61
-
62
- onTilt({
63
- y: howMuchToRotateX * 2,
64
- x: howMuchToRotateY * 2,
65
- });
66
- };
67
- const handler = throttle(({ x, y }: MouseEvent) => {
68
- updatePositions(x, y);
69
- }, 1000 / 30);
70
- const touchHandler = throttle(({ touches }: TouchEvent) => {
71
- const { pageX, pageY } = touches[0];
72
- updatePositions(pageX, pageY);
73
- }, 1000 / 30);
74
- window.addEventListener("mousemove", handler);
75
- window.addEventListener("touchmove", touchHandler);
76
- let _inverseMatrix: number[] | undefined;
77
- const _limits: {
78
- [k in "beta" | "gamma"]?: [number, number];
79
- } = {
80
- beta: undefined,
81
- gamma: undefined,
82
- };
83
- const orientationListener: (e: DeviceOrientationEvent) => void = ({
84
- beta,
85
- gamma,
86
- }) => {
87
- beta = beta! * 0.5;
88
- gamma = gamma! * 0.5;
89
- if (!_inverseMatrix) {
90
- window.removeEventListener("mousemove", handler);
91
- window.removeEventListener("touchmove", touchHandler);
92
- const offset = 12.5;
93
- _limits.beta = [beta! - offset, beta! + offset];
94
- _limits.gamma = [gamma! - offset, gamma! + offset];
95
- }
96
- const _beta = Math.min(
97
- _limits.beta![1],
98
- Math.max(_limits.beta![0], beta!)
99
- );
100
- const _gamma = Math.min(
101
- _limits.gamma![1],
102
- Math.max(_limits.gamma![0], gamma!)
103
- );
104
- if (!_inverseMatrix && onInverseMatrix) {
105
- onInverseMatrix(() => {
106
- return (_inverseMatrix = flattenMatrix(
107
- invertMatrix(
108
- generateMatrixFromOperations(
109
- {
110
- type: "rotateY",
111
- angle: _gamma!,
112
- },
113
- {
114
- type: "rotateX",
115
- angle: -_beta!,
116
- }
117
- )
118
- )
119
- ));
120
- });
121
- }
122
- onTilt({
123
- y: -_beta * sensorScale,
124
- x: _gamma * sensorScale,
125
- });
126
- };
127
- function removeListeners() {
128
- window.removeEventListener("mousemove", handler);
129
- window.removeEventListener("touchmove", touchHandler);
130
- }
131
- if (options?.gyroEnabled ?? true) {
132
- window.addEventListener("deviceorientation", orientationListener);
133
- return () => {
134
- window.removeEventListener("deviceorientation", orientationListener);
135
- removeListeners();
136
- };
137
- } else {
138
- return () => removeListeners();
139
- }
140
- }
141
- }, [active, onInverseMatrix, onTilt]);
142
- }
143
-
144
- /**
145
- * This hook binds to two methods for calculating tilt
146
- *
147
- * When available: The device sensors
148
- * When on desktop: The mouse position relative to a ref
149
- */
150
- export default function useTilt(
151
- active: boolean,
152
- /**
153
- * A scale to increase the values from the sensors
154
- *
155
- * @hack You can set this value to 0 as a way to disable the tilt calc on mobile
156
- */
157
- sensorScale: number = 1,
158
- maxTilt: { x: number; y: number } = MAX_TILT,
159
- options?: Options
160
- ) {
161
- const [tilt, setTilt] = useState<{ x: number; y: number }>({
162
- x: 0,
163
- y: 0,
164
- });
165
- const [tiltResetMatrix, setTiltResetMatrix] = useState<number[]>(() =>
166
- flattenMatrix(IDENTITY_MATRIX())
167
- );
168
- const relativeTo = useRef<HTMLDivElement>(null);
169
-
170
- useTiltUpdates(
171
- active,
172
- relativeTo,
173
- setTilt,
174
- setTiltResetMatrix,
175
- sensorScale,
176
- maxTilt,
177
- options
178
- );
179
-
180
- return {
181
- /** The element to monitor mouse hover relative to */
182
- relativeTo,
183
- /**
184
- * The matrix that represents the original tilt, so it can be used with the tilt prop to tilt relative to the user
185
- * Use it on css like so transform: matrix3d(tiltResetMatrix.join(",")) rotateX(tilt.x) rotateY(tilt.y)
186
- */
187
- tiltResetMatrix,
188
-
189
- /**
190
- * How much tilt should be applied based
191
- */
192
- tilt,
193
- };
194
- }
195
-
196
- export function calculateDistanceRelativeToBounds(
197
- mousePosition: number,
198
- elementInitialPosition: number,
199
- elementSizeDimension: number,
200
- shouldRound: boolean
201
- ) {
202
- const normalizeInitialPosition = mousePosition - elementInitialPosition;
203
- const doNotAllowGoingBeyondLowerLimit = Math.max(normalizeInitialPosition, 0);
204
- const doNotAllowHoingBeyondHigherLimit = Math.min(
205
- doNotAllowGoingBeyondLowerLimit,
206
- elementSizeDimension
207
- );
208
- const threeRule =
209
- (doNotAllowHoingBeyondHigherLimit * 100) / elementSizeDimension;
210
- const result = (shouldRound ? Math.round(threeRule) : threeRule) / 100;
211
- return result;
212
- }
213
-
214
- export function givenTheRelativePositionHowMuchToRotate(
215
- relativePosition: number,
216
- maxRotation: number
217
- ) {
218
- return relativePosition * maxRotation - maxRotation / 2;
219
- }
@@ -1,34 +0,0 @@
1
- @import "../../assets/styles/variables.scss";
2
-
3
- .zoomableIndicator {
4
- cursor: zoom-in;
5
- }
6
-
7
- $stubZIndex: 1000000;
8
-
9
- .backdrop {
10
- position: fixed;
11
- width: 100vw;
12
- height: 100vh;
13
- top: 0;
14
- left: 0;
15
- z-index: $stubZIndex;
16
- background: var(--zoomable--backdrop-bg, #0009);
17
- transition: opacity $fast linear;
18
- opacity: 0;
19
- > * {
20
- height: 100%;
21
- width: 100%;
22
- display: flex;
23
- align-items: center;
24
- justify-content: center;
25
- > * {
26
- cursor: zoom-out;
27
- }
28
- }
29
- }
30
-
31
- .backdrop + * {
32
- z-index: $stubZIndex + 1;
33
- max-width: initial;
34
- }
@@ -1,144 +0,0 @@
1
- import React, { useEffect, useMemo, useRef } from "react";
2
- import { createRoot } from "react-dom/client";
3
- import ReactDOM from "react-dom";
4
- import Styles from "./useZoomable.module.scss";
5
- import useHero from "../useHero";
6
- import { useMergeRefsFunc } from "../useMergeRefs";
7
- import ownEvent from "../../utils/ownEvent";
8
- /**
9
- * Allows an element to be zoomable for fullscreen
10
- */
11
- export default function useZoomable(id: string) {
12
- const zoomableID = useMemo(() => `zoomable-${id}`, []);
13
- const getBackdrop = () => {
14
- return document.querySelector(
15
- `[data-zoomable="${zoomableID}"]`
16
- )! as HTMLDivElement;
17
- };
18
- const { heroRef, trigger } = useHero(
19
- zoomableID,
20
- {
21
- "data-preffix": "zoomable",
22
- repeatable: true,
23
- },
24
- {
25
- onHeroStart: (clone, ...args) => {
26
- const bd = getBackdrop();
27
- const removeCb = ({ currentTarget, target }: TransitionEvent) => {
28
- if (target === currentTarget) {
29
- if (("unmountComponentAtNode" in ReactDOM) as any)
30
- (ReactDOM as any).unmountComponentAtNode(bd);
31
- else
32
- console.error("This component doesn't work with the new versions of react yet...")
33
- bd.remove();
34
- }
35
- };
36
- bd.style.opacity = "0";
37
- const middlewayClick = () => {
38
- bd.removeEventListener("transitionend", removeCb);
39
- clone.removeEventListener("click", middlewayClick);
40
- _zoom();
41
- };
42
- clone.addEventListener("click", middlewayClick);
43
- bd.addEventListener("transitionend", removeCb);
44
- bd.addEventListener("transitionstart", () => {
45
- bd.addEventListener(
46
- "transitioncancel",
47
- ownEvent(() => bd.removeEventListener("transitionend", removeCb))
48
- );
49
- });
50
- },
51
- }
52
- );
53
- const zoomableEl = useRef<HTMLDivElement>(null);
54
- function _unzoom() {
55
- trigger();
56
- }
57
-
58
- function _zoom() {
59
- const el = zoomableEl.current!;
60
- const elClone = el.cloneNode(true) as HTMLDivElement;
61
- elClone.style.visibility = "hidden";
62
-
63
- function HeroMount() {
64
- const { heroRef } = useHero(
65
- zoomableID,
66
- {
67
- "data-preffix": "zoomable",
68
- repeatable: true,
69
- },
70
- {
71
- onHeroStart: (clone, ...args) => {
72
- getBackdrop().style.opacity = "1";
73
- const unzoomCb = () => {
74
- _unzoom();
75
- clone.removeEventListener("click", unzoomCb);
76
- };
77
- clone.addEventListener("click", unzoomCb);
78
- },
79
- onHeroEnd: () => {
80
- heroRef.current!.classList.remove(Styles.zoomableIndicator);
81
- },
82
- }
83
- );
84
-
85
- return (
86
- <div
87
- ref={(ref) => {
88
- if (ref) {
89
- ref.appendChild(elClone);
90
- (heroRef as any).current = elClone;
91
- const verticalProportion = el.clientWidth / el.clientHeight;
92
- const targetWidth = ref.clientHeight * verticalProportion;
93
-
94
- if (targetWidth > ref.clientWidth) {
95
- const horizontalProportion = el.clientHeight / el.clientWidth;
96
- elClone.style.width = ref.clientWidth + "px";
97
- elClone.style.height =
98
- ref.clientWidth * horizontalProportion + "px";
99
- } else {
100
- elClone.style.height = ref.clientHeight + "px";
101
- elClone.style.width = targetWidth + "px";
102
- }
103
- }
104
- }}
105
- />
106
- );
107
- }
108
-
109
- const existingBackdrop = getBackdrop();
110
- if (!existingBackdrop) {
111
- const backdrop = document.createElement("div");
112
-
113
- backdrop.classList.add(Styles.backdrop);
114
- backdrop.addEventListener("click", _unzoom);
115
- backdrop.setAttribute("data-zoomable", zoomableID);
116
-
117
- document.body.appendChild(backdrop);
118
- createRoot(backdrop).render(<HeroMount />);
119
- } else {
120
- createRoot(existingBackdrop).render(<HeroMount />);
121
- }
122
- }
123
- useEffect(() => {
124
- const el = zoomableEl.current!;
125
- el.classList.add(Styles.zoomableIndicator);
126
- el.addEventListener("click", _zoom);
127
- return () => {
128
- el.classList.remove(Styles.zoomableIndicator);
129
- const bd = getBackdrop();
130
- if (bd) {
131
- bd.style.opacity = "0";
132
- bd.addEventListener("transitionend", () => {
133
- bd.remove();
134
- });
135
- }
136
- };
137
- }, []);
138
-
139
- const mergedRefs = useMergeRefsFunc(heroRef, zoomableEl);
140
-
141
- return {
142
- zoomableEl: mergedRefs,
143
- };
144
- }
@@ -1,25 +0,0 @@
1
- # Protecting an async function
2
- ```tsx
3
- const control = useAsyncControl()
4
-
5
- control.process(() => anAsyncFunction());
6
- ```
7
-
8
- # Using multiple async functions
9
- ```tsx
10
- const control = useAsyncControl({
11
- asyncFunctionOne,
12
- asyncFunctionTwo,
13
- })
14
-
15
- control.asyncFunctionOne();
16
- control.asyncFunctionTwo();
17
- ```
18
-
19
- # Storing data
20
- ```tsx
21
- const [result, setResult] = useState()
22
- const control = useAsyncControl({anAsyncFunctionThatReturnsData})
23
-
24
- control.anAsyncFunctionThatReturnsData().then(setResult);
25
- ```