Skip to content

Commit 05a6c5e

Browse files
chore: remove deprecated events props and ChildrenType -> ReactNode
1 parent 97bbbbd commit 05a6c5e

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
@@ -32,7 +32,6 @@ const Tooltip = ({
3232
anchorSelect,
3333
place = 'top',
3434
offset = 10,
35-
events = ['hover'],
3635
openOnClick = false,
3736
positionStrategy = 'absolute',
3837
middlewares,
@@ -43,9 +42,6 @@ const Tooltip = ({
4342
hidden = false,
4443
noArrow = false,
4544
clickable = false,
46-
closeOnEsc = false,
47-
closeOnScroll = false,
48-
closeOnResize = false,
4945
openEvents,
5046
closeEvents,
5147
globalCloseEvents,
@@ -88,12 +84,8 @@ const Tooltip = ({
8884
const [anchorElements, setAnchorElements] = useState<HTMLElement[]>([])
8985
const mounted = useRef(false)
9086

91-
/**
92-
* @todo Update when deprecated stuff gets removed.
93-
*/
94-
const shouldOpenOnClick = openOnClick || events.includes('click')
9587
const hasClickEvent =
96-
shouldOpenOnClick || openEvents?.click || openEvents?.dblclick || openEvents?.mousedown
88+
openOnClick || openEvents?.click || openEvents?.dblclick || openEvents?.mousedown
9789
const actualOpenEvents: AnchorOpenEvents = openEvents
9890
? { ...openEvents }
9991
: {
@@ -104,7 +96,7 @@ const Tooltip = ({
10496
dblclick: false,
10597
mousedown: false,
10698
}
107-
if (!openEvents && shouldOpenOnClick) {
99+
if (!openEvents && openOnClick) {
108100
Object.assign(actualOpenEvents, {
109101
mouseenter: false,
110102
focus: false,
@@ -122,7 +114,7 @@ const Tooltip = ({
122114
dblclick: false,
123115
mouseup: false,
124116
}
125-
if (!closeEvents && shouldOpenOnClick) {
117+
if (!closeEvents && openOnClick) {
126118
Object.assign(actualCloseEvents, {
127119
mouseleave: false,
128120
blur: false,
@@ -132,9 +124,9 @@ const Tooltip = ({
132124
const actualGlobalCloseEvents: GlobalCloseEvents = globalCloseEvents
133125
? { ...globalCloseEvents }
134126
: {
135-
escape: closeOnEsc || false,
136-
scroll: closeOnScroll || false,
137-
resize: closeOnResize || false,
127+
escape: false,
128+
scroll: false,
129+
resize: false,
138130
clickOutsideAnchor: hasClickEvent || false,
139131
}
140132

@@ -618,7 +610,7 @@ const Tooltip = ({
618610
openEvents,
619611
closeEvents,
620612
globalCloseEvents,
621-
shouldOpenOnClick,
613+
hasClickEvent,
622614
delayShow,
623615
delayHide,
624616
])

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
*/
@@ -111,18 +106,14 @@ export interface ITooltip {
111106
forwardRef?: React.ForwardedRef<TooltipRefProps>
112107
className?: string
113108
classNameArrow?: string
114-
content?: ChildrenType
109+
content?: ReactNode
115110
contentWrapperRef?: RefObject<HTMLDivElement>
116111
place?: PlacesType
117112
offset?: number
118113
id?: string
119114
variant?: VariantType
120115
anchorSelect?: string
121116
wrapper: WrapperType
122-
/**
123-
* @deprecated Use `openOnClick` instead.
124-
*/
125-
events?: EventsType[]
126117
openOnClick?: boolean
127118
positionStrategy?: PositionStrategy
128119
middlewares?: Middleware[]
@@ -132,9 +123,6 @@ export interface ITooltip {
132123
hidden?: boolean
133124
noArrow?: boolean
134125
clickable?: boolean
135-
closeOnEsc?: boolean
136-
closeOnScroll?: boolean
137-
closeOnResize?: boolean
138126
openEvents?: AnchorOpenEvents
139127
closeEvents?: AnchorCloseEvents
140128
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)