UNPKG

@braineet/ui

Version:

Braineet design system

44 lines (43 loc) 2.09 kB
var _excluded = ["children", "content", "disabled", "placement", "timeout", "options"]; function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } 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 } from "react/jsx-runtime"; import { Fragment as _Fragment } from "react/jsx-runtime"; import { 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 = {};