I'm trying to implement a CSSTransition to a modal in my project. The problem is that I am using css modules.
My modal's render method
render() {
return (
<Aux>
<Backdrop
show={this.props.show}
clicked={this.props.modalClosed}/>
<CSSTransition
in={this.props.show}
timeout={1000}
mountOnEnter
unmountOnExit
classNames={?}
>
<div
className={classes.Modal}
>
{this.props.children}
</div>
</CSSTransition>
</Aux>
)
}
My Modal.css
.fade-enter {
}
.fade-enter-active {
animation:openModal 0.4s ease-out forwards;
}
.fade-exit{
}
.fade-exit-active{
animation: closeModal 0.4s ease-out forwards;
}
What do i pass to the classNames attribute in the CSSTransition component in order to make it work?
We will use CSS modules in the context of React but they are not limited to just React. You can use the CSS modules with any module bundler like webpack or browserify or any other way which supports importing CSS files. An alternative to CSS modules in React to create local scope is to use styled components.
Though easy to use, this property can perform a lot of amazing animations in a web page. CSS Transitions are not the only way animations can be implemented with CSS but happen to nonetheless be effective for most animation tasks. React 18 introduced a new hook called useTransition() .
All you need to do is put your array of items within the group to get started. You'll need an appear, appear active, enter, enter-active, leave, and leave-active. That's all you need!
JSX:
<CSSTransition in={focused} timeout={500} classNames={{
enterActive: styles.MyClassEnterActive,
enterDone: styles.MyClassEnterDone,
exitActive: styles.MyClassExit,
exitDone: styles.MyClassExitActive
}}>
<span className={styles.MyClass}>animated</span>
</CSSTransition>
CSS Module:
.MyClass {
position: absolute;
left: 5px;
}
.MyClassEnterActive {
left: 15px;
transition: left 500ms;
}
.MyClassEnterDone {
left: 15px;
}
.MyClassExit {
left: 15px;
}
.MyClassExitActive {
left: 5px;
transition: left 500ms;
}
Gracias Lionel!
Solved by entering classes like this:
render() {
return (
<Aux>
<Backdrop
show={this.props.show}
clicked={this.props.modalClosed}/>
<CSSTransition
in={this.props.show}
timeout={1000}
mountOnEnter
unmountOnExit
classNames={{
enterActive: classes["fade-enter-active"],
exitActive:classes["fade-exit-active"]
}}
>
<div
className={classes.Modal}
>
{this.props.children}
</div>
</CSSTransition>
</Aux>
)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With