@jobber/components 4.77.5 → 4.78.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.
- package/AnimatedPresence.d.ts +1 -0
- package/AnimatedPresence.js +17 -0
- package/dist/AnimatedPresence/AnimatedPresence.d.ts +24 -0
- package/dist/AnimatedPresence/AnimatedPresence.transitions.d.ts +11 -0
- package/dist/AnimatedPresence/hooks/usePreviousValue.d.ts +2 -0
- package/dist/AnimatedPresence/index.d.ts +1 -0
- package/dist/AnimatedPresence/index.js +106 -0
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./dist/AnimatedPresence";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var AnimatedPresence = require("./dist/AnimatedPresence");
|
|
8
|
+
|
|
9
|
+
Object.keys(AnimatedPresence).forEach(function(key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
Object.defineProperty(exports, key, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function get() {
|
|
14
|
+
return AnimatedPresence[key];
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
declare const transitions: {
|
|
3
|
+
fromBottom: import("framer-motion").Variants;
|
|
4
|
+
fromTop: import("framer-motion").Variants;
|
|
5
|
+
fromLeft: import("framer-motion").Variants;
|
|
6
|
+
fromRight: import("framer-motion").Variants;
|
|
7
|
+
popIn: import("framer-motion").Variants;
|
|
8
|
+
fromLeftToRight: import("framer-motion").Variants;
|
|
9
|
+
fromRightToLeft: import("framer-motion").Variants;
|
|
10
|
+
fade: import("framer-motion").Variants;
|
|
11
|
+
};
|
|
12
|
+
export type AnimatedPresenceTransitions = keyof typeof transitions;
|
|
13
|
+
interface AnimatedPresenceProps extends Required<PropsWithChildren> {
|
|
14
|
+
/**
|
|
15
|
+
* The type of transition you can use.
|
|
16
|
+
*/
|
|
17
|
+
readonly transition?: AnimatedPresenceTransitions;
|
|
18
|
+
/**
|
|
19
|
+
* Whether or not to animate the children on mount. By default it's set to false.
|
|
20
|
+
*/
|
|
21
|
+
readonly initial?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function AnimatedPresence(props: AnimatedPresenceProps): JSX.Element;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Variants } from "framer-motion";
|
|
2
|
+
export declare const TIMING_QUICK: number;
|
|
3
|
+
export declare const TIMING_BASE: number;
|
|
4
|
+
export declare const fade: Variants;
|
|
5
|
+
export declare const popIn: Variants;
|
|
6
|
+
export declare const fromTop: Variants;
|
|
7
|
+
export declare const fromBottom: Variants;
|
|
8
|
+
export declare const fromLeft: Variants;
|
|
9
|
+
export declare const fromRight: Variants;
|
|
10
|
+
export declare const fromLeftToRight: Variants;
|
|
11
|
+
export declare const fromRightToLeft: Variants;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./AnimatedPresence";
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var framerMotion = require('framer-motion');
|
|
7
|
+
var design = require('@jobber/design');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
12
|
+
|
|
13
|
+
const TIMING_QUICK = toSeconds(design.tokens["timing-quick"]);
|
|
14
|
+
const TIMING_BASE = toSeconds(design.tokens["timing-base"]);
|
|
15
|
+
const baseTransition = {
|
|
16
|
+
visible: { opacity: 1 },
|
|
17
|
+
hidden: { opacity: 0 },
|
|
18
|
+
};
|
|
19
|
+
const fade = {
|
|
20
|
+
visible: { opacity: 1 },
|
|
21
|
+
hidden: { opacity: 0 },
|
|
22
|
+
};
|
|
23
|
+
const popIn = {
|
|
24
|
+
visible: Object.assign({ scale: 1 }, baseTransition.visible),
|
|
25
|
+
hidden: Object.assign({ scale: 0.95 }, baseTransition.hidden),
|
|
26
|
+
};
|
|
27
|
+
const fromTop = {
|
|
28
|
+
visible: Object.assign({ y: 0 }, baseTransition.visible),
|
|
29
|
+
hidden: Object.assign({ y: -design.tokens["space-base"] }, baseTransition.hidden),
|
|
30
|
+
};
|
|
31
|
+
const fromBottom = {
|
|
32
|
+
visible: Object.assign({ y: 0 }, baseTransition.visible),
|
|
33
|
+
hidden: Object.assign({ y: design.tokens["space-base"] }, baseTransition.hidden),
|
|
34
|
+
};
|
|
35
|
+
const fromLeft = {
|
|
36
|
+
visible: Object.assign({ x: 0 }, baseTransition.visible),
|
|
37
|
+
hidden: Object.assign({ x: -design.tokens["space-base"] }, baseTransition.hidden),
|
|
38
|
+
};
|
|
39
|
+
const fromRight = {
|
|
40
|
+
visible: Object.assign({ x: 0 }, baseTransition.visible),
|
|
41
|
+
hidden: Object.assign({ x: design.tokens["space-base"] }, baseTransition.hidden),
|
|
42
|
+
};
|
|
43
|
+
const fromLeftToRight = {
|
|
44
|
+
initial: Object.assign({ x: -design.tokens["space-base"] }, baseTransition.hidden),
|
|
45
|
+
visible: Object.assign({ x: 0 }, baseTransition.visible),
|
|
46
|
+
hidden: Object.assign({ x: design.tokens["space-base"] }, baseTransition.hidden),
|
|
47
|
+
};
|
|
48
|
+
const fromRightToLeft = {
|
|
49
|
+
initial: Object.assign({ x: design.tokens["space-base"] }, baseTransition.hidden),
|
|
50
|
+
visible: Object.assign({ x: 0 }, baseTransition.visible),
|
|
51
|
+
hidden: Object.assign({ x: -design.tokens["space-base"] }, baseTransition.hidden),
|
|
52
|
+
};
|
|
53
|
+
function toSeconds(ms) {
|
|
54
|
+
return ms / 1000;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function usePreviousValue(value) {
|
|
58
|
+
const [previousValue, setPreviousValue] = React.useState(value);
|
|
59
|
+
React.useEffect(() => {
|
|
60
|
+
setPreviousValue(value);
|
|
61
|
+
}, [value]);
|
|
62
|
+
return [previousValue, setPreviousValue];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const transitions = {
|
|
66
|
+
fromBottom,
|
|
67
|
+
fromTop,
|
|
68
|
+
fromLeft,
|
|
69
|
+
fromRight,
|
|
70
|
+
popIn,
|
|
71
|
+
fromLeftToRight,
|
|
72
|
+
fromRightToLeft,
|
|
73
|
+
fade,
|
|
74
|
+
};
|
|
75
|
+
function AnimatedPresence(props) {
|
|
76
|
+
const shouldReduceMotion = framerMotion.useReducedMotion();
|
|
77
|
+
if (shouldReduceMotion) {
|
|
78
|
+
return React__default["default"].createElement(React__default["default"].Fragment, null, props.children);
|
|
79
|
+
}
|
|
80
|
+
return React__default["default"].createElement(InternalAnimatedPresence, Object.assign({}, props));
|
|
81
|
+
}
|
|
82
|
+
function InternalAnimatedPresence({ transition = "fromTop", initial = false, children, }) {
|
|
83
|
+
const transitionVariation = transitions[transition];
|
|
84
|
+
const hasInitialTransition = "initial" in transitionVariation;
|
|
85
|
+
const childCount = React.Children.count(children);
|
|
86
|
+
// Set the initial value to 0 so it staggers the animation on mount when
|
|
87
|
+
// initial is true.
|
|
88
|
+
const [lastChildIndex, setLastChildIndex] = usePreviousValue(0);
|
|
89
|
+
// Whenever the children count changes, update the last index.
|
|
90
|
+
React.useEffect(() => {
|
|
91
|
+
setLastChildIndex(childCount - 1);
|
|
92
|
+
}, [childCount]);
|
|
93
|
+
return (React__default["default"].createElement(framerMotion.AnimatePresence, { initial: initial, mode: "popLayout" }, React.Children.map(children, (child, i) => child && (React__default["default"].createElement(framerMotion.motion.div, { layout: true, variants: transitionVariation, initial: hasInitialTransition ? "initial" : "hidden", animate: "visible", exit: "hidden", transition: {
|
|
94
|
+
duration: TIMING_BASE,
|
|
95
|
+
delay: generateDelayTime(i),
|
|
96
|
+
} }, child)))));
|
|
97
|
+
function generateDelayTime(index) {
|
|
98
|
+
// Don't add a delay if it's already rendered.
|
|
99
|
+
if (lastChildIndex > index)
|
|
100
|
+
return 0;
|
|
101
|
+
// Stagger the animation starting after the previous last child index.
|
|
102
|
+
return (index - lastChildIndex) * TIMING_QUICK;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
exports.AnimatedPresence = AnimatedPresence;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.78.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"> 1%",
|
|
85
85
|
"IE 10"
|
|
86
86
|
],
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "e6ea2817fa008fa463a8adbc6b918566d05d9d38"
|
|
88
88
|
}
|