|
| 1 | +/* eslint-disable jsx-a11y/no-static-element-interactions */ |
| 2 | +/* eslint-disable jsx-a11y/click-events-have-key-events */ |
1 | 3 | import { TooltipController as Tooltip } from 'components/TooltipController'
|
2 | 4 | import { TooltipProvider, TooltipWrapper } from 'components/TooltipProvider'
|
| 5 | +import { IPosition } from 'components/Tooltip/TooltipTypes.d' |
3 | 6 | import { useState } from 'react'
|
4 | 7 | import styles from './styles.module.css'
|
5 | 8 |
|
@@ -39,6 +42,30 @@ function WithProviderMultiple() {
|
39 | 42 | function App() {
|
40 | 43 | const [anchorId, setAnchorId] = useState('button')
|
41 | 44 | const [isDarkOpen, setIsDarkOpen] = useState(false)
|
| 45 | + const [position, setPosition] = useState<IPosition>({}) |
| 46 | + const [tooltipEffect, setTooltipEffect] = useState('float') |
| 47 | + |
| 48 | + const handlePositionClick = (event: MouseEvent) => { |
| 49 | + if (tooltipEffect === 'float') { |
| 50 | + return |
| 51 | + } |
| 52 | + |
| 53 | + const x = event.clientX |
| 54 | + const y = event.clientY |
| 55 | + |
| 56 | + setPosition({ x, y }) |
| 57 | + } |
| 58 | + |
| 59 | + const handleMouseMove = (event: MouseEvent) => { |
| 60 | + if (tooltipEffect !== 'float') { |
| 61 | + return |
| 62 | + } |
| 63 | + |
| 64 | + const x = event.clientX |
| 65 | + const y = event.clientY |
| 66 | + |
| 67 | + setPosition({ x, y }) |
| 68 | + } |
42 | 69 |
|
43 | 70 | return (
|
44 | 71 | <main className={styles['main']}>
|
@@ -112,12 +139,33 @@ function App() {
|
112 | 139 | <TooltipProvider>
|
113 | 140 | <WithProviderMultiple />
|
114 | 141 | </TooltipProvider>
|
115 |
| - <div id="freeTooltipAnchor" className={styles.freeAnchor} /> |
| 142 | + |
| 143 | + <button |
| 144 | + onClick={() => { |
| 145 | + if (tooltipEffect === 'float') { |
| 146 | + setTooltipEffect('coordinates') |
| 147 | + } else if (tooltipEffect === 'coordinates') { |
| 148 | + setTooltipEffect('float') |
| 149 | + } |
| 150 | + }} |
| 151 | + > |
| 152 | + Switch tooltip effect |
| 153 | + </button> |
| 154 | + <div |
| 155 | + id="freeTooltipAnchor" |
| 156 | + className={styles.freeAnchor} |
| 157 | + onClick={(event: any) => { |
| 158 | + handlePositionClick(event as MouseEvent) |
| 159 | + }} |
| 160 | + onMouseMove={(event: any) => { |
| 161 | + handleMouseMove(event as MouseEvent) |
| 162 | + }} |
| 163 | + /> |
116 | 164 | <Tooltip
|
117 | 165 | anchorId="freeTooltipAnchor"
|
118 | 166 | content="This is a free tooltip"
|
119 |
| - type="free" |
120 | 167 | events={['click']}
|
| 168 | + position={position} |
121 | 169 | />
|
122 | 170 | </main>
|
123 | 171 | )
|
|
0 commit comments