@arcblock/ux 2.12.2 → 2.12.4

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.
@@ -4,6 +4,7 @@ import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } f
4
4
  import { Box } from '@mui/material';
5
5
  import { styled } from '../Theme';
6
6
  import DidAddress from './did-address';
7
+ import { getFontSize } from '../Util';
7
8
 
8
9
  /**
9
10
  * 根据父容器宽度自动切换 compact 模式
@@ -18,7 +19,7 @@ const ResponsiveDidAddress = /*#__PURE__*/forwardRef(({
18
19
  style,
19
20
  className,
20
21
  component = 'span',
21
- size,
22
+ size = 0,
22
23
  ...rest
23
24
  }, ref) => {
24
25
  const [compact, setCompact] = useState(false);
@@ -79,6 +80,8 @@ const ResponsiveDidAddress = /*#__PURE__*/forwardRef(({
79
80
  ref: containerRef,
80
81
  style: style,
81
82
  className: className,
83
+ size: size,
84
+ inline: rest.inline,
82
85
  children: [/*#__PURE__*/_jsx(StyledDidAddress, {
83
86
  style: {
84
87
  position: loading ? 'absolute' : 'static',
@@ -99,10 +102,14 @@ const ResponsiveDidAddress = /*#__PURE__*/forwardRef(({
99
102
  });
100
103
  });
101
104
  export default ResponsiveDidAddress;
102
- const Root = styled(Box)`
105
+ const Root = styled(Box, {
106
+ shouldForwardProp: prop => prop !== 'size'
107
+ })`
103
108
  display: block;
104
109
  width: 100%; /* flex & column & align-items: flex-start 时, 块级元素不会自动铺满容器 */
105
- font-size: 0;
110
+ font-size: ${({
111
+ size
112
+ }) => getFontSize(size)};
106
113
  overflow: hidden;
107
114
  ${({
108
115
  inline
@@ -38,7 +38,7 @@ export interface ItemProps extends React.HTMLAttributes<HTMLLIElement> {
38
38
  }
39
39
  export declare const Item: import("react").ForwardRefExoticComponent<ItemProps & import("react").RefAttributes<HTMLLIElement>>;
40
40
  export interface SubProps extends Omit<ItemProps, 'children' | 'active'> {
41
- children?: Array<React.ReactElement> | ((props: {
41
+ children?: Array<React.ReactElement | null> | ((props: {
42
42
  isOpen: boolean;
43
43
  }) => React.ReactElement | null);
44
44
  expandIcon?: React.ReactNode | ((props: {
@@ -5,7 +5,8 @@ import { MoreHoriz as MoreHorizIcon, ExpandMore as ExpandMoreIcon, Menu as MenuI
5
5
  import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
6
6
  import { useCreation, useMemoizedFn, useReactive, useSize, useThrottleFn } from 'ahooks';
7
7
  import { NavMenuProvider, useNavMenuContext } from './nav-menu-context';
8
- import { NavMenuRoot, NavMenuList, NavMenuItem, NavMenuSub, NavMenuSubList } from './style';
8
+ import { NavMenuRoot, NavMenuItem, NavMenuSub, NavMenuSubList, NavMenuStyled } from './style';
9
+ import { SubContainer } from './sub-container';
9
10
 
10
11
  // 过滤 children 中的 Item/Sub, 忽略其它类型的 element
11
12
  function filterItems(children) {
@@ -73,6 +74,7 @@ function NavMenu({
73
74
  const navMenuRef = useRef(null);
74
75
  const itemRefs = useRef([]);
75
76
  const moreIconRef = useRef(null);
77
+ const containerWidth = useRef(0);
76
78
  const isAllItemsHidden = currentState.hiddenItemCount === itemRefs.current?.length;
77
79
  const style = isAllItemsHidden ? {
78
80
  marginLeft: '0px'
@@ -96,14 +98,13 @@ function NavMenu({
96
98
  let totalWidthUsed = 0;
97
99
  let newHiddenCount = 0;
98
100
  let leftAllHidden = false;
99
- const containerWidth = containerSize?.width || 0;
100
101
  const moreIconWidth = moreIconRef.current ? moreIconRef.current.offsetWidth + parseFloat(window.getComputedStyle(moreIconRef.current).marginLeft) : 0;
101
102
  itemRefs.current.forEach((item, index) => {
102
103
  if (item) {
103
104
  item.style.display = 'flex';
104
105
  const marginLeft = index > 0 ? parseFloat(window.getComputedStyle(item).marginLeft) : 0;
105
106
  const currentItemWidth = item.offsetWidth + marginLeft;
106
- if (containerWidth - moreIconWidth >= totalWidthUsed + currentItemWidth && !leftAllHidden) {
107
+ if (containerWidth.current - moreIconWidth >= totalWidthUsed + currentItemWidth && !leftAllHidden) {
107
108
  totalWidthUsed += currentItemWidth;
108
109
  } else {
109
110
  item.style.display = 'none';
@@ -119,6 +120,7 @@ function NavMenu({
119
120
  wait: 100
120
121
  });
121
122
  useLayoutEffect(() => {
123
+ containerWidth.current = containerSize?.width || navMenuRef.current?.clientWidth || 0;
122
124
  if (mode === 'horizontal') {
123
125
  checkItemsFit();
124
126
  }
@@ -144,8 +146,14 @@ function NavMenu({
144
146
  // eslint-disable-next-line react-hooks/exhaustive-deps
145
147
  }, [activeId]);
146
148
  const classes = clsx('navmenu', `navmenu--${mode}`, rest.className);
147
- const renderItem = (item, index, isTopLevel = false) => {
149
+ const renderItem = (item, index, level = 0) => {
150
+ const isTopLevel = level === 0;
148
151
  if (item?.children) {
152
+ // 只渲染两级子菜单
153
+ if (level > 0) {
154
+ return null;
155
+ }
156
+
149
157
  // 对于 Sub 组件,如果它是顶级组件,则包含 ref
150
158
  return /*#__PURE__*/_jsx(Sub, {
151
159
  id: item.id,
@@ -158,7 +166,7 @@ function NavMenu({
158
166
  children: typeof item.children === 'function' ? item.children : item.children.map((childItem, childIndex) => renderItem({
159
167
  ...childItem,
160
168
  variant: 'panel'
161
- }, childIndex, false))
169
+ }, childIndex, level + 1))
162
170
  }, item.id);
163
171
  }
164
172
 
@@ -175,18 +183,21 @@ function NavMenu({
175
183
  } : undefined
176
184
  }, item.id);
177
185
  };
178
- const content = items ? items?.slice(-currentState.hiddenItemCount).map((item, index) => renderItem(item, index)) : children?.slice(-currentState.hiddenItemCount);
186
+ const content = items ? items?.slice(-currentState.hiddenItemCount).map((item, index) => renderItem(item, index, 1)) : children?.slice(-currentState.hiddenItemCount);
187
+
188
+ // 当前展开的子菜单
189
+ const openedId = currentState.openedIds[0];
179
190
  return /*#__PURE__*/_jsx(NavMenuProvider, {
180
191
  value: contextValue,
181
- children: /*#__PURE__*/_jsx(NavMenuRoot, {
192
+ children: /*#__PURE__*/_jsx(NavMenuStyled, {
182
193
  ...rest,
183
194
  className: classes,
184
195
  $textColor: textColor,
185
196
  $bgColor: bgColor,
186
- children: /*#__PURE__*/_jsxs(NavMenuList, {
187
- className: clsx('navmenu-list', `navmenu-list--${mode}`),
197
+ children: /*#__PURE__*/_jsxs(NavMenuRoot, {
198
+ className: clsx('navmenu-root', `navmenu-root--${mode}`),
188
199
  ref: navMenuRef,
189
- children: [items ? items.map((item, index) => renderItem(item, index, true)) : renderChildrenWithRef(children || []), currentState.hiddenItemCount > 0 && /*#__PURE__*/_jsx(Sub, {
200
+ children: [items ? items.map((item, index) => renderItem(item, index)) : renderChildrenWithRef(children || []), currentState.hiddenItemCount > 0 && /*#__PURE__*/_jsx(Sub, {
190
201
  expandIcon: false,
191
202
  icon: icon,
192
203
  label: "",
@@ -329,8 +340,7 @@ export const Sub = /*#__PURE__*/forwardRef(({
329
340
  children: typeof expandIcon === 'function' ? expandIcon({
330
341
  isOpen
331
342
  }) : expandIcon
332
- }), /*#__PURE__*/_jsx("div", {
333
- className: "navmenu-sub__container",
343
+ }), /*#__PURE__*/_jsx(SubContainer, {
334
344
  ...containerProps,
335
345
  children: typeof children === 'function' ? children({
336
346
  isOpen
@@ -1,10 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from "react";
3
- import { useLayoutEffect, useRef } from 'react';
3
+ import { useRef } from 'react';
4
4
  import { Link } from 'react-router-dom';
5
5
  import { useCreation, useMemoizedFn } from 'ahooks';
6
6
  import { Box, Grid } from '@mui/material';
7
- import { useWindowSize } from 'react-use';
8
7
  import SubItemGroup from './sub-item-group';
9
8
  import { Item } from './nav-menu';
10
9
  import { styled } from '../Theme';
@@ -1437,10 +1436,6 @@ export default function Products({
1437
1436
  mode
1438
1437
  } = useNavMenuContext();
1439
1438
  const wrapperRef = useRef(null);
1440
- const {
1441
- width,
1442
- height
1443
- } = useWindowSize();
1444
1439
  const {
1445
1440
  locale = 'en'
1446
1441
  } = useLocaleContext() || {};
@@ -1452,6 +1447,8 @@ export default function Products({
1452
1447
  children: [[{
1453
1448
  label: /*#__PURE__*/_jsx(Link, {
1454
1449
  to: `https://www.nftstudio.rocks/${locale}`,
1450
+ target: "_blank",
1451
+ rel: "noreferrer noopener",
1455
1452
  children: "NFT Studio"
1456
1453
  }),
1457
1454
  description: t('products.nftStudio.description'),
@@ -1459,6 +1456,8 @@ export default function Products({
1459
1456
  }, {
1460
1457
  label: /*#__PURE__*/_jsx(Link, {
1461
1458
  to: `https://www.arcblock.io/content/collections/${locale}/creator-studio`,
1459
+ target: "_blank",
1460
+ rel: "noreferrer noopener",
1462
1461
  children: "Creator Studio"
1463
1462
  }),
1464
1463
  description: t('products.creatorStudio.description'),
@@ -1466,6 +1465,8 @@ export default function Products({
1466
1465
  }], [{
1467
1466
  label: /*#__PURE__*/_jsx(Link, {
1468
1467
  to: `https://www.aigne.io/${locale}`,
1468
+ target: "_blank",
1469
+ rel: "noreferrer noopener",
1469
1470
  children: "AIGNE"
1470
1471
  }),
1471
1472
  description: t('products.aigne.description'),
@@ -1473,6 +1474,8 @@ export default function Products({
1473
1474
  }, {
1474
1475
  label: /*#__PURE__*/_jsx(Link, {
1475
1476
  to: `https://www.aistro.io/${locale}`,
1477
+ target: "_blank",
1478
+ rel: "noreferrer noopener",
1476
1479
  children: "Aistro"
1477
1480
  }),
1478
1481
  description: t('products.aistro.description'),
@@ -1484,6 +1487,8 @@ export default function Products({
1484
1487
  children: [[{
1485
1488
  label: /*#__PURE__*/_jsx(Link, {
1486
1489
  to: `https://launcher.arcblock.io/${locale}`,
1490
+ target: "_blank",
1491
+ rel: "noreferrer noopener",
1487
1492
  children: "Blocklet Launcher"
1488
1493
  }),
1489
1494
  description: t('products.blockletLauncher.description'),
@@ -1491,6 +1496,8 @@ export default function Products({
1491
1496
  }, {
1492
1497
  label: /*#__PURE__*/_jsx(Link, {
1493
1498
  to: `https://www.arcblock.io/content/collections/${locale}/ai-kit`,
1499
+ target: "_blank",
1500
+ rel: "noreferrer noopener",
1494
1501
  children: "Al Kit"
1495
1502
  }),
1496
1503
  description: t('products.alKit.description'),
@@ -1498,6 +1505,8 @@ export default function Products({
1498
1505
  }], [{
1499
1506
  label: /*#__PURE__*/_jsx(Link, {
1500
1507
  to: `https://store.blocklet.dev/${locale}`,
1508
+ target: "_blank",
1509
+ rel: "noreferrer noopener",
1501
1510
  children: "Blocklet Store"
1502
1511
  }),
1503
1512
  description: t('products.blockletStore.description'),
@@ -1505,6 +1514,8 @@ export default function Products({
1505
1514
  }, {
1506
1515
  label: /*#__PURE__*/_jsx(Link, {
1507
1516
  to: `https://www.web3kit.rocks/${locale}`,
1517
+ target: "_blank",
1518
+ rel: "noreferrer noopener",
1508
1519
  children: "Web3 Kit"
1509
1520
  }),
1510
1521
  description: t('products.web3Kit.description'),
@@ -1516,6 +1527,8 @@ export default function Products({
1516
1527
  children: [[{
1517
1528
  label: /*#__PURE__*/_jsx(Link, {
1518
1529
  to: `https://www.arcblock.io/content/collections/${locale}/blocklet`,
1530
+ target: "_blank",
1531
+ rel: "noreferrer noopener",
1519
1532
  children: "Blocklet Framework"
1520
1533
  }),
1521
1534
  description: t('products.blockletFramework.description'),
@@ -1523,6 +1536,8 @@ export default function Products({
1523
1536
  }, {
1524
1537
  label: /*#__PURE__*/_jsx(Link, {
1525
1538
  to: `https://www.didspaces.com/${locale}`,
1539
+ target: "_blank",
1540
+ rel: "noreferrer noopener",
1526
1541
  children: "DID Spaces"
1527
1542
  }),
1528
1543
  description: t('products.didSpaces.description'),
@@ -1530,6 +1545,8 @@ export default function Products({
1530
1545
  }, {
1531
1546
  label: /*#__PURE__*/_jsx(Link, {
1532
1547
  to: `https://main.abtnetwork.io/${locale}`,
1548
+ target: "_blank",
1549
+ rel: "noreferrer noopener",
1533
1550
  children: "ABT Network"
1534
1551
  }),
1535
1552
  description: t('products.abtNetwork.description'),
@@ -1537,6 +1554,8 @@ export default function Products({
1537
1554
  }], [{
1538
1555
  label: /*#__PURE__*/_jsx(Link, {
1539
1556
  to: `https://www.arcblock.io/content/collections/${locale}/blocklet-server`,
1557
+ target: "_blank",
1558
+ rel: "noreferrer noopener",
1540
1559
  children: "Blocklet Server"
1541
1560
  }),
1542
1561
  description: t('products.blockletServer.description'),
@@ -1544,6 +1563,8 @@ export default function Products({
1544
1563
  }, {
1545
1564
  label: /*#__PURE__*/_jsx(Link, {
1546
1565
  to: `https://www.arcblock.io/content/collections/${locale}/blockchain`,
1566
+ target: "_blank",
1567
+ rel: "noreferrer noopener",
1547
1568
  children: "\u041E\u0421\u0410\u0420"
1548
1569
  }),
1549
1570
  description: t('products.osar.description'),
@@ -1555,6 +1576,8 @@ export default function Products({
1555
1576
  children: [[{
1556
1577
  label: /*#__PURE__*/_jsx(Link, {
1557
1578
  to: `https://www.arcblock.io/content/collections/${locale}/did`,
1579
+ target: "_blank",
1580
+ rel: "noreferrer noopener",
1558
1581
  children: "DID"
1559
1582
  }),
1560
1583
  description: t('products.did.description'),
@@ -1562,6 +1585,8 @@ export default function Products({
1562
1585
  }, {
1563
1586
  label: /*#__PURE__*/_jsx(Link, {
1564
1587
  to: `https://www.didwallet.io/${locale}`,
1588
+ target: "_blank",
1589
+ rel: "noreferrer noopener",
1565
1590
  children: "DID Wallet"
1566
1591
  }),
1567
1592
  description: t('products.didWallet.description'),
@@ -1569,13 +1594,17 @@ export default function Products({
1569
1594
  }, {
1570
1595
  label: /*#__PURE__*/_jsx(Link, {
1571
1596
  to: `https://www.didnames.io/${locale}`,
1572
- children: "DID Name Service"
1597
+ target: "_blank",
1598
+ rel: "noreferrer noopener",
1599
+ children: "DID Names"
1573
1600
  }),
1574
1601
  description: t('products.didNameService.description'),
1575
1602
  icon: /*#__PURE__*/_jsx(DidNameServiceSvg, {})
1576
1603
  }], [{
1577
1604
  label: /*#__PURE__*/_jsx(Link, {
1578
1605
  to: `https://www.arcblock.io/content/collections/${locale}/verifiable-credential`,
1606
+ target: "_blank",
1607
+ rel: "noreferrer noopener",
1579
1608
  children: "VC"
1580
1609
  }),
1581
1610
  description: t('products.vc.description'),
@@ -1583,6 +1612,8 @@ export default function Products({
1583
1612
  }, {
1584
1613
  label: /*#__PURE__*/_jsx(Link, {
1585
1614
  to: `https://www.didconnect.io/${locale}`,
1615
+ target: "_blank",
1616
+ rel: "noreferrer noopener",
1586
1617
  children: "DID Connect"
1587
1618
  }),
1588
1619
  description: t('products.didConnect.description'),
@@ -1590,26 +1621,6 @@ export default function Products({
1590
1621
  }]]
1591
1622
  }];
1592
1623
  }, [t, locale]);
1593
-
1594
- // 防止弹框超出 window
1595
- useLayoutEffect(() => {
1596
- const wrapper = wrapperRef.current;
1597
- if (!wrapper) return;
1598
- if (!isOpen) {
1599
- wrapper.style.transform = '';
1600
- return;
1601
- }
1602
- const rect = wrapper.getBoundingClientRect();
1603
- const windowWidth = window.innerWidth;
1604
- if (rect.right > windowWidth) {
1605
- const offset = rect.right - windowWidth;
1606
- wrapper.style.transform = `translateX(-${offset + 16}px)`;
1607
- } else if (rect.left < 0) {
1608
- wrapper.style.transform = `translateX(${Math.abs(rect.left) + 16}px)`;
1609
- } else {
1610
- wrapper.style.transform = '';
1611
- }
1612
- }, [width, height, isOpen]);
1613
1624
  return /*#__PURE__*/_jsx(Wrapper, {
1614
1625
  ref: wrapperRef,
1615
1626
  className: `is-${mode} ${className}`,
@@ -2,8 +2,8 @@ type NavMenuProps = {
2
2
  $bgColor: string;
3
3
  $textColor: string;
4
4
  };
5
- export declare const NavMenuRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & NavMenuProps, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, {}>;
6
- export declare const NavMenuList: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, {}>;
5
+ export declare const NavMenuStyled: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & NavMenuProps, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, {}>;
6
+ export declare const NavMenuRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLUListElement>, HTMLUListElement>, {}>;
7
7
  type NavMenuItemProps = {
8
8
  $activeTextColor: string;
9
9
  };
@@ -1,12 +1,13 @@
1
1
  import { styled } from '../Theme';
2
- // .navmenu-root
3
- export const NavMenuRoot = styled('nav', {
2
+ // .navmenu
3
+ export const NavMenuStyled = styled('nav', {
4
4
  shouldForwardProp: prop => prop !== '$bgColor' && prop !== '$textColor'
5
5
  })(({
6
6
  $bgColor,
7
7
  $textColor
8
8
  }) => ({
9
- padding: '8px 16px',
9
+ position: 'relative',
10
+ padding: '0 16px',
10
11
  minWidth: '50px',
11
12
  // FIXME: @zhanghan 这个只是临时的解决方案,会导致 header align right 不能真正的右对齐,需要修改 header 才能真正解决这个问题
12
13
  flexGrow: 100,
@@ -15,15 +16,15 @@ export const NavMenuRoot = styled('nav', {
15
16
  fontSize: '16px'
16
17
  }));
17
18
 
18
- // .navmenu-list
19
- export const NavMenuList = styled('ul')(() => ({
19
+ // .navmenu-root
20
+ export const NavMenuRoot = styled('ul')(() => ({
20
21
  listStyle: 'none',
21
22
  margin: 0,
22
23
  padding: 0,
23
24
  display: 'flex',
24
25
  alignItems: 'center',
25
26
  // inline 布局
26
- '&.navmenu-list--inline ': {
27
+ '&.navmenu-root--inline ': {
27
28
  flexDirection: 'column',
28
29
  alignItems: 'stretch'
29
30
  }
@@ -32,15 +33,18 @@ export const NavMenuList = styled('ul')(() => ({
32
33
  export const NavMenuItem = styled('li', {
33
34
  shouldForwardProp: prop => prop !== '$activeTextColor'
34
35
  })(({
35
- $activeTextColor
36
+ $activeTextColor,
37
+ theme
36
38
  }) => ({
37
39
  display: 'flex',
38
40
  alignItems: 'center',
39
41
  position: 'relative',
40
- padding: '0 12px',
42
+ padding: '8px 12px',
41
43
  whiteSpace: 'nowrap',
42
44
  cursor: 'pointer',
43
- transition: 'color 0.2s ease-in-out',
45
+ transition: theme.transitions.create('color', {
46
+ duration: theme.transitions.duration.standard
47
+ }),
44
48
  // 间距调整
45
49
  '&:first-of-type': {
46
50
  paddingLeft: 0
@@ -93,7 +97,9 @@ export const NavMenuItem = styled('li', {
93
97
  marginLeft: '6px',
94
98
  fontSize: '14px',
95
99
  opacity: 0,
96
- transition: 'opacity 0.2s ease-in-out'
100
+ transition: theme.transitions.create('opacity', {
101
+ duration: theme.transitions.duration.standard
102
+ })
97
103
  }
98
104
  },
99
105
  '.navmenu-item__desc': {
@@ -131,13 +137,17 @@ export const NavMenuItem = styled('li', {
131
137
  },
132
138
  '&:hover': {
133
139
  background: '#f9f9fb',
134
- transition: 'background 0.2s ease-in-out',
140
+ transition: theme.transitions.create('background', {
141
+ duration: theme.transitions.duration.standard
142
+ }),
135
143
  '.navmenu-item__label-arrow': {
136
144
  opacity: 1
137
145
  },
138
146
  '.navmenu-item__desc': {
139
147
  color: '#26292e',
140
- transition: 'color 0.2s ease-in-out'
148
+ transition: theme.transitions.create('color', {
149
+ duration: theme.transitions.duration.standard
150
+ })
141
151
  }
142
152
  },
143
153
  '&.navmenu-item--active': {
@@ -155,24 +165,28 @@ export const NavMenuItem = styled('li', {
155
165
  }));
156
166
 
157
167
  // 包含子菜单的导航项 .navmenu-item .navmenu-sub
158
- export const NavMenuSub = styled(NavMenuItem)(() => ({
168
+ export const NavMenuSub = styled(NavMenuItem)(({
169
+ theme
170
+ }) => ({
159
171
  '.navmenu-item': {
160
- marginLeft: 0
172
+ marginLeft: 0,
173
+ overflow: 'hidden'
161
174
  },
162
175
  '& .navmenu-sub__container': {
163
- visibility: 'hidden',
176
+ pointerEvents: 'none',
164
177
  opacity: 0,
165
178
  position: 'absolute',
166
179
  top: '100%',
167
- left: '50%',
168
- zIndex: 1,
169
- transform: 'translateX(-50%)',
170
- paddingTop: '16px',
171
- transition: 'opacity 0.2s ease-in-out, visibility 0.2s ease-in-out'
180
+ left: 0,
181
+ zIndex: 1
172
182
  },
173
183
  '&.navmenu-sub--opened > .navmenu-sub__container': {
174
- visibility: 'visible',
175
- opacity: 1
184
+ pointerEvents: 'auto',
185
+ opacity: 1,
186
+ transition: theme.transitions.create('opacity', {
187
+ duration: theme.transitions.duration.standard,
188
+ easing: theme.transitions.easing.easeOut
189
+ })
176
190
  },
177
191
  // 扩展图标
178
192
  '.navmenu-sub__expand-icon': {
@@ -183,7 +197,9 @@ export const NavMenuSub = styled(NavMenuItem)(() => ({
183
197
  '& > *': {
184
198
  width: '0.8em',
185
199
  height: '0.8em',
186
- transition: 'transform 0.2s ease-in-out'
200
+ transition: theme.transitions.create('transform', {
201
+ duration: theme.transitions.duration.standard
202
+ })
187
203
  },
188
204
  '.navmenu-item--inline &': {
189
205
  marginLeft: 'auto'
@@ -199,7 +215,9 @@ export const NavMenuSub = styled(NavMenuItem)(() => ({
199
215
  padding: 0,
200
216
  height: 0,
201
217
  overflow: 'hidden',
202
- transition: 'height 0.2s ease-in-out'
218
+ transition: theme.transitions.create('height', {
219
+ duration: theme.transitions.duration.standard
220
+ })
203
221
  },
204
222
  '&.navmenu-sub--opened > .navmenu-sub__container': {
205
223
  height: 'auto'
@@ -208,11 +226,14 @@ export const NavMenuSub = styled(NavMenuItem)(() => ({
208
226
  padding: 0,
209
227
  paddingLeft: '16px',
210
228
  boxShadow: 'none'
229
+ },
230
+ '.navmenu-item__content': {
231
+ height: '48px'
211
232
  }
212
233
  }
213
234
  }));
214
235
 
215
- // 下拉子菜单 .navmenu-sub-list
236
+ // 下拉子菜单 .navmenu-sub__list
216
237
  export const NavMenuSubList = styled('ul')(() => ({
217
238
  margin: 0,
218
239
  padding: '16px',
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface SubContainerProps extends React.HTMLAttributes<HTMLDivElement> {
3
+ children: React.ReactNode;
4
+ }
5
+ export declare function SubContainer({ children, ...props }: SubContainerProps): import("react/jsx-runtime").JSX.Element;
6
+ export default SubContainer;
@@ -0,0 +1,83 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ const paddingTop = 8;
4
+
5
+ // 下拉子菜单容器
6
+ export function SubContainer({
7
+ children,
8
+ ...props
9
+ }) {
10
+ const rootRef = useRef(null);
11
+ const [position, setPosition] = useState(0); // 只需要保存水平偏移量
12
+
13
+ const updatePosition = () => {
14
+ if (!rootRef.current) return;
15
+ const anchor = rootRef.current.parentElement; // 以父容器作为参照
16
+ if (!anchor) return;
17
+ const anchorRect = anchor.getBoundingClientRect();
18
+ const containerRect = rootRef.current.getBoundingClientRect();
19
+ const windowWidth = window.innerWidth;
20
+ const padding = 32;
21
+
22
+ // 1. 计算相对于父元素的水平居中位置
23
+ let left = (anchorRect.width - containerRect.width) / 2;
24
+
25
+ // 2. 检查容器在视口中的绝对位置
26
+ const absoluteLeft = anchorRect.left + left;
27
+
28
+ // 3. 调整水平位置确保不超出窗口
29
+ if (absoluteLeft < 0) {
30
+ // 如果超出左边界,向右偏移
31
+ left = left - absoluteLeft + padding;
32
+ } else if (absoluteLeft + containerRect.width > windowWidth) {
33
+ // 如果超出右边界,向左偏移
34
+ left -= absoluteLeft + containerRect.width - windowWidth + padding;
35
+ }
36
+ setPosition(left);
37
+ };
38
+
39
+ // 监听自身大小变化
40
+ useEffect(() => {
41
+ const resizeObserver = new ResizeObserver(() => {
42
+ updatePosition();
43
+ });
44
+ resizeObserver.observe(rootRef.current);
45
+ return () => resizeObserver.disconnect();
46
+ // eslint-disable-next-line react-hooks/exhaustive-deps
47
+ }, []);
48
+
49
+ // 监听 anchor 的大小变化
50
+ useEffect(() => {
51
+ const anchor = rootRef.current?.parentElement;
52
+ let resizeObserver = null;
53
+ if (anchor) {
54
+ resizeObserver = new ResizeObserver(() => {
55
+ updatePosition();
56
+ });
57
+ resizeObserver.observe(anchor);
58
+ }
59
+ return () => resizeObserver?.disconnect();
60
+ // eslint-disable-next-line react-hooks/exhaustive-deps
61
+ }, []);
62
+
63
+ // 监听窗口大小变化
64
+ useEffect(() => {
65
+ const handleResize = () => {
66
+ updatePosition();
67
+ };
68
+ window.addEventListener('resize', handleResize);
69
+ return () => window.removeEventListener('resize', handleResize);
70
+ // eslint-disable-next-line react-hooks/exhaustive-deps
71
+ }, []);
72
+ return /*#__PURE__*/_jsx("div", {
73
+ ref: rootRef,
74
+ className: "navmenu-sub__container",
75
+ style: {
76
+ paddingTop: `${paddingTop}px`,
77
+ transform: `translateX(${position}px)`
78
+ },
79
+ ...props,
80
+ children: children
81
+ });
82
+ }
83
+ export default SubContainer;
@@ -58,7 +58,7 @@ export declare function openWebWallet({ webWalletUrl, action, locale, url, windo
58
58
  }): {
59
59
  type: string;
60
60
  };
61
- export declare const getFontSize: (size: string) => string;
61
+ export declare const getFontSize: (size: string | number) => string;
62
62
  export declare const isEthereumDid: (did: string) => boolean;
63
63
  export declare const appendParams: (url: string, params: {
64
64
  imageFilter: "crop" | "resize";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcblock/ux",
3
- "version": "2.12.2",
3
+ "version": "2.12.4",
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": "4dc132cab82765eef5194cf00075a13bd5d8e458",
71
+ "gitHead": "f8648a2f55bb57212a24a5948a5f026e2c20b1a7",
72
72
  "dependencies": {
73
73
  "@arcblock/did-motif": "^1.1.13",
74
- "@arcblock/icons": "^2.12.2",
75
- "@arcblock/nft-display": "^2.12.2",
76
- "@arcblock/react-hooks": "^2.12.2",
74
+ "@arcblock/icons": "^2.12.4",
75
+ "@arcblock/nft-display": "^2.12.4",
76
+ "@arcblock/react-hooks": "^2.12.4",
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",