@arcblock/ux 2.12.40 → 2.12.42
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/NavMenu/style.js
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { useThrottleFn } from 'ahooks';
|
2
3
|
import React, { useEffect, useRef, useState } from 'react';
|
3
4
|
const paddingTop = 8;
|
4
5
|
|
@@ -8,19 +9,23 @@ export function SubContainer({
|
|
8
9
|
...props
|
9
10
|
}) {
|
10
11
|
const rootRef = useRef(null);
|
12
|
+
const contentRef = useRef(null);
|
13
|
+
const [positionUpdated, setPositionUpdated] = useState(false);
|
11
14
|
const [position, setPosition] = useState(0); // 只需要保存水平偏移量
|
12
15
|
|
13
|
-
const
|
14
|
-
|
16
|
+
const {
|
17
|
+
run: updatePosition
|
18
|
+
} = useThrottleFn(() => {
|
19
|
+
if (!rootRef.current || !contentRef.current) return;
|
15
20
|
const anchor = rootRef.current.parentElement; // 以父容器作为参照
|
16
21
|
if (!anchor) return;
|
17
22
|
const anchorRect = anchor.getBoundingClientRect();
|
18
|
-
const
|
23
|
+
const contentRect = contentRef.current.getBoundingClientRect();
|
19
24
|
const windowWidth = window.innerWidth;
|
20
25
|
const padding = 32;
|
21
26
|
|
22
27
|
// 1. 计算相对于父元素的水平居中位置
|
23
|
-
let left = (anchorRect.width -
|
28
|
+
let left = (anchorRect.width - contentRect.width) / 2;
|
24
29
|
|
25
30
|
// 2. 检查容器在视口中的绝对位置
|
26
31
|
const absoluteLeft = anchorRect.left + left;
|
@@ -29,12 +34,17 @@ export function SubContainer({
|
|
29
34
|
if (absoluteLeft < 0) {
|
30
35
|
// 如果超出左边界,向右偏移
|
31
36
|
left = left - absoluteLeft + padding;
|
32
|
-
} else if (absoluteLeft +
|
37
|
+
} else if (absoluteLeft + contentRect.width > windowWidth) {
|
33
38
|
// 如果超出右边界,向左偏移
|
34
|
-
left -= absoluteLeft +
|
39
|
+
left -= absoluteLeft + contentRect.width - windowWidth + padding;
|
35
40
|
}
|
36
41
|
setPosition(left);
|
37
|
-
|
42
|
+
if (!positionUpdated) {
|
43
|
+
setPositionUpdated(true);
|
44
|
+
}
|
45
|
+
}, {
|
46
|
+
wait: 100
|
47
|
+
});
|
38
48
|
|
39
49
|
// 监听自身大小变化
|
40
50
|
useEffect(() => {
|
@@ -73,11 +83,20 @@ export function SubContainer({
|
|
73
83
|
ref: rootRef,
|
74
84
|
className: "navmenu-sub__container",
|
75
85
|
style: {
|
86
|
+
width: '100%',
|
76
87
|
paddingTop: `${paddingTop}px`,
|
77
|
-
transform: `translateX(${position}px)
|
88
|
+
transform: `translateX(${position}px)`,
|
89
|
+
overflow: positionUpdated ? 'visible' : 'hidden'
|
78
90
|
},
|
79
91
|
...props,
|
80
|
-
children:
|
92
|
+
children: /*#__PURE__*/_jsx("div", {
|
93
|
+
style: {
|
94
|
+
display: 'inline-block',
|
95
|
+
boxShadow: '0px 40px 60px rgba(0, 0, 0, 0.08)'
|
96
|
+
},
|
97
|
+
ref: contentRef,
|
98
|
+
children: children
|
99
|
+
})
|
81
100
|
});
|
82
101
|
}
|
83
102
|
export default SubContainer;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@arcblock/ux",
|
3
|
-
"version": "2.12.
|
3
|
+
"version": "2.12.42",
|
4
4
|
"description": "Common used react components for arcblock products",
|
5
5
|
"keywords": [
|
6
6
|
"react",
|
@@ -68,12 +68,12 @@
|
|
68
68
|
"react": ">=18.2.0",
|
69
69
|
"react-router-dom": ">=6.22.3"
|
70
70
|
},
|
71
|
-
"gitHead": "
|
71
|
+
"gitHead": "744430cb09820799f4b3c6f811cbfbbb08015453",
|
72
72
|
"dependencies": {
|
73
73
|
"@arcblock/did-motif": "^1.1.13",
|
74
|
-
"@arcblock/icons": "^2.12.
|
75
|
-
"@arcblock/nft-display": "^2.12.
|
76
|
-
"@arcblock/react-hooks": "^2.12.
|
74
|
+
"@arcblock/icons": "^2.12.42",
|
75
|
+
"@arcblock/nft-display": "^2.12.42",
|
76
|
+
"@arcblock/react-hooks": "^2.12.42",
|
77
77
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
78
78
|
"@fontsource/inter": "^5.0.16",
|
79
79
|
"@fontsource/ubuntu-mono": "^5.0.18",
|
package/src/NavMenu/style.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { useThrottleFn } from 'ahooks';
|
1
2
|
import React, { useEffect, useRef, useState } from 'react';
|
2
3
|
|
3
4
|
interface SubContainerProps extends React.HTMLAttributes<HTMLDivElement> {
|
@@ -9,35 +10,45 @@ const paddingTop = 8;
|
|
9
10
|
// 下拉子菜单容器
|
10
11
|
export function SubContainer({ children, ...props }: SubContainerProps) {
|
11
12
|
const rootRef = useRef<HTMLDivElement>(null);
|
13
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
14
|
+
const [positionUpdated, setPositionUpdated] = useState(false);
|
12
15
|
const [position, setPosition] = useState(0); // 只需要保存水平偏移量
|
13
16
|
|
14
|
-
const updatePosition = (
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
17
|
+
const { run: updatePosition } = useThrottleFn(
|
18
|
+
() => {
|
19
|
+
if (!rootRef.current || !contentRef.current) return;
|
20
|
+
const anchor = rootRef.current.parentElement; // 以父容器作为参照
|
21
|
+
if (!anchor) return;
|
22
|
+
|
23
|
+
const anchorRect = anchor.getBoundingClientRect();
|
24
|
+
const contentRect = contentRef.current.getBoundingClientRect();
|
25
|
+
const windowWidth = window.innerWidth;
|
26
|
+
const padding = 32;
|
27
|
+
|
28
|
+
// 1. 计算相对于父元素的水平居中位置
|
29
|
+
let left = (anchorRect.width - contentRect.width) / 2;
|
30
|
+
|
31
|
+
// 2. 检查容器在视口中的绝对位置
|
32
|
+
const absoluteLeft = anchorRect.left + left;
|
33
|
+
|
34
|
+
// 3. 调整水平位置确保不超出窗口
|
35
|
+
if (absoluteLeft < 0) {
|
36
|
+
// 如果超出左边界,向右偏移
|
37
|
+
left = left - absoluteLeft + padding;
|
38
|
+
} else if (absoluteLeft + contentRect.width > windowWidth) {
|
39
|
+
// 如果超出右边界,向左偏移
|
40
|
+
left -= absoluteLeft + contentRect.width - windowWidth + padding;
|
41
|
+
}
|
42
|
+
|
43
|
+
setPosition(left);
|
44
|
+
if (!positionUpdated) {
|
45
|
+
setPositionUpdated(true);
|
46
|
+
}
|
47
|
+
},
|
48
|
+
{
|
49
|
+
wait: 100,
|
37
50
|
}
|
38
|
-
|
39
|
-
setPosition(left);
|
40
|
-
};
|
51
|
+
);
|
41
52
|
|
42
53
|
// 监听自身大小变化
|
43
54
|
useEffect(() => {
|
@@ -84,11 +95,15 @@ export function SubContainer({ children, ...props }: SubContainerProps) {
|
|
84
95
|
ref={rootRef}
|
85
96
|
className="navmenu-sub__container"
|
86
97
|
style={{
|
98
|
+
width: '100%',
|
87
99
|
paddingTop: `${paddingTop}px`,
|
88
100
|
transform: `translateX(${position}px)`,
|
101
|
+
overflow: positionUpdated ? 'visible' : 'hidden',
|
89
102
|
}}
|
90
103
|
{...props}>
|
91
|
-
{
|
104
|
+
<div style={{ display: 'inline-block', boxShadow: '0px 40px 60px rgba(0, 0, 0, 0.08)' }} ref={contentRef}>
|
105
|
+
{children}
|
106
|
+
</div>
|
92
107
|
</div>
|
93
108
|
);
|
94
109
|
}
|