Skip to content

Commit 613bf61

Browse files
committed
feat: 💄 make tooltip to appear according to its placement; add scale to its animation
1 parent 1142b0f commit 613bf61

File tree

1 file changed

+41
-32
lines changed

1 file changed

+41
-32
lines changed

src/components/tooltip/tooltip.js

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,39 +48,48 @@ let Arrow = styled.div`
4848
`
4949

5050
let Tooltip = ({ isOpen, className, children }) => (
51-
<Transition
52-
items={isOpen}
53-
from={{ transform: 'translateY(20px)', opacity: 0 }}
54-
enter={{ transform: 'translateY(0)', opacity: 1 }}
55-
leave={{ transform: 'translateY(20px)', opacity: 0 }}
56-
>
57-
{transitionIsOpen =>
58-
transitionIsOpen &&
59-
(transitionStyle => (
60-
<Popper>
61-
{({ ref, style, placement, arrowProps }) => (
62-
<div
63-
ref={ref}
64-
style={style}
65-
data-placement={placement}
66-
className={className}
67-
>
68-
<Popover style={transitionStyle}>{children}</Popover>
51+
<Popper>
52+
{({ ref, style, placement, arrowProps }) => {
53+
let translateSign = placement === 'bottom' ? '-' : ''
6954

70-
<Arrow
71-
{...arrowProps}
72-
style={{
73-
...arrowProps.style,
74-
opacity: transitionStyle.opacity,
75-
}}
76-
placement={placement}
77-
/>
78-
</div>
79-
)}
80-
</Popper>
81-
))
82-
}
83-
</Transition>
55+
return (
56+
<Transition
57+
items={isOpen}
58+
from={{
59+
transform: `translateY(${translateSign}30px) scale(0.9)`,
60+
opacity: 0,
61+
}}
62+
enter={{ transform: `translateY(0) scale(1)`, opacity: 1 }}
63+
leave={{
64+
transform: `translateY(${translateSign}30px) scale(0.9)`,
65+
opacity: 0,
66+
}}
67+
>
68+
{transitionIsOpen =>
69+
transitionIsOpen &&
70+
(transitionStyle => (
71+
<div
72+
ref={ref}
73+
style={style}
74+
data-placement={placement}
75+
className={className}
76+
>
77+
<Popover style={transitionStyle}>{children}</Popover>
78+
79+
<Arrow
80+
{...{ ...arrowProps, placement }}
81+
style={{
82+
...arrowProps.style,
83+
opacity: transitionStyle.opacity,
84+
}}
85+
/>
86+
</div>
87+
))
88+
}
89+
</Transition>
90+
)
91+
}}
92+
</Popper>
8493
)
8594

8695
export default Tooltip

0 commit comments

Comments
 (0)