zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
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
import React from 'react';
import PropTypes from 'prop-types';
import { _ } from '../classes/gettext';
 
class ErrorMessage extends React.Component {
    static propTypes = {
        bind: PropTypes.array.isRequired // two element array, 
                                               // with first element being the parent element 
                                               // and the second the error property to display
                                               // ex. [this, 'error']
    };
 
    constructor(props){
        super(props);
        this.close = this.close.bind(this);
    }
 
    close(){
        const [parent, prop] = this.props.bind;
        parent.setState({[prop]: ""});
    }
 
    render(){
        const [parent, prop] = this.props.bind;
 
        if (parent.state[prop]){
            return (
                <div className={"alert alert-warning alert-dismissible " + (this.props.className ? this.props.className : "")}>
                    <button type="button" className="close" title={_("Close")} onClick={this.close}><span aria-hidden="true">&times;</span></button>
                    {parent.state[prop]}
                </div>
            );
        }else{
            return (<div></div>);
        }
    }
}
 
export default ErrorMessage;