{"version":3,"file":"TourTooltip.mjs","names":["classes"],"sources":["../../../../src/components/Tour/TourTooltip/TourTooltip.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport { flip, offset, shift, useFloating } from '@floating-ui/react';\nimport { useMergedRef } from '@mantine/hooks';\nimport {\n  Box,\n  BoxProps,\n  CompoundStylesApiProps,\n  ElementProps,\n  factory,\n  Factory,\n  useDirection,\n  useProps,\n} from '../../../core';\nimport { getFloatingPosition, type FloatingPosition } from '../../../utils/Floating';\nimport { FocusTrap } from '../../FocusTrap';\nimport { Transition, type TransitionOverride } from '../../Transition';\nimport { pressAwareAutoUpdate } from '../press-aware-auto-update';\nimport { useTourContext } from '../Tour.context';\nimport { useTooltipAutoFocus } from '../use-tooltip-auto-focus';\nimport classes from '../Tour.module.css';\n\nexport type TourTooltipStylesNames = 'tooltip';\n\nexport interface TourTooltipProps\n  extends BoxProps, CompoundStylesApiProps<TourTooltipFactory>, ElementProps<'div'> {\n  /** Target element to position against */\n  targetElement?: HTMLElement | null;\n\n  /** Tooltip position @default 'bottom' */\n  position?: FloatingPosition;\n\n  /** Whether the tooltip is visible */\n  mounted?: boolean;\n\n  /** Transition props for the tooltip, merged with `transitionProps` of `Tour.Root` */\n  transitionProps?: TransitionOverride;\n}\n\nexport type TourTooltipFactory = Factory<{\n  props: TourTooltipProps;\n  ref: HTMLDivElement;\n  stylesNames: TourTooltipStylesNames;\n  compound: true;\n}>;\n\nconst defaultProps: Partial<TourTooltipProps> = {\n  position: 'bottom',\n};\n\nexport const TourTooltip = factory<TourTooltipFactory>((_props) => {\n  const props = useProps('TourTooltip', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    vars,\n    targetElement,\n    position,\n    mounted,\n    transitionProps,\n    children,\n    ref,\n    role,\n    tabIndex,\n    'aria-label': ariaLabel,\n    'aria-labelledby': ariaLabelledBy,\n    'aria-describedby': ariaDescribedBy,\n    ...others\n  } = props;\n\n  const ctx = useTourContext();\n  const { dir } = useDirection();\n  const { setTargetElement } = ctx;\n\n  useEffect(() => {\n    setTargetElement(targetElement ?? null);\n    return () => setTargetElement(null);\n  }, [targetElement, setTargetElement]);\n\n  const { refs, floatingStyles } = useFloating({\n    elements: { reference: targetElement },\n    placement: getFloatingPosition(dir, position!),\n    whileElementsMounted: pressAwareAutoUpdate,\n    middleware: [offset(12), flip(), shift({ padding: 8, crossAxis: true })],\n  });\n\n  const trapActive = !!mounted && ctx.withOverlay && !ctx.withOverlayInteraction;\n  const autoFocusRef = useTooltipAutoFocus({\n    autoFocus: !!mounted && !trapActive,\n    opened: !!mounted,\n    step: ctx.step,\n  });\n  const transition = { ...ctx.transitionProps, ...transitionProps };\n  const mergedRef = useMergedRef(refs.setFloating, autoFocusRef, ref);\n  const tooltipStyles = ctx.getStyles('tooltip', { className, classNames, style, styles });\n\n  return (\n    <Transition\n      mounted={!!mounted}\n      duration={transition.duration ?? 200}\n      transition={transition.transition ?? 'fade'}\n      timingFunction={transition.timingFunction}\n    >\n      {(transitionStyles) => (\n        <FocusTrap active={trapActive} innerRef={mergedRef}>\n          <Box\n            role={role ?? 'dialog'}\n            tabIndex={tabIndex ?? -1}\n            aria-labelledby={ariaLabelledBy ?? (ctx.titleMounted ? ctx.titleId : undefined)}\n            aria-label={\n              ariaLabel ??\n              (ctx.titleMounted ? undefined : ctx.labels.stepCounter(ctx.step + 1, ctx.stepsCount))\n            }\n            aria-describedby={ariaDescribedBy ?? (ctx.bodyMounted ? ctx.bodyId : undefined)}\n            {...tooltipStyles}\n            data-centered={!targetElement || undefined}\n            style={{\n              ...tooltipStyles.style,\n              ...(targetElement ? floatingStyles : {}),\n              ...transitionStyles,\n            }}\n            {...others}\n          >\n            {trapActive && <FocusTrap.InitialFocus />}\n            {children}\n          </Box>\n        </FocusTrap>\n      )}\n    </Transition>\n  );\n});\n\nTourTooltip.classes = classes;\nTourTooltip.displayName = '@mantine/core/TourTooltip';\n\nexport namespace TourTooltip {\n  export type Props = TourTooltipProps;\n}\n"],"mappings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