@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.
@@ -20,7 +20,7 @@ type Props = {
20
20
  style?: React.CSSProperties;
21
21
  /**
22
22
  * [Optional] The corner style of the badge.
23
- * @default "pill"
23
+ * @default "rounded"
24
24
  */
25
25
  corners?: CornerType;
26
26
  };
@@ -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 Modal: ({ open, onClose, children, backdropStyle, backdropClassName, }: Props) => JSX.Element | null;
26
- export default Modal;
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 Modal = function (_a) {
6
- var open = _a.open, onClose = _a.onClose, children = _a.children, _b = _a.backdropStyle, backdropStyle = _b === void 0 ? {} : _b, backdropClassName = _a.backdropClassName;
7
- var _c = useScrollLock(), lock = _c.lock, unlock = _c.unlock;
8
- var focusRef = useFocusTrap(open);
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
- document.addEventListener("keydown", handleEscape);
15
+ if (!disableEscape)
16
+ document.addEventListener("keydown", handleEscape);
16
17
  return function () {
17
- document.removeEventListener("keydown", handleEscape);
18
+ if (!disableEscape)
19
+ document.removeEventListener("keydown", handleEscape);
18
20
  };
19
- }, [onClose]);
21
+ }, [onClose, disableEscape]);
20
22
  useEffect(function () {
21
- if (open)
22
- lock();
23
- else
24
- unlock();
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
- }) })) : null;
33
+ }) }));
34
34
  };
35
- export default Modal;
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, open: open, children: _jsxs("div", { className: classNames("ajui-modal", className), role: "dialog", "aria-modal": "true", style: style, children: [_jsx("div", { 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
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;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * A hook for trapping focus within an element.
3
3
  *
4
- * @param isActive true if an element is active, false otherwise
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>;
@@ -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 an element is active, false otherwise
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamjanicki/ui",
3
- "version": "1.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "Basic UI components and hooks for React in TypeScript",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
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: #f5f5f5;
53
- --ajui-static-color: #424242;
54
- --ajui-static-border: #bdbdbd;
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: #333333;
98
- --ajui-static-color: #e5e5e5;
99
- --ajui-static-border: #595959;
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 */