@adamjanicki/ui 1.0.8 → 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.
- package/components/Badge/Badge.d.ts +1 -1
- package/components/Layer/Layer.d.ts +7 -6
- package/components/Layer/Layer.js +15 -15
- package/components/Modal/Modal.js +2 -2
- package/components/Spinner/Spinner.d.ts +12 -0
- package/components/Spinner/Spinner.js +31 -0
- package/components/Spinner/index.d.ts +2 -0
- package/components/Spinner/index.js +2 -0
- package/hooks/useFocusTrap.d.ts +1 -1
- package/hooks/useFocusTrap.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/style.css +22 -8
|
@@ -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;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type Props = {
|
|
2
|
+
/**
|
|
3
|
+
* [Optional] Additional class names to apply to the spinner.
|
|
4
|
+
*/
|
|
5
|
+
className?: string;
|
|
6
|
+
/**
|
|
7
|
+
* [Optional] Additional styles to apply to the spinner.
|
|
8
|
+
*/
|
|
9
|
+
style?: React.CSSProperties;
|
|
10
|
+
};
|
|
11
|
+
declare const Spinner: ({ className, ...props }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export default Spinner;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
import { classNames } from "../../utils/util";
|
|
25
|
+
var Spinner = function (_a) {
|
|
26
|
+
var className = _a.className, props = __rest(_a, ["className"]);
|
|
27
|
+
return (
|
|
28
|
+
// Designed on 2023-08-18
|
|
29
|
+
_jsx("svg", __assign({ xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 512 512", className: classNames("ajui-spinner", className) }, props, { children: _jsx("path", { fill: "currentColor", d: "M256,0C114.62,0,0,114.62,0,256S114.62,512,256,512c70.64,0,134.59-28.61,180.91-74.88l-31.11-31.11c-38.35,38.3-91.31,61.99-149.8,61.99-117.08,0-212-94.92-212-212S138.92,44,256,44V0Z" }) })));
|
|
30
|
+
};
|
|
31
|
+
export default Spinner;
|
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/index.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export { default as Select } from "./components/Select";
|
|
|
11
11
|
export { default as ClickOutside } from "./components/ClickOutside";
|
|
12
12
|
export { default as Modal } from "./components/Modal";
|
|
13
13
|
export { default as Layer } from "./components/Layer";
|
|
14
|
+
export { default as Spinner } from "./components/Spinner";
|
|
14
15
|
export * from "./hooks";
|
package/index.js
CHANGED
|
@@ -12,5 +12,6 @@ export { default as Select } from "./components/Select";
|
|
|
12
12
|
export { default as ClickOutside } from "./components/ClickOutside";
|
|
13
13
|
export { default as Modal } from "./components/Modal";
|
|
14
14
|
export { default as Layer } from "./components/Layer";
|
|
15
|
+
export { default as Spinner } from "./components/Spinner";
|
|
15
16
|
// Hooks
|
|
16
17
|
export * from "./hooks";
|
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 */
|
|
@@ -192,7 +192,6 @@ a {
|
|
|
192
192
|
.ajui-button-base {
|
|
193
193
|
background: none;
|
|
194
194
|
color: inherit;
|
|
195
|
-
fill: inherit;
|
|
196
195
|
border: none;
|
|
197
196
|
padding: 0;
|
|
198
197
|
cursor: pointer;
|
|
@@ -220,7 +219,6 @@ a {
|
|
|
220
219
|
.ajui-button--primary {
|
|
221
220
|
background-color: var(--ajui-button-primary-background);
|
|
222
221
|
color: var(--ajui-button-primary-color);
|
|
223
|
-
fill: var(--ajui-button-primary-color);
|
|
224
222
|
transition: opacity var(--ajui-default-transition);
|
|
225
223
|
}
|
|
226
224
|
|
|
@@ -329,3 +327,19 @@ a {
|
|
|
329
327
|
font-size: 1.5rem;
|
|
330
328
|
padding: 0 0.25rem;
|
|
331
329
|
}
|
|
330
|
+
|
|
331
|
+
/* Spinner */
|
|
332
|
+
.ajui-spinner {
|
|
333
|
+
animation: ajui-spinner-animation 1s linear infinite;
|
|
334
|
+
transform-origin: center;
|
|
335
|
+
height: 1.5rem;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
@keyframes ajui-spinner-animation {
|
|
339
|
+
0% {
|
|
340
|
+
transform: rotate(0deg);
|
|
341
|
+
}
|
|
342
|
+
100% {
|
|
343
|
+
transform: rotate(360deg);
|
|
344
|
+
}
|
|
345
|
+
}
|