@adamjanicki/ui 1.3.5 → 1.3.6

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.
@@ -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,17 @@ 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
+ var _a;
58
+ var activeEl = document.activeElement;
59
+ if (!returnFocusOnEscape) {
60
+ (_a = activeEl === null || activeEl === void 0 ? void 0 : activeEl.blur) === null || _a === void 0 ? void 0 : _a.call(activeEl);
61
+ }
62
+ }, [returnFocusOnEscape]);
44
63
  return _jsx(BaseLayer, __assign({}, props, { visible: true }));
45
64
  };
46
65
  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.6",
4
4
  "description": "Basic UI components and hooks for React in TypeScript",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -11,7 +11,7 @@
11
11
  "url": "git+https://github.com/adamjanicki2/ui.git"
12
12
  },
13
13
  "scripts": {
14
- "build": "tsc; cp src/style.css ./style.css",
14
+ "build": "tsc; cp src/style.css ./style.css; rm -rf site/src/lib; cp -r src site/src/lib",
15
15
  "clean": "./clean.sh",
16
16
  "dev": "nodemon --watch src --ext ts,tsx,css --exec \"npm run build\"",
17
17
  "test": "jest --config jest.config.js",