ag-common 0.0.660 → 0.0.661
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.
|
@@ -66,10 +66,7 @@ const ChevronStyled = (0, styled_1.default)(Chevron_1.Chevron) `
|
|
|
66
66
|
const MinSidebar = ({ chevronColour, children, className, style, }) => {
|
|
67
67
|
const ref = (0, react_1.useRef)(null);
|
|
68
68
|
const [open, setOpen] = (0, react_1.useState)(false);
|
|
69
|
-
(0, helpers_1.useOnClickOutside)({ ref }, () => {
|
|
70
|
-
if (!open || window.innerWidth > media_1.smallScreenPx) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
69
|
+
(0, helpers_1.useOnClickOutside)({ ref, disabled: () => !open || window.innerWidth > media_1.smallScreenPx }, () => {
|
|
73
70
|
setOpen(false);
|
|
74
71
|
});
|
|
75
72
|
return (react_1.default.createElement(Base, { style: style, "data-type": "sidebar", className: className, "data-open": open, onClick: () => !open && setOpen(true), ref: ref },
|
|
@@ -168,10 +168,7 @@ const ChevronStyled = (0, styled_1.default)(Chevron_1.Chevron) `
|
|
|
168
168
|
const Sidebar = ({ children, className, mode = 'defaultClosed', }) => {
|
|
169
169
|
const ref = (0, react_2.useRef)(null);
|
|
170
170
|
const [open, setOpen] = (0, react_2.useState)(mode === 'defaultClosed' ? false : null);
|
|
171
|
-
(0, helpers_1.useOnClickOutside)({ ref }, () => {
|
|
172
|
-
if (!open || window.innerWidth > media_1.smallScreenPx) {
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
171
|
+
(0, helpers_1.useOnClickOutside)({ ref, disabled: () => !open || window.innerWidth > media_1.smallScreenPx }, () => {
|
|
175
172
|
setOpen(false);
|
|
176
173
|
});
|
|
177
174
|
return (react_2.default.createElement(Base, { "data-type": "sidebar", className: className, "data-open": open, onClick: () => !open && setOpen(true), "data-hover": true, ref: ref },
|
|
@@ -2,10 +2,8 @@ import type { RefObject } from 'react';
|
|
|
2
2
|
type Event = MouseEvent | TouchEvent;
|
|
3
3
|
export declare function useOnClickOutside<T extends HTMLElement = HTMLElement>(p: {
|
|
4
4
|
ref: RefObject<T>;
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
*/
|
|
8
|
-
disabled?: boolean;
|
|
5
|
+
/** can either be a boolean, or a callback */
|
|
6
|
+
disabled?: boolean | (() => boolean);
|
|
9
7
|
/** if true, will also consider moving mouse outside div. default false */
|
|
10
8
|
moveMouseOutside?: boolean;
|
|
11
9
|
}, handler: (event: Event) => void): void;
|
|
@@ -6,21 +6,34 @@ const react_1 = require("react");
|
|
|
6
6
|
const dom_1 = require("./dom");
|
|
7
7
|
function useOnClickOutside(p, handler) {
|
|
8
8
|
(0, react_1.useEffect)(() => {
|
|
9
|
-
if (p.disabled || typeof window === 'undefined') {
|
|
10
|
-
return () => {
|
|
11
|
-
//
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
9
|
const listener = (event) => {
|
|
15
|
-
var _a;
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const disabled = !p.disabled || typeof p.disabled === 'boolean'
|
|
12
|
+
? (_a = p.disabled) !== null && _a !== void 0 ? _a : false
|
|
13
|
+
: p.disabled();
|
|
14
|
+
if (disabled) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
16
17
|
//
|
|
17
18
|
const isRightMB = (0, dom_1.isRightClick)(event);
|
|
18
19
|
if (isRightMB) {
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
|
-
const el = (
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
const el = (_b = p.ref) === null || _b === void 0 ? void 0 : _b.current;
|
|
23
|
+
if (!el) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
//walk dom tree to see if nodes match
|
|
27
|
+
let n = event.target;
|
|
28
|
+
let found = false;
|
|
29
|
+
while (n) {
|
|
30
|
+
if (n.isEqualNode(el)) {
|
|
31
|
+
found = true;
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
n = n.parentNode;
|
|
35
|
+
}
|
|
36
|
+
if (found) {
|
|
24
37
|
return;
|
|
25
38
|
}
|
|
26
39
|
handler(event);
|
package/package.json
CHANGED