Skip to content

Commit 81125fa

Browse files
OupslaGabriel Jablonski
authored andcommitted
feat(Tooltip): implement afterShow callback
1 parent 4ea799a commit 81125fa

File tree

5 files changed

+19
-0
lines changed

5 files changed

+19
-0
lines changed

src/App.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ function App() {
165165
/>
166166
</div>
167167
</div>
168+
169+
<div style={{ marginTop: '1rem' }}>
170+
<button id="buttonAfterShow">Check the dev console</button>
171+
<Tooltip
172+
place="bottom"
173+
anchorId="buttonAfterShow"
174+
afterShow={() => console.log('Hello world')}
175+
content="Showing tooltip and calling afterShow method"
176+
/>
177+
</div>
168178
</main>
169179
)
170180
}

src/components/Tooltip/Tooltip.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const Tooltip = ({
2727
clickable = false,
2828
style: externalStyles,
2929
position,
30+
afterShow,
3031
// props handled by controller
3132
isHtmlContent = false,
3233
content,
@@ -52,6 +53,10 @@ const Tooltip = ({
5253
} else if (isOpen === undefined) {
5354
setShow(value)
5455
}
56+
57+
if (value && afterShow) {
58+
afterShow()
59+
}
5560
}
5661

5762
const handleShowTooltipDelayed = () => {

src/components/Tooltip/TooltipTypes.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ export interface ITooltip {
5454
position?: IPosition
5555
isOpen?: boolean
5656
setIsOpen?: (value: boolean) => void
57+
afterShow?: () => void
5758
}

src/components/TooltipController/TooltipController.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const TooltipController = ({
3535
position,
3636
isOpen,
3737
setIsOpen,
38+
afterShow,
3839
}: ITooltipController) => {
3940
const [tooltipContent, setTooltipContent] = useState(content || html)
4041
const [tooltipPlace, setTooltipPlace] = useState(place)
@@ -190,6 +191,7 @@ const TooltipController = ({
190191
position,
191192
isOpen,
192193
setIsOpen,
194+
afterShow,
193195
}
194196

195197
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
@@ -33,6 +33,7 @@ export interface ITooltipController {
3333
position?: IPosition
3434
isOpen?: boolean
3535
setIsOpen?: (value: boolean) => void
36+
afterShow?: () => void
3637
}
3738

3839
declare module 'react' {

0 commit comments

Comments
 (0)