x-ui-design 0.8.83 → 0.8.85

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.
@@ -5,10 +5,11 @@ type TPopupPosition = {
5
5
  setOpen: Dispatch<SetStateAction<boolean>>;
6
6
  targetRef: RefObject<HTMLDivElement | null>;
7
7
  popupRef: RefObject<HTMLDivElement | null>;
8
- placement: Placement;
8
+ placement?: Placement;
9
9
  inBody: boolean;
10
10
  };
11
11
  export declare const usePopupPosition: ({ open, setOpen, inBody, popupRef, targetRef, placement }: TPopupPosition) => {
12
+ _placement: Placement;
12
13
  popupStyle: CSSProperties;
13
14
  };
14
15
  export {};
package/dist/index.esm.js CHANGED
@@ -442,7 +442,7 @@ function styleInject(css, ref) {
442
442
  }
443
443
  }
444
444
 
445
- var css_248z$q = ":root{--xui-color-hover:#f5f5f5;--xui-color-disabled:#e6e6e6;--xui-primary-color:#1677ff;--xui-primary-color-light:#40a9ff;--xui-text-color:rgba(0,0,0,.88);--xui-text-color-light:rgba(0,0,0,.5);--xui-error-color:#ff4d4f;--xui-error-color-light:#ff6668;--xui-success-color:#52c41a;--xui-background-color:#fff;--xui-font-size-xs:12px;--xui-font-size-sm:14px;--xui-font-size-md:14px;--xui-font-size-lg:16px;--xui-border-radius-sm:4px;--xui-border-radius-md:4px;--xui-border-radius-lg:6px;--xui-border-color:#d9d9d9;--xui-select-primary-color:var(--xui-primary-color);--xui-select-background-color:var(--xui-background-color);--xui-result-bg:#fff;--xui-result-color:rgba(0,0,0,.85);--xui-subtle-color:rgba(0,0,0,.45);--xui-padding:24px;--xui-gap:16px;--xui-icon-size:72px;--xui-max-width:560px;--xui-font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,\"Helvetica Neue\",Arial}html{font-family:sans-serif}.globalEllipsis{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.xUi-popup-position{&:after,&:before{content:\"\";height:12px;left:0;position:absolute;top:-12px;width:100%;z-index:10000}&:after{bottom:-12px;top:unset}}.xUi-popup-position-bottom,.xUi-popup-position-bottomLeft,.xUi-popup-position-bottomRight,.xUi-popup-position-top,.xUi-popup-position-topLeft,.xUi-popup-position-topRight{background:var(--xui-background-color);border-left:.5px solid var(--xui-border-color);border-top:.5px solid var(--xui-border-color);height:10px;position:absolute;width:10px}.xUi-popup-position-bottom,.xUi-popup-position-bottomLeft,.xUi-popup-position-bottomRight{top:-6px;transform:rotate(45deg)}.xUi-popup-position-top,.xUi-popup-position-topLeft,.xUi-popup-position-topRight{bottom:-6px;top:unset;transform:rotate(-135deg)}.xUi-popup-position-bottom,.xUi-popup-position-top{left:50%;right:50%}.xUi-popup-position-bottomLeft,.xUi-popup-position-topLeft{left:12px;right:unset}.xUi-popup-position-bottomRight,.xUi-popup-position-topRight{left:unset;right:12px}";
445
+ var css_248z$q = ":root{--xui-color-hover:#f5f5f5;--xui-color-disabled:#e6e6e6;--xui-primary-color:#1677ff;--xui-primary-color-light:#40a9ff;--xui-text-color:rgba(0,0,0,.88);--xui-text-color-light:rgba(0,0,0,.5);--xui-error-color:#ff4d4f;--xui-error-color-light:#ff6668;--xui-success-color:#52c41a;--xui-background-color:#fff;--xui-font-size-xs:12px;--xui-font-size-sm:14px;--xui-font-size-md:14px;--xui-font-size-lg:16px;--xui-border-radius-sm:4px;--xui-border-radius-md:4px;--xui-border-radius-lg:6px;--xui-border-color:#d9d9d9;--xui-select-primary-color:var(--xui-primary-color);--xui-select-background-color:var(--xui-background-color);--xui-result-bg:#fff;--xui-result-color:rgba(0,0,0,.85);--xui-subtle-color:rgba(0,0,0,.45);--xui-padding:24px;--xui-gap:16px;--xui-icon-size:72px;--xui-max-width:560px;--xui-font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,\"Helvetica Neue\",Arial}html{font-family:sans-serif}.globalEllipsis{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.xUi-popup-position{&:after,&:before{content:\"\";height:12px;left:0;position:absolute;top:-12px;width:100%;z-index:10000}&:after{bottom:-12px;top:unset}}.xUi-popup-position-bottom,.xUi-popup-position-bottomLeft,.xUi-popup-position-bottomRight,.xUi-popup-position-top,.xUi-popup-position-topLeft,.xUi-popup-position-topRight{background:var(--xui-background-color);border-left:.5px solid var(--xui-border-color);border-top:.5px solid var(--xui-border-color);height:10px;position:absolute;width:10px}.xUi-popup-position-bottom,.xUi-popup-position-bottomLeft,.xUi-popup-position-bottomRight{top:-5px;transform:rotate(45deg)}.xUi-popup-position-top,.xUi-popup-position-topLeft,.xUi-popup-position-topRight{bottom:-5px;top:unset;transform:rotate(-135deg)}.xUi-popup-position-bottom,.xUi-popup-position-top{left:50%;right:50%}.xUi-popup-position-bottomLeft,.xUi-popup-position-topLeft{left:12px;right:unset}.xUi-popup-position-bottomRight,.xUi-popup-position-topRight{left:unset;right:12px}";
446
446
  styleInject(css_248z$q);
447
447
 
448
448
  const ClearIcon = () => /*#__PURE__*/React.createElement("svg", {
@@ -2603,6 +2603,7 @@ const usePopupPosition = ({
2603
2603
  targetRef,
2604
2604
  placement
2605
2605
  }) => {
2606
+ const [_placement, _setPlacement] = useState(placement ?? "bottomLeft");
2606
2607
  const [popupPosition, setPopupPosition] = useState({});
2607
2608
  const calculatePosition = useCallback(e => {
2608
2609
  const container = targetRef.current?.getBoundingClientRect();
@@ -2610,11 +2611,28 @@ const usePopupPosition = ({
2610
2611
  return;
2611
2612
  }
2612
2613
  const scrollableParents = getScrollParent(targetRef.current, true);
2613
- e?.target === scrollableParents;
2614
+ const scrollSameTarget = e?.target === scrollableParents;
2615
+ if (!inBody) {
2616
+ const hidePopupFromTop = Math.round((targetRef.current?.offsetTop || 0) - (scrollableParents?.scrollTop || 0) + container?.height);
2617
+ const hidePopupFromBottom = Math.round((targetRef.current?.offsetTop || 0) - (scrollableParents?.offsetHeight || 0) - (scrollableParents?.scrollTop || 0) + container?.height);
2618
+ const spaceAboveFromTop = hidePopupFromTop - Math.round((popupRef.current?.clientHeight || 0) + container?.height + OFFSET);
2619
+ const spaceAboveFromBottom = -Math.round((popupRef.current?.clientHeight || 0) + container?.height - OFFSET);
2620
+ if (spaceAboveFromBottom <= hidePopupFromBottom) {
2621
+ _setPlacement(_placement.replace('bottom', 'top'));
2622
+ }
2623
+ if (spaceAboveFromTop <= 0) {
2624
+ _setPlacement(_placement.replace('top', 'bottom'));
2625
+ }
2626
+ }
2627
+ if (scrollSameTarget && inBody) {
2628
+ setOpen(false);
2629
+ setPopupPosition({});
2630
+ return;
2631
+ }
2614
2632
  const _calculation = () => {
2615
- const _bottomCollectionTop = !placement.includes('bottom') ? 0 : (inBody ? (targetRef.current?.offsetTop || 0) + (targetRef.current?.clientHeight || 0) - (scrollableParents?.scrollTop || 0) + (scrollableParents?.offsetTop || 0) : (targetRef.current?.offsetTop || 0) + (targetRef.current?.clientHeight || 0)) + OFFSET;
2616
- const _topCollectionTop = !placement.includes('top') ? 0 : (inBody ? (targetRef.current?.offsetTop || 0) - (popupRef.current?.clientHeight || 0) - (scrollableParents?.scrollTop || 0) + (scrollableParents?.offsetTop || 0) : (targetRef.current?.offsetTop || 0) - (popupRef.current?.clientHeight || 0)) - OFFSET;
2617
- switch (placement) {
2633
+ const _bottomCollectionTop = !_placement.includes('bottom') ? 0 : (inBody ? (targetRef.current?.offsetTop || 0) + (targetRef.current?.clientHeight || 0) - (scrollableParents?.scrollTop || 0) + (scrollableParents?.offsetTop || 0) : (targetRef.current?.offsetTop || 0) + (targetRef.current?.clientHeight || 0)) + OFFSET;
2634
+ const _topCollectionTop = !_placement.includes('top') ? 0 : (inBody ? (targetRef.current?.offsetTop || 0) - (popupRef.current?.clientHeight || 0) - (scrollableParents?.scrollTop || 0) + (scrollableParents?.offsetTop || 0) : (targetRef.current?.offsetTop || 0) - (popupRef.current?.clientHeight || 0)) - OFFSET;
2635
+ switch (_placement) {
2618
2636
  case "bottom":
2619
2637
  setPopupPosition({
2620
2638
  top: _bottomCollectionTop,
@@ -2653,15 +2671,8 @@ const usePopupPosition = ({
2653
2671
  break;
2654
2672
  }
2655
2673
  };
2656
- const spaceAboveFromTop = Math.round(container?.top + container?.height) <= 0 || Math.round((targetRef.current?.offsetTop || 0) - (scrollableParents?.scrollTop || 0) + container?.height) <= 0;
2657
- const spaceAboveFromBottom = Math.round((targetRef.current?.offsetTop || 0) - (scrollableParents?.offsetHeight || 0) - (scrollableParents?.scrollTop || 0) + container?.height) >= 0;
2658
- if (spaceAboveFromTop || spaceAboveFromBottom) {
2659
- setOpen(false);
2660
- setPopupPosition({});
2661
- return;
2662
- }
2663
2674
  _calculation();
2664
- }, [targetRef, popupRef, placement, inBody, setOpen]);
2675
+ }, [targetRef, popupRef, inBody, _placement, setOpen]);
2665
2676
  useEffect(() => {
2666
2677
  if (!open) {
2667
2678
  return;
@@ -2681,6 +2692,7 @@ const usePopupPosition = ({
2681
2692
  };
2682
2693
  }, [inBody, open, targetRef, calculatePosition]);
2683
2694
  return {
2695
+ _placement,
2684
2696
  popupStyle: {
2685
2697
  zIndex: 10000,
2686
2698
  position: "absolute",
@@ -2744,7 +2756,8 @@ const DatePicker = ({
2744
2756
  }));
2745
2757
  const localeWeekdays = locale?.shortWeekDays || ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
2746
2758
  const {
2747
- popupStyle
2759
+ popupStyle,
2760
+ _placement
2748
2761
  } = usePopupPosition({
2749
2762
  targetRef,
2750
2763
  popupRef,
@@ -3026,7 +3039,7 @@ const DatePicker = ({
3026
3039
  handleSelect(DateNow.getDate(), DateNow.getMonth(), DateNow.getFullYear());
3027
3040
  }
3028
3041
  }, locale?.today || 'Today'))), /*#__PURE__*/React.createElement("div", {
3029
- className: `${prefixCls}-arrow ${prefixClsPopupPosition}-${placement}`
3042
+ className: `${prefixCls}-arrow ${prefixClsPopupPosition}-${_placement}`
3030
3043
  }))));
3031
3044
  };
3032
3045
 
@@ -3078,7 +3091,8 @@ const RangePicker = ({
3078
3091
  const [currentYear, setCurrentYear] = useState(new Date().getFullYear());
3079
3092
  const [viewMode, setViewMode] = useState(picker === 'month' ? 'month' : picker === 'year' ? 'year' : 'day');
3080
3093
  const {
3081
- popupStyle
3094
+ popupStyle,
3095
+ _placement
3082
3096
  } = usePopupPosition({
3083
3097
  targetRef,
3084
3098
  popupRef,
@@ -3350,7 +3364,7 @@ const RangePicker = ({
3350
3364
  }, /*#__PURE__*/React.createElement("div", {
3351
3365
  className: `${prefixCls}-dropdown-range`
3352
3366
  }, renderCalendar(0, viewMode !== 'day'), viewMode === 'day' && renderCalendar(1, viewMode !== 'day'), /*#__PURE__*/React.createElement("div", {
3353
- className: `${prefixCls}-arrow ${prefixClsPopupPosition}-${placement}`
3367
+ className: `${prefixCls}-arrow ${prefixClsPopupPosition}-${_placement}`
3354
3368
  })))));
3355
3369
  };
3356
3370
 
@@ -3397,7 +3411,8 @@ const TimePicker = ({
3397
3411
  const minuteRef = useRef(null);
3398
3412
  const secondRef = useRef(null);
3399
3413
  const {
3400
- popupStyle
3414
+ popupStyle,
3415
+ _placement
3401
3416
  } = usePopupPosition({
3402
3417
  open,
3403
3418
  popupRef,
@@ -3656,7 +3671,7 @@ const TimePicker = ({
3656
3671
  disabled: selectedHour === null || selectedMinute === null || selectedSecond === null,
3657
3672
  onClick: handleOkButton
3658
3673
  }, "OK")), /*#__PURE__*/React.createElement("div", {
3659
- className: `${prefixCls}-arrow ${prefixClsPopupPosition}-${placement}`
3674
+ className: `${prefixCls}-arrow ${prefixClsPopupPosition}-${_placement}`
3660
3675
  }));
3661
3676
  };
3662
3677
  return /*#__PURE__*/React.createElement("div", {
@@ -5374,7 +5389,8 @@ const Dropdown = ({
5374
5389
  const popupRef = useRef(null);
5375
5390
  const menuRef = useRef(null);
5376
5391
  const {
5377
- popupStyle
5392
+ popupStyle,
5393
+ _placement
5378
5394
  } = usePopupPosition({
5379
5395
  open,
5380
5396
  targetRef,
@@ -5448,7 +5464,7 @@ const Dropdown = ({
5448
5464
  ...popupStyle
5449
5465
  }
5450
5466
  }, arrow && /*#__PURE__*/React.createElement("div", {
5451
- className: `${prefixCls}-arrow ${prefixClsPopupPosition}-${placement}`
5467
+ className: `${prefixCls}-arrow ${prefixClsPopupPosition}-${_placement}`
5452
5468
  }), overlay ? typeof overlay === 'function' ? overlay() : overlay : popupRender ? popupRender(menu ? /*#__PURE__*/React.createElement(MenuInner, {
5453
5469
  prefixCls: prefixCls,
5454
5470
  items: menu.items,
@@ -5542,7 +5558,8 @@ const Popover = ({
5542
5558
  const [innerOpen, setInnerOpen] = useState(false);
5543
5559
  const isOpen = visible !== undefined ? visible : open !== undefined ? open : innerOpen;
5544
5560
  const {
5545
- popupStyle
5561
+ popupStyle,
5562
+ _placement
5546
5563
  } = usePopupPosition({
5547
5564
  targetRef,
5548
5565
  popupRef,
@@ -5634,7 +5651,7 @@ const Popover = ({
5634
5651
  }, Children.map(_content, (child, index) => /*#__PURE__*/React.createElement("div", {
5635
5652
  key: index
5636
5653
  }, child))), /*#__PURE__*/React.createElement("div", {
5637
- className: `${prefixCls}-arrow ${prefixClsPopupPosition}-${placement}`
5654
+ className: `${prefixCls}-arrow ${prefixClsPopupPosition}-${_placement}`
5638
5655
  }))));
5639
5656
  };
5640
5657