Skip to content

Commit 46a64e3

Browse files
gabrieljablonskidanielbarion
authored andcommitted
chore: remove deprecated tooltip provider
1 parent 354ae26 commit 46a64e3

File tree

8 files changed

+11
-230
lines changed

8 files changed

+11
-230
lines changed

jest.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ export default {
2525
// dev stuff
2626
'!src/*',
2727
'!src/**/*.d.ts',
28-
// deprecated
29-
'!src/components/TooltipProvider/*',
3028
],
3129

3230
// The directory where Jest should output its coverage files

src/components/Tooltip/Tooltip.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
cssTimeToMs,
1111
} from 'utils'
1212
import type { IComputedPosition } from 'utils'
13-
import { useTooltip } from 'components/TooltipProvider'
1413
import coreStyles from './core-styles.module.css'
1514
import styles from './styles.module.css'
1615
import type {
@@ -85,10 +84,6 @@ const Tooltip = ({
8584
)
8685
const wasShowing = useRef(false)
8786
const lastFloatPosition = useRef<IPosition | null>(null)
88-
/**
89-
* @todo Remove this in a future version (provider/wrapper method is deprecated)
90-
*/
91-
const { anchorRefs, setActiveAnchor: setProviderActiveAnchor } = useTooltip(id)
9287
const hoveringTooltip = useRef(false)
9388
const [anchorsBySelect, setAnchorsBySelect] = useState<HTMLElement[]>([])
9489
const mounted = useRef(false)
@@ -292,7 +287,6 @@ const Tooltip = ({
292287
* at the same time the tooltip gets triggered
293288
*/
294289
setActiveAnchor(null)
295-
setProviderActiveAnchor({ current: null })
296290
return
297291
}
298292
if (delayShow) {
@@ -301,7 +295,6 @@ const Tooltip = ({
301295
handleShow(true)
302296
}
303297
setActiveAnchor(target)
304-
setProviderActiveAnchor({ current: target })
305298

306299
if (tooltipHideDelayTimerRef.current) {
307300
clearTimeout(tooltipHideDelayTimerRef.current)
@@ -463,15 +456,15 @@ const Tooltip = ({
463456
])
464457

465458
useEffect(() => {
466-
const elementRefs = new Set(anchorRefs)
459+
const elementRefs = new Set<HTMLElement>()
467460

468461
anchorsBySelect.forEach((anchor) => {
469-
elementRefs.add({ current: anchor })
462+
elementRefs.add(anchor)
470463
})
471464

472465
const anchorById = document.querySelector<HTMLElement>(`[id='${anchorId}']`)
473466
if (anchorById) {
474-
elementRefs.add({ current: anchorById })
467+
elementRefs.add(anchorById)
475468
}
476469

477470
const handleScrollResize = () => {
@@ -593,7 +586,7 @@ const Tooltip = ({
593586

594587
enabledEvents.forEach(({ event, listener }) => {
595588
elementRefs.forEach((ref) => {
596-
ref.current?.addEventListener(event, listener)
589+
ref.addEventListener(event, listener)
597590
})
598591
})
599592

@@ -620,7 +613,7 @@ const Tooltip = ({
620613
}
621614
enabledEvents.forEach(({ event, listener }) => {
622615
elementRefs.forEach((ref) => {
623-
ref.current?.removeEventListener(event, listener)
616+
ref.removeEventListener(event, listener)
624617
})
625618
})
626619
}
@@ -632,7 +625,6 @@ const Tooltip = ({
632625
activeAnchor,
633626
updateTooltipPosition,
634627
rendered,
635-
anchorRefs,
636628
anchorsBySelect,
637629
// the effect uses the `actual*Events` objects, but this should work
638630
openEvents,

src/components/TooltipController/TooltipController.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import type {
1111
ChildrenType,
1212
TooltipRefProps,
1313
} from 'components/Tooltip/TooltipTypes'
14-
import { useTooltip } from 'components/TooltipProvider'
1514
import { cssSupports } from 'utils'
1615
import clsx from 'clsx'
1716
import type { ITooltipController } from './TooltipControllerTypes'
@@ -77,10 +76,6 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
7776
const [tooltipClassName, setTooltipClassName] = useState<string | null>(null)
7877
const [activeAnchor, setActiveAnchor] = useState<HTMLElement | null>(null)
7978
const styleInjectionRef = useRef(disableStyleInjection)
80-
/**
81-
* @todo Remove this in a future version (provider/wrapper method is deprecated)
82-
*/
83-
const { anchorRefs, activeAnchor: providerActiveAnchor } = useTooltip(id)
8479

8580
const getDataAttributesFromAnchorElement = (elementReference: HTMLElement) => {
8681
const dataAttributes = elementReference?.getAttributeNames().reduce((acc, name) => {
@@ -206,7 +201,7 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
206201
}, [])
207202

208203
useEffect(() => {
209-
const elementRefs = new Set(anchorRefs)
204+
const elementRefs = new Set<HTMLElement>()
210205

211206
let selector = anchorSelect
212207
if (!selector && id) {
@@ -216,7 +211,7 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
216211
try {
217212
const anchorsBySelect = document.querySelectorAll<HTMLElement>(selector)
218213
anchorsBySelect.forEach((anchor) => {
219-
elementRefs.add({ current: anchor })
214+
elementRefs.add(anchor)
220215
})
221216
} catch {
222217
/* c8 ignore start */
@@ -230,14 +225,14 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
230225

231226
const anchorById = document.querySelector<HTMLElement>(`[id='${anchorId}']`)
232227
if (anchorById) {
233-
elementRefs.add({ current: anchorById })
228+
elementRefs.add(anchorById)
234229
}
235230

236231
if (!elementRefs.size) {
237232
return () => null
238233
}
239234

240-
const anchorElement = activeAnchor ?? anchorById ?? providerActiveAnchor.current
235+
const anchorElement = activeAnchor ?? anchorById
241236

242237
const observerCallback: MutationCallback = (mutationList) => {
243238
mutationList.forEach((mutation) => {
@@ -272,7 +267,7 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
272267
// Remove the observer when the tooltip is destroyed
273268
observer.disconnect()
274269
}
275-
}, [anchorRefs, providerActiveAnchor, activeAnchor, anchorId, anchorSelect])
270+
}, [activeAnchor, anchorId, anchorSelect])
276271

277272
useEffect(() => {
278273
/* c8 ignore start */
@@ -358,7 +353,7 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
358353
afterShow,
359354
afterHide,
360355
activeAnchor,
361-
setActiveAnchor: (anchor: HTMLElement | null) => setActiveAnchor(anchor),
356+
setActiveAnchor,
362357
role,
363358
}
364359

src/components/TooltipProvider/TooltipProvider.tsx

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/components/TooltipProvider/TooltipProviderTypes.d.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/components/TooltipProvider/TooltipWrapper.tsx

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/components/TooltipProvider/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type {
1515
TooltipRefProps,
1616
} from './components/Tooltip/TooltipTypes'
1717
import type { ITooltipController } from './components/TooltipController/TooltipControllerTypes'
18-
import type { ITooltipWrapper } from './components/TooltipProvider/TooltipProviderTypes'
1918

2019
// those content will be replaced in build time with the `react-tooltip.css` builded content
2120
const TooltipCoreStyles = 'react-tooltip-core-css-placeholder'
@@ -35,7 +34,6 @@ if (typeof window !== 'undefined') {
3534
}
3635

3736
export { TooltipController as Tooltip } from './components/TooltipController'
38-
export { TooltipProvider, TooltipWrapper } from './components/TooltipProvider'
3937
export type {
4038
ChildrenType,
4139
DataAttribute,
@@ -45,7 +43,6 @@ export type {
4543
VariantType,
4644
WrapperType,
4745
ITooltipController as ITooltip,
48-
ITooltipWrapper,
4946
IPosition,
5047
Middleware,
5148
TooltipRefProps,

0 commit comments

Comments
 (0)