index.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use client'
  2. import classNames from 'classnames'
  3. import type { FC } from 'react'
  4. import React from 'react'
  5. import { Tooltip as ReactTooltip } from 'react-tooltip' // fixed version to 5.8.3 https://github.com/ReactTooltip/react-tooltip/issues/972
  6. import 'react-tooltip/dist/react-tooltip.css'
  7. type TooltipProps = {
  8. selector: string
  9. content?: string
  10. disabled?: boolean
  11. htmlContent?: React.ReactNode
  12. className?: string // This should use !impornant to override the default styles eg: '!bg-white'
  13. position?: 'top' | 'right' | 'bottom' | 'left'
  14. clickable?: boolean
  15. children: React.ReactNode
  16. }
  17. const Tooltip: FC<TooltipProps> = ({
  18. selector,
  19. content,
  20. disabled,
  21. position = 'top',
  22. children,
  23. htmlContent,
  24. className,
  25. clickable,
  26. }) => {
  27. return (
  28. <div className='tooltip-container'>
  29. {React.cloneElement(children as React.ReactElement, {
  30. 'data-tooltip-id': selector,
  31. })
  32. }
  33. <ReactTooltip
  34. id={selector}
  35. content={content}
  36. className={classNames('!z-[999] !bg-white !text-xs !font-normal !text-gray-700 !shadow-lg !opacity-100', className)}
  37. place={position}
  38. clickable={clickable}
  39. isOpen={disabled ? false : undefined}
  40. >
  41. {htmlContent && htmlContent}
  42. </ReactTooltip>
  43. </div>
  44. )
  45. }
  46. export default Tooltip