File size: 1,825 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
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();
};
/*
* Use the prop update trap in order to trigger
* displaying the status bar. Because we can hook
* in here, there is no need to have an explicit
* `show()` function.
*/
// @TODO: Please update https://github.com/Automattic/wp-calypso/issues/58453 if you are refactoring away from UNSAFE_* lifecycle methods!
UNSAFE_componentWillReceiveProps( nextProps ) {
if ( '' === nextProps.statusMessage ) {
return;
}
if ( nextProps.statusMessage === this.props.statusMessage ) {
return;
}
const component = this;
/* We only want this to appear for a bit, then disappear */
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;
|