()
| 5 | import styles from './styles.module.css' |
| 6 | |
| 7 | function App() { |
| 8 | const [anchorId, setAnchorId] = useState('button') |
| 9 | const [isDarkOpen, setIsDarkOpen] = useState(false) |
| 10 | const [position, setPosition] = useState<IPosition>({ x: 0, y: 0 }) |
| 11 | const [toggle, setToggle] = useState(false) |
| 12 | const tooltipRef = useRef<TooltipRefProps>(null) |
| 13 | |
| 14 | const handlePositionClick: React.MouseEventHandler<HTMLDivElement> = (event) => { |
| 15 | const x = event.clientX |
| 16 | const y = event.clientY |
| 17 | setPosition({ x, y }) |
| 18 | } |
| 19 | |
| 20 | const handleButtonClick: React.MouseEventHandler<HTMLButtonElement> = (event) => { |
| 21 | const target = event.target as HTMLElement |
| 22 | setAnchorId(target.id) |
| 23 | } |
| 24 | |
| 25 | useEffect(() => { |
| 26 | const handleQ = (event: KeyboardEvent) => { |
| 27 | if (event.key === 'q') { |
| 28 | // q |
| 29 | tooltipRef.current?.close() |
| 30 | } |
| 31 | } |
| 32 | window.addEventListener('keydown', handleQ) |
| 33 | return () => { |
| 34 | window.removeEventListener('keydown', handleQ) |
| 35 | } |
| 36 | }, []) |
| 37 | |
| 38 | return ( |
| 39 | <main className={styles['main']}> |
| 40 | <button |
| 41 | id="button" |
| 42 | aria-describedby="tooltip" |
| 43 | data-tooltip-content="My big tooltip content 1" |
| 44 | onClick={handleButtonClick} |
| 45 | > |
| 46 | My button |
| 47 | </button> |
| 48 | <Tooltip |
| 49 | id="button1" |
| 50 | place="bottom" |
| 51 | anchorSelect={`#${anchorId}`} |
| 52 | isOpen={isDarkOpen} |
| 53 | setIsOpen={setIsDarkOpen} |
| 54 | /> |
| 55 | <Tooltip |
| 56 | id="button2" |
| 57 | place="top" |
| 58 | variant="success" |
| 59 | anchorSelect="#button2" |
| 60 | isOpen={isDarkOpen} |
| 61 | setIsOpen={setIsDarkOpen} |
| 62 | /> |
| 63 | <Tooltip |
| 64 | place="top" |
nothing calls this directly
no test coverage detected