mango-ui-v3/components/Tooltip.tsx

51 lines
1.1 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
2021-04-16 11:16:31 -07:00
}
const Tooltip = ({
children,
content,
className,
placement = 'top',
}: 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
content={
<div
className={`rounded p-3 text-xs bg-th-bkg-3 leading-5 shadow-md text-th-fgd-3 outline-none focus:outline-none ${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