-
{ this.props.title }+
-
- {
- this.props.children
- }
-
+class Dialog extends React.Component {
+ constructor() {
+ super();
+ this.modalHandler = (e) => {
+ this.setState({
+ data: e.detail.data,
+ visible: true
+ });
+ };
+ this.state = {
+ data: {
+ title: '',
+ content: ''
+ },
+ visible: false
+ };
+ this.close = this.close.bind(this);
+ this.modalClick = this.modalClick.bind(this);
+ }
+ render() {
+ return
+
+
{ this.state.data.title }+
+
+ {
+ this.state.data.content
+ }
- }
- close() {
- this.props.close();
- }
- modalClick() {
- if (this.props.clickModal2Hide) {
- this.close();
- }
- }
- dialogClick(e) {
- e.stopPropagation();
- }
+
}
+ componentDidMount() {
+ document.addEventListener('modal', this.modalHandler);
+ }
+ componentWillUnmount() {
+ document.removeEventListener('modal', this.modalHandler);
+ }
+ close() {
+ this.setState({
+ visible: false
+ });
+ }
+ static show(data) {
+ document.dispatchEvent(new CustomEvent('modal', {
+ detail: {
+ data
+ }
+ }));
+ }
+ modalClick() {
+ if (this.props.clickModal2Hide) this.close();
+ }
+}
```
```jsx
- let ModalDialog =
;
- ReactDOM.render(
, Node);
+// add to render function
+