@adamjanicki/ui 1.2.9 → 1.3.1
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/components/Animated/Animated.d.ts +52 -0
- package/components/Animated/Animated.js +39 -0
- package/components/Animated/index.d.ts +2 -0
- package/components/Animated/index.js +2 -0
- package/components/Layer/Layer.d.ts +0 -14
- package/components/Layer/Layer.js +0 -25
- package/components/Layer/index.d.ts +1 -2
- package/components/Layer/index.js +1 -2
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type Props = {
|
|
3
|
+
/**
|
|
4
|
+
* Whether the component is visible or not
|
|
5
|
+
*/
|
|
6
|
+
visible: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Duration of the animation in milliseconds
|
|
9
|
+
*/
|
|
10
|
+
duration?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Whether to keep the component mounted when it is not visible
|
|
13
|
+
*/
|
|
14
|
+
keepMountedOnExit?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Animation configuration for the enter state
|
|
17
|
+
*/
|
|
18
|
+
enter?: {
|
|
19
|
+
/**
|
|
20
|
+
* Class name to apply to the component during the enter animation
|
|
21
|
+
*/
|
|
22
|
+
className?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Inline styles to apply to the component during the enter animation
|
|
25
|
+
*/
|
|
26
|
+
style?: React.CSSProperties;
|
|
27
|
+
};
|
|
28
|
+
exit?: {
|
|
29
|
+
/**
|
|
30
|
+
* Class name to apply to the component during the exit animation
|
|
31
|
+
*/
|
|
32
|
+
className?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Inline styles to apply to the component during the exit animation
|
|
35
|
+
*/
|
|
36
|
+
style?: React.CSSProperties;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Children to render
|
|
40
|
+
*/
|
|
41
|
+
children: React.ReactNode | React.ReactNode[];
|
|
42
|
+
/**
|
|
43
|
+
* [Optional] className to apply to the component always
|
|
44
|
+
*/
|
|
45
|
+
className?: string;
|
|
46
|
+
/**
|
|
47
|
+
* [Optional] Inline styles to apply to the component always
|
|
48
|
+
*/
|
|
49
|
+
style?: React.CSSProperties;
|
|
50
|
+
};
|
|
51
|
+
declare const Animated: ({ visible, duration, keepMountedOnExit, enter, exit, children, className, style, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
52
|
+
export default Animated;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { useState, useEffect } from "react";
|
|
14
|
+
import { classNames } from "../../utils/util";
|
|
15
|
+
var Animated = function (_a) {
|
|
16
|
+
var visible = _a.visible, _b = _a.duration, duration = _b === void 0 ? 250 : _b, _c = _a.keepMountedOnExit, keepMountedOnExit = _c === void 0 ? false : _c, enter = _a.enter, exit = _a.exit, children = _a.children, className = _a.className, style = _a.style;
|
|
17
|
+
var _d = useState(visible), shouldRender = _d[0], setShouldRender = _d[1];
|
|
18
|
+
var _e = useState(visible ? "entering" : "exiting"), animationState = _e[0], setAnimationState = _e[1];
|
|
19
|
+
useEffect(function () {
|
|
20
|
+
var timeoutId;
|
|
21
|
+
if (visible && !shouldRender) {
|
|
22
|
+
// Start enter animation
|
|
23
|
+
setShouldRender(true);
|
|
24
|
+
setAnimationState("entering");
|
|
25
|
+
}
|
|
26
|
+
else if (!visible && shouldRender) {
|
|
27
|
+
// Start exit animation
|
|
28
|
+
setAnimationState("exiting");
|
|
29
|
+
timeoutId = setTimeout(function () {
|
|
30
|
+
if (!keepMountedOnExit) {
|
|
31
|
+
setShouldRender(false);
|
|
32
|
+
}
|
|
33
|
+
}, duration);
|
|
34
|
+
}
|
|
35
|
+
return function () { return clearTimeout(timeoutId); };
|
|
36
|
+
}, [visible, shouldRender, duration, keepMountedOnExit]);
|
|
37
|
+
return (_jsx("div", { className: classNames(className, animationState === "entering" ? enter === null || enter === void 0 ? void 0 : enter.className : exit === null || exit === void 0 ? void 0 : exit.className), style: __assign(__assign(__assign({}, style), (animationState === "entering" ? enter === null || enter === void 0 ? void 0 : enter.style : exit === null || exit === void 0 ? void 0 : exit.style)), { transition: "all ".concat(duration, "ms ease-in-out") }), children: shouldRender && children }));
|
|
38
|
+
};
|
|
39
|
+
export default Animated;
|
|
@@ -23,19 +23,5 @@ type LayerProps = {
|
|
|
23
23
|
*/
|
|
24
24
|
disableEscape?: boolean;
|
|
25
25
|
};
|
|
26
|
-
type AnimatedLayerProps = LayerProps & {
|
|
27
|
-
/**
|
|
28
|
-
* [Optional] Config for visibility, including styles and class names
|
|
29
|
-
* Set the `transition` property on the `style` prop to animate the layer
|
|
30
|
-
*/
|
|
31
|
-
visibility: {
|
|
32
|
-
visible: boolean;
|
|
33
|
-
invisibleStyle?: React.CSSProperties;
|
|
34
|
-
visibleStyle?: React.CSSProperties;
|
|
35
|
-
invisibleClassName?: string;
|
|
36
|
-
visibleClassName?: string;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
26
|
declare const Layer: (props: LayerProps) => JSX.Element;
|
|
40
|
-
export declare const AnimatedLayer: ({ visibility, className, style, ...props }: AnimatedLayerProps) => JSX.Element;
|
|
41
27
|
export default Layer;
|
|
@@ -9,17 +9,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
13
|
import React, { useEffect } from "react";
|
|
25
14
|
import { useFocusTrap, useScrollLock } from "../../hooks";
|
|
@@ -54,18 +43,4 @@ var Layer = function (props) {
|
|
|
54
43
|
useScrollLock();
|
|
55
44
|
return _jsx(BaseLayer, __assign({}, props, { visible: true }));
|
|
56
45
|
};
|
|
57
|
-
var defaultInvisibleStyle = {
|
|
58
|
-
visibility: "hidden",
|
|
59
|
-
opacity: 0,
|
|
60
|
-
};
|
|
61
|
-
var defaultVisibleStyle = { opacity: 1 };
|
|
62
|
-
export var AnimatedLayer = function (_a) {
|
|
63
|
-
var visibility = _a.visibility, className = _a.className, _b = _a.style, style = _b === void 0 ? {} : _b, props = __rest(_a, ["visibility", "className", "style"]);
|
|
64
|
-
var visible = visibility.visible, _c = visibility.invisibleStyle, invisibleStyle = _c === void 0 ? defaultInvisibleStyle : _c, _d = visibility.visibleStyle, visibleStyle = _d === void 0 ? defaultVisibleStyle : _d, invisibleClassName = visibility.invisibleClassName, visibleClassName = visibility.visibleClassName;
|
|
65
|
-
// lock and unlock on visibility change
|
|
66
|
-
useScrollLock(visible);
|
|
67
|
-
var mergedStyle = __assign(__assign({}, style), (visible ? visibleStyle : invisibleStyle));
|
|
68
|
-
var mergedClassName = classNames(className, visible ? visibleClassName : invisibleClassName);
|
|
69
|
-
return (_jsx(BaseLayer, __assign({}, props, { style: mergedStyle, className: mergedClassName, visible: visible })));
|
|
70
|
-
};
|
|
71
46
|
export default Layer;
|
package/index.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ export { default as Link } from "./components/Link";
|
|
|
5
5
|
export * from "./components/Input";
|
|
6
6
|
export { default as Input } from "./components/Input";
|
|
7
7
|
export { default as Alert } from "./components/Alert";
|
|
8
|
+
export { default as Animated } from "./components/Animated";
|
|
8
9
|
export { default as Badge } from "./components/Badge";
|
|
9
10
|
export { default as Banner } from "./components/Banner";
|
|
10
11
|
export { default as Select } from "./components/Select";
|
|
11
12
|
export { default as ClickOutside } from "./components/ClickOutside";
|
|
12
|
-
export * from "./components/Layer";
|
|
13
13
|
export { default as Layer } from "./components/Layer";
|
|
14
14
|
export { default as Spinner } from "./components/Spinner";
|
|
15
15
|
export * from "./hooks";
|
package/index.js
CHANGED
|
@@ -6,11 +6,11 @@ export { default as Link } from "./components/Link";
|
|
|
6
6
|
export * from "./components/Input";
|
|
7
7
|
export { default as Input } from "./components/Input";
|
|
8
8
|
export { default as Alert } from "./components/Alert";
|
|
9
|
+
export { default as Animated } from "./components/Animated";
|
|
9
10
|
export { default as Badge } from "./components/Badge";
|
|
10
11
|
export { default as Banner } from "./components/Banner";
|
|
11
12
|
export { default as Select } from "./components/Select";
|
|
12
13
|
export { default as ClickOutside } from "./components/ClickOutside";
|
|
13
|
-
export * from "./components/Layer";
|
|
14
14
|
export { default as Layer } from "./components/Layer";
|
|
15
15
|
export { default as Spinner } from "./components/Spinner";
|
|
16
16
|
// Hooks
|