Skip to content

Commit f028426

Browse files
committed
chore: add example into app.tsx about position feature
1 parent eed1200 commit f028426

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

src/App.tsx

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
/* eslint-disable jsx-a11y/no-static-element-interactions */
2+
/* eslint-disable jsx-a11y/click-events-have-key-events */
13
import { TooltipController as Tooltip } from 'components/TooltipController'
24
import { TooltipProvider, TooltipWrapper } from 'components/TooltipProvider'
5+
import { IPosition } from 'components/Tooltip/TooltipTypes.d'
36
import { useState } from 'react'
47
import styles from './styles.module.css'
58

@@ -39,6 +42,30 @@ function WithProviderMultiple() {
3942
function App() {
4043
const [anchorId, setAnchorId] = useState('button')
4144
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+
}
4269

4370
return (
4471
<main className={styles['main']}>
@@ -112,12 +139,33 @@ function App() {
112139
<TooltipProvider>
113140
<WithProviderMultiple />
114141
</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+
/>
116164
<Tooltip
117165
anchorId="freeTooltipAnchor"
118166
content="This is a free tooltip"
119-
type="free"
120167
events={['click']}
168+
position={position}
121169
/>
122170
</main>
123171
)

0 commit comments

Comments
 (0)