index.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. noArrow?: boolean
  17. }
  18. const Tooltip: FC<TooltipProps> = ({
  19. selector,
  20. content,
  21. disabled,
  22. position = 'top',
  23. children,
  24. htmlContent,
  25. className,
  26. clickable,
  27. noArrow,
  28. }) => {
  29. return (
  30. <div className='tooltip-container'>
  31. {React.cloneElement(children as React.ReactElement, {
  32. 'data-tooltip-id': selector,
  33. })
  34. }
  35. <ReactTooltip
  36. id={selector}
  37. content={content}
  38. className={classNames('!z-[999] !bg-white !text-xs !font-normal !text-gray-700 !shadow-lg !opacity-100', className)}
  39. place={position}
  40. clickable={clickable}
  41. isOpen={disabled ? false : undefined}
  42. noArrow={noArrow}
  43. >
  44. {htmlContent && htmlContent}
  45. </ReactTooltip>
  46. </div>
  47. )
  48. }
  49. export default Tooltip