UNPKG

1.67 kBJavaScriptView Raw
1"use client";
2
3import classNames from 'classnames';
4import * as React from 'react';
5import { useBootstrapPrefix, useIsRTL } from './ThemeProvider';
6import { getOverlayDirection } from './helpers';
7import getInitialPopperStyles from './getInitialPopperStyles';
8import { jsx as _jsx } from "react/jsx-runtime";
9import { jsxs as _jsxs } from "react/jsx-runtime";
10const Tooltip = /*#__PURE__*/React.forwardRef(({
11 bsPrefix,
12 placement = 'right',
13 className,
14 style,
15 children,
16 arrowProps,
17 hasDoneInitialMeasure,
18 popper,
19 show,
20 ...props
21}, ref) => {
22 bsPrefix = useBootstrapPrefix(bsPrefix, 'tooltip');
23 const isRTL = useIsRTL();
24 const [primaryPlacement] = (placement == null ? void 0 : placement.split('-')) || [];
25 const bsDirection = getOverlayDirection(primaryPlacement, isRTL);
26 let computedStyle = style;
27 if (show && !hasDoneInitialMeasure) {
28 computedStyle = {
29 ...style,
30 ...getInitialPopperStyles(popper == null ? void 0 : popper.strategy)
31 };
32 }
33 return /*#__PURE__*/_jsxs("div", {
34 ref: ref,
35 style: computedStyle,
36 role: "tooltip",
37 "x-placement": primaryPlacement,
38 className: classNames(className, bsPrefix, `bs-tooltip-${bsDirection}`),
39 ...props,
40 children: [/*#__PURE__*/_jsx("div", {
41 className: "tooltip-arrow",
42 ...arrowProps
43 }), /*#__PURE__*/_jsx("div", {
44 className: `${bsPrefix}-inner`,
45 children: children
46 })]
47 });
48});
49Tooltip.displayName = 'Tooltip';
50export default Object.assign(Tooltip, {
51 // Default tooltip offset.
52 // https://github.com/twbs/bootstrap/blob/beca2a6c7f6bc88b6449339fc76edcda832c59e5/js/src/tooltip.js#L65
53 TOOLTIP_OFFSET: [0, 6]
54});
\No newline at end of file