@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.esm.js CHANGED
@@ -32644,6 +32644,56 @@ function Toggle(_ref) {
32644
32644
  });
32645
32645
  }
32646
32646
 
32647
+ var useTooltip = function useTooltip() {
32648
+ var calculatePosition = useCallback(function (args) {
32649
+ var _args$maxWidth;
32650
+ var result = {
32651
+ maxWidth: 'none',
32652
+ width: 'auto',
32653
+ left: '0px',
32654
+ top: '0px',
32655
+ bottom: '0px',
32656
+ translateX: '0',
32657
+ translateY: '0'
32658
+ };
32659
+ result.maxWidth = (_args$maxWidth = args.maxWidth) != null ? _args$maxWidth : 'none';
32660
+ var offsetH = args.tooltipSize === 'small' ? 11 : 22;
32661
+ var targetHorizontalCenter = args.dimensions.right - (args.dimensions.right - args.dimensions.left) / 2;
32662
+ var targetLeft = args.dimensions.left;
32663
+ var targetRight = args.dimensions.right;
32664
+ var targetWidth = args.dimensions.width;
32665
+ switch (args.horizontalAlign) {
32666
+ case 'center':
32667
+ result.left = targetHorizontalCenter + "px";
32668
+ result.translateX = '-50%';
32669
+ break;
32670
+ case 'left':
32671
+ result.left = targetLeft - offsetH + "px";
32672
+ result.translateX = targetWidth / 2 + "px";
32673
+ break;
32674
+ case 'right':
32675
+ result.left = targetRight + offsetH + "px";
32676
+ result.translateX = "-" + targetWidth / 2 + "px";
32677
+ break;
32678
+ }
32679
+ switch (args.verticalPosition) {
32680
+ case 'bottom':
32681
+ result.top = args.dimensions.top + args.dimensions.height + window.scrollY + "px";
32682
+ result.bottom = 'unset';
32683
+ break;
32684
+ case 'top':
32685
+ result.top = args.dimensions.top + window.scrollY + "px";
32686
+ result.bottom = 'unset';
32687
+ result.translateY = '-100%';
32688
+ break;
32689
+ }
32690
+ return result;
32691
+ }, []);
32692
+ return {
32693
+ calculatePosition: calculatePosition
32694
+ };
32695
+ };
32696
+
32647
32697
  var TailIcon = function TailIcon(props) {
32648
32698
  var tailClasses = clsx$1('absolute fill-background-uiBackgroundTooltip', {
32649
32699
  'rotate-180': props.verticalPosition === 'bottom',
@@ -32685,6 +32735,53 @@ var TailIcon = function TailIcon(props) {
32685
32735
  }
32686
32736
  };
32687
32737
 
32738
+ var TooltipContent = function TooltipContent(_ref) {
32739
+ var content = _ref.content,
32740
+ horizontalAlign = _ref.horizontalAlign,
32741
+ verticalPosition = _ref.verticalPosition,
32742
+ size = _ref.size,
32743
+ tooltipPosition = _ref.tooltipPosition,
32744
+ maxWidth = _ref.maxWidth,
32745
+ isPortal = _ref.isPortal;
32746
+ var tooltipWrapperClasses = clsx$1('absolute z-tooltip m-auto flex', {
32747
+ 'top-0': !isPortal && verticalPosition === 'top',
32748
+ 'bottom-0': !isPortal && verticalPosition === 'bottom',
32749
+ 'justify-start': horizontalAlign === 'left',
32750
+ 'justify-center': horizontalAlign === 'center',
32751
+ 'justify-end': horizontalAlign === 'right',
32752
+ 'w-[24px]': size === 'small',
32753
+ 'w-[46px]': size !== 'small'
32754
+ });
32755
+ var tooltipBodyClasses = clsx$1('absolute z-tooltip inline-block w-max rounded bg-background-uiBackgroundTooltip text-text-textOnColor', {
32756
+ 'typography-body3regular': size === 'small',
32757
+ 'typography-body2regular': size === 'medium',
32758
+ 'px-2 pb-1 pt-1.5': size === 'small',
32759
+ 'px-4 py-3': size === 'medium',
32760
+ 'bottom-2': verticalPosition !== 'bottom' && size === 'small',
32761
+ 'bottom-3': verticalPosition !== 'bottom' && size === 'medium',
32762
+ 'top-2': verticalPosition === 'bottom' && size === 'small',
32763
+ 'top-3': verticalPosition === 'bottom' && size === 'medium'
32764
+ });
32765
+ var tooltipWrapperStyle = isPortal ? _extends({
32766
+ transform: "translate(" + tooltipPosition.translateX + ", " + tooltipPosition.translateY + ")"
32767
+ }, tooltipPosition) : {};
32768
+ return /*#__PURE__*/jsx("div", {
32769
+ className: tooltipWrapperClasses,
32770
+ style: tooltipWrapperStyle,
32771
+ children: /*#__PURE__*/jsxs("div", {
32772
+ className: tooltipBodyClasses,
32773
+ style: {
32774
+ maxWidth: maxWidth
32775
+ },
32776
+ children: [content, /*#__PURE__*/jsx(TailIcon, {
32777
+ size: size,
32778
+ verticalPosition: verticalPosition,
32779
+ horizontalAlign: horizontalAlign
32780
+ })]
32781
+ })
32782
+ });
32783
+ };
32784
+
32688
32785
  function Tooltip(_ref) {
32689
32786
  var children = _ref.children,
32690
32787
  content = _ref.content,
@@ -32696,10 +32793,24 @@ function Tooltip(_ref) {
32696
32793
  _ref$horizontalAlign = _ref.horizontalAlign,
32697
32794
  horizontalAlign = _ref$horizontalAlign === void 0 ? 'center' : _ref$horizontalAlign,
32698
32795
  _ref$isDisabledHover = _ref.isDisabledHover,
32699
- isDisabledHover = _ref$isDisabledHover === void 0 ? false : _ref$isDisabledHover;
32796
+ isDisabledHover = _ref$isDisabledHover === void 0 ? false : _ref$isDisabledHover,
32797
+ portalTargetRef = _ref.portalTargetRef;
32798
+ var _useTooltip = useTooltip(),
32799
+ calculatePosition = _useTooltip.calculatePosition;
32700
32800
  var _useState = useState(false),
32701
32801
  isVisible = _useState[0],
32702
32802
  setIsVisible = _useState[1];
32803
+ var _useState2 = useState({
32804
+ maxWidth: 'none',
32805
+ width: 'auto',
32806
+ left: '0px',
32807
+ top: '0px',
32808
+ bottom: '0px',
32809
+ translateX: '0',
32810
+ translateY: '0'
32811
+ }),
32812
+ tooltipPosition = _useState2[0],
32813
+ setTooltipPosition = _useState2[1];
32703
32814
  var targetRef = useRef(null);
32704
32815
  var handleMouseOverWrapper = useCallback(function () {
32705
32816
  if (isDisabledHover) {
@@ -32710,44 +32821,40 @@ function Tooltip(_ref) {
32710
32821
  var handleMouseOutWrapper = useCallback(function () {
32711
32822
  setIsVisible(false);
32712
32823
  }, []);
32713
- var tooltipWrapClasses = clsx$1('absolute inset-x-0 z-tooltip m-auto flex', {
32714
- 'top-0': verticalPosition !== 'bottom',
32715
- 'bottom-0': verticalPosition === 'bottom',
32716
- 'justify-start': horizontalAlign === 'left',
32717
- 'justify-center': horizontalAlign === 'center',
32718
- 'justify-end': horizontalAlign === 'right',
32719
- 'w-[24px]': size === 'small',
32720
- 'w-[46px]': size !== 'small'
32721
- });
32722
- var tooltipBodyClasses = clsx$1('absolute z-tooltip inline-block w-max rounded bg-background-uiBackgroundTooltip text-text-textOnColor', {
32723
- 'typography-body3regular': size === 'small',
32724
- 'typography-body2regular': size === 'medium',
32725
- 'px-2 pb-1 pt-1.5': size === 'small',
32726
- 'px-4 py-3': size === 'medium',
32727
- 'bottom-2': verticalPosition !== 'bottom' && size === 'small',
32728
- 'bottom-3': verticalPosition !== 'bottom' && size === 'medium',
32729
- 'top-2': verticalPosition === 'bottom' && size === 'small',
32730
- 'top-3': verticalPosition === 'bottom' && size === 'medium'
32731
- });
32824
+ useEffect(function () {
32825
+ var _targetRef$current;
32826
+ if (targetRef.current === null) return;
32827
+ var dimensions = (_targetRef$current = targetRef.current) == null ? void 0 : _targetRef$current.getBoundingClientRect();
32828
+ var position = calculatePosition({
32829
+ dimensions: dimensions,
32830
+ maxWidth: maxWidth,
32831
+ verticalPosition: verticalPosition,
32832
+ horizontalAlign: horizontalAlign,
32833
+ tooltipSize: size
32834
+ });
32835
+ setTooltipPosition(position);
32836
+ }, [calculatePosition, horizontalAlign, maxWidth, size, verticalPosition]);
32732
32837
  return /*#__PURE__*/jsxs("div", {
32733
32838
  ref: targetRef,
32734
32839
  className: "relative flex items-center justify-center",
32735
32840
  onMouseOver: handleMouseOverWrapper,
32736
32841
  onMouseLeave: handleMouseOutWrapper,
32737
- children: [children, isVisible && /*#__PURE__*/jsx("div", {
32738
- className: tooltipWrapClasses,
32739
- children: /*#__PURE__*/jsxs("div", {
32740
- className: tooltipBodyClasses,
32741
- style: {
32742
- maxWidth: maxWidth
32743
- },
32744
- children: [content, /*#__PURE__*/jsx(TailIcon, {
32745
- size: size,
32746
- verticalPosition: verticalPosition,
32747
- horizontalAlign: horizontalAlign
32748
- })]
32749
- })
32750
- })]
32842
+ children: [children, isVisible && ((portalTargetRef == null ? void 0 : portalTargetRef.current) == null ? /*#__PURE__*/jsx(TooltipContent, {
32843
+ content: content,
32844
+ size: size,
32845
+ maxWidth: maxWidth,
32846
+ verticalPosition: verticalPosition,
32847
+ horizontalAlign: horizontalAlign,
32848
+ tooltipPosition: tooltipPosition
32849
+ }) : ( /*#__PURE__*/reactDom.createPortal( /*#__PURE__*/jsx(TooltipContent, {
32850
+ isPortal: true,
32851
+ content: content,
32852
+ size: size,
32853
+ maxWidth: maxWidth,
32854
+ verticalPosition: verticalPosition,
32855
+ horizontalAlign: horizontalAlign,
32856
+ tooltipPosition: tooltipPosition
32857
+ }), (portalTargetRef == null ? void 0 : portalTargetRef.current) != null ? portalTargetRef.current : document.body)))]
32751
32858
  });
32752
32859
  }
32753
32860