@hexure/ui 1.13.3 → 1.13.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.
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useContext, useState, useEffect, useRef } from 'react';
1
+ import React, { useContext, useState, useRef, useEffect } from 'react';
2
2
  import styled, { ThemeContext, keyframes } from 'styled-components';
3
3
  import Icon, { Icon as Icon$1 } from '@mdi/react';
4
4
  import { mdiChevronUp, mdiChevronDown, mdiLoading, mdiInformationOutline, mdiAlertOctagonOutline, mdiAlertOutline, mdiCheckboxMarkedCircleOutline, mdiClose, mdiChevronRight, mdiChevronLeft, mdiDotsHorizontal, mdiMinusCircle, mdiFolderPlusOutline, mdiCheck } from '@mdi/js';
@@ -734,47 +734,17 @@ const MenuWrapper = styled.div `
734
734
  display: inline-block;
735
735
  `;
736
736
  const StyledMoreMenu = styled(MoreMenu) `
737
- position: absolute;
737
+ position: fixed;
738
+ top: ${props => props.$top};
739
+ left: ${props => props.$left};
738
740
  width: ${props => props.$menuWidth};
739
741
  max-height: ${props => props.maxHeight};
740
742
  z-index: 10;
741
-
742
- ${props => {
743
- switch (props.$position) {
744
- case 'top':
745
- return `
746
- bottom: 100%;
747
- left: 0;
748
- transform: translateY(-5px); /* Adjust this value as needed */
749
- `;
750
- case 'bottom':
751
- return `
752
- top: 100%;
753
- left: 0;
754
- transform: translateY(5px); /* Adjust this value as needed */
755
- `;
756
- case 'left':
757
- return `
758
- right: 100%;
759
- top: 0;
760
- transform: translateX(-5px); /* Adjust this value as needed */
761
- `;
762
- case 'right':
763
- return `
764
- left: 100%;
765
- top: 0;
766
- transform: translateX(5px); /* Adjust this value as needed */
767
- `;
768
- default:
769
- return `
770
- top: 0;
771
- left: 0;
772
- `;
773
- }
774
- }}
775
743
  `;
776
- const ButtonMenu = ({ disabled, label, maxHeight, menuItems, small, position = 'right', format = 'primary', menuWidth = '200px', enableHover = true, enableClick = false, }) => {
744
+ const ButtonMenu = ({ disabled, label, maxHeight, menuItems, small, position = 'bottomLeft', format = 'primary', menuWidth = '200px', enableHover = true, enableClick = false, }) => {
777
745
  const [showMenu, toggleMenu] = useState(false);
746
+ const [menuPosition, setMenuPosition] = useState({ top: '0px', left: '0px' });
747
+ const menuWrapperRef = useRef(null);
778
748
  const handleMouseEnter = () => {
779
749
  if (!disabled && enableHover) {
780
750
  toggleMenu(true);
@@ -790,9 +760,55 @@ const ButtonMenu = ({ disabled, label, maxHeight, menuItems, small, position = '
790
760
  toggleMenu(!showMenu);
791
761
  }
792
762
  };
793
- return (React.createElement(MenuWrapper, { onClick: handleClick, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave },
763
+ useEffect(() => {
764
+ if (showMenu && menuWrapperRef.current) {
765
+ const rect = menuWrapperRef.current.getBoundingClientRect();
766
+ let top = rect.top;
767
+ let left = rect.left;
768
+ switch (position) {
769
+ case 'top':
770
+ top = rect.top - rect.height;
771
+ left = rect.left;
772
+ break;
773
+ case 'bottom':
774
+ top = rect.bottom;
775
+ left = rect.left;
776
+ break;
777
+ case 'left':
778
+ top = rect.top;
779
+ left = rect.left - rect.width;
780
+ break;
781
+ case 'right':
782
+ top = rect.top;
783
+ left = rect.right;
784
+ break;
785
+ case 'bottomRight':
786
+ top = rect.bottom;
787
+ left = rect.left;
788
+ break;
789
+ case 'bottomLeft':
790
+ top = rect.bottom;
791
+ left = rect.right - parseInt(menuWidth, 10);
792
+ break;
793
+ case 'topRight':
794
+ top = rect.top - parseInt(menuWidth, 10);
795
+ left = rect.left;
796
+ break;
797
+ case 'topLeft':
798
+ top = rect.top - parseInt(menuWidth, 10);
799
+ left = rect.right - parseInt(menuWidth, 10);
800
+ break;
801
+ default:
802
+ top = rect.bottom;
803
+ left = rect.left;
804
+ break;
805
+ }
806
+ setMenuPosition({ top: `${top}px`, left: `${left}px` });
807
+ }
808
+ }, [showMenu, position, menuWidth]);
809
+ return (React.createElement(MenuWrapper, { onClick: handleClick, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, ref: menuWrapperRef },
794
810
  React.createElement(Button, { disabled: disabled, format: format, icon: mdiDotsHorizontal, small: small }, label),
795
- showMenu && (React.createElement(StyledMoreMenu, { "$menuWidth": menuWidth, "$position": position, "$small": small, maxHeight: maxHeight, menuItems: menuItems }))));
811
+ showMenu && (React.createElement(StyledMoreMenu, { "$left": menuPosition.left, "$menuWidth": menuWidth, "$top": menuPosition.top, maxHeight: maxHeight, menuItems: menuItems }))));
796
812
  };
797
813
 
798
814
  const Wrapper$c = styled.div `