UNPKG

@braineet/ui

Version:

Braineet design system

42 lines (41 loc) 1.85 kB
var _excluded = ["children", "content", "disabled", "placement", "timeout", "options"]; function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } import React from 'react'; import { useTooltipAnchor } from 'ariakit/tooltip'; import { useTooltip } from './tooltip-state'; import { TooltipPopover } from './TooltipPopover'; /** * The `Tooltip` component. */ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; export var Tooltip = /*#__PURE__*/React.forwardRef(function (_ref, ref) { var children = _ref.children, content = _ref.content, disabled = _ref.disabled, placement = _ref.placement, timeout = _ref.timeout, _ref$options = _ref.options, options = _ref$options === void 0 ? {} : _ref$options, restProps = _objectWithoutPropertiesLoose(_ref, _excluded); var tooltip = useTooltip(_extends({ timeout: timeout, placement: placement }, options)); var anchorProps = useTooltipAnchor(_extends({ state: tooltip }, children == null ? void 0 : children.props, restProps)); if (disabled) { return children; } return /*#__PURE__*/_jsxs(_Fragment, { children: [/*#__PURE__*/React.cloneElement(children, _extends({}, anchorProps, { ref: ref })), tooltip.mounted && /*#__PURE__*/_jsx(TooltipPopover, { className: "tooltip-content", state: tooltip, children: content })] }); }); Tooltip.defaultProps = {};