Skip to content

Commit c011a10

Browse files
OupslaGabriel Jablonski
authored andcommitted
feat(Tooltip): implement afterHide callback
1 parent 81125fa commit c011a10

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

src/App.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,14 @@ function App() {
167167
</div>
168168

169169
<div style={{ marginTop: '1rem' }}>
170-
<button id="buttonAfterShow">Check the dev console</button>
170+
<button id="buttonCallbacks">Check the dev console</button>
171171
<Tooltip
172172
place="bottom"
173-
anchorId="buttonAfterShow"
174-
afterShow={() => console.log('Hello world')}
173+
anchorId="buttonCallbacks"
174+
// eslint-disable-next-line no-console
175+
afterShow={() => console.log('After show')}
176+
// eslint-disable-next-line no-console
177+
afterHide={() => console.log('After hide')}
175178
content="Showing tooltip and calling afterShow method"
176179
/>
177180
</div>

src/components/Tooltip/Tooltip.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const Tooltip = ({
2828
style: externalStyles,
2929
position,
3030
afterShow,
31+
afterHide,
3132
// props handled by controller
3233
isHtmlContent = false,
3334
content,
@@ -54,9 +55,13 @@ const Tooltip = ({
5455
setShow(value)
5556
}
5657

57-
if (value && afterShow) {
58+
// Callbacks
59+
if (value === true && afterShow) {
5860
afterShow()
5961
}
62+
if (value === false && afterHide) {
63+
afterHide()
64+
}
6065
}
6166

6267
const handleShowTooltipDelayed = () => {

src/components/Tooltip/TooltipTypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@ export interface ITooltip {
5555
isOpen?: boolean
5656
setIsOpen?: (value: boolean) => void
5757
afterShow?: () => void
58+
afterHide?: () => void
5859
}

src/components/TooltipController/TooltipController.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const TooltipController = ({
3636
isOpen,
3737
setIsOpen,
3838
afterShow,
39+
afterHide,
3940
}: ITooltipController) => {
4041
const [tooltipContent, setTooltipContent] = useState(content || html)
4142
const [tooltipPlace, setTooltipPlace] = useState(place)
@@ -192,6 +193,7 @@ const TooltipController = ({
192193
isOpen,
193194
setIsOpen,
194195
afterShow,
196+
afterHide,
195197
}
196198

197199
return children ? <Tooltip {...props}>{children}</Tooltip> : <Tooltip {...props} />

src/components/TooltipController/TooltipControllerTypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface ITooltipController {
3434
isOpen?: boolean
3535
setIsOpen?: (value: boolean) => void
3636
afterShow?: () => void
37+
afterHide?: () => void
3738
}
3839

3940
declare module 'react' {

0 commit comments

Comments
 (0)