react-ui-animate 2.0.0 → 3.0.0-rc.0

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 (222) hide show
  1. package/.vscode/settings.json +3 -3
  2. package/LICENSE +21 -21
  3. package/README.md +115 -115
  4. package/dist/animation/animationType.d.ts +15 -15
  5. package/dist/animation/core/animation/Animation.d.ts +16 -0
  6. package/dist/animation/core/animation/FluidValue.d.ts +21 -0
  7. package/dist/animation/core/animation/RequestAnimationFrame.d.ts +8 -0
  8. package/dist/animation/core/animation/SpringAnimation.d.ts +41 -0
  9. package/dist/animation/core/animation/TimingAnimation.d.ts +35 -0
  10. package/dist/animation/core/animation/TransitionValue.d.ts +21 -0
  11. package/dist/animation/core/controllers/Animation.d.ts +16 -0
  12. package/dist/animation/core/controllers/FluidValue.d.ts +32 -0
  13. package/dist/animation/core/controllers/RequestAnimationFrame.d.ts +8 -0
  14. package/dist/animation/core/controllers/SpringAnimation.d.ts +41 -0
  15. package/dist/animation/core/controllers/TimingAnimation.d.ts +35 -0
  16. package/dist/animation/core/easing/Bezier.d.ts +8 -0
  17. package/dist/animation/core/easing/Easing.d.ts +40 -0
  18. package/dist/animation/core/helpers/camelCaseToKebabCase.d.ts +8 -0
  19. package/dist/animation/core/helpers/camelToDash.d.ts +7 -0
  20. package/dist/animation/core/helpers/canInterpolate.d.ts +11 -0
  21. package/dist/animation/core/helpers/getAnimatableObject.d.ts +22 -0
  22. package/dist/animation/core/helpers/getCleanProps.d.ts +10 -0
  23. package/dist/animation/core/helpers/getCssValue.d.ts +8 -0
  24. package/dist/animation/core/helpers/getNonAnimatableStyle.d.ts +6 -0
  25. package/dist/animation/core/helpers/index.d.ts +5 -0
  26. package/dist/animation/core/helpers/isDefined.d.ts +12 -0
  27. package/dist/animation/core/helpers/isFluidValue.d.ts +6 -0
  28. package/dist/animation/core/index.d.ts +11 -0
  29. package/dist/animation/core/interpolation/Colors.d.ts +25 -0
  30. package/dist/animation/core/interpolation/Interpolation.d.ts +80 -0
  31. package/dist/animation/core/interpolation/__tests__/Colors.test.d.ts +1 -0
  32. package/dist/animation/core/react/Tags.d.ts +3 -0
  33. package/dist/animation/core/react/TransformStyles.d.ts +8 -0
  34. package/dist/animation/core/react/animated.d.ts +29 -0
  35. package/dist/animation/core/react/combineRefs.d.ts +2 -0
  36. package/dist/animation/core/react/fluid.d.ts +6 -0
  37. package/dist/animation/core/react/functions/camelToDash.d.ts +7 -0
  38. package/dist/animation/core/react/functions/getAnimatableObject.d.ts +22 -0
  39. package/dist/animation/core/react/functions/getCleanProps.d.ts +4 -0
  40. package/dist/animation/core/react/functions/getCssValue.d.ts +8 -0
  41. package/dist/animation/core/react/functions/getNonAnimatableStyle.d.ts +6 -0
  42. package/dist/animation/core/react/functions/index.d.ts +7 -0
  43. package/dist/animation/core/react/functions/isDefined.d.ts +6 -0
  44. package/dist/animation/core/react/functions/isTransitionValue.d.ts +6 -0
  45. package/dist/animation/core/react/helpers/camelToDash.d.ts +7 -0
  46. package/dist/animation/core/react/helpers/canInterpolate.d.ts +7 -0
  47. package/dist/animation/core/react/helpers/getAnimatableObject.d.ts +22 -0
  48. package/dist/animation/core/react/helpers/getCleanProps.d.ts +4 -0
  49. package/dist/animation/core/react/helpers/getCssValue.d.ts +8 -0
  50. package/dist/animation/core/react/helpers/getNonAnimatableStyle.d.ts +6 -0
  51. package/dist/animation/core/react/helpers/index.d.ts +7 -0
  52. package/dist/animation/core/react/helpers/isDefined.d.ts +6 -0
  53. package/dist/animation/core/react/helpers/isFluidValue.d.ts +6 -0
  54. package/dist/animation/core/react/helpers/isTransitionValue.d.ts +6 -0
  55. package/dist/animation/core/react/makeFluid.d.ts +30 -0
  56. package/dist/animation/core/react/transforms.d.ts +6 -0
  57. package/dist/animation/core/react/useFluidValue.d.ts +9 -0
  58. package/dist/animation/core/react/useMount.d.ts +20 -0
  59. package/dist/animation/core/react/useMounts.d.ts +26 -0
  60. package/dist/animation/core/react/useTransition.d.ts +9 -0
  61. package/dist/animation/core/react/useTransitions.d.ts +11 -0
  62. package/dist/animation/core/types/animation.d.ts +54 -0
  63. package/dist/animation/core/types/common.d.ts +4 -0
  64. package/dist/animation/core/types/fluid.d.ts +19 -0
  65. package/dist/animation/core/types/index.d.ts +2 -0
  66. package/dist/animation/getInitialConfig.d.ts +3 -3
  67. package/dist/animation/index.d.ts +6 -6
  68. package/dist/animation/interpolation.d.ts +21 -21
  69. package/dist/animation/lib/animationType.d.ts +15 -0
  70. package/dist/animation/lib/getInitialConfig.d.ts +3 -0
  71. package/dist/animation/lib/index.d.ts +5 -0
  72. package/dist/animation/lib/interpolation.d.ts +20 -0
  73. package/dist/animation/lib/modules/AnimatedBlock.d.ts +8 -0
  74. package/dist/animation/lib/modules/AnimatedImage.d.ts +8 -0
  75. package/dist/animation/lib/modules/AnimatedInline.d.ts +8 -0
  76. package/dist/animation/lib/modules/MountedBlock.d.ts +29 -0
  77. package/dist/animation/lib/modules/ScrollableBlock.d.ts +22 -0
  78. package/dist/animation/lib/modules/TransitionBlock.d.ts +18 -0
  79. package/dist/animation/lib/modules/index.d.ts +6 -0
  80. package/dist/animation/lib/useAnimatedValue.d.ts +17 -0
  81. package/dist/animation/lib/useMountedValue.d.ts +14 -0
  82. package/dist/animation/modules/AnimatedBlock.d.ts +8 -8
  83. package/dist/animation/modules/AnimatedImage.d.ts +8 -8
  84. package/dist/animation/modules/AnimatedInline.d.ts +8 -8
  85. package/dist/animation/modules/MountedBlock.d.ts +29 -18
  86. package/dist/animation/modules/ScrollableBlock.d.ts +21 -21
  87. package/dist/animation/modules/TransitionBlock.d.ts +17 -17
  88. package/dist/animation/modules/index.d.ts +6 -6
  89. package/dist/animation/useAnimatedValue.d.ts +22 -22
  90. package/dist/animation/useMountedValue.d.ts +15 -15
  91. package/dist/gestures/controllers/DragGesture.d.ts +17 -17
  92. package/dist/gestures/controllers/Gesture.d.ts +20 -20
  93. package/dist/gestures/controllers/MouseMoveGesture.d.ts +13 -13
  94. package/dist/gestures/controllers/ScrollGesture.d.ts +14 -14
  95. package/dist/gestures/controllers/WheelGesture.d.ts +15 -15
  96. package/dist/gestures/controllers/index.d.ts +4 -4
  97. package/dist/gestures/eventAttacher.d.ts +11 -11
  98. package/dist/gestures/helpers/eventAttacher.d.ts +11 -0
  99. package/dist/gestures/helpers/index.d.ts +1 -0
  100. package/dist/gestures/helpers/math.d.ts +34 -0
  101. package/dist/gestures/helpers/withDefault.d.ts +4 -0
  102. package/dist/gestures/hooks/index.d.ts +5 -5
  103. package/dist/gestures/hooks/useDrag.d.ts +4 -4
  104. package/dist/gestures/hooks/useGesture.d.ts +9 -9
  105. package/dist/gestures/hooks/useMouseMove.d.ts +4 -4
  106. package/dist/gestures/hooks/useRecognizer.d.ts +10 -10
  107. package/dist/gestures/hooks/useScroll.d.ts +4 -4
  108. package/dist/gestures/hooks/useWheel.d.ts +4 -4
  109. package/dist/gestures/index.d.ts +2 -2
  110. package/dist/gestures/math.d.ts +34 -34
  111. package/dist/gestures/types.d.ts +51 -51
  112. package/dist/gestures/withDefault.d.ts +4 -4
  113. package/dist/hooks/index.d.ts +3 -3
  114. package/dist/hooks/useMeasure.d.ts +14 -14
  115. package/dist/hooks/useOutsideClick.d.ts +2 -2
  116. package/dist/hooks/useWindowDimension.d.ts +9 -9
  117. package/dist/index.d.ts +9 -5
  118. package/dist/index.js +2758 -1052
  119. package/dist/index.js.map +1 -1
  120. package/dist/utils/delay.d.ts +5 -5
  121. package/dist/utils/index.d.ts +1 -2
  122. package/dist/utils/isDefined.d.ts +1 -1
  123. package/ecosystem.config.js +12 -0
  124. package/example/README.md +46 -0
  125. package/example/package-lock.json +19597 -0
  126. package/example/package.json +45 -0
  127. package/example/public/favicon.ico +0 -0
  128. package/example/public/index.html +20 -0
  129. package/example/public/logo192.png +0 -0
  130. package/example/public/logo512.png +0 -0
  131. package/example/public/manifest.json +25 -0
  132. package/example/public/robots.txt +3 -0
  133. package/example/src/App.tsx +41 -0
  134. package/example/src/components/Draggable.tsx +46 -0
  135. package/example/src/components/Gestures.tsx +151 -0
  136. package/example/src/components/Interpolation.tsx +21 -0
  137. package/example/src/components/Loop.tsx +48 -0
  138. package/example/src/components/MountedBlock.tsx +25 -0
  139. package/example/src/components/MouseMove.tsx +59 -0
  140. package/example/src/components/MultistageTransition.tsx +34 -0
  141. package/example/src/components/Scroll.tsx +39 -0
  142. package/example/src/components/ScrollableBlock.tsx +27 -0
  143. package/example/src/components/SnapTo.tsx +55 -0
  144. package/example/src/components/TransitionBlock.tsx +37 -0
  145. package/example/src/components/Wheel.tsx +39 -0
  146. package/example/src/components/index.ts +18 -0
  147. package/example/src/components/svgLine.tsx +48 -0
  148. package/example/src/components/useAnimatedValue.tsx +57 -0
  149. package/example/src/components/useMountedValue.tsx +62 -0
  150. package/example/src/index.css +8 -0
  151. package/example/src/index.tsx +16 -0
  152. package/example/tsconfig.json +26 -0
  153. package/package.json +48 -48
  154. package/{rollup.config.js → rollup.config.mjs} +18 -18
  155. package/src/animation/core/controllers/Animation.ts +27 -0
  156. package/src/animation/core/controllers/FluidValue.ts +97 -0
  157. package/src/animation/core/controllers/RequestAnimationFrame.ts +13 -0
  158. package/src/animation/core/controllers/SpringAnimation.ts +218 -0
  159. package/src/animation/core/controllers/TimingAnimation.ts +152 -0
  160. package/src/animation/core/easing/Bezier.ts +146 -0
  161. package/src/animation/core/easing/Easing.ts +132 -0
  162. package/src/animation/core/helpers/camelCaseToKebabCase.ts +10 -0
  163. package/src/animation/core/helpers/getCleanProps.ts +16 -0
  164. package/src/animation/core/helpers/getCssValue.ts +60 -0
  165. package/src/animation/core/helpers/index.ts +5 -0
  166. package/src/animation/core/helpers/isDefined.ts +14 -0
  167. package/src/animation/core/helpers/isFluidValue.ts +11 -0
  168. package/src/animation/core/index.ts +16 -0
  169. package/src/animation/core/interpolation/Colors.ts +232 -0
  170. package/src/animation/core/interpolation/Interpolation.ts +395 -0
  171. package/src/animation/core/interpolation/__tests__/Colors.test.tsx +35 -0
  172. package/src/animation/core/react/fluid.ts +197 -0
  173. package/src/animation/core/react/makeFluid.ts +294 -0
  174. package/src/animation/core/react/transforms.ts +90 -0
  175. package/src/animation/core/react/useFluidValue.ts +43 -0
  176. package/src/animation/core/react/useMount.ts +58 -0
  177. package/src/animation/core/types/animation.d.ts +56 -0
  178. package/src/animation/core/types/common.d.ts +4 -0
  179. package/src/animation/core/types/fluid.d.ts +38 -0
  180. package/src/animation/{animationType.ts → lib/animationType.ts} +17 -17
  181. package/src/animation/{getInitialConfig.ts → lib/getInitialConfig.ts} +61 -61
  182. package/src/animation/lib/index.ts +12 -0
  183. package/src/animation/{interpolation.ts → lib/interpolation.ts} +47 -48
  184. package/src/animation/{modules → lib/modules}/AnimatedBlock.ts +8 -8
  185. package/src/animation/{modules → lib/modules}/AnimatedImage.ts +8 -8
  186. package/src/animation/{modules → lib/modules}/AnimatedInline.ts +8 -8
  187. package/src/animation/lib/modules/MountedBlock.tsx +51 -0
  188. package/src/animation/{modules → lib/modules}/ScrollableBlock.tsx +68 -69
  189. package/src/animation/{modules → lib/modules}/TransitionBlock.tsx +28 -29
  190. package/src/animation/{modules → lib/modules}/index.ts +6 -6
  191. package/src/animation/{useAnimatedValue.ts → lib/useAnimatedValue.ts} +60 -71
  192. package/src/animation/{useMountedValue.ts → lib/useMountedValue.ts} +18 -19
  193. package/src/gestures/controllers/DragGesture.ts +178 -177
  194. package/src/gestures/controllers/Gesture.ts +54 -54
  195. package/src/gestures/controllers/MouseMoveGesture.ts +111 -111
  196. package/src/gestures/controllers/ScrollGesture.ts +107 -107
  197. package/src/gestures/controllers/WheelGesture.ts +123 -123
  198. package/src/gestures/controllers/index.ts +4 -4
  199. package/src/gestures/{eventAttacher.ts → helpers/eventAttacher.ts} +67 -67
  200. package/src/gestures/helpers/index.ts +1 -0
  201. package/src/gestures/{math.ts → helpers/math.ts} +120 -120
  202. package/src/gestures/{withDefault.ts → helpers/withDefault.ts} +3 -3
  203. package/src/gestures/hooks/index.ts +5 -5
  204. package/src/gestures/hooks/useDrag.ts +14 -14
  205. package/src/gestures/hooks/useGesture.ts +38 -38
  206. package/src/gestures/hooks/useMouseMove.ts +11 -11
  207. package/src/gestures/hooks/useRecognizer.ts +59 -59
  208. package/src/gestures/hooks/useScroll.ts +11 -11
  209. package/src/gestures/hooks/useWheel.ts +11 -11
  210. package/src/gestures/{types.ts → types/index.d.ts} +49 -49
  211. package/src/hooks/index.ts +3 -3
  212. package/src/hooks/useMeasure.ts +132 -133
  213. package/src/hooks/useOutsideClick.ts +36 -36
  214. package/src/hooks/useWindowDimension.ts +58 -59
  215. package/src/index.ts +42 -5
  216. package/src/utils/delay.ts +9 -9
  217. package/src/utils/index.ts +1 -2
  218. package/tsconfig.json +24 -25
  219. package/src/animation/index.ts +0 -10
  220. package/src/animation/modules/MountedBlock.tsx +0 -25
  221. package/src/gestures/index.ts +0 -2
  222. package/src/utils/isDefined.ts +0 -4
@@ -1,61 +1,61 @@
1
- import { Easing, TransitionValueConfig } from '@raidipesh78/re-motion';
2
- export type InitialConfigType =
3
- | 'linear'
4
- | 'easein'
5
- | 'easeout'
6
- | 'easeinout'
7
- | 'ease'
8
- | 'power1'
9
- | 'power2'
10
- | 'power3'
11
- | 'power4'
12
- | 'elastic'
13
- | 'stiff'
14
- | 'wooble'
15
- | 'bounce';
16
-
17
- export const getInitialConfig = (
18
- animationType?: InitialConfigType
19
- ): TransitionValueConfig => {
20
- switch (animationType) {
21
- case 'elastic':
22
- return { mass: 1, friction: 18, tension: 250 };
23
-
24
- case 'stiff':
25
- return { mass: 1, friction: 18, tension: 350 };
26
-
27
- case 'wooble':
28
- return { mass: 1, friction: 8, tension: 250 };
29
-
30
- case 'bounce':
31
- return { duration: 500, easing: Easing.bounce };
32
-
33
- case 'power1':
34
- return { duration: 500, easing: Easing.bezier(0.17, 0.42, 0.51, 0.97) };
35
-
36
- case 'power2':
37
- return { duration: 500, easing: Easing.bezier(0.07, 0.11, 0.13, 1) };
38
-
39
- case 'power3':
40
- return { duration: 500, easing: Easing.bezier(0.09, 0.7, 0.16, 1.04) };
41
-
42
- case 'power4':
43
- return { duration: 500, easing: Easing.bezier(0.05, 0.54, 0, 1.03) };
44
-
45
- case 'linear':
46
- return { duration: 500, easing: Easing.linear };
47
-
48
- case 'easein':
49
- return { duration: 500, easing: Easing.in(Easing.ease) };
50
-
51
- case 'easeout':
52
- return { duration: 500, easing: Easing.out(Easing.ease) };
53
-
54
- case 'easeinout':
55
- return { duration: 500, easing: Easing.inOut(Easing.ease) };
56
-
57
- case 'ease':
58
- default:
59
- return { mass: 1, friction: 34, tension: 290 };
60
- }
61
- };
1
+ import { Easing, FluidValueConfig } from '../core';
2
+ export type InitialConfigType =
3
+ | 'linear'
4
+ | 'easein'
5
+ | 'easeout'
6
+ | 'easeinout'
7
+ | 'ease'
8
+ | 'power1'
9
+ | 'power2'
10
+ | 'power3'
11
+ | 'power4'
12
+ | 'elastic'
13
+ | 'stiff'
14
+ | 'wooble'
15
+ | 'bounce';
16
+
17
+ export const getInitialConfig = (
18
+ animationType?: InitialConfigType
19
+ ): FluidValueConfig => {
20
+ switch (animationType) {
21
+ case 'elastic':
22
+ return { mass: 1, friction: 18, tension: 250 };
23
+
24
+ case 'stiff':
25
+ return { mass: 1, friction: 18, tension: 350 };
26
+
27
+ case 'wooble':
28
+ return { mass: 1, friction: 8, tension: 250 };
29
+
30
+ case 'bounce':
31
+ return { duration: 500, easing: Easing.bounce };
32
+
33
+ case 'power1':
34
+ return { duration: 500, easing: Easing.bezier(0.17, 0.42, 0.51, 0.97) };
35
+
36
+ case 'power2':
37
+ return { duration: 500, easing: Easing.bezier(0.07, 0.11, 0.13, 1) };
38
+
39
+ case 'power3':
40
+ return { duration: 500, easing: Easing.bezier(0.09, 0.7, 0.16, 1.04) };
41
+
42
+ case 'power4':
43
+ return { duration: 500, easing: Easing.bezier(0.05, 0.54, 0, 1.03) };
44
+
45
+ case 'linear':
46
+ return { duration: 500, easing: Easing.linear };
47
+
48
+ case 'easein':
49
+ return { duration: 500, easing: Easing.in(Easing.ease) };
50
+
51
+ case 'easeout':
52
+ return { duration: 500, easing: Easing.out(Easing.ease) };
53
+
54
+ case 'easeinout':
55
+ return { duration: 500, easing: Easing.inOut(Easing.ease) };
56
+
57
+ case 'ease':
58
+ default:
59
+ return { mass: 1, friction: 34, tension: 290 };
60
+ }
61
+ };
@@ -0,0 +1,12 @@
1
+ export { interpolate, bInterpolate } from './interpolation';
2
+ export {
3
+ AnimatedBlock,
4
+ AnimatedImage,
5
+ AnimatedInline,
6
+ MountedBlock,
7
+ ScrollableBlock,
8
+ TransitionBlock,
9
+ } from './modules';
10
+ export { useAnimatedValue, UseAnimatedValueConfig } from './useAnimatedValue';
11
+ export { useMountedValue } from './useMountedValue';
12
+ export { AnimationConfigUtils } from './animationType';
@@ -1,48 +1,47 @@
1
- import { ExtrapolateConfig, FluidValue } from '@raidipesh78/re-motion';
2
- import { ValueType } from './useAnimatedValue';
3
- import { interpolate as internalInterpolate } from '@raidipesh78/re-motion';
4
-
5
- /**
6
- * interpolate functions maps input range to given output range
7
- * @param value - number | TransitionValue
8
- * @param inputRange - Array<number>
9
- * @param outputRange - Array<number | string>
10
- * @param extrapolateConfig - "clamp" | "identity" | "extend"
11
- * @returns - number | TransitionValue
12
- */
13
- export function interpolate(
14
- value: number | FluidValue | ValueType,
15
- inputRange: Array<number>,
16
- outputRange: Array<number | string>,
17
- extrapolateConfig?: ExtrapolateConfig
18
- ) {
19
- return internalInterpolate(
20
- value as any,
21
- inputRange,
22
- outputRange,
23
- extrapolateConfig
24
- );
25
- }
26
-
27
- /**
28
- * bInterpolate functions maps input range [0, 1] to given [minOutput, maxOutput]
29
- * sorthand function to interpolate input range [0, 1]
30
- * @param value - number | TransitionValue
31
- * @param minOutput - number | string
32
- * @param maxOutput - number | string
33
- * @param extrapolateConfig - "clamp" | "identity" | "extend"
34
- * @returns - number | TransitionValue
35
- */
36
- export function bInterpolate(
37
- value: number | FluidValue | ValueType,
38
- minOutput: number | string,
39
- maxOutput: number | string,
40
- extrapolateConfig?: ExtrapolateConfig
41
- ) {
42
- return internalInterpolate(
43
- value as any,
44
- [0, 1],
45
- [minOutput, maxOutput],
46
- extrapolateConfig
47
- );
48
- }
1
+ import { ExtrapolateConfig, FluidValue } from '../core';
2
+ import { interpolate as internalInterpolate } from '../core';
3
+
4
+ /**
5
+ * interpolate functions maps input range to given output range
6
+ * @param value - number | TransitionValue
7
+ * @param inputRange - Array<number>
8
+ * @param outputRange - Array<number | string>
9
+ * @param extrapolateConfig - "clamp" | "identity" | "extend"
10
+ * @returns - number | TransitionValue
11
+ */
12
+ export function interpolate(
13
+ value: number | FluidValue,
14
+ inputRange: Array<number>,
15
+ outputRange: Array<number | string>,
16
+ extrapolateConfig?: ExtrapolateConfig
17
+ ) {
18
+ return internalInterpolate(
19
+ value as any,
20
+ inputRange,
21
+ outputRange,
22
+ extrapolateConfig
23
+ );
24
+ }
25
+
26
+ /**
27
+ * bInterpolate functions maps input range [0, 1] to given [minOutput, maxOutput]
28
+ * sorthand function to interpolate input range [0, 1]
29
+ * @param value - number | TransitionValue
30
+ * @param minOutput - number | string
31
+ * @param maxOutput - number | string
32
+ * @param extrapolateConfig - "clamp" | "identity" | "extend"
33
+ * @returns - number | TransitionValue
34
+ */
35
+ export function bInterpolate(
36
+ value: number | FluidValue,
37
+ minOutput: number | string,
38
+ maxOutput: number | string,
39
+ extrapolateConfig?: ExtrapolateConfig
40
+ ) {
41
+ return internalInterpolate(
42
+ value as any,
43
+ [0, 1],
44
+ [minOutput, maxOutput],
45
+ extrapolateConfig
46
+ );
47
+ }
@@ -1,8 +1,8 @@
1
- import { makeAnimatedComponent } from '@raidipesh78/re-motion';
2
-
3
- /**
4
- * AnimatedBlock - A higher order component built upon `div` element
5
- * which can accept `AnimatedValue`. It also exposes some extra style properties like
6
- * translateX, translateY, rotateX, rotateY, scaleX, etc.
7
- */
8
- export const AnimatedBlock = makeAnimatedComponent('div');
1
+ import { makeFluid } from '../../core';
2
+
3
+ /**
4
+ * AnimatedBlock - A higher order component built upon `div` element
5
+ * which can accept `AnimatedValue`. It also exposes some extra style properties like
6
+ * translateX, translateY, rotateX, rotateY, scaleX, etc.
7
+ */
8
+ export const AnimatedBlock = makeFluid('div');
@@ -1,8 +1,8 @@
1
- import { makeAnimatedComponent } from '@raidipesh78/re-motion';
2
-
3
- /**
4
- * AnimatedImage - A higher order component built upon `img` element
5
- * which can accept `AnimatedValue`. It also exposes some extra style properties like
6
- * translateX, translateY, rotateX, rotateY, scaleX, etc.
7
- */
8
- export const AnimatedImage = makeAnimatedComponent('img');
1
+ import { makeFluid } from '../../core';
2
+
3
+ /**
4
+ * AnimatedImage - A higher order component built upon `img` element
5
+ * which can accept `AnimatedValue`. It also exposes some extra style properties like
6
+ * translateX, translateY, rotateX, rotateY, scaleX, etc.
7
+ */
8
+ export const AnimatedImage = makeFluid('img');
@@ -1,8 +1,8 @@
1
- import { makeAnimatedComponent } from '@raidipesh78/re-motion';
2
-
3
- /**
4
- * AnimatedInline - A higher order component built upon `span` element
5
- * which can accept `AnimatedValue`. It also exposes some extra style properties like
6
- * translateX, translateY, rotateX, rotateY, scaleX, etc.
7
- */
8
- export const AnimatedInline = makeAnimatedComponent('span');
1
+ import { makeFluid } from '../../core';
2
+
3
+ /**
4
+ * AnimatedInline - A higher order component built upon `span` element
5
+ * which can accept `AnimatedValue`. It also exposes some extra style properties like
6
+ * translateX, translateY, rotateX, rotateY, scaleX, etc.
7
+ */
8
+ export const AnimatedInline = makeFluid('span');
@@ -0,0 +1,51 @@
1
+ import * as React from 'react';
2
+ import { FluidValue, FluidValueConfig } from '../../core';
3
+ import { useMountedValue } from '../useMountedValue';
4
+
5
+ interface MountedValueConfig extends FluidValueConfig {}
6
+
7
+ interface MountedBlockProps {
8
+ state: boolean;
9
+ children: (animation: { value: FluidValue }) => React.ReactNode;
10
+ from?: number;
11
+ enter?: number;
12
+ exit?: number;
13
+ config?: MountedValueConfig;
14
+ enterConfig?: MountedValueConfig;
15
+ exitConfig?: MountedValueConfig;
16
+ }
17
+
18
+ /**
19
+ * MountedBlock - Higher order component which handles mounting and unmounting of a component.
20
+ * @prop { boolean } state - Boolean indicating the component should mount or unmount.
21
+ * @prop { function } children - Child as a function with `AnimatedValue` on `.value` property.
22
+ * @prop { number } from - Number that dictates the beginning state for animation.
23
+ * @prop { number } enter - Number that dictates the entry state for animation.
24
+ * @prop { number } exit - Number that dictates the exit state for animation.
25
+ * @prop { MountedValueConfig } config - Animation configuration for overall animation.
26
+ * @prop { MountedValueConfig } enterConfig - Animation configuration for the entering state of animation.
27
+ * @prop { MountedValueConfig } exitConfig - Animation configuration for the entering state of animation.
28
+ */
29
+ export const MountedBlock = ({
30
+ state,
31
+ children,
32
+ from = 0,
33
+ enter = 1,
34
+ exit = 0,
35
+ config,
36
+ enterConfig,
37
+ exitConfig,
38
+ }: MountedBlockProps) => {
39
+ const open = useMountedValue(state, {
40
+ from,
41
+ enter,
42
+ exit,
43
+ config,
44
+ enterConfig,
45
+ exitConfig,
46
+ });
47
+
48
+ return (
49
+ <>{open((animation, mounted) => mounted && children(animation as any))}</>
50
+ );
51
+ };
@@ -1,69 +1,68 @@
1
- import * as React from 'react';
2
- import {
3
- useAnimatedValue,
4
- UseAnimatedValueConfig,
5
- ValueType,
6
- } from '../useAnimatedValue';
7
-
8
- interface ScrollableBlockProps {
9
- children?: (animation: { value: ValueType }) => React.ReactNode;
10
- direction?: 'single' | 'both';
11
- threshold?: number;
12
- animationConfig?: UseAnimatedValueConfig;
13
- }
14
-
15
- /**
16
- * ScrollableBlock - Higher order component to handle the entrance or exit animation
17
- * of a component when it enters or exit the viewport. Accepts child as a function with
18
- * `AnimatedValue` as its first argument which can be interpolated on input range [0, 1]
19
- * @prop { function } children - child as a function with `AnimatedValue` as its first argument.
20
- * @prop { 'single' | 'both' } direction - single applies animation on enter once, both applies on enter and exit.
21
- * @prop { number } threshold - should be in range 0 to 1 which equivalent to `IntersectionObserver` threshold.
22
- * @prop { UseAnimatedValueConfig } animationConfig - Animation config
23
- */
24
- export const ScrollableBlock = (props: ScrollableBlockProps) => {
25
- const {
26
- children,
27
- direction = 'single',
28
- animationConfig,
29
- threshold = 0.2,
30
- } = props;
31
- const scrollableBlockRef = React.useRef<HTMLDivElement>(null);
32
- const animation = useAnimatedValue(0, animationConfig); // 0: not intersecting | 1: intersecting
33
-
34
- React.useEffect(() => {
35
- const _scrollableBlock = scrollableBlockRef.current;
36
-
37
- const observer = new IntersectionObserver(
38
- function ([entry]) {
39
- const { isIntersecting } = entry;
40
-
41
- if (isIntersecting) {
42
- animation.value = 1;
43
- } else {
44
- if (direction === 'both') animation.value = 0;
45
- }
46
- },
47
- {
48
- root: null, // FOR VIEWPORT ONLY
49
- threshold,
50
- }
51
- );
52
-
53
- if (_scrollableBlock) {
54
- observer.observe(_scrollableBlock);
55
- }
56
-
57
- return () => {
58
- if (_scrollableBlock) {
59
- observer.unobserve(_scrollableBlock);
60
- }
61
- };
62
- }, []);
63
-
64
- return (
65
- <div ref={scrollableBlockRef}>
66
- {children && children({ value: animation.value })}
67
- </div>
68
- );
69
- };
1
+ import * as React from 'react';
2
+ import { useAnimatedValue, UseAnimatedValueConfig } from '../useAnimatedValue';
3
+ import { FluidValue } from '../../core';
4
+
5
+ interface ScrollableBlockProps {
6
+ children?: (animation: {
7
+ value?: FluidValue | string | number;
8
+ }) => React.ReactNode;
9
+ direction?: 'single' | 'both';
10
+ threshold?: number;
11
+ animationConfig?: UseAnimatedValueConfig;
12
+ }
13
+
14
+ /**
15
+ * ScrollableBlock - Higher order component to handle the entrance or exit animation
16
+ * of a component when it enters or exit the viewport. Accepts child as a function with
17
+ * `AnimatedValue` as its first argument which can be interpolated on input range [0, 1]
18
+ * @prop { function } children - child as a function with `AnimatedValue` as its first argument.
19
+ * @prop { 'single' | 'both' } direction - single applies animation on enter once, both applies on enter and exit.
20
+ * @prop { number } threshold - should be in range 0 to 1 which equivalent to `IntersectionObserver` threshold.
21
+ * @prop { UseAnimatedValueConfig } animationConfig - Animation config
22
+ */
23
+ export const ScrollableBlock = (props: ScrollableBlockProps) => {
24
+ const {
25
+ children,
26
+ direction = 'single',
27
+ animationConfig,
28
+ threshold = 0.2,
29
+ } = props;
30
+ const scrollableBlockRef = React.useRef<HTMLDivElement>(null);
31
+ const animation = useAnimatedValue(0, animationConfig); // 0: not intersecting | 1: intersecting
32
+
33
+ React.useEffect(() => {
34
+ const _scrollableBlock = scrollableBlockRef.current;
35
+
36
+ const observer = new IntersectionObserver(
37
+ function ([entry]) {
38
+ const { isIntersecting } = entry;
39
+
40
+ if (isIntersecting) {
41
+ animation.value = 1;
42
+ } else {
43
+ if (direction === 'both') animation.value = 0;
44
+ }
45
+ },
46
+ {
47
+ root: null, // FOR VIEWPORT ONLY
48
+ threshold,
49
+ }
50
+ );
51
+
52
+ if (_scrollableBlock) {
53
+ observer.observe(_scrollableBlock);
54
+ }
55
+
56
+ return () => {
57
+ if (_scrollableBlock) {
58
+ observer.unobserve(_scrollableBlock);
59
+ }
60
+ };
61
+ }, []);
62
+
63
+ return (
64
+ <div ref={scrollableBlockRef}>
65
+ {children && children({ value: animation.value })}
66
+ </div>
67
+ );
68
+ };
@@ -1,29 +1,28 @@
1
- import * as React from 'react';
2
- import { bin } from '../../gestures/math';
3
- import {
4
- useAnimatedValue,
5
- UseAnimatedValueConfig,
6
- ValueType,
7
- } from '../useAnimatedValue';
8
-
9
- interface TransitionBlockProps {
10
- state: boolean;
11
- children: (animation: { value: ValueType }) => React.ReactNode;
12
- config?: UseAnimatedValueConfig;
13
- }
14
-
15
- /**
16
- * TransitionBlock - Higher order component which animates on state change.
17
- * @prop { boolean } state - Boolean indicating the current state of animation, usually `false = 0 and true = 1`.
18
- * @prop { function } children - Child as a function with `AnimatedValue` on `.value` property.
19
- * @prop { UseAnimatedValueConfig } config - Animation configuration.
20
- */
21
- export const TransitionBlock = ({
22
- state,
23
- children,
24
- config,
25
- }: TransitionBlockProps) => {
26
- const amv = useAnimatedValue(bin(state), config);
27
-
28
- return <>{children({ value: amv.value })}</>;
29
- };
1
+ import * as React from 'react';
2
+ import { bin } from '../../../gestures/helpers/math';
3
+ import { useAnimatedValue, UseAnimatedValueConfig } from '../useAnimatedValue';
4
+ import { FluidValue } from '../../core';
5
+
6
+ interface TransitionBlockProps {
7
+ state: boolean;
8
+ children: (animation: {
9
+ value?: FluidValue | string | number;
10
+ }) => React.ReactNode;
11
+ config?: UseAnimatedValueConfig;
12
+ }
13
+
14
+ /**
15
+ * TransitionBlock - Higher order component which animates on state change.
16
+ * @prop { boolean } state - Boolean indicating the current state of animation, usually `false = 0 and true = 1`.
17
+ * @prop { function } children - Child as a function with `AnimatedValue` on `.value` property.
18
+ * @prop { UseAnimatedValueConfig } config - Animation configuration.
19
+ */
20
+ export const TransitionBlock = ({
21
+ state,
22
+ children,
23
+ config,
24
+ }: TransitionBlockProps) => {
25
+ const amv = useAnimatedValue(bin(state), config);
26
+
27
+ return <>{children({ value: amv.value })}</>;
28
+ };
@@ -1,6 +1,6 @@
1
- export * from './AnimatedBlock';
2
- export * from './AnimatedInline';
3
- export * from './AnimatedImage';
4
- export * from './MountedBlock';
5
- export * from './ScrollableBlock';
6
- export * from './TransitionBlock';
1
+ export * from './AnimatedBlock';
2
+ export * from './AnimatedInline';
3
+ export * from './AnimatedImage';
4
+ export * from './MountedBlock';
5
+ export * from './ScrollableBlock';
6
+ export * from './TransitionBlock';