Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 516bc67

Browse files
gabrieljablonskidanielbarion
authored andcommittedApr 16, 2024
chore: remove deprecated events props and ChildrenType -> ReactNode
1 parent 956c253 commit 516bc67

File tree

6 files changed

+16
-77
lines changed

6 files changed

+16
-77
lines changed
 

‎src/App.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function App() {
157157
<Tooltip
158158
anchorSelect="#onClickAnchor"
159159
content={`This is an on click tooltip (x:${position.x},y:${position.y})`}
160-
events={['click']}
160+
openOnClick
161161
position={position}
162162
positionStrategy="fixed"
163163
/>
@@ -197,7 +197,7 @@ function App() {
197197

198198
<button id="buttonCallbacksClick">With click event</button>
199199
<Tooltip
200-
events={['click']}
200+
openOnClick
201201
place="bottom"
202202
anchorSelect="#buttonCallbacksClick"
203203
// eslint-disable-next-line no-console

‎src/components/Tooltip/Tooltip.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const Tooltip = ({
3131
anchorSelect,
3232
place = 'top',
3333
offset = 10,
34-
events = ['hover'],
3534
openOnClick = false,
3635
positionStrategy = 'absolute',
3736
middlewares,
@@ -42,9 +41,6 @@ const Tooltip = ({
4241
hidden = false,
4342
noArrow = false,
4443
clickable = false,
45-
closeOnEsc = false,
46-
closeOnScroll = false,
47-
closeOnResize = false,
4844
openEvents,
4945
closeEvents,
5046
globalCloseEvents,
@@ -87,12 +83,8 @@ const Tooltip = ({
8783
const [anchorElements, setAnchorElements] = useState<HTMLElement[]>([])
8884
const mounted = useRef(false)
8985

90-
/**
91-
* @todo Update when deprecated stuff gets removed.
92-
*/
93-
const shouldOpenOnClick = openOnClick || events.includes('click')
9486
const hasClickEvent =
95-
shouldOpenOnClick || openEvents?.click || openEvents?.dblclick || openEvents?.mousedown
87+
openOnClick || openEvents?.click || openEvents?.dblclick || openEvents?.mousedown
9688
const actualOpenEvents: AnchorOpenEvents = openEvents
9789
? { ...openEvents }
9890
: {
@@ -102,7 +94,7 @@ const Tooltip = ({
10294
dblclick: false,
10395
mousedown: false,
10496
}
105-
if (!openEvents && shouldOpenOnClick) {
97+
if (!openEvents && openOnClick) {
10698
Object.assign(actualOpenEvents, {
10799
mouseenter: false,
108100
focus: false,
@@ -118,7 +110,7 @@ const Tooltip = ({
118110
dblclick: false,
119111
mouseup: false,
120112
}
121-
if (!closeEvents && shouldOpenOnClick) {
113+
if (!closeEvents && openOnClick) {
122114
Object.assign(actualCloseEvents, {
123115
mouseleave: false,
124116
blur: false,
@@ -127,9 +119,9 @@ const Tooltip = ({
127119
const actualGlobalCloseEvents: GlobalCloseEvents = globalCloseEvents
128120
? { ...globalCloseEvents }
129121
: {
130-
escape: closeOnEsc || false,
131-
scroll: closeOnScroll || false,
132-
resize: closeOnResize || false,
122+
escape: false,
123+
scroll: false,
124+
resize: false,
133125
clickOutsideAnchor: hasClickEvent || false,
134126
}
135127

@@ -625,7 +617,7 @@ const Tooltip = ({
625617
openEvents,
626618
closeEvents,
627619
globalCloseEvents,
628-
shouldOpenOnClick,
620+
hasClickEvent,
629621
delayShow,
630622
delayHide,
631623
])

‎src/components/Tooltip/TooltipTypes.d.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ElementType, ReactNode, CSSProperties, RefObject } from 'react'
1+
import type { ElementType, CSSProperties, RefObject, ReactNode } from 'react'
22

33
export type PlacesType =
44
| 'top'
@@ -18,10 +18,6 @@ export type VariantType = 'dark' | 'light' | 'success' | 'warning' | 'error' | '
1818

1919
export type WrapperType = ElementType | 'div' | 'span'
2020

21-
export type ChildrenType = Element | ElementType | ReactNode
22-
23-
export type EventsType = 'hover' | 'click'
24-
2521
export type PositionStrategy = 'absolute' | 'fixed'
2622

2723
export type DataAttribute =
@@ -30,7 +26,6 @@ export type DataAttribute =
3026
| 'variant'
3127
| 'offset'
3228
| 'wrapper'
33-
| 'events'
3429
| 'position-strategy'
3530
| 'delay-show'
3631
| 'delay-hide'
@@ -53,7 +48,7 @@ export interface TooltipImperativeOpenOptions {
5348
anchorSelect?: string
5449
position?: IPosition
5550
place?: PlacesType
56-
content?: ChildrenType
51+
content?: ReactNode
5752
/**
5853
* @description Delay (in ms) before opening the tooltip.
5954
*/
@@ -109,18 +104,14 @@ export interface ITooltip {
109104
forwardRef?: React.ForwardedRef<TooltipRefProps>
110105
className?: string
111106
classNameArrow?: string
112-
content?: ChildrenType
107+
content?: ReactNode
113108
contentWrapperRef?: RefObject<HTMLDivElement>
114109
place?: PlacesType
115110
offset?: number
116111
id?: string
117112
variant?: VariantType
118113
anchorSelect?: string
119114
wrapper: WrapperType
120-
/**
121-
* @deprecated Use `openOnClick` instead.
122-
*/
123-
events?: EventsType[]
124115
openOnClick?: boolean
125116
positionStrategy?: PositionStrategy
126117
middlewares?: Middleware[]
@@ -130,9 +121,6 @@ export interface ITooltip {
130121
hidden?: boolean
131122
noArrow?: boolean
132123
clickable?: boolean
133-
closeOnEsc?: boolean
134-
closeOnScroll?: boolean
135-
closeOnResize?: boolean
136124
openEvents?: AnchorOpenEvents
137125
closeEvents?: AnchorCloseEvents
138126
globalCloseEvents?: GlobalCloseEvents

‎src/components/TooltipController/TooltipController.tsx

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import React, { useEffect, useRef, useState } from 'react'
22
import { Tooltip } from 'components/Tooltip'
33
import type {
4-
EventsType,
54
PositionStrategy,
65
PlacesType,
76
VariantType,
87
WrapperType,
98
DataAttribute,
109
ITooltip,
11-
ChildrenType,
1210
TooltipRefProps,
1311
} from 'components/Tooltip/TooltipTypes'
1412
import { cssSupports } from 'utils'
@@ -29,7 +27,6 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
2927
offset = 10,
3028
wrapper = 'div',
3129
children = null,
32-
events = ['hover'],
3330
openOnClick = false,
3431
positionStrategy = 'absolute',
3532
middlewares,
@@ -39,9 +36,6 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
3936
hidden = false,
4037
noArrow = false,
4138
clickable = false,
42-
closeOnEsc = false,
43-
closeOnScroll = false,
44-
closeOnResize = false,
4539
openEvents,
4640
closeEvents,
4741
globalCloseEvents,
@@ -70,7 +64,6 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
7064
const [tooltipFloat, setTooltipFloat] = useState(float)
7165
const [tooltipHidden, setTooltipHidden] = useState(hidden)
7266
const [tooltipWrapper, setTooltipWrapper] = useState<WrapperType>(wrapper)
73-
const [tooltipEvents, setTooltipEvents] = useState(events)
7467
const [tooltipPositionStrategy, setTooltipPositionStrategy] = useState(positionStrategy)
7568
const [tooltipClassName, setTooltipClassName] = useState<string | null>(null)
7669
const [activeAnchor, setActiveAnchor] = useState<HTMLElement | null>(null)
@@ -107,10 +100,6 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
107100
wrapper: (value) => {
108101
setTooltipWrapper((value as WrapperType) ?? wrapper)
109102
},
110-
events: (value) => {
111-
const parsed = value?.split(' ') as EventsType[]
112-
setTooltipEvents(parsed ?? events)
113-
},
114103
'position-strategy': (value) => {
115104
setTooltipPositionStrategy((value as PositionStrategy) ?? positionStrategy)
116105
},
@@ -263,7 +252,7 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
263252
* content priority: children < render or content < html
264253
* children should be lower priority so that it can be used as the "default" content
265254
*/
266-
let renderedContent: ChildrenType = children
255+
let renderedContent = children
267256
const contentWrapperRef = useRef<HTMLDivElement>(null)
268257
if (render) {
269258
const actualContent =
@@ -290,7 +279,6 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
290279
variant: tooltipVariant,
291280
offset: tooltipOffset,
292281
wrapper: tooltipWrapper,
293-
events: tooltipEvents,
294282
openOnClick,
295283
positionStrategy: tooltipPositionStrategy,
296284
middlewares,
@@ -300,9 +288,6 @@ const TooltipController = React.forwardRef<TooltipRefProps, ITooltipController>(
300288
hidden: tooltipHidden,
301289
noArrow,
302290
clickable,
303-
closeOnEsc,
304-
closeOnScroll,
305-
closeOnResize,
306291
openEvents,
307292
closeEvents,
308293
globalCloseEvents,

‎src/components/TooltipController/TooltipControllerTypes.d.ts

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import type { CSSProperties } from 'react'
1+
import type { CSSProperties, ReactNode } from 'react'
22

33
import type {
44
PlacesType,
55
VariantType,
66
WrapperType,
7-
ChildrenType,
8-
EventsType,
97
PositionStrategy,
108
IPosition,
119
Middleware,
@@ -18,18 +16,14 @@ export interface ITooltipController {
1816
className?: string
1917
classNameArrow?: string
2018
content?: string
21-
render?: (render: { content: string | null; activeAnchor: HTMLElement | null }) => ChildrenType
19+
render?: (render: { content: string | null; activeAnchor: HTMLElement | null }) => ReactNode
2220
place?: PlacesType
2321
offset?: number
2422
id?: string
2523
variant?: VariantType
2624
anchorSelect?: string
2725
wrapper?: WrapperType
28-
children?: ChildrenType
29-
/**
30-
* @deprecated Use `openOnClick` or `openEvents`/`closeEvents` instead.
31-
*/
32-
events?: EventsType[]
26+
children?: ReactNode
3327
openOnClick?: boolean
3428
positionStrategy?: PositionStrategy
3529
middlewares?: Middleware[]
@@ -39,18 +33,6 @@ export interface ITooltipController {
3933
hidden?: boolean
4034
noArrow?: boolean
4135
clickable?: boolean
42-
/**
43-
* @deprecated Use `globalCloseEvents={{ escape: true }}` instead.
44-
*/
45-
closeOnEsc?: boolean
46-
/**
47-
* @deprecated Use `globalCloseEvents={{ scroll: true }}` instead.
48-
*/
49-
closeOnScroll?: boolean
50-
/**
51-
* @deprecated Use `globalCloseEvents={{ resize: true }}` instead.
52-
*/
53-
closeOnResize?: boolean
5436
/**
5537
* @description The events to be listened on anchor elements to open the tooltip.
5638
*/
@@ -97,10 +79,6 @@ declare module 'react' {
9779
'data-tooltip-variant'?: VariantType
9880
'data-tooltip-offset'?: number
9981
'data-tooltip-wrapper'?: WrapperType
100-
/**
101-
* @deprecated Use `openOnClick` tooltip prop instead.
102-
*/
103-
'data-tooltip-events'?: EventsType[]
10482
'data-tooltip-position-strategy'?: PositionStrategy
10583
'data-tooltip-delay-show'?: number
10684
'data-tooltip-delay-hide'?: number

‎src/index.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import './tokens.css'
33
import { injectStyle } from 'utils/handle-style'
44

55
import type {
6-
ChildrenType,
76
DataAttribute,
8-
EventsType,
97
PlacesType,
108
PositionStrategy,
119
VariantType,
@@ -35,9 +33,7 @@ if (typeof window !== 'undefined') {
3533

3634
export { TooltipController as Tooltip } from './components/TooltipController'
3735
export type {
38-
ChildrenType,
3936
DataAttribute,
40-
EventsType,
4137
PlacesType,
4238
PositionStrategy,
4339
VariantType,

0 commit comments

Comments
 (0)
Please sign in to comment.