|
|
import { Component } from 'react'; |
|
|
import Gridicon from './gridicons'; |
|
|
|
|
|
export class StatusBar extends Component { |
|
|
static defaultProps = { |
|
|
statusTimeout: 4000, |
|
|
}; |
|
|
|
|
|
state = { |
|
|
isVisible: false, |
|
|
}; |
|
|
|
|
|
disappear = () => { |
|
|
this.setState( { |
|
|
isVisible: false, |
|
|
} ); |
|
|
|
|
|
this.props.statusReset(); |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UNSAFE_componentWillReceiveProps( nextProps ) { |
|
|
if ( '' === nextProps.statusMessage ) { |
|
|
return; |
|
|
} |
|
|
|
|
|
if ( nextProps.statusMessage === this.props.statusMessage ) { |
|
|
return; |
|
|
} |
|
|
|
|
|
const component = this; |
|
|
|
|
|
|
|
|
window.setTimeout( |
|
|
function () { |
|
|
component.disappear(); |
|
|
}, |
|
|
nextProps.statusTimeout ? nextProps.statusTimeout : this.props.statusTimeout |
|
|
); |
|
|
|
|
|
this.setState( { |
|
|
isVisible: true, |
|
|
} ); |
|
|
} |
|
|
|
|
|
render() { |
|
|
const visibility = this.state.isVisible ? { display: 'flex' } : { display: 'none' }; |
|
|
|
|
|
const classes = [ 'wpnc__status-bar' ]; |
|
|
if ( 'undefined' !== typeof this.props.statusClasses && this.props.statusClasses.length > 0 ) { |
|
|
classes.push.apply( classes, this.props.statusClasses ); |
|
|
} |
|
|
|
|
|
return ( |
|
|
<div className={ classes.join( ' ' ) } style={ visibility }> |
|
|
<span /> |
|
|
<span |
|
|
// eslint-disable-next-line react/no-danger |
|
|
dangerouslySetInnerHTML={ { |
|
|
__html: this.props.statusMessage, |
|
|
} } |
|
|
/> |
|
|
<button className="wpnc__close-link" onClick={ this.disappear }> |
|
|
<Gridicon icon="cross" size={ 18 } /> |
|
|
</button> |
|
|
</div> |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
export default StatusBar; |
|
|
|