| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import React from 'react' | 
					
						
							|  |  |  | import { Tooltip as ReactTooltip } from 'react-tooltip' // fixed version to 5.8.3 https://github.com/ReactTooltip/react-tooltip/issues/972
 | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import classNames from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import 'react-tooltip/dist/react-tooltip.css' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type TooltipProps = { | 
					
						
							|  |  |  |   selector: string | 
					
						
							|  |  |  |   content?: string | 
					
						
							|  |  |  |   disabled?: boolean | 
					
						
							|  |  |  |   htmlContent?: React.ReactNode | 
					
						
							|  |  |  |   className?: string // This should use !impornant to override the default styles eg: '!bg-white'
 | 
					
						
							|  |  |  |   position?: 'top' | 'right' | 'bottom' | 'left' | 
					
						
							|  |  |  |   clickable?: boolean | 
					
						
							|  |  |  |   children: React.ReactNode | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   noArrow?: boolean | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const Tooltip: FC<TooltipProps> = ({ | 
					
						
							|  |  |  |   selector, | 
					
						
							|  |  |  |   content, | 
					
						
							|  |  |  |   disabled, | 
					
						
							|  |  |  |   position = 'top', | 
					
						
							|  |  |  |   children, | 
					
						
							|  |  |  |   htmlContent, | 
					
						
							|  |  |  |   className, | 
					
						
							|  |  |  |   clickable, | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |   noArrow, | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | }) => { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className='tooltip-container'> | 
					
						
							|  |  |  |       {React.cloneElement(children as React.ReactElement, { | 
					
						
							|  |  |  |         'data-tooltip-id': selector, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       <ReactTooltip | 
					
						
							|  |  |  |         id={selector} | 
					
						
							|  |  |  |         content={content} | 
					
						
							| 
									
										
										
										
											2023-06-05 10:49:06 +08:00
										 |  |  |         className={classNames('!z-[999] !bg-white !text-xs !font-normal !text-gray-700 !shadow-lg !opacity-100', className)} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         place={position} | 
					
						
							|  |  |  |         clickable={clickable} | 
					
						
							|  |  |  |         isOpen={disabled ? false : undefined} | 
					
						
							| 
									
										
										
										
											2024-04-08 18:51:46 +08:00
										 |  |  |         noArrow={noArrow} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |       > | 
					
						
							|  |  |  |         {htmlContent && htmlContent} | 
					
						
							|  |  |  |       </ReactTooltip> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default Tooltip |