Skip to content

Commit

Permalink
feat: 💄 make tooltip to appear according to its placement; add scale …
Browse files Browse the repository at this point in the history
…to its animation
  • Loading branch information
kitos committed Jan 16, 2019
1 parent 1142b0f commit 613bf61
Showing 1 changed file with 41 additions and 32 deletions.
73 changes: 41 additions & 32 deletions src/components/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,48 @@ let Arrow = styled.div`
`

let Tooltip = ({ isOpen, className, children }) => (
<Transition
items={isOpen}
from={{ transform: 'translateY(20px)', opacity: 0 }}
enter={{ transform: 'translateY(0)', opacity: 1 }}
leave={{ transform: 'translateY(20px)', opacity: 0 }}
>
{transitionIsOpen =>
transitionIsOpen &&
(transitionStyle => (
<Popper>
{({ ref, style, placement, arrowProps }) => (
<div
ref={ref}
style={style}
data-placement={placement}
className={className}
>
<Popover style={transitionStyle}>{children}</Popover>
<Popper>
{({ ref, style, placement, arrowProps }) => {
let translateSign = placement === 'bottom' ? '-' : ''

<Arrow
{...arrowProps}
style={{
...arrowProps.style,
opacity: transitionStyle.opacity,
}}
placement={placement}
/>
</div>
)}
</Popper>
))
}
</Transition>
return (
<Transition
items={isOpen}
from={{
transform: `translateY(${translateSign}30px) scale(0.9)`,
opacity: 0,
}}
enter={{ transform: `translateY(0) scale(1)`, opacity: 1 }}
leave={{
transform: `translateY(${translateSign}30px) scale(0.9)`,
opacity: 0,
}}
>
{transitionIsOpen =>
transitionIsOpen &&
(transitionStyle => (
<div
ref={ref}
style={style}
data-placement={placement}
className={className}
>
<Popover style={transitionStyle}>{children}</Popover>

<Arrow
{...{ ...arrowProps, placement }}
style={{
...arrowProps.style,
opacity: transitionStyle.opacity,
}}
/>
</div>
))
}
</Transition>
)
}}
</Popper>
)

export default Tooltip
Expand Down

0 comments on commit 613bf61

Please sign in to comment.