@arcblock/ux 2.12.40 → 2.12.41

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.
@@ -239,7 +239,6 @@ export const NavMenuSubList = styled('ul')(() => ({
239
239
  padding: '16px',
240
240
  borderRadius: '4px',
241
241
  background: '#fff',
242
- boxShadow: '0 2px 8px rgba(0, 0, 0, 0.15)',
243
242
  '& .navmenu-item + .navmenu-item': {
244
243
  marginTop: '8px'
245
244
  }
@@ -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 updatePosition = () => {
14
- if (!rootRef.current) return;
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 containerRect = rootRef.current.getBoundingClientRect();
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 - containerRect.width) / 2;
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 + containerRect.width > windowWidth) {
37
+ } else if (absoluteLeft + contentRect.width > windowWidth) {
33
38
  // 如果超出右边界,向左偏移
34
- left -= absoluteLeft + containerRect.width - windowWidth + padding;
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: 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.40",
3
+ "version": "2.12.41",
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": "076b70d60366280b6a7a803b3af4a2578bb8332c",
71
+ "gitHead": "7330c7db64e3ff07abfc8360b8ee1e396ab0c8c2",
72
72
  "dependencies": {
73
73
  "@arcblock/did-motif": "^1.1.13",
74
- "@arcblock/icons": "^2.12.40",
75
- "@arcblock/nft-display": "^2.12.40",
76
- "@arcblock/react-hooks": "^2.12.40",
74
+ "@arcblock/icons": "^2.12.41",
75
+ "@arcblock/nft-display": "^2.12.41",
76
+ "@arcblock/react-hooks": "^2.12.41",
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",
@@ -241,7 +241,6 @@ export const NavMenuSubList = styled('ul')(() => ({
241
241
  padding: '16px',
242
242
  borderRadius: '4px',
243
243
  background: '#fff',
244
- boxShadow: '0 2px 8px rgba(0, 0, 0, 0.15)',
245
244
  '& .navmenu-item + .navmenu-item': {
246
245
  marginTop: '8px',
247
246
  },
@@ -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
- if (!rootRef.current) return;
16
- const anchor = rootRef.current.parentElement; // 以父容器作为参照
17
- if (!anchor) return;
18
-
19
- const anchorRect = anchor.getBoundingClientRect();
20
- const containerRect = rootRef.current.getBoundingClientRect();
21
- const windowWidth = window.innerWidth;
22
- const padding = 32;
23
-
24
- // 1. 计算相对于父元素的水平居中位置
25
- let left = (anchorRect.width - containerRect.width) / 2;
26
-
27
- // 2. 检查容器在视口中的绝对位置
28
- const absoluteLeft = anchorRect.left + left;
29
-
30
- // 3. 调整水平位置确保不超出窗口
31
- if (absoluteLeft < 0) {
32
- // 如果超出左边界,向右偏移
33
- left = left - absoluteLeft + padding;
34
- } else if (absoluteLeft + containerRect.width > windowWidth) {
35
- // 如果超出右边界,向左偏移
36
- left -= absoluteLeft + containerRect.width - windowWidth + padding;
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
- {children}
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
  }