Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 5c68a26

Browse files
lekoafTigge
authored andcommitted
feat: export tooltip delay time and animation
Exports the tooltip delay and animation for reuse in custom components.
1 parent 3ae32c8 commit 5c68a26

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

packages/core/src/Tooltip/index.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React, {
55
Children,
66
ReactElement,
77
} from 'react'
8-
import styled from 'styled-components'
8+
import styled, { css } from 'styled-components'
99
import { useBoolean } from 'react-hooks-shareable'
1010

1111
import { Typography, TypographyProps } from '../Typography'
@@ -21,6 +21,8 @@ import { font } from '../theme'
2121
* aliigned to it's center.
2222
*/
2323

24+
export const TOOLTIP_DELAY_MS = 250
25+
2426
const BaseTooltipWrapper = styled.div`
2527
display: flex;
2628
max-width: 280px;
@@ -43,6 +45,20 @@ const TooltipWrapper = styled(BaseTooltipWrapper)`
4345
background-color: ${({ theme }) => theme.color.text04()};
4446
`
4547

48+
export const ExpandedTooltipAnimation = css`
49+
animation: fadein 200ms ease-out;
50+
51+
@keyframes fadein {
52+
from {
53+
opacity: 0;
54+
}
55+
56+
to {
57+
opacity: 1;
58+
}
59+
}
60+
`
61+
4662
const ExpandedTooltipWrapper = styled(BaseTooltipWrapper)`
4763
flex-direction: column;
4864
align-items: flex-start;
@@ -59,17 +75,7 @@ const ExpandedTooltipWrapper = styled(BaseTooltipWrapper)`
5975
6076
word-break: break-word;
6177
62-
animation: fadein 200ms ease-out;
63-
64-
@keyframes fadein {
65-
from {
66-
opacity: 0;
67-
}
68-
69-
to {
70-
opacity: 1;
71-
}
72-
}
78+
${ExpandedTooltipAnimation}
7379
`
7480

7581
const ExpandedTooltipTop = styled.div`
@@ -170,7 +176,7 @@ export const Tooltip: React.FC<TooltipProps | ExpandedTooltipProps> = ({
170176

171177
useEffect(() => {
172178
const delayVisible = () => setDebouncedVisible(visible)
173-
const delayed = setTimeout(delayVisible, 250)
179+
const delayed = setTimeout(delayVisible, TOOLTIP_DELAY_MS)
174180
return () => {
175181
clearTimeout(delayed)
176182
}

0 commit comments

Comments
 (0)