mango-ui-v3/components/Tooltip.tsx

54 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-08-16 10:00:43 -07:00
import React, { ReactNode } from 'react'
2021-04-16 11:16:31 -07:00
import Tippy from '@tippyjs/react'
import 'tippy.js/animations/scale.css'
type TooltipProps = {
content: ReactNode
placement?: any
className?: string
2021-08-16 10:00:43 -07:00
children?: ReactNode
delay?: number
2021-04-16 11:16:31 -07:00
}
const Tooltip = ({
children,
content,
className,
placement = 'top',
delay = 0,
}: TooltipProps) => {
2021-04-16 11:16:31 -07:00
return (
<Tippy
animation="scale"
placement={placement}
2021-04-16 12:07:59 -07:00
appendTo={() => document.body}
maxWidth="20rem"
2021-04-16 11:16:31 -07:00
interactive
delay={delay}
2021-04-16 11:16:31 -07:00
content={
<div
2021-10-18 13:38:03 -07:00
className={`rounded p-2.5 text-xs bg-th-bkg-3 leading-4 shadow-md text-th-fgd-3 outline-none focus:outline-none border border-th-bkg-4 ${className}`}
>
2021-04-16 11:16:31 -07:00
{content}
</div>
}
>
<div className="outline-none focus:outline-none">{children}</div>
2021-04-16 11:16:31 -07:00
</Tippy>
)
}
2021-08-16 14:35:16 -07:00
const Content = ({ className = '', children }) => {
2021-08-16 10:00:43 -07:00
return (
<div
2021-08-16 14:35:16 -07:00
className={`inline-block cursor-help border-b border-th-fgd-3 border-dashed border-opacity-20 default-transition hover:border-th-bkg-2 ${className}`}
2021-08-16 10:00:43 -07:00
>
{children}
</div>
)
}
Tooltip.Content = Content
2021-04-16 11:16:31 -07:00
export default Tooltip