@zenkigen-inc/component-ui 1.7.0 → 1.7.1

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/index.js CHANGED
@@ -32596,6 +32596,56 @@ function Toggle({
32596
32596
  });
32597
32597
  }
32598
32598
 
32599
+ const useTooltip = () => {
32600
+ const calculatePosition = useCallback(args => {
32601
+ var _args$maxWidth;
32602
+ const result = {
32603
+ maxWidth: 'none',
32604
+ width: 'auto',
32605
+ left: '0px',
32606
+ top: '0px',
32607
+ bottom: '0px',
32608
+ translateX: '0',
32609
+ translateY: '0'
32610
+ };
32611
+ result.maxWidth = (_args$maxWidth = args.maxWidth) != null ? _args$maxWidth : 'none';
32612
+ const offsetH = args.tooltipSize === 'small' ? 11 : 22;
32613
+ const targetHorizontalCenter = args.dimensions.right - (args.dimensions.right - args.dimensions.left) / 2;
32614
+ const targetLeft = args.dimensions.left;
32615
+ const targetRight = args.dimensions.right;
32616
+ const targetWidth = args.dimensions.width;
32617
+ switch (args.horizontalAlign) {
32618
+ case 'center':
32619
+ result.left = `${targetHorizontalCenter}px`;
32620
+ result.translateX = '-50%';
32621
+ break;
32622
+ case 'left':
32623
+ result.left = `${targetLeft - offsetH}px`;
32624
+ result.translateX = `${targetWidth / 2}px`;
32625
+ break;
32626
+ case 'right':
32627
+ result.left = `${targetRight + offsetH}px`;
32628
+ result.translateX = `-${targetWidth / 2}px`;
32629
+ break;
32630
+ }
32631
+ switch (args.verticalPosition) {
32632
+ case 'bottom':
32633
+ result.top = `${args.dimensions.top + args.dimensions.height + window.scrollY}px`;
32634
+ result.bottom = 'unset';
32635
+ break;
32636
+ case 'top':
32637
+ result.top = `${args.dimensions.top + window.scrollY}px`;
32638
+ result.bottom = 'unset';
32639
+ result.translateY = '-100%';
32640
+ break;
32641
+ }
32642
+ return result;
32643
+ }, []);
32644
+ return {
32645
+ calculatePosition
32646
+ };
32647
+ };
32648
+
32599
32649
  const TailIcon = props => {
32600
32650
  const tailClasses = clsx$1('absolute fill-background-uiBackgroundTooltip', {
32601
32651
  'rotate-180': props.verticalPosition === 'bottom',
@@ -32637,6 +32687,54 @@ const TailIcon = props => {
32637
32687
  }
32638
32688
  };
32639
32689
 
32690
+ const TooltipContent = ({
32691
+ content,
32692
+ horizontalAlign,
32693
+ verticalPosition,
32694
+ size,
32695
+ tooltipPosition,
32696
+ maxWidth,
32697
+ isPortal
32698
+ }) => {
32699
+ const tooltipWrapperClasses = clsx$1('absolute z-tooltip m-auto flex', {
32700
+ 'top-0': !isPortal && verticalPosition === 'top',
32701
+ 'bottom-0': !isPortal && verticalPosition === 'bottom',
32702
+ 'justify-start': horizontalAlign === 'left',
32703
+ 'justify-center': horizontalAlign === 'center',
32704
+ 'justify-end': horizontalAlign === 'right',
32705
+ 'w-[24px]': size === 'small',
32706
+ 'w-[46px]': size !== 'small'
32707
+ });
32708
+ const tooltipBodyClasses = clsx$1('absolute z-tooltip inline-block w-max rounded bg-background-uiBackgroundTooltip text-text-textOnColor', {
32709
+ 'typography-body3regular': size === 'small',
32710
+ 'typography-body2regular': size === 'medium',
32711
+ 'px-2 pb-1 pt-1.5': size === 'small',
32712
+ 'px-4 py-3': size === 'medium',
32713
+ 'bottom-2': verticalPosition !== 'bottom' && size === 'small',
32714
+ 'bottom-3': verticalPosition !== 'bottom' && size === 'medium',
32715
+ 'top-2': verticalPosition === 'bottom' && size === 'small',
32716
+ 'top-3': verticalPosition === 'bottom' && size === 'medium'
32717
+ });
32718
+ const tooltipWrapperStyle = isPortal ? _extends({
32719
+ transform: `translate(${tooltipPosition.translateX}, ${tooltipPosition.translateY})`
32720
+ }, tooltipPosition) : {};
32721
+ return /*#__PURE__*/jsx("div", {
32722
+ className: tooltipWrapperClasses,
32723
+ style: tooltipWrapperStyle,
32724
+ children: /*#__PURE__*/jsxs("div", {
32725
+ className: tooltipBodyClasses,
32726
+ style: {
32727
+ maxWidth
32728
+ },
32729
+ children: [content, /*#__PURE__*/jsx(TailIcon, {
32730
+ size: size,
32731
+ verticalPosition: verticalPosition,
32732
+ horizontalAlign: horizontalAlign
32733
+ })]
32734
+ })
32735
+ });
32736
+ };
32737
+
32640
32738
  function Tooltip({
32641
32739
  children,
32642
32740
  content,
@@ -32644,9 +32742,22 @@ function Tooltip({
32644
32742
  maxWidth,
32645
32743
  verticalPosition = 'bottom',
32646
32744
  horizontalAlign = 'center',
32647
- isDisabledHover = false
32745
+ isDisabledHover = false,
32746
+ portalTargetRef
32648
32747
  }) {
32748
+ const {
32749
+ calculatePosition
32750
+ } = useTooltip();
32649
32751
  const [isVisible, setIsVisible] = useState(false);
32752
+ const [tooltipPosition, setTooltipPosition] = useState({
32753
+ maxWidth: 'none',
32754
+ width: 'auto',
32755
+ left: '0px',
32756
+ top: '0px',
32757
+ bottom: '0px',
32758
+ translateX: '0',
32759
+ translateY: '0'
32760
+ });
32650
32761
  const targetRef = useRef(null);
32651
32762
  const handleMouseOverWrapper = useCallback(() => {
32652
32763
  if (isDisabledHover) {
@@ -32657,44 +32768,40 @@ function Tooltip({
32657
32768
  const handleMouseOutWrapper = useCallback(() => {
32658
32769
  setIsVisible(false);
32659
32770
  }, []);
32660
- const tooltipWrapClasses = clsx$1('absolute inset-x-0 z-tooltip m-auto flex', {
32661
- 'top-0': verticalPosition !== 'bottom',
32662
- 'bottom-0': verticalPosition === 'bottom',
32663
- 'justify-start': horizontalAlign === 'left',
32664
- 'justify-center': horizontalAlign === 'center',
32665
- 'justify-end': horizontalAlign === 'right',
32666
- 'w-[24px]': size === 'small',
32667
- 'w-[46px]': size !== 'small'
32668
- });
32669
- const tooltipBodyClasses = clsx$1('absolute z-tooltip inline-block w-max rounded bg-background-uiBackgroundTooltip text-text-textOnColor', {
32670
- 'typography-body3regular': size === 'small',
32671
- 'typography-body2regular': size === 'medium',
32672
- 'px-2 pb-1 pt-1.5': size === 'small',
32673
- 'px-4 py-3': size === 'medium',
32674
- 'bottom-2': verticalPosition !== 'bottom' && size === 'small',
32675
- 'bottom-3': verticalPosition !== 'bottom' && size === 'medium',
32676
- 'top-2': verticalPosition === 'bottom' && size === 'small',
32677
- 'top-3': verticalPosition === 'bottom' && size === 'medium'
32678
- });
32771
+ useEffect(() => {
32772
+ var _targetRef$current;
32773
+ if (targetRef.current === null) return;
32774
+ const dimensions = (_targetRef$current = targetRef.current) == null ? void 0 : _targetRef$current.getBoundingClientRect();
32775
+ const position = calculatePosition({
32776
+ dimensions,
32777
+ maxWidth,
32778
+ verticalPosition,
32779
+ horizontalAlign,
32780
+ tooltipSize: size
32781
+ });
32782
+ setTooltipPosition(position);
32783
+ }, [calculatePosition, horizontalAlign, maxWidth, size, verticalPosition]);
32679
32784
  return /*#__PURE__*/jsxs("div", {
32680
32785
  ref: targetRef,
32681
32786
  className: "relative flex items-center justify-center",
32682
32787
  onMouseOver: handleMouseOverWrapper,
32683
32788
  onMouseLeave: handleMouseOutWrapper,
32684
- children: [children, isVisible && /*#__PURE__*/jsx("div", {
32685
- className: tooltipWrapClasses,
32686
- children: /*#__PURE__*/jsxs("div", {
32687
- className: tooltipBodyClasses,
32688
- style: {
32689
- maxWidth
32690
- },
32691
- children: [content, /*#__PURE__*/jsx(TailIcon, {
32692
- size: size,
32693
- verticalPosition: verticalPosition,
32694
- horizontalAlign: horizontalAlign
32695
- })]
32696
- })
32697
- })]
32789
+ children: [children, isVisible && ((portalTargetRef == null ? void 0 : portalTargetRef.current) == null ? /*#__PURE__*/jsx(TooltipContent, {
32790
+ content: content,
32791
+ size: size,
32792
+ maxWidth: maxWidth,
32793
+ verticalPosition: verticalPosition,
32794
+ horizontalAlign: horizontalAlign,
32795
+ tooltipPosition: tooltipPosition
32796
+ }) : ( /*#__PURE__*/reactDom.createPortal( /*#__PURE__*/jsx(TooltipContent, {
32797
+ isPortal: true,
32798
+ content: content,
32799
+ size: size,
32800
+ maxWidth: maxWidth,
32801
+ verticalPosition: verticalPosition,
32802
+ horizontalAlign: horizontalAlign,
32803
+ tooltipPosition: tooltipPosition
32804
+ }), (portalTargetRef == null ? void 0 : portalTargetRef.current) != null ? portalTargetRef.current : document.body)))]
32698
32805
  });
32699
32806
  }
32700
32807