@adamjanicki/ui 1.2.2 → 1.2.4

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.
@@ -28,7 +28,7 @@ export var UnstyledButton = forwardRef(function (_a, ref) {
28
28
  var to = _a.to, LinkElement = _a.LinkElement, className = _a.className, props = __rest(_a, ["to", "LinkElement", "className"]);
29
29
  className = classNames("ajui-button-base", className);
30
30
  if (to) {
31
- return (_jsx(UnstyledLink, { to: to, className: className, style: props.style, role: "button", children: props.children, LinkElement: LinkElement, "aria-label": props["aria-label"] }));
31
+ return (_jsx(UnstyledLink, { to: to, className: className, style: props.style, role: "button", LinkElement: LinkElement, "aria-label": props["aria-label"], children: props.children }));
32
32
  }
33
33
  return _jsx("button", __assign({}, props, { className: className, ref: ref }));
34
34
  });
@@ -3,7 +3,7 @@ type Props = {
3
3
  /**
4
4
  * Callback that fires when the user clicks outside the layer
5
5
  */
6
- onClose: () => void;
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,26 @@ type Props = {
12
12
  /**
13
13
  * [Optional] Additional class name
14
14
  */
15
- backdropClassName?: string;
15
+ className?: string;
16
16
  /**
17
17
  * [Optional] Additional styles
18
18
  */
19
- backdropStyle?: React.CSSProperties;
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
+ /**
26
+ * [Optional] Config for visibility
27
+ */
28
+ visibility?: {
29
+ visible: boolean;
30
+ invisibleStyle?: React.CSSProperties;
31
+ visibleStyle?: React.CSSProperties;
32
+ invisibleClassName?: string;
33
+ visibleClassName?: string;
34
+ };
25
35
  };
26
- declare const Layer: ({ onClose, children, backdropStyle, backdropClassName, disableEscape, }: Props) => JSX.Element | null;
36
+ declare const Layer: ({ onClose, children, style, className, disableEscape, visibility, }: Props) => JSX.Element | null;
27
37
  export default Layer;
@@ -1,15 +1,32 @@
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
+ };
1
12
  import { jsx as _jsx } from "react/jsx-runtime";
2
13
  import React, { useEffect } from "react";
3
14
  import { useFocusTrap, useScrollLock } from "../../hooks";
4
15
  import { classNames } from "../../utils/util";
5
16
  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;
17
+ var onClose = _a.onClose, children = _a.children, _b = _a.style, style = _b === void 0 ? {} : _b, className = _a.className, _c = _a.disableEscape, disableEscape = _c === void 0 ? false : _c, _d = _a.visibility, visibility = _d === void 0 ? { visible: true } : _d;
18
+ var visible = visibility.visible, _e = visibility.invisibleStyle, invisibleStyle = _e === void 0 ? {
19
+ zIndex: -1,
20
+ opacity: 0,
21
+ pointerEvents: "none",
22
+ userSelect: "none",
23
+ } : _e, _f = visibility.visibleStyle, visibleStyle = _f === void 0 ? { opacity: 1 } : _f, invisibleClassName = visibility.invisibleClassName, visibleClassName = visibility.visibleClassName;
24
+ var _g = useScrollLock(), lock = _g.lock, unlock = _g.unlock;
8
25
  var focusRef = useFocusTrap(true);
9
26
  useEffect(function () {
10
27
  var handleEscape = function (event) {
11
28
  if (event.key === "Escape") {
12
- onClose();
29
+ onClose === null || onClose === void 0 ? void 0 : onClose();
13
30
  }
14
31
  };
15
32
  if (!disableEscape)
@@ -23,7 +40,7 @@ var Layer = function (_a) {
23
40
  lock();
24
41
  return unlock;
25
42
  }, [lock, unlock]);
26
- return (_jsx("div", { className: classNames("ajui-layer-backdrop", backdropClassName), style: backdropStyle, onClick: onClose, children: React.cloneElement(children, {
43
+ return (_jsx("div", { className: classNames("ajui-layer-backdrop", className, visible ? visibleClassName : invisibleClassName), style: __assign(__assign({}, style), (visible ? visibleStyle : invisibleStyle)), onClick: onClose, children: React.cloneElement(children, {
27
44
  ref: focusRef,
28
45
  onClick: function (e) {
29
46
  var _a, _b;
@@ -25,7 +25,7 @@ import { forwardRef } from "react";
25
25
  import { classNames } from "../../utils/util";
26
26
  var identity = function (x) { return x; };
27
27
  var Select = function (_a, ref) {
28
- var className = _a.className, options = _a.options, _b = _a.getOptionValue, getOptionValue = _b === void 0 ? identity : _b, _c = _a.getOptionLabel, getOptionLabel = _c === void 0 ? identity : _c, _d = _a.corners, corners = _d === void 0 ? "rounded" : _d, _e = _a.style, style = _e === void 0 ? {} : _e, innerStyle = _a.innerStyle, innerClassName = _a.innerClassName, disabled = _a.disabled, props = __rest(_a, ["className", "options", "getOptionValue", "getOptionLabel", "corners", "style", "innerStyle", "innerClassName", "disabled"]);
29
- return (_jsxs("div", { className: classNames("ajui-select-container", disabled ? "ajui-select-disabled" : undefined, className) || undefined, children: [_jsx("select", __assign({}, props, { ref: ref, className: classNames("ajui-select-base corners--".concat(corners), innerClassName), style: innerStyle, disabled: disabled, children: options.map(function (option, index) { return (_jsx("option", { value: getOptionValue(option), children: getOptionLabel(option) }, index)); }) })), _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 64 64", className: "ajui-select-triangle", "aria-hidden": "true", children: _jsx("path", { fill: "currentColor", d: "M 29.175781 50.824219 C 30.738281 52.386719 33.273438 52.386719 34.835938 50.824219 L 58.835938 26.824219 C 60.398438 25.261719 60.398438 22.726562 58.835938 21.164062 C 57.273438 19.601562 54.738281 19.601562 53.175781 21.164062 L 32 42.335938 L 10.824219 21.175781 C 9.261719 19.613281 6.726562 19.613281 5.164062 21.175781 C 3.601562 22.738281 3.601562 25.273438 5.164062 26.835938 L 29.164062 50.835938 Z M 29.175781 50.824219" }) })] }));
28
+ var className = _a.className, options = _a.options, _b = _a.getOptionValue, getOptionValue = _b === void 0 ? identity : _b, _c = _a.getOptionLabel, getOptionLabel = _c === void 0 ? identity : _c, _d = _a.corners, corners = _d === void 0 ? "rounded" : _d, style = _a.style, innerStyle = _a.innerStyle, innerClassName = _a.innerClassName, disabled = _a.disabled, props = __rest(_a, ["className", "options", "getOptionValue", "getOptionLabel", "corners", "style", "innerStyle", "innerClassName", "disabled"]);
29
+ return (_jsxs("div", { className: classNames("ajui-select-container", disabled ? "ajui-select-disabled" : undefined, className) || undefined, style: style, children: [_jsx("select", __assign({}, props, { ref: ref, className: classNames("ajui-select-base corners--".concat(corners), innerClassName), style: innerStyle, disabled: disabled, children: options.map(function (option, index) { return (_jsx("option", { value: getOptionValue(option), children: getOptionLabel(option) }, index)); }) })), _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 64 64", className: "ajui-select-triangle", "aria-hidden": "true", children: _jsx("path", { fill: "currentColor", d: "M 29.175781 50.824219 C 30.738281 52.386719 33.273438 52.386719 34.835938 50.824219 L 58.835938 26.824219 C 60.398438 25.261719 60.398438 22.726562 58.835938 21.164062 C 57.273438 19.601562 54.738281 19.601562 53.175781 21.164062 L 32 42.335938 L 10.824219 21.175781 C 9.261719 19.613281 6.726562 19.613281 5.164062 21.175781 C 3.601562 22.738281 3.601562 25.273438 5.164062 26.835938 L 29.164062 50.835938 Z M 29.175781 50.824219" }) })] }));
30
30
  };
31
31
  export default forwardRef(Select);
@@ -1,3 +1,4 @@
1
+ import React from "react";
1
2
  type Props = {
2
3
  /**
3
4
  * [Optional] Additional class names to apply to the spinner.
@@ -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
- if (!focusableElements.length)
16
- return;
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
- firstFocusableElement.focus();
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/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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamjanicki/ui",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
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
@@ -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
- /* Modal */
56
- --ajui-layer-backdrop-background: rgba(0, 0, 0, 0.25);
55
+ /* Layer */
56
+ --ajui-layer-backdrop-background: rgba(200, 200, 200, 0.7);
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
- /* Modal */
101
- --ajui-layer-backdrop-background: rgba(0, 0, 0, 0.4);
100
+ /* Layer */
101
+ --ajui-layer-backdrop-background: rgba(55, 55, 55, 0.7);
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
- /* Modal */
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;
@@ -1,2 +0,0 @@
1
- import Modal from "./Modal";
2
- export default Modal;
@@ -1,2 +0,0 @@
1
- import Modal from "./Modal";
2
- export default Modal;