@adamjanicki/ui 1.2.1 → 1.2.3
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/Layer/Layer.d.ts +4 -4
- package/components/Layer/Layer.js +4 -4
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useFocusTrap.js +7 -12
- package/hooks/useScrollLock.d.ts +1 -1
- package/hooks/useScrollLock.js +1 -1
- package/hooks/useWindowResize.d.ts +7 -0
- package/hooks/useWindowResize.js +13 -0
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +1 -1
- package/style.css +5 -18
- package/components/Modal/Modal.d.ts +0 -25
- package/components/Modal/Modal.js +0 -12
- package/components/Modal/index.d.ts +0 -2
- package/components/Modal/index.js +0 -2
|
@@ -3,7 +3,7 @@ type Props = {
|
|
|
3
3
|
/**
|
|
4
4
|
* Callback that fires when the user clicks outside the layer
|
|
5
5
|
*/
|
|
6
|
-
onClose
|
|
6
|
+
onClose?: () => void;
|
|
7
7
|
/**
|
|
8
8
|
* The child of the layer.
|
|
9
9
|
* IMPORTANT: the child must be able to accept a ref
|
|
@@ -12,16 +12,16 @@ type Props = {
|
|
|
12
12
|
/**
|
|
13
13
|
* [Optional] Additional class name
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
className?: string;
|
|
16
16
|
/**
|
|
17
17
|
* [Optional] Additional styles
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
style?: React.CSSProperties;
|
|
20
20
|
/**
|
|
21
21
|
* [Optional] Whether to disable the escape key to close the layer
|
|
22
22
|
* @default false
|
|
23
23
|
*/
|
|
24
24
|
disableEscape?: boolean;
|
|
25
25
|
};
|
|
26
|
-
declare const Layer: ({ onClose, children,
|
|
26
|
+
declare const Layer: ({ onClose, children, style, className, disableEscape, }: Props) => JSX.Element | null;
|
|
27
27
|
export default Layer;
|
|
@@ -3,13 +3,13 @@ import React, { useEffect } from "react";
|
|
|
3
3
|
import { useFocusTrap, useScrollLock } from "../../hooks";
|
|
4
4
|
import { classNames } from "../../utils/util";
|
|
5
5
|
var Layer = function (_a) {
|
|
6
|
-
var onClose = _a.onClose, children = _a.children,
|
|
7
|
-
var
|
|
6
|
+
var onClose = _a.onClose, children = _a.children, style = _a.style, className = _a.className, _b = _a.disableEscape, disableEscape = _b === void 0 ? false : _b;
|
|
7
|
+
var _c = useScrollLock(), lock = _c.lock, unlock = _c.unlock;
|
|
8
8
|
var focusRef = useFocusTrap(true);
|
|
9
9
|
useEffect(function () {
|
|
10
10
|
var handleEscape = function (event) {
|
|
11
11
|
if (event.key === "Escape") {
|
|
12
|
-
onClose();
|
|
12
|
+
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
if (!disableEscape)
|
|
@@ -23,7 +23,7 @@ var Layer = function (_a) {
|
|
|
23
23
|
lock();
|
|
24
24
|
return unlock;
|
|
25
25
|
}, [lock, unlock]);
|
|
26
|
-
return (_jsx("div", { className: classNames("ajui-layer-backdrop",
|
|
26
|
+
return (_jsx("div", { className: classNames("ajui-layer-backdrop", className), style: style, onClick: onClose, children: React.cloneElement(children, {
|
|
27
27
|
ref: focusRef,
|
|
28
28
|
onClick: function (e) {
|
|
29
29
|
var _a, _b;
|
package/hooks/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export { default as useMediaQuery } from "./useMediaQuery";
|
|
|
3
3
|
export { default as useWatchScroll } from "./useWatchScroll";
|
|
4
4
|
export { default as useFocusTrap } from "./useFocusTrap";
|
|
5
5
|
export { default as useScrollToHash } from "./useScrollToHash";
|
|
6
|
+
export { default as useWindowResize } from "./useWindowResize";
|
package/hooks/index.js
CHANGED
|
@@ -3,3 +3,4 @@ export { default as useMediaQuery } from "./useMediaQuery";
|
|
|
3
3
|
export { default as useWatchScroll } from "./useWatchScroll";
|
|
4
4
|
export { default as useFocusTrap } from "./useFocusTrap";
|
|
5
5
|
export { default as useScrollToHash } from "./useScrollToHash";
|
|
6
|
+
export { default as useWindowResize } from "./useWindowResize";
|
package/hooks/useFocusTrap.js
CHANGED
|
@@ -12,33 +12,28 @@ var useFocusTrap = function (isActive) {
|
|
|
12
12
|
if (!isActive || !trapRef.current)
|
|
13
13
|
return;
|
|
14
14
|
var focusableElements = trapRef.current.querySelectorAll(focusableElementsString);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var firstFocusableElement = focusableElements[0];
|
|
18
|
-
var lastFocusableElement = focusableElements[focusableElements.length - 1];
|
|
15
|
+
var firstFocusableElement = focusableElements[0] || trapRef.current;
|
|
16
|
+
var lastFocusableElement = focusableElements[focusableElements.length - 1] || trapRef.current;
|
|
19
17
|
var trapFocus = function (event) {
|
|
20
18
|
if (event.key !== "Tab")
|
|
21
19
|
return;
|
|
22
20
|
if (event.shiftKey) {
|
|
23
21
|
// Shift + Tab
|
|
24
22
|
if (document.activeElement === firstFocusableElement) {
|
|
25
|
-
lastFocusableElement.focus();
|
|
26
|
-
event.preventDefault();
|
|
23
|
+
lastFocusableElement === null || lastFocusableElement === void 0 ? void 0 : lastFocusableElement.focus();
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
26
|
else {
|
|
30
27
|
// Tab
|
|
31
28
|
if (document.activeElement === lastFocusableElement) {
|
|
32
|
-
firstFocusableElement.focus();
|
|
33
|
-
event.preventDefault();
|
|
29
|
+
firstFocusableElement === null || firstFocusableElement === void 0 ? void 0 : firstFocusableElement.focus();
|
|
34
30
|
}
|
|
35
31
|
}
|
|
32
|
+
event.preventDefault();
|
|
36
33
|
};
|
|
34
|
+
firstFocusableElement === null || firstFocusableElement === void 0 ? void 0 : firstFocusableElement.focus();
|
|
37
35
|
document.addEventListener("keydown", trapFocus);
|
|
38
|
-
|
|
39
|
-
return function () {
|
|
40
|
-
document.removeEventListener("keydown", trapFocus);
|
|
41
|
-
};
|
|
36
|
+
return function () { return document.removeEventListener("keydown", trapFocus); };
|
|
42
37
|
}, [isActive]);
|
|
43
38
|
return trapRef;
|
|
44
39
|
};
|
package/hooks/useScrollLock.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type ScrollLock = {
|
|
|
9
9
|
unlock: () => void;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
* Hook to lock and unlock the scroll position
|
|
12
|
+
* Hook to lock and unlock the scroll position.
|
|
13
13
|
* @returns Object with lock and unlock functions to lock and unlock the scroll position
|
|
14
14
|
*/
|
|
15
15
|
declare const useScrollLock: () => ScrollLock;
|
package/hooks/useScrollLock.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
2
|
/**
|
|
3
|
-
* Hook to lock and unlock the scroll position
|
|
3
|
+
* Hook to lock and unlock the scroll position.
|
|
4
4
|
* @returns Object with lock and unlock functions to lock and unlock the scroll position
|
|
5
5
|
*/
|
|
6
6
|
var useScrollLock = function () {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A hook that listens for window resize events.
|
|
4
|
+
*
|
|
5
|
+
* @param callback the callback function fired when the window is resized.
|
|
6
|
+
*/
|
|
7
|
+
var useWindowResize = function (callback) {
|
|
8
|
+
useEffect(function () {
|
|
9
|
+
window.addEventListener("resize", callback);
|
|
10
|
+
return function () { return window.removeEventListener("resize", callback); };
|
|
11
|
+
}, [callback]);
|
|
12
|
+
};
|
|
13
|
+
export default useWindowResize;
|
package/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export { default as Badge } from "./components/Badge";
|
|
|
9
9
|
export { default as Banner } from "./components/Banner";
|
|
10
10
|
export { default as Select } from "./components/Select";
|
|
11
11
|
export { default as ClickOutside } from "./components/ClickOutside";
|
|
12
|
-
export { default as Modal } from "./components/Modal";
|
|
13
12
|
export { default as Layer } from "./components/Layer";
|
|
14
13
|
export { default as Spinner } from "./components/Spinner";
|
|
15
14
|
export * from "./hooks";
|
package/index.js
CHANGED
|
@@ -10,7 +10,6 @@ export { default as Badge } from "./components/Badge";
|
|
|
10
10
|
export { default as Banner } from "./components/Banner";
|
|
11
11
|
export { default as Select } from "./components/Select";
|
|
12
12
|
export { default as ClickOutside } from "./components/ClickOutside";
|
|
13
|
-
export { default as Modal } from "./components/Modal";
|
|
14
13
|
export { default as Layer } from "./components/Layer";
|
|
15
14
|
export { default as Spinner } from "./components/Spinner";
|
|
16
15
|
// Hooks
|
package/package.json
CHANGED
package/style.css
CHANGED
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
--ajui-static-background: #e8e8e8;
|
|
53
53
|
--ajui-static-color: var(--ajui-default-color);
|
|
54
54
|
--ajui-static-border: var(--ajui-default-border);
|
|
55
|
-
/*
|
|
56
|
-
--ajui-layer-backdrop-background: rgba(
|
|
55
|
+
/* Layer */
|
|
56
|
+
--ajui-layer-backdrop-background: rgba(200, 200, 200, 0.6);
|
|
57
57
|
/* Link */
|
|
58
58
|
--ajui-link-color: #0070ff;
|
|
59
59
|
}
|
|
@@ -97,8 +97,8 @@
|
|
|
97
97
|
--ajui-static-background: var(--ajui-darkest-gray);
|
|
98
98
|
--ajui-static-color: var(--ajui-default-color);
|
|
99
99
|
--ajui-static-border: var(--ajui-default-border);
|
|
100
|
-
/*
|
|
101
|
-
--ajui-layer-backdrop-background: rgba(
|
|
100
|
+
/* Layer */
|
|
101
|
+
--ajui-layer-backdrop-background: rgba(40, 40, 40, 0.6);
|
|
102
102
|
/* Link */
|
|
103
103
|
--ajui-link-color: #009ef3;
|
|
104
104
|
}
|
|
@@ -332,7 +332,7 @@ a {
|
|
|
332
332
|
right: calc(var(--size) - 0.25rem);
|
|
333
333
|
}
|
|
334
334
|
|
|
335
|
-
/*
|
|
335
|
+
/* Layer */
|
|
336
336
|
.ajui-layer-backdrop {
|
|
337
337
|
position: fixed;
|
|
338
338
|
top: 0;
|
|
@@ -346,19 +346,6 @@ a {
|
|
|
346
346
|
align-items: center;
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
-
.ajui-modal {
|
|
350
|
-
background: var(--ajui-default-background);
|
|
351
|
-
box-shadow: inset 0 0 0 1px var(--ajui-default-border);
|
|
352
|
-
border-radius: var(--ajui-rounded-radius);
|
|
353
|
-
min-width: 50%;
|
|
354
|
-
max-width: 90%;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
.ajui-modal-close {
|
|
358
|
-
font-size: 1.5rem;
|
|
359
|
-
padding: 0 0.25rem;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
349
|
/* Spinner */
|
|
363
350
|
.ajui-spinner {
|
|
364
351
|
animation: ajui-spinner-animation 1s linear infinite;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
type Props = {
|
|
3
|
-
/**
|
|
4
|
-
* Whether the modal is open or not
|
|
5
|
-
*/
|
|
6
|
-
open: boolean;
|
|
7
|
-
/**
|
|
8
|
-
* Callback that fires when the user clicks the close button or outside the modal
|
|
9
|
-
*/
|
|
10
|
-
onClose: () => void;
|
|
11
|
-
/**
|
|
12
|
-
* The content of the modal
|
|
13
|
-
*/
|
|
14
|
-
children: React.ReactNode;
|
|
15
|
-
/**
|
|
16
|
-
* [Optional] Additional class name
|
|
17
|
-
*/
|
|
18
|
-
className?: string;
|
|
19
|
-
/**
|
|
20
|
-
* [Optional] Additional styles
|
|
21
|
-
*/
|
|
22
|
-
style?: React.CSSProperties;
|
|
23
|
-
};
|
|
24
|
-
declare const Modal: ({ open, onClose, children, className, style, }: Props) => JSX.Element | null;
|
|
25
|
-
export default Modal;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { IconButton } from "../Button";
|
|
3
|
-
import { classNames } from "../../utils/util";
|
|
4
|
-
import Layer from "../Layer";
|
|
5
|
-
var Modal = function (_a) {
|
|
6
|
-
var open = _a.open, onClose = _a.onClose, children = _a.children, className = _a.className, style = _a.style;
|
|
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
|
-
display: "flex",
|
|
9
|
-
justifyContent: "flex-end",
|
|
10
|
-
}, children: _jsx(IconButton, { "aria-label": "close", icon: "\u00D7", onClick: onClose, className: "ajui-modal-close" }) }), children] }) })) : null;
|
|
11
|
-
};
|
|
12
|
-
export default Modal;
|