@nutui/nutui-react 2.0.2 → 2.0.3

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.
@@ -6,7 +6,7 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
  var _a;
8
8
  /*!
9
- * @nutui/nutui-react v2.0.2 Fri Jul 07 2023 14:02:05 GMT+0800 (China Standard Time)
9
+ * @nutui/nutui-react v2.0.3 Wed Jul 12 2023 17:49:44 GMT+0800 (China Standard Time)
10
10
  * (c) 2023 @jdf2e.
11
11
  * Released under the MIT License.
12
12
  */
@@ -11593,9 +11593,9 @@ const TabPane = (props) => {
11593
11593
  );
11594
11594
  return children ? /* @__PURE__ */ React__default.createElement("div", { className: classes }, !disabled && children) : null;
11595
11595
  };
11596
- const _window = window;
11597
11596
  function requestAniFrame() {
11598
- if (typeof _window !== "undefined") {
11597
+ if (typeof window !== "undefined") {
11598
+ const _window = window;
11599
11599
  return _window.requestAnimationFrame || _window.webkitRequestAnimationFrame || function(callback) {
11600
11600
  _window.setTimeout(callback, 1e3 / 60);
11601
11601
  };
@@ -16473,11 +16473,14 @@ const MenuItem = forwardRef((props, ref) => {
16473
16473
  ...defaultProps$Q,
16474
16474
  ...props
16475
16475
  };
16476
- const [_showPopup, setShowPopup] = useState(show2);
16477
- const [_value, setValue] = useState(value);
16476
+ const [showPopup, setShowPopup] = useState(show2);
16477
+ const [innerValue, setValue] = useState(value);
16478
16478
  useEffect(() => {
16479
16479
  setShowPopup(show2);
16480
16480
  }, [show2]);
16481
+ useEffect(() => {
16482
+ getParentOffset();
16483
+ }, [showPopup]);
16481
16484
  useImperativeHandle(ref, () => ({
16482
16485
  toggle: parent.toggleMenuItem
16483
16486
  }));
@@ -16499,16 +16502,33 @@ const MenuItem = forwardRef((props, ref) => {
16499
16502
  onChange && onChange(item);
16500
16503
  };
16501
16504
  const isShow = () => {
16502
- if (_showPopup)
16505
+ if (showPopup)
16503
16506
  return {};
16504
16507
  return { display: "none" };
16505
16508
  };
16509
+ const [position, setPosition] = useState({
16510
+ top: 0,
16511
+ height: 0
16512
+ });
16513
+ const getParentOffset = () => {
16514
+ setTimeout(() => {
16515
+ const p = parent.menuRef.current;
16516
+ const rect = p.getBoundingClientRect();
16517
+ setPosition({
16518
+ height: rect.height,
16519
+ top: rect.top
16520
+ });
16521
+ });
16522
+ };
16506
16523
  const getPosition = () => {
16507
- return direction === "down" ? { position: "absolute", height: `${window.innerHeight}px` } : {
16508
- position: "absolute",
16509
- bottom: "100%",
16524
+ return direction === "down" ? {
16525
+ top: `${position.top + position.height}px`,
16526
+ bottom: "0",
16527
+ height: "initial"
16528
+ } : {
16529
+ bottom: `${window.innerHeight - position.top}px`,
16510
16530
  top: "auto",
16511
- height: `${window.innerHeight}px`
16531
+ height: "initial"
16512
16532
  };
16513
16533
  };
16514
16534
  const micRef = useRef(null);
@@ -16522,15 +16542,14 @@ const MenuItem = forwardRef((props, ref) => {
16522
16542
  targetSet,
16523
16543
  "click",
16524
16544
  false,
16525
- _showPopup,
16545
+ showPopup,
16526
16546
  closeOnClickAway
16527
16547
  );
16528
16548
  return /* @__PURE__ */ React__default.createElement(
16529
16549
  "div",
16530
16550
  {
16531
16551
  className: "nut-menu-item-container",
16532
- ref: micRef,
16533
- style: { position: "absolute", left: 0, right: 0 }
16552
+ ref: micRef
16534
16553
  },
16535
16554
  /* @__PURE__ */ React__default.createElement(
16536
16555
  Overlay,
@@ -16538,7 +16557,7 @@ const MenuItem = forwardRef((props, ref) => {
16538
16557
  className: "nut-menu__overlay",
16539
16558
  style: getPosition(),
16540
16559
  lockScroll: parent.lockScroll,
16541
- visible: _showPopup,
16560
+ visible: showPopup,
16542
16561
  closeOnOverlayClick: parent.closeOnOverlayClick,
16543
16562
  onClick: () => {
16544
16563
  parent.closeOnOverlayClick && parent.toggleMenuItem(index);
@@ -16560,7 +16579,7 @@ const MenuItem = forwardRef((props, ref) => {
16560
16579
  /* @__PURE__ */ React__default.createElement(
16561
16580
  CSSTransition$1,
16562
16581
  {
16563
- in: _showPopup,
16582
+ in: showPopup,
16564
16583
  timeout: 100,
16565
16584
  classNames: direction === "down" ? "menu-item" : "menu-item-up"
16566
16585
  },
@@ -16569,7 +16588,7 @@ const MenuItem = forwardRef((props, ref) => {
16569
16588
  "div",
16570
16589
  {
16571
16590
  className: `nut-menu-item__option ${classNames({
16572
- active: item.value === _value
16591
+ active: item.value === innerValue
16573
16592
  })}`,
16574
16593
  key: item.text,
16575
16594
  style: {
@@ -16579,7 +16598,7 @@ const MenuItem = forwardRef((props, ref) => {
16579
16598
  handleClick2(item);
16580
16599
  }
16581
16600
  },
16582
- item.value === _value ? /* @__PURE__ */ React__default.createElement("i", null, icon || /* @__PURE__ */ React__default.createElement(
16601
+ item.value === innerValue ? /* @__PURE__ */ React__default.createElement("i", null, icon || /* @__PURE__ */ React__default.createElement(
16583
16602
  x$f,
16584
16603
  {
16585
16604
  color: activeColor,
@@ -16591,7 +16610,7 @@ const MenuItem = forwardRef((props, ref) => {
16591
16610
  {
16592
16611
  className: getIconCName(item.value, value),
16593
16612
  style: {
16594
- color: `${item.value === _value ? activeColor : ""}`
16613
+ color: `${item.value === innerValue ? activeColor : ""}`
16595
16614
  }
16596
16615
  },
16597
16616
  item.text
@@ -16610,7 +16629,11 @@ const defaultProps$P = {
16610
16629
  closeOnOverlayClick: true,
16611
16630
  scrollFixed: false,
16612
16631
  lockScroll: true,
16613
- icon: null
16632
+ icon: null,
16633
+ onOpen: () => {
16634
+ },
16635
+ onClose: () => {
16636
+ }
16614
16637
  };
16615
16638
  const Menu = (props) => {
16616
16639
  const {
@@ -16621,6 +16644,8 @@ const Menu = (props) => {
16621
16644
  closeOnOverlayClick,
16622
16645
  children,
16623
16646
  activeColor,
16647
+ onClose,
16648
+ onOpen,
16624
16649
  ...rest
16625
16650
  } = {
16626
16651
  ...defaultProps$P,
@@ -16647,6 +16672,11 @@ const Menu = (props) => {
16647
16672
  const [menuItemTitle, setMenuItemTitle] = useState([]);
16648
16673
  const toggleMenuItem = (index) => {
16649
16674
  showMenuItem[index] = !showMenuItem[index];
16675
+ if (showMenuItem[index]) {
16676
+ onOpen && onOpen();
16677
+ } else {
16678
+ onClose && onClose();
16679
+ }
16650
16680
  const temp = showMenuItem.map(
16651
16681
  (i, idx) => idx === index ? i : false
16652
16682
  );
@@ -16655,6 +16685,7 @@ const Menu = (props) => {
16655
16685
  const hideMenuItem = (index) => {
16656
16686
  showMenuItem[index] = false;
16657
16687
  setShowMenuItem([...showMenuItem]);
16688
+ onClose && onClose();
16658
16689
  };
16659
16690
  const updateTitle = (text, index) => {
16660
16691
  menuItemTitle[index] = text;
@@ -9,7 +9,7 @@ var __publicField = (obj, key, value) => {
9
9
  return value;
10
10
  };
11
11
  /*!
12
- * @nutui/nutui-react v2.0.2 Fri Jul 07 2023 14:02:05 GMT+0800 (China Standard Time)
12
+ * @nutui/nutui-react v2.0.3 Wed Jul 12 2023 17:49:44 GMT+0800 (China Standard Time)
13
13
  * (c) 2023 @jdf2e.
14
14
  * Released under the MIT License.
15
15
  */
@@ -11611,9 +11611,9 @@ Please add \`${key}Action\` when creating your handler.`);
11611
11611
  );
11612
11612
  return children ? /* @__PURE__ */ React.createElement("div", { className: classes }, !disabled && children) : null;
11613
11613
  };
11614
- const _window = window;
11615
11614
  function requestAniFrame() {
11616
- if (typeof _window !== "undefined") {
11615
+ if (typeof window !== "undefined") {
11616
+ const _window = window;
11617
11617
  return _window.requestAnimationFrame || _window.webkitRequestAnimationFrame || function(callback) {
11618
11618
  _window.setTimeout(callback, 1e3 / 60);
11619
11619
  };
@@ -16491,11 +16491,14 @@ Please add \`${key}Action\` when creating your handler.`);
16491
16491
  ...defaultProps$Q,
16492
16492
  ...props
16493
16493
  };
16494
- const [_showPopup, setShowPopup] = React.useState(show2);
16495
- const [_value, setValue] = React.useState(value);
16494
+ const [showPopup, setShowPopup] = React.useState(show2);
16495
+ const [innerValue, setValue] = React.useState(value);
16496
16496
  React.useEffect(() => {
16497
16497
  setShowPopup(show2);
16498
16498
  }, [show2]);
16499
+ React.useEffect(() => {
16500
+ getParentOffset();
16501
+ }, [showPopup]);
16499
16502
  React.useImperativeHandle(ref, () => ({
16500
16503
  toggle: parent.toggleMenuItem
16501
16504
  }));
@@ -16517,16 +16520,33 @@ Please add \`${key}Action\` when creating your handler.`);
16517
16520
  onChange && onChange(item);
16518
16521
  };
16519
16522
  const isShow = () => {
16520
- if (_showPopup)
16523
+ if (showPopup)
16521
16524
  return {};
16522
16525
  return { display: "none" };
16523
16526
  };
16527
+ const [position, setPosition] = React.useState({
16528
+ top: 0,
16529
+ height: 0
16530
+ });
16531
+ const getParentOffset = () => {
16532
+ setTimeout(() => {
16533
+ const p = parent.menuRef.current;
16534
+ const rect = p.getBoundingClientRect();
16535
+ setPosition({
16536
+ height: rect.height,
16537
+ top: rect.top
16538
+ });
16539
+ });
16540
+ };
16524
16541
  const getPosition = () => {
16525
- return direction === "down" ? { position: "absolute", height: `${window.innerHeight}px` } : {
16526
- position: "absolute",
16527
- bottom: "100%",
16542
+ return direction === "down" ? {
16543
+ top: `${position.top + position.height}px`,
16544
+ bottom: "0",
16545
+ height: "initial"
16546
+ } : {
16547
+ bottom: `${window.innerHeight - position.top}px`,
16528
16548
  top: "auto",
16529
- height: `${window.innerHeight}px`
16549
+ height: "initial"
16530
16550
  };
16531
16551
  };
16532
16552
  const micRef = React.useRef(null);
@@ -16540,15 +16560,14 @@ Please add \`${key}Action\` when creating your handler.`);
16540
16560
  targetSet,
16541
16561
  "click",
16542
16562
  false,
16543
- _showPopup,
16563
+ showPopup,
16544
16564
  closeOnClickAway
16545
16565
  );
16546
16566
  return /* @__PURE__ */ React.createElement(
16547
16567
  "div",
16548
16568
  {
16549
16569
  className: "nut-menu-item-container",
16550
- ref: micRef,
16551
- style: { position: "absolute", left: 0, right: 0 }
16570
+ ref: micRef
16552
16571
  },
16553
16572
  /* @__PURE__ */ React.createElement(
16554
16573
  Overlay,
@@ -16556,7 +16575,7 @@ Please add \`${key}Action\` when creating your handler.`);
16556
16575
  className: "nut-menu__overlay",
16557
16576
  style: getPosition(),
16558
16577
  lockScroll: parent.lockScroll,
16559
- visible: _showPopup,
16578
+ visible: showPopup,
16560
16579
  closeOnOverlayClick: parent.closeOnOverlayClick,
16561
16580
  onClick: () => {
16562
16581
  parent.closeOnOverlayClick && parent.toggleMenuItem(index);
@@ -16578,7 +16597,7 @@ Please add \`${key}Action\` when creating your handler.`);
16578
16597
  /* @__PURE__ */ React.createElement(
16579
16598
  CSSTransition$1,
16580
16599
  {
16581
- in: _showPopup,
16600
+ in: showPopup,
16582
16601
  timeout: 100,
16583
16602
  classNames: direction === "down" ? "menu-item" : "menu-item-up"
16584
16603
  },
@@ -16587,7 +16606,7 @@ Please add \`${key}Action\` when creating your handler.`);
16587
16606
  "div",
16588
16607
  {
16589
16608
  className: `nut-menu-item__option ${classNames({
16590
- active: item.value === _value
16609
+ active: item.value === innerValue
16591
16610
  })}`,
16592
16611
  key: item.text,
16593
16612
  style: {
@@ -16597,7 +16616,7 @@ Please add \`${key}Action\` when creating your handler.`);
16597
16616
  handleClick2(item);
16598
16617
  }
16599
16618
  },
16600
- item.value === _value ? /* @__PURE__ */ React.createElement("i", null, icon || /* @__PURE__ */ React.createElement(
16619
+ item.value === innerValue ? /* @__PURE__ */ React.createElement("i", null, icon || /* @__PURE__ */ React.createElement(
16601
16620
  x$f,
16602
16621
  {
16603
16622
  color: activeColor,
@@ -16609,7 +16628,7 @@ Please add \`${key}Action\` when creating your handler.`);
16609
16628
  {
16610
16629
  className: getIconCName(item.value, value),
16611
16630
  style: {
16612
- color: `${item.value === _value ? activeColor : ""}`
16631
+ color: `${item.value === innerValue ? activeColor : ""}`
16613
16632
  }
16614
16633
  },
16615
16634
  item.text
@@ -16628,7 +16647,11 @@ Please add \`${key}Action\` when creating your handler.`);
16628
16647
  closeOnOverlayClick: true,
16629
16648
  scrollFixed: false,
16630
16649
  lockScroll: true,
16631
- icon: null
16650
+ icon: null,
16651
+ onOpen: () => {
16652
+ },
16653
+ onClose: () => {
16654
+ }
16632
16655
  };
16633
16656
  const Menu = (props) => {
16634
16657
  const {
@@ -16639,6 +16662,8 @@ Please add \`${key}Action\` when creating your handler.`);
16639
16662
  closeOnOverlayClick,
16640
16663
  children,
16641
16664
  activeColor,
16665
+ onClose,
16666
+ onOpen,
16642
16667
  ...rest
16643
16668
  } = {
16644
16669
  ...defaultProps$P,
@@ -16665,6 +16690,11 @@ Please add \`${key}Action\` when creating your handler.`);
16665
16690
  const [menuItemTitle, setMenuItemTitle] = React.useState([]);
16666
16691
  const toggleMenuItem = (index) => {
16667
16692
  showMenuItem[index] = !showMenuItem[index];
16693
+ if (showMenuItem[index]) {
16694
+ onOpen && onOpen();
16695
+ } else {
16696
+ onClose && onClose();
16697
+ }
16668
16698
  const temp = showMenuItem.map(
16669
16699
  (i, idx) => idx === index ? i : false
16670
16700
  );
@@ -16673,6 +16703,7 @@ Please add \`${key}Action\` when creating your handler.`);
16673
16703
  const hideMenuItem = (index) => {
16674
16704
  showMenuItem[index] = false;
16675
16705
  setShowMenuItem([...showMenuItem]);
16706
+ onClose && onClose();
16676
16707
  };
16677
16708
  const updateTitle = (text, index) => {
16678
16709
  menuItemTitle[index] = text;
@@ -57,8 +57,8 @@
57
57
  }
58
58
 
59
59
  .placeholder-element {
60
- position: absolute;
61
- top: -$menu-bar-line-height;
60
+ position: fixed;
61
+ top: $menu-placeholder-top;
62
62
  left: 0;
63
63
  right: 0;
64
64
  z-index: $menu-bar-opened-z-index;