@adamjanicki/ui 1.0.3 → 1.0.5
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/ClickOutside/ClickOutside.js +19 -18
- package/components/Link/Link.d.ts +6 -5
- package/components/Link/Link.js +6 -0
- package/components/Link/index.d.ts +2 -0
- package/components/Link/index.js +2 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +1 -0
- package/hooks/useScrollToHash.d.ts +6 -0
- package/hooks/useScrollToHash.js +22 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +2 -9
- package/style.css +9 -1
|
@@ -1,37 +1,38 @@
|
|
|
1
|
-
import { cloneElement, useEffect, useRef } from "react";
|
|
1
|
+
import { cloneElement, useCallback, useEffect, useRef } from "react";
|
|
2
2
|
var ClickOutside = function (_a) {
|
|
3
3
|
var children = _a.children, onClickOutside = _a.onClickOutside;
|
|
4
|
-
var ref = useRef(
|
|
4
|
+
var ref = useRef();
|
|
5
5
|
var bubbledRef = useRef(false);
|
|
6
6
|
var startedRef = useRef(false);
|
|
7
7
|
useEffect(function () {
|
|
8
|
-
|
|
9
|
-
var timeoutId = setTimeout(function () {
|
|
8
|
+
setTimeout(function () {
|
|
10
9
|
startedRef.current = true;
|
|
11
10
|
}, 0);
|
|
12
|
-
var handleClickOutside = function (event) {
|
|
13
|
-
var bubbledUp = bubbledRef.current;
|
|
14
|
-
bubbledRef.current = false;
|
|
15
|
-
if (!startedRef.current || !ref.current || bubbledUp)
|
|
16
|
-
return;
|
|
17
|
-
var isOnEventPath = event.composedPath().includes(ref.current);
|
|
18
|
-
if (!isOnEventPath) {
|
|
19
|
-
onClickOutside(event);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
document.addEventListener("click", handleClickOutside);
|
|
23
11
|
return function () {
|
|
24
|
-
clearTimeout(timeoutId);
|
|
25
12
|
startedRef.current = false;
|
|
26
|
-
document.removeEventListener("click", handleClickOutside);
|
|
27
13
|
};
|
|
14
|
+
}, []);
|
|
15
|
+
var handleClickOutside = useCallback(function (event) {
|
|
16
|
+
var bubbledUp = bubbledRef.current;
|
|
17
|
+
bubbledRef.current = false;
|
|
18
|
+
if (!startedRef.current || !ref.current || bubbledUp)
|
|
19
|
+
return;
|
|
20
|
+
var isOnEventPath = event.composedPath().includes(ref.current);
|
|
21
|
+
!isOnEventPath && onClickOutside(event);
|
|
28
22
|
}, [onClickOutside]);
|
|
23
|
+
useEffect(function () {
|
|
24
|
+
document.addEventListener("click", handleClickOutside);
|
|
25
|
+
return function () { return document.removeEventListener("click", handleClickOutside); };
|
|
26
|
+
}, [handleClickOutside]);
|
|
29
27
|
return cloneElement(children, {
|
|
30
28
|
ref: ref,
|
|
31
29
|
onClick: function (event) {
|
|
32
30
|
var _a, _b;
|
|
31
|
+
// point of this is to let us know that click bubbled up
|
|
32
|
+
// from the child element, so we can ignore it if it
|
|
33
|
+
// happens on the element itself
|
|
33
34
|
bubbledRef.current = true;
|
|
34
|
-
(_b = (_a = children.props).
|
|
35
|
+
(_b = (_a = children.props).onclick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
35
36
|
},
|
|
36
37
|
});
|
|
37
38
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
type BuiltinLinkProps = Omit<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "href"
|
|
3
|
-
export type CustomLinkElement = (props: Partial<BuiltinLinkProps & {
|
|
2
|
+
type BuiltinLinkProps = Omit<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "href">;
|
|
3
|
+
export type CustomLinkElement = (props: Partial<BuiltinLinkProps> & {
|
|
4
4
|
to: string;
|
|
5
|
-
}
|
|
6
|
-
ref?: React.
|
|
5
|
+
} & {
|
|
6
|
+
ref?: React.MutableRefObject<HTMLAnchorElement>;
|
|
7
7
|
}) => React.ReactNode;
|
|
8
8
|
type DefaultLinkProps = BuiltinLinkProps & {
|
|
9
9
|
/**
|
|
@@ -18,4 +18,5 @@ type DefaultLinkProps = BuiltinLinkProps & {
|
|
|
18
18
|
LinkElement?: CustomLinkElement;
|
|
19
19
|
};
|
|
20
20
|
export declare const UnstyledLink: React.ForwardRefExoticComponent<Omit<DefaultLinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
21
|
-
|
|
21
|
+
declare const Link: React.ForwardRefExoticComponent<Omit<DefaultLinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
|
|
22
|
+
export default Link;
|
package/components/Link/Link.js
CHANGED
|
@@ -22,6 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
};
|
|
23
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
24
|
import { forwardRef } from "react";
|
|
25
|
+
import { classNames } from "../../utils/util";
|
|
25
26
|
var DefaultLinkElement = forwardRef(function (_a, ref) {
|
|
26
27
|
var to = _a.to, props = __rest(_a, ["to"]);
|
|
27
28
|
return _jsx("a", __assign({}, props, { href: to, ref: ref }));
|
|
@@ -30,3 +31,8 @@ export var UnstyledLink = forwardRef(function (_a, ref) {
|
|
|
30
31
|
var _b = _a.LinkElement, LinkElement = _b === void 0 ? DefaultLinkElement : _b, props = __rest(_a, ["LinkElement"]);
|
|
31
32
|
return (_jsx(LinkElement, __assign({}, props, { ref: ref })));
|
|
32
33
|
});
|
|
34
|
+
var Link = forwardRef(function (_a, ref) {
|
|
35
|
+
var className = _a.className, props = __rest(_a, ["className"]);
|
|
36
|
+
return (_jsx(UnstyledLink, __assign({}, props, { className: classNames("ajui-link-default", className), ref: ref })));
|
|
37
|
+
});
|
|
38
|
+
export default Link;
|
package/components/Link/index.js
CHANGED
package/hooks/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { default as useScrollLock } from "./useScrollLock";
|
|
|
2
2
|
export { default as useMediaQuery } from "./useMediaQuery";
|
|
3
3
|
export { default as useWatchScroll } from "./useWatchScroll";
|
|
4
4
|
export { default as useFocusTrap } from "./useFocusTrap";
|
|
5
|
+
export { default as useScrollToHash } from "./useScrollToHash";
|
package/hooks/index.js
CHANGED
|
@@ -2,3 +2,4 @@ export { default as useScrollLock } from "./useScrollLock";
|
|
|
2
2
|
export { default as useMediaQuery } from "./useMediaQuery";
|
|
3
3
|
export { default as useWatchScroll } from "./useWatchScroll";
|
|
4
4
|
export { default as useFocusTrap } from "./useFocusTrap";
|
|
5
|
+
export { default as useScrollToHash } from "./useScrollToHash";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* A hook for scrolling to a hash on the page.
|
|
4
|
+
* @returns a function that scrolls to the hash on the page
|
|
5
|
+
*/
|
|
6
|
+
var useScrollToHash = function () {
|
|
7
|
+
return useCallback(
|
|
8
|
+
/**
|
|
9
|
+
* Scrolls to the hash on the page.
|
|
10
|
+
* @param behavior the behavior of the scroll
|
|
11
|
+
*/
|
|
12
|
+
function (behavior) {
|
|
13
|
+
var hash = window.location.hash;
|
|
14
|
+
if (hash) {
|
|
15
|
+
var element = document.getElementById(hash.substring(1));
|
|
16
|
+
if (element) {
|
|
17
|
+
element.scrollIntoView({ behavior: behavior });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}, []);
|
|
21
|
+
};
|
|
22
|
+
export default useScrollToHash;
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./components/Button";
|
|
2
2
|
export { default as Button } from "./components/Button";
|
|
3
3
|
export * from "./components/Link";
|
|
4
|
+
export { default as Link } from "./components/Link";
|
|
4
5
|
export * from "./components/Input";
|
|
5
6
|
export { default as Input } from "./components/Input";
|
|
6
7
|
export { default as Alert } from "./components/Alert";
|
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export * from "./components/Button";
|
|
3
3
|
export { default as Button } from "./components/Button";
|
|
4
4
|
export * from "./components/Link";
|
|
5
|
+
export { default as Link } from "./components/Link";
|
|
5
6
|
export * from "./components/Input";
|
|
6
7
|
export { default as Input } from "./components/Input";
|
|
7
8
|
export { default as Alert } from "./components/Alert";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamjanicki/ui",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "Basic UI components and hooks for React in TypeScript",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -28,24 +28,17 @@
|
|
|
28
28
|
"@types/jest": "^29.5.8",
|
|
29
29
|
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
|
30
30
|
"@typescript-eslint/parser": "^6.11.0",
|
|
31
|
-
"css-loader": "^7.1.2",
|
|
32
31
|
"eslint": "^8.53.0",
|
|
33
32
|
"eslint-config-prettier": "^9.0.0",
|
|
34
33
|
"eslint-plugin-react": "^7.33.2",
|
|
35
34
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
36
|
-
"identity-obj-proxy": "^3.0.0",
|
|
37
35
|
"jest": "^29.7.0",
|
|
38
36
|
"jest-canvas-mock": "^2.5.2",
|
|
39
37
|
"jest-css-modules": "^2.1.0",
|
|
40
38
|
"jest-environment-jsdom": "^29.7.0",
|
|
41
|
-
"mini-css-extract-plugin": "^2.9.0",
|
|
42
39
|
"nodemon": "^3.1.4",
|
|
43
|
-
"style-loader": "^4.0.0",
|
|
44
40
|
"ts-jest": "^29.2.2",
|
|
45
|
-
"
|
|
46
|
-
"typescript": "^5.2.2",
|
|
47
|
-
"webpack": "^5.93.0",
|
|
48
|
-
"webpack-cli": "^5.1.4"
|
|
41
|
+
"typescript": "^5.2.2"
|
|
49
42
|
},
|
|
50
43
|
"eslintConfig": {
|
|
51
44
|
"extends": [
|
package/style.css
CHANGED
|
@@ -52,6 +52,8 @@
|
|
|
52
52
|
--ajui-static-border: #bdbdbd;
|
|
53
53
|
/* Modal */
|
|
54
54
|
--ajui-modal-backdrop-background: rgba(0, 0, 0, 0.5);
|
|
55
|
+
/* Link */
|
|
56
|
+
--ajui-link-color: #0070ff;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
a:not([disabled]):is(:focus-visible),
|
|
@@ -181,9 +183,15 @@ a {
|
|
|
181
183
|
background-color: var(--ajui-button-secondary-background);
|
|
182
184
|
}
|
|
183
185
|
|
|
186
|
+
.ajui-link-default {
|
|
187
|
+
color: var(--ajui-link-color);
|
|
188
|
+
transition: opacity var(--ajui-default-transition);
|
|
189
|
+
}
|
|
190
|
+
|
|
184
191
|
@media (hover: hover) {
|
|
185
192
|
.ajui-button--primary:not([disabled]):hover,
|
|
186
|
-
.ajui-icon-button:not([disabled]):hover
|
|
193
|
+
.ajui-icon-button:not([disabled]):hover,
|
|
194
|
+
.ajui-link-default:hover {
|
|
187
195
|
opacity: var(--ajui-default-opacity-dim);
|
|
188
196
|
}
|
|
189
197
|
|