I am creating a fade out warning/error message (bootstrap style) in a react component, and I am having some issues with the fade out timing.
My fade out works fine so far, and this is how it's done now:
import React, { Component } from 'react'
import classnames from 'classnames'
class AlertMessage extends Component {
state = ({ autoHide: false })
componentDidMount(){
const { autoHide } = this.props
if (autoHide && !this.state.hasClosed) {
setTimeout(() => {
this.setState({ autoHide: true, hasClosed: true })
}, 5000)
}
}
render() {
const { error, info, success, warning, text } = this.props
const classNames = {
'error': error,
'info': info,
'success': success,
'warning': warning,
'alert-hidden': this.state.autoHide
}
return (
<div className={classnames("alert-message", classNames)}>
{text}
</div>
)
}
}
export default AlertMessage
Now, I would like to remove the setTimeout and the state, making it a functional stateless component. My problem is that the transition-delay in my style seems not to work, and I am afraid it is related to how classNames applies the classes to the component.
Here my style:
.alert-message{
overflow-y: hidden;
opacity: 1;
max-height: 80px;
transition-property: all 450ms;
transition-duration: 450ms;
transition-timing-function: cubic-bezier(0, 1, 0.5, 1);
transition-delay: 5000ms;
Thanks