@adamjanicki/ui 1.0.9 → 1.1.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.
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
type Props = {
|
|
3
|
-
/**
|
|
4
|
-
* Whether the layer is open or not
|
|
5
|
-
*/
|
|
6
|
-
open: boolean;
|
|
7
3
|
/**
|
|
8
4
|
* Callback that fires when the user clicks outside the layer
|
|
9
5
|
*/
|
|
@@ -21,6 +17,11 @@ type Props = {
|
|
|
21
17
|
* [Optional] Additional styles
|
|
22
18
|
*/
|
|
23
19
|
backdropStyle?: React.CSSProperties;
|
|
20
|
+
/**
|
|
21
|
+
* [Optional] Whether to disable the escape key to close the layer
|
|
22
|
+
* @default false
|
|
23
|
+
*/
|
|
24
|
+
disableEscape?: boolean;
|
|
24
25
|
};
|
|
25
|
-
declare const
|
|
26
|
-
export default
|
|
26
|
+
declare const Layer: ({ onClose, children, backdropStyle, backdropClassName, disableEscape, }: Props) => JSX.Element | null;
|
|
27
|
+
export default Layer;
|
|
@@ -2,34 +2,34 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import React, { useEffect } from "react";
|
|
3
3
|
import { useFocusTrap, useScrollLock } from "../../hooks";
|
|
4
4
|
import { classNames } from "../../utils/util";
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var focusRef = useFocusTrap(
|
|
5
|
+
var Layer = function (_a) {
|
|
6
|
+
var onClose = _a.onClose, children = _a.children, _b = _a.backdropStyle, backdropStyle = _b === void 0 ? {} : _b, backdropClassName = _a.backdropClassName, _c = _a.disableEscape, disableEscape = _c === void 0 ? false : _c;
|
|
7
|
+
var _d = useScrollLock(), lock = _d.lock, unlock = _d.unlock;
|
|
8
|
+
var focusRef = useFocusTrap(true);
|
|
9
9
|
useEffect(function () {
|
|
10
10
|
var handleEscape = function (event) {
|
|
11
11
|
if (event.key === "Escape") {
|
|
12
12
|
onClose();
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
if (!disableEscape)
|
|
16
|
+
document.addEventListener("keydown", handleEscape);
|
|
16
17
|
return function () {
|
|
17
|
-
|
|
18
|
+
if (!disableEscape)
|
|
19
|
+
document.removeEventListener("keydown", handleEscape);
|
|
18
20
|
};
|
|
19
|
-
}, [onClose]);
|
|
21
|
+
}, [onClose, disableEscape]);
|
|
20
22
|
useEffect(function () {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}, [open, lock, unlock]);
|
|
26
|
-
return open ? (_jsx("div", { className: classNames("ajui-layer-backdrop", backdropClassName), style: backdropStyle, onClick: onClose, children: React.cloneElement(children, {
|
|
23
|
+
lock();
|
|
24
|
+
return unlock;
|
|
25
|
+
}, [lock, unlock]);
|
|
26
|
+
return (_jsx("div", { className: classNames("ajui-layer-backdrop", backdropClassName), style: backdropStyle, onClick: onClose, children: React.cloneElement(children, {
|
|
27
27
|
ref: focusRef,
|
|
28
28
|
onClick: function (e) {
|
|
29
29
|
var _a, _b;
|
|
30
30
|
e.stopPropagation();
|
|
31
31
|
(_b = (_a = children.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
32
32
|
},
|
|
33
|
-
}) }))
|
|
33
|
+
}) }));
|
|
34
34
|
};
|
|
35
|
-
export default
|
|
35
|
+
export default Layer;
|
|
@@ -4,9 +4,9 @@ import { classNames } from "../../utils/util";
|
|
|
4
4
|
import Layer from "../Layer";
|
|
5
5
|
var Modal = function (_a) {
|
|
6
6
|
var open = _a.open, onClose = _a.onClose, children = _a.children, className = _a.className, style = _a.style;
|
|
7
|
-
return (_jsx(Layer, { onClose: onClose,
|
|
7
|
+
return open ? (_jsx(Layer, { onClose: onClose, children: _jsxs("div", { className: classNames("ajui-modal", className), role: "dialog", "aria-modal": "true", style: style, children: [_jsx("div", { style: {
|
|
8
8
|
display: "flex",
|
|
9
9
|
justifyContent: "flex-end",
|
|
10
|
-
}, children: _jsx(IconButton, { name: "close", icon: "\u00D7", onClick: onClose, className: "ajui-modal-close" }) }), children] }) }));
|
|
10
|
+
}, children: _jsx(IconButton, { name: "close", icon: "\u00D7", onClick: onClose, className: "ajui-modal-close" }) }), children] }) })) : null;
|
|
11
11
|
};
|
|
12
12
|
export default Modal;
|
package/hooks/useFocusTrap.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* A hook for trapping focus within an element.
|
|
3
3
|
*
|
|
4
|
-
* @param isActive true if
|
|
4
|
+
* @param isActive true if the element is active, false otherwise
|
|
5
5
|
* @returns ref object that must be passed to the element that should be trapped
|
|
6
6
|
*/
|
|
7
7
|
declare const useFocusTrap: <T extends HTMLElement>(isActive: boolean) => import("react").MutableRefObject<T | null>;
|
package/hooks/useFocusTrap.js
CHANGED
|
@@ -3,7 +3,7 @@ var focusableElementsString = 'a[href], area[href], input:not([disabled]), selec
|
|
|
3
3
|
/**
|
|
4
4
|
* A hook for trapping focus within an element.
|
|
5
5
|
*
|
|
6
|
-
* @param isActive true if
|
|
6
|
+
* @param isActive true if the element is active, false otherwise
|
|
7
7
|
* @returns ref object that must be passed to the element that should be trapped
|
|
8
8
|
*/
|
|
9
9
|
var useFocusTrap = function (isActive) {
|
package/package.json
CHANGED
package/style.css
CHANGED
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
--ajui-info-color: #0d47a1;
|
|
50
50
|
--ajui-info-border: #90caf9;
|
|
51
51
|
|
|
52
|
-
--ajui-static-background: #
|
|
53
|
-
--ajui-static-color:
|
|
54
|
-
--ajui-static-border:
|
|
52
|
+
--ajui-static-background: #e8e8e8;
|
|
53
|
+
--ajui-static-color: var(--ajui-default-color);
|
|
54
|
+
--ajui-static-border: var(--ajui-default-border);
|
|
55
55
|
/* Modal */
|
|
56
56
|
--ajui-layer-backdrop-background: rgba(0, 0, 0, 0.25);
|
|
57
57
|
/* Link */
|
|
@@ -94,9 +94,9 @@
|
|
|
94
94
|
--ajui-info-color: #d4f1f5;
|
|
95
95
|
--ajui-info-border: #1d8ea4;
|
|
96
96
|
|
|
97
|
-
--ajui-static-background:
|
|
98
|
-
--ajui-static-color:
|
|
99
|
-
--ajui-static-border:
|
|
97
|
+
--ajui-static-background: var(--ajui-darkest-gray);
|
|
98
|
+
--ajui-static-color: var(--ajui-default-color);
|
|
99
|
+
--ajui-static-border: var(--ajui-default-border);
|
|
100
100
|
/* Modal */
|
|
101
101
|
--ajui-layer-backdrop-background: rgba(0, 0, 0, 0.4);
|
|
102
102
|
/* Link */
|