@arcblock/ux 3.3.6 → 3.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/lib/SplitButton/index.js
CHANGED
|
@@ -1,45 +1,48 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as
|
|
1
|
+
import { jsxs as p, Fragment as P, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { useState as b, useRef as m, createElement as w, isValidElement as E } from "react";
|
|
3
3
|
import { ExpandMore as L } from "@mui/icons-material";
|
|
4
|
-
import { ButtonGroup as S, Popper as
|
|
5
|
-
import
|
|
6
|
-
import { styled as
|
|
7
|
-
|
|
4
|
+
import { ButtonGroup as S, Popper as z, MenuItem as d, Button as u, Paper as R, ClickAwayListener as j, MenuList as G } from "@mui/material";
|
|
5
|
+
import v from "lodash/noop";
|
|
6
|
+
import { styled as f } from "../Theme/index.js";
|
|
7
|
+
import F from "./useClickAway.js";
|
|
8
|
+
function O({ ...o }) {
|
|
8
9
|
const {
|
|
9
|
-
size:
|
|
10
|
+
size: h = "medium",
|
|
10
11
|
color: r = "primary",
|
|
11
12
|
menu: i = [],
|
|
12
13
|
children: l = null,
|
|
13
|
-
variant:
|
|
14
|
-
onClick:
|
|
15
|
-
menuButtonProps:
|
|
16
|
-
...
|
|
17
|
-
} = o, [
|
|
14
|
+
variant: y = "contained",
|
|
15
|
+
onClick: g = v,
|
|
16
|
+
menuButtonProps: x = {},
|
|
17
|
+
...k
|
|
18
|
+
} = o, [C, a] = b(!1), n = m(null), s = m(null), M = Array.isArray(i) ? (
|
|
18
19
|
// eslint-disable-next-line react/no-array-index-key
|
|
19
|
-
i.map((t,
|
|
20
|
-
) : i,
|
|
20
|
+
i.map((t, A) => E(t) ? t : /* @__PURE__ */ w(d, { ...t, key: A }))
|
|
21
|
+
) : i, B = () => {
|
|
21
22
|
a((t) => !t);
|
|
22
|
-
},
|
|
23
|
+
}, c = (t) => {
|
|
23
24
|
n.current && n.current.contains(t.target) || a(!1);
|
|
24
|
-
}
|
|
25
|
+
};
|
|
26
|
+
F(s, c);
|
|
27
|
+
const I = (t) => {
|
|
25
28
|
t.target.closest(".MuiMenuItem-root") && a(!1);
|
|
26
29
|
};
|
|
27
|
-
return /* @__PURE__ */
|
|
28
|
-
/* @__PURE__ */
|
|
29
|
-
typeof l == "function" ? l() : /* @__PURE__ */ e(
|
|
30
|
-
/* @__PURE__ */ e(
|
|
30
|
+
return /* @__PURE__ */ p(P, { children: [
|
|
31
|
+
/* @__PURE__ */ p(T, { variant: y, size: h, color: r, ref: n, ...k, children: [
|
|
32
|
+
typeof l == "function" ? l() : /* @__PURE__ */ e(u, { onClick: g, color: r, children: l }),
|
|
33
|
+
/* @__PURE__ */ e(u, { onClick: B, color: r, ...x, "aria-label": "more functions", children: /* @__PURE__ */ e(L, {}) })
|
|
31
34
|
] }),
|
|
32
|
-
/* @__PURE__ */ e(
|
|
35
|
+
/* @__PURE__ */ e(V, { open: C, anchorEl: n.current, placement: "bottom-end", disablePortal: !1, children: /* @__PURE__ */ e(R, { ref: s, children: /* @__PURE__ */ e(j, { onClickAway: c, children: /* @__PURE__ */ e(G, { onClick: I, children: M }) }) }) })
|
|
33
36
|
] });
|
|
34
37
|
}
|
|
35
|
-
|
|
36
|
-
const
|
|
38
|
+
O.Item = d;
|
|
39
|
+
const T = f(S)`
|
|
37
40
|
> .MuiButtonBase-root:last-of-type {
|
|
38
41
|
min-width: 2em;
|
|
39
42
|
padding-left: 0;
|
|
40
43
|
padding-right: 0;
|
|
41
44
|
}
|
|
42
|
-
`,
|
|
45
|
+
`, V = f(z)`
|
|
43
46
|
z-index: ${(o) => o.theme.zIndex.tooltip};
|
|
44
47
|
.MuiList-root {
|
|
45
48
|
padding: 4px 0;
|
|
@@ -50,5 +53,5 @@ const F = d(S)`
|
|
|
50
53
|
}
|
|
51
54
|
`;
|
|
52
55
|
export {
|
|
53
|
-
|
|
56
|
+
O as default
|
|
54
57
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { useEffect as u } from "react";
|
|
2
|
+
function i(t, e) {
|
|
3
|
+
u(() => {
|
|
4
|
+
function n(r) {
|
|
5
|
+
!t || !t.current || t.current.contains(r.target) || e(r);
|
|
6
|
+
}
|
|
7
|
+
return document.addEventListener("click", n, !0), () => {
|
|
8
|
+
document.removeEventListener("click", n, !0);
|
|
9
|
+
};
|
|
10
|
+
}, [t, e]);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
i as default
|
|
14
|
+
};
|
package/lib/package.json.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcblock/ux",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.8",
|
|
4
4
|
"description": "Common used react components for arcblock products",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -68,16 +68,16 @@
|
|
|
68
68
|
"react": "^19.0.0",
|
|
69
69
|
"react-router-dom": "^6.22.3"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "b4c40eaa794d708a6d21b721306b8e1cf6fb00ce",
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@arcblock/bridge": "3.3.
|
|
73
|
+
"@arcblock/bridge": "3.3.8",
|
|
74
74
|
"@arcblock/did": "^1.27.16",
|
|
75
75
|
"@arcblock/did-motif": "^1.1.14",
|
|
76
|
-
"@arcblock/icons": "3.3.
|
|
77
|
-
"@arcblock/nft-display": "3.3.
|
|
78
|
-
"@arcblock/react-hooks": "3.3.
|
|
76
|
+
"@arcblock/icons": "3.3.8",
|
|
77
|
+
"@arcblock/nft-display": "3.3.8",
|
|
78
|
+
"@arcblock/react-hooks": "3.3.8",
|
|
79
79
|
"@blocklet/js-sdk": "^1.17.6",
|
|
80
|
-
"@blocklet/theme": "3.3.
|
|
80
|
+
"@blocklet/theme": "3.3.8",
|
|
81
81
|
"@fontsource/roboto": "~5.1.1",
|
|
82
82
|
"@fontsource/ubuntu-mono": "^5.2.6",
|
|
83
83
|
"@iconify-icons/logos": "^1.2.36",
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
import noop from 'lodash/noop';
|
|
16
16
|
|
|
17
17
|
import { styled } from '../Theme';
|
|
18
|
+
import useClickAway from './useClickAway';
|
|
18
19
|
|
|
19
20
|
export interface SplitButtonProps extends Omit<ButtonGroupProps, 'children'> {
|
|
20
21
|
menu?:
|
|
@@ -40,6 +41,9 @@ export default function SplitButton({ ...props }: SplitButtonProps) {
|
|
|
40
41
|
|
|
41
42
|
const [open, setOpen] = useState(false);
|
|
42
43
|
const anchorRef = useRef<HTMLDivElement | null>(null);
|
|
44
|
+
// ClickAwayListener 只会监听事件的冒泡阶段,这会导致如果其他事件禁用了冒泡,那么下拉菜单将无法隐藏
|
|
45
|
+
// 所以定义一个 ref 来监听事件的捕获阶段
|
|
46
|
+
const paperRef = useRef<HTMLDivElement | null>(null);
|
|
43
47
|
const menuItems = Array.isArray(menu)
|
|
44
48
|
? // eslint-disable-next-line react/no-array-index-key
|
|
45
49
|
menu.map((item, index) => (isValidElement(item) ? item : <MenuItem {...item} key={index} />))
|
|
@@ -56,6 +60,8 @@ export default function SplitButton({ ...props }: SplitButtonProps) {
|
|
|
56
60
|
setOpen(false);
|
|
57
61
|
};
|
|
58
62
|
|
|
63
|
+
useClickAway(paperRef as React.RefObject<HTMLElement>, handleClose);
|
|
64
|
+
|
|
59
65
|
// 点击 item 后收起下拉菜单, 如果想要点击 action 后不收起下拉菜单, 可以在 item#onClick 时调用 e.stopPropagation()
|
|
60
66
|
const handleItemClick: React.MouseEventHandler<HTMLUListElement> = (e) => {
|
|
61
67
|
if ((e.target as HTMLElement).closest('.MuiMenuItem-root')) {
|
|
@@ -78,7 +84,7 @@ export default function SplitButton({ ...props }: SplitButtonProps) {
|
|
|
78
84
|
</Button>
|
|
79
85
|
</StyledButtonGroup>
|
|
80
86
|
<StyledPopper open={open} anchorEl={anchorRef.current} placement="bottom-end" disablePortal={false}>
|
|
81
|
-
<Paper>
|
|
87
|
+
<Paper ref={paperRef}>
|
|
82
88
|
<ClickAwayListener onClickAway={handleClose}>
|
|
83
89
|
<MenuList onClick={handleItemClick}>{menuItems}</MenuList>
|
|
84
90
|
</ClickAwayListener>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
// 监听事件的捕获阶段,用于 ClickAwayListener 无法监听的事件
|
|
4
|
+
function useClickAway(ref: React.RefObject<HTMLElement> | null, onClickAway: (event: MouseEvent) => void) {
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
function handleClick(event: MouseEvent) {
|
|
7
|
+
if (!ref || !ref.current) return;
|
|
8
|
+
|
|
9
|
+
// 如果点击事件目标在 menu 元素内,阻止菜单关闭
|
|
10
|
+
if (ref.current.contains(event.target as Node)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
onClickAway(event);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
document.addEventListener('click', handleClick, true);
|
|
18
|
+
return () => {
|
|
19
|
+
document.removeEventListener('click', handleClick, true);
|
|
20
|
+
};
|
|
21
|
+
}, [ref, onClickAway]);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default useClickAway;
|