@adamjanicki/ui 1.3.6 → 1.3.8
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/Animated/Animated.js +1 -1
- package/components/Layer/Layer.js +7 -5
- package/functions/index.d.ts +2 -1
- package/functions/index.js +2 -1
- package/functions/scrollToId.d.ts +6 -0
- package/functions/scrollToId.js +17 -0
- package/hooks/useScrollToHash.d.ts +11 -2
- package/hooks/useScrollToHash.js +11 -15
- package/package.json +2 -2
- package/style.css +2 -2
|
@@ -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;
|
|
@@ -54,11 +54,13 @@ var Layer = function (_a) {
|
|
|
54
54
|
// Lock and unlock on mount and unmount
|
|
55
55
|
useScrollLock();
|
|
56
56
|
useEffect(function () {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
(
|
|
61
|
-
|
|
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
|
+
};
|
|
62
64
|
}, [returnFocusOnEscape]);
|
|
63
65
|
return _jsx(BaseLayer, __assign({}, props, { visible: true }));
|
|
64
66
|
};
|
package/functions/index.d.ts
CHANGED
package/functions/index.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scroll to the element with the given id
|
|
3
|
+
* @param id the id of the element to scroll to
|
|
4
|
+
* @param behavior behavior of the scroll
|
|
5
|
+
*/
|
|
6
|
+
export default function scrollToId(id, behavior) {
|
|
7
|
+
try {
|
|
8
|
+
// catch cases where hash is not a valid id
|
|
9
|
+
var element = document.getElementById(id);
|
|
10
|
+
if (element) {
|
|
11
|
+
element.scrollIntoView({ behavior: behavior });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch (_a) {
|
|
15
|
+
// do nothing
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
type UseScrollToHashConfig = {
|
|
2
|
+
/**
|
|
3
|
+
* Whether or not to scroll to the hash
|
|
4
|
+
*/
|
|
5
|
+
active: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* The scroll behavior to use
|
|
8
|
+
*/
|
|
9
|
+
behavior?: ScrollBehavior;
|
|
10
|
+
};
|
|
1
11
|
/**
|
|
2
12
|
* A hook for scrolling to a hash on the page.
|
|
3
|
-
* @returns a function that scrolls to the hash on the page
|
|
4
13
|
*/
|
|
5
|
-
declare const useScrollToHash: (
|
|
14
|
+
declare const useScrollToHash: ({ active, behavior, }: UseScrollToHashConfig) => void;
|
|
6
15
|
export default useScrollToHash;
|
package/hooks/useScrollToHash.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import scrollToId from "../functions/scrollToId";
|
|
2
3
|
/**
|
|
3
4
|
* A hook for scrolling to a hash on the page.
|
|
4
|
-
* @returns a function that scrolls to the hash on the page
|
|
5
5
|
*/
|
|
6
|
-
var useScrollToHash = function () {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
function (behavior) {
|
|
6
|
+
var useScrollToHash = function (_a) {
|
|
7
|
+
var active = _a.active, _b = _a.behavior, behavior = _b === void 0 ? "smooth" : _b;
|
|
8
|
+
useEffect(function () {
|
|
9
|
+
if (!active)
|
|
10
|
+
return;
|
|
13
11
|
var hash = window.location.hash;
|
|
14
|
-
if (hash) {
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
element.scrollIntoView({ behavior: behavior });
|
|
18
|
-
}
|
|
12
|
+
if ((hash === null || hash === void 0 ? void 0 : hash.length) > 1) {
|
|
13
|
+
var id = hash.substring(1);
|
|
14
|
+
scrollToId(id, behavior);
|
|
19
15
|
}
|
|
20
|
-
}, []);
|
|
16
|
+
}, [active, behavior]);
|
|
21
17
|
};
|
|
22
18
|
export default useScrollToHash;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamjanicki/ui",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.8",
|
|
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",
|
|
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",
|
package/style.css
CHANGED
|
@@ -170,11 +170,11 @@ button:not([disabled]):focus-visible {
|
|
|
170
170
|
|
|
171
171
|
/* Badge */
|
|
172
172
|
.ajui-badge {
|
|
173
|
-
padding:
|
|
173
|
+
padding: 2px 6px;
|
|
174
174
|
border-style: solid;
|
|
175
175
|
border-width: 1px;
|
|
176
176
|
font-weight: 600;
|
|
177
|
-
font-size:
|
|
177
|
+
font-size: 14px;
|
|
178
178
|
width: fit-content;
|
|
179
179
|
}
|
|
180
180
|
|