UNPKG

general-assistant

Version:

General Assistant components

35 lines (34 loc) 1.99 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import classNames from 'classnames'; import React, { useContext } from 'react'; import { Tooltip as ReactTooltip } from 'react-tooltip'; import { RandomString } from '../_utils/tools'; import './index.css'; import { useStore } from 'zustand'; import StoreContext from '../_store/StoreContext'; const Tooltips = ({ title, children, variant, openOnClick = false, noArrow = false, offset, ...restProps }) => { const dataStore = useContext(StoreContext); const { tooltipDelay } = useStore(dataStore, (state) => ({ tooltipDelay: state.tooltipDelay })); const id = RandomString(); const _defClass = 'DS-GA-visible DS-GA-z-[1989] !DS-GA-rounded-md DS-GA-shadow-sm !DS-GA-text-xs'; const _bgClass = '!DS-GA-bg-text-deep-10'; const _textClass = '!DS-GA-text-text-reverse-9'; const { className = '' } = restProps; const myRestProps = Object.assign(restProps, { className: classNames(_defClass, (className.search('bg-') === -1 ? _bgClass + ' ' + className : className), (className.search('text-') === -1 ? _textClass + ' ' + className : className)), delayHide: tooltipDelay !== undefined ? tooltipDelay : restProps.delayHide, delayShow: tooltipDelay !== undefined ? tooltipDelay : restProps.delayShow }); const withTooltipId = React.Children.map(children, (child) => { if (React.isValidElement(child)) { return React.cloneElement(child, { 'data-tooltip-id': id }); } else if (typeof child === 'string') { return React.createElement('div', { className: 'o-text DS-GA-inline-block', 'data-tooltip-id': id }, child); } }); return (_jsxs(_Fragment, { children: [withTooltipId, _jsx(ReactTooltip, { id: id, clickable: true, openOnClick: openOnClick, variant: variant, opacity: 1, noArrow: noArrow, offset: offset, ...myRestProps, children: title })] })); }; export default Tooltips;