@adamjanicki/ui 1.3.5 → 1.3.7

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.
@@ -34,6 +34,6 @@ var Animated = function (_a) {
34
34
  }
35
35
  return function () { return clearTimeout(timeoutId); };
36
36
  }, [visible, shouldRender, duration, keepMountedOnExit]);
37
- return (_jsx("div", { className: classNames(className, animationState === "entering" ? enter === null || enter === void 0 ? void 0 : enter.className : exit === null || exit === void 0 ? void 0 : exit.className), style: __assign(__assign(__assign({}, style), (animationState === "entering" ? enter === null || enter === void 0 ? void 0 : enter.style : exit === null || exit === void 0 ? void 0 : exit.style)), { transition: "all ".concat(duration, "ms ease-in-out") }), children: shouldRender && children }));
37
+ return (_jsx("div", { className: classNames(className, animationState === "entering" ? enter === null || enter === void 0 ? void 0 : enter.className : exit === null || exit === void 0 ? void 0 : exit.className), style: __assign(__assign(__assign({}, style), (animationState === "entering" ? enter === null || enter === void 0 ? void 0 : enter.style : exit === null || exit === void 0 ? void 0 : exit.style)), { transition: "all ".concat(duration, "ms ease-in-out") }), "aria-hidden": !visible, children: shouldRender && children }));
38
38
  };
39
39
  export default Animated;
@@ -22,6 +22,11 @@ type LayerProps = {
22
22
  * @default false
23
23
  */
24
24
  disableEscape?: boolean;
25
+ /**
26
+ * [Optional] Whether to return focus to the element that triggered the layer
27
+ * @default false
28
+ */
29
+ returnFocusOnEscape?: boolean;
25
30
  };
26
- declare const Layer: (props: LayerProps) => JSX.Element;
31
+ declare const Layer: ({ returnFocusOnEscape, ...props }: LayerProps) => JSX.Element;
27
32
  export default Layer;
@@ -9,6 +9,17 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
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
+ };
12
23
  import { jsx as _jsx } from "react/jsx-runtime";
13
24
  import React, { useEffect } from "react";
14
25
  import { useFocusTrap, useScrollLock } from "../../hooks";
@@ -38,9 +49,19 @@ var BaseLayer = function (_a) {
38
49
  },
39
50
  }) }));
40
51
  };
41
- var Layer = function (props) {
52
+ var Layer = function (_a) {
53
+ var _b = _a.returnFocusOnEscape, returnFocusOnEscape = _b === void 0 ? false : _b, props = __rest(_a, ["returnFocusOnEscape"]);
42
54
  // Lock and unlock on mount and unmount
43
55
  useScrollLock();
56
+ useEffect(function () {
57
+ return function () {
58
+ var _a;
59
+ var activeEl = document.activeElement;
60
+ if (!returnFocusOnEscape) {
61
+ (_a = activeEl === null || activeEl === void 0 ? void 0 : activeEl.blur) === null || _a === void 0 ? void 0 : _a.call(activeEl);
62
+ }
63
+ };
64
+ }, [returnFocusOnEscape]);
44
65
  return _jsx(BaseLayer, __assign({}, props, { visible: true }));
45
66
  };
46
67
  export default Layer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamjanicki/ui",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
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
@@ -170,11 +170,11 @@ button:not([disabled]):focus-visible {
170
170
 
171
171
  /* Badge */
172
172
  .ajui-badge {
173
- padding: 0.125rem 0.375rem;
173
+ padding: 2px 6px;
174
174
  border-style: solid;
175
175
  border-width: 1px;
176
176
  font-weight: 600;
177
- font-size: 0.875rem;
177
+ font-size: 14px;
178
178
  width: fit-content;
179
179
  }
180
180