📄 Tooltip-B8gZJWmn.js
/home/palash/git/site/node_modules/react-activity-calendar/build/chunks/Tooltip-B8gZJWmn.js
Language: js • Lines: 76
'use client';
import { useState, useRef, cloneElement } from 'react';
import { useFloating, autoUpdate, flip, offset, shift, arrow, useHover, useDismiss, useRole, useInteractions, useTransitionStyles, FloatingPortal, FloatingArrow } from '@floating-ui/react';
import { g as getClassName } from './index-CLOTiFb2.js';
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import 'date-fns';

function Tooltip({
  children,
  text,
  colorScheme,
  placement,
  offset: offsetProp = 4,
  transitionStyles: transitionStylesProp,
  hoverRestMs = 150,
  withArrow = false
}) {
  const [isOpen, setIsOpen] = useState(false);
  const arrowRef = useRef(null);
  const {
    context,
    refs,
    floatingStyles
  } = useFloating({
    open: isOpen,
    onOpenChange: setIsOpen,
    placement,
    middleware: [flip(), offset(offsetProp), shift({
      padding: 8
    }), withArrow ? arrow({
      element: arrowRef
    }) : null // eslint-disable-line react-hooks/refs
    ],
    whileElementsMounted: autoUpdate
  });
  const hover = useHover(context, {
    restMs: hoverRestMs
  });
  const dismiss = useDismiss(context);
  const role = useRole(context, {
    role: 'tooltip'
  });
  const {
    getReferenceProps,
    getFloatingProps
  } = useInteractions([hover, dismiss, role]);
  const {
    isMounted,
    styles: transitionStyles
  } = useTransitionStyles(context, transitionStylesProp);
  return /*#__PURE__*/jsxs(Fragment, {
    children: [/*#__PURE__*/cloneElement(children, {
      ref: refs.setReference,
      ...getReferenceProps()
    }), isMounted && /*#__PURE__*/jsx(FloatingPortal, {
      children: /*#__PURE__*/jsxs("div", {
        ref: refs.setFloating,
        className: getClassName('tooltip'),
        style: {
          ...floatingStyles,
          ...transitionStyles
        },
        "data-color-scheme": colorScheme,
        ...getFloatingProps(),
        children: [text, withArrow && /*#__PURE__*/jsx(FloatingArrow, {
          ref: arrowRef,
          context: context,
          className: getClassName('tooltip-arrow')
        })]
      })
    })]
  });
}

export { Tooltip };
//# sourceMappingURL=Tooltip-B8gZJWmn.js.map