Commit 2a5f7d1e by Johannes Schill

panel-header: Add fade in transition to tooltip

parent e73466a8
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { Manager, Popper as ReactPopper, Reference } from 'react-popper'; import { Manager, Popper as ReactPopper, Reference } from 'react-popper';
import Transition from 'react-transition-group/Transition';
const defaultTransitionStyles = {
transition: 'opacity 200ms linear',
opacity: 0,
};
const transitionStyles = {
exited: { opacity: 0 },
entering: { opacity: 0 },
entered: { opacity: 1 },
exiting: { opacity: 0 },
};
interface Props { interface Props {
renderContent: (content: any) => any; renderContent: (content: any) => any;
...@@ -13,6 +26,7 @@ class Popper extends PureComponent<Props> { ...@@ -13,6 +26,7 @@ class Popper extends PureComponent<Props> {
render() { render() {
const { children, renderContent, show, placement, refClassName } = this.props; const { children, renderContent, show, placement, refClassName } = this.props;
const { content } = this.props; const { content } = this.props;
return ( return (
<Manager> <Manager>
<Reference> <Reference>
...@@ -22,20 +36,31 @@ class Popper extends PureComponent<Props> { ...@@ -22,20 +36,31 @@ class Popper extends PureComponent<Props> {
</div> </div>
)} )}
</Reference> </Reference>
{show && ( <Transition in={show} timeout={100}>
<ReactPopper placement={placement}> {transitionState => (
{({ ref, style, placement, arrowProps }) => { <ReactPopper placement={placement}>
return ( {({ ref, style, placement, arrowProps }) => {
<div ref={ref} style={style} data-placement={placement} className="popper"> return (
<div className="popper__background"> <div
{renderContent(content)} ref={ref}
<div ref={arrowProps.ref} data-placement={placement} className="popper__arrow" /> style={{
...style,
...defaultTransitionStyles,
...transitionStyles[transitionState],
}}
data-placement={placement}
className="popper"
>
<div className="popper__background">
{renderContent(content)}
<div ref={arrowProps.ref} data-placement={placement} className="popper__arrow" />
</div>
</div> </div>
</div> );
); }}
}} </ReactPopper>
</ReactPopper> )}
)} </Transition>
</Manager> </Manager>
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment