@adamjanicki/ui 1.3.0 → 1.3.2
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.
|
@@ -35,7 +35,18 @@ type Props = {
|
|
|
35
35
|
*/
|
|
36
36
|
style?: React.CSSProperties;
|
|
37
37
|
};
|
|
38
|
-
|
|
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;
|
|
39
50
|
};
|
|
40
|
-
declare const Animated: ({ visible, duration, keepMountedOnExit, enter, exit, children, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
51
|
+
declare const Animated: ({ visible, duration, keepMountedOnExit, enter, exit, children, className, style, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
41
52
|
export default Animated;
|
|
@@ -13,7 +13,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
13
13
|
import { useState, useEffect } from "react";
|
|
14
14
|
import { classNames } from "../../utils/util";
|
|
15
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;
|
|
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
17
|
var _d = useState(visible), shouldRender = _d[0], setShouldRender = _d[1];
|
|
18
18
|
var _e = useState(visible ? "entering" : "exiting"), animationState = _e[0], setAnimationState = _e[1];
|
|
19
19
|
useEffect(function () {
|
|
@@ -34,6 +34,6 @@ var Animated = function (_a) {
|
|
|
34
34
|
}
|
|
35
35
|
return function () { return clearTimeout(timeoutId); };
|
|
36
36
|
}, [visible, shouldRender, duration, keepMountedOnExit]);
|
|
37
|
-
return (_jsx("div", { className: classNames(animationState === "entering" ? enter === null || enter === void 0 ? void 0 : enter.className : exit === null || exit === void 0 ? void 0 : exit.className), style: __assign(__assign({}, (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 }));
|
|
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
38
|
};
|
|
39
39
|
export default Animated;
|
|
@@ -29,12 +29,12 @@ var BaseLayer = function (_a) {
|
|
|
29
29
|
document.removeEventListener("keydown", handleEscape);
|
|
30
30
|
};
|
|
31
31
|
}, [onClose, disableEscape]);
|
|
32
|
-
return (_jsx("div", { className: classNames("ajui-layer-backdrop", className), style: style,
|
|
32
|
+
return (_jsx("div", { className: classNames("ajui-layer-backdrop", className), style: style, onMouseDown: onClose, children: React.cloneElement(children, {
|
|
33
33
|
ref: focusRef,
|
|
34
|
-
|
|
34
|
+
onMouseDown: function (e) {
|
|
35
35
|
var _a, _b;
|
|
36
36
|
e.stopPropagation();
|
|
37
|
-
(_b = (_a = children.props).
|
|
37
|
+
(_b = (_a = children.props).onMouseDown) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
38
38
|
},
|
|
39
39
|
}) }));
|
|
40
40
|
};
|
package/hooks/useFocusTrap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
2
|
var focusableElementsString = 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex="0"], [contenteditable]';
|
|
3
3
|
/**
|
|
4
4
|
* A hook for trapping focus within an element.
|
|
@@ -8,33 +8,37 @@ var focusableElementsString = 'a[href], area[href], input:not([disabled]), selec
|
|
|
8
8
|
*/
|
|
9
9
|
var useFocusTrap = function (isActive) {
|
|
10
10
|
var trapRef = useRef(null);
|
|
11
|
+
var _a = useState(undefined), currentIndex = _a[0], setCurrentIndex = _a[1];
|
|
11
12
|
useEffect(function () {
|
|
12
13
|
if (!isActive || !trapRef.current)
|
|
13
14
|
return;
|
|
14
15
|
var focusableElements = trapRef.current.querySelectorAll(focusableElementsString);
|
|
15
|
-
var firstFocusableElement = focusableElements[0] || trapRef.current;
|
|
16
|
-
var lastFocusableElement = focusableElements[focusableElements.length - 1] || trapRef.current;
|
|
17
16
|
var trapFocus = function (event) {
|
|
17
|
+
var _a;
|
|
18
18
|
if (event.key !== "Tab")
|
|
19
19
|
return;
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
if (focusableElements.length === 0)
|
|
22
|
+
return;
|
|
23
|
+
var newIndex = currentIndex;
|
|
20
24
|
if (event.shiftKey) {
|
|
21
25
|
// Shift + Tab
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
newIndex =
|
|
27
|
+
((currentIndex !== null && currentIndex !== void 0 ? currentIndex : 0) - 1 + focusableElements.length) %
|
|
28
|
+
focusableElements.length;
|
|
25
29
|
}
|
|
26
30
|
else {
|
|
27
31
|
// Tab
|
|
28
|
-
|
|
29
|
-
firstFocusableElement === null || firstFocusableElement === void 0 ? void 0 : firstFocusableElement.focus();
|
|
30
|
-
}
|
|
32
|
+
newIndex = ((currentIndex !== null && currentIndex !== void 0 ? currentIndex : -1) + 1) % focusableElements.length;
|
|
31
33
|
}
|
|
32
|
-
|
|
34
|
+
(_a = focusableElements[newIndex]) === null || _a === void 0 ? void 0 : _a.focus();
|
|
35
|
+
setCurrentIndex(newIndex);
|
|
33
36
|
};
|
|
34
|
-
firstFocusableElement === null || firstFocusableElement === void 0 ? void 0 : firstFocusableElement.focus();
|
|
35
37
|
document.addEventListener("keydown", trapFocus);
|
|
36
|
-
return function () {
|
|
37
|
-
|
|
38
|
+
return function () {
|
|
39
|
+
document.removeEventListener("keydown", trapFocus);
|
|
40
|
+
};
|
|
41
|
+
}, [isActive, currentIndex]);
|
|
38
42
|
return trapRef;
|
|
39
43
|
};
|
|
40
44
|
export default useFocusTrap;
|