JavaScript
51
Вклад в тег
npm install react-transition-group
import { TransitionGroup, CSSTransition } from "react-transition-group";
<TransitionGroup className="items-section__list">
{list.map(elem => (
<CSSTransition key={elem} timeout={500} classNames="move">
<h5 key={elem}>{elem}</h5>
</CSSTransition>
))}
</TransitionGroup>
.move-enter {
opacity: 0.01;
transform: translate(-40px, 0);
}
.move-enter-active {
opacity: 1;
transform: translate(0, 0);
transition: all 500ms ease-in;
}
.move-exit {
opacity: 1;
transform: translate(0, 0);
}
.move-exit-active {
opacity: 0.01;
transform: translate(40px, 0);
transition: all 500ms ease-in;
}
componentDidMount() {
document.addEventListener('click', this.close);
}
componentWillUnmount() {
document.removeEventListener('click', this.close);
}
close = (event) => {
const domNode = ReactDOM.findDOMNode(this);
if (!domNode || !domNode.contains(event.target)) {
this.setState({ isOpened: false });
}
}