/
dialog.jsx
86 lines (72 loc) · 2.6 KB
/
dialog.jsx
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
79
80
81
82
83
84
85
86
import React, {Component} from "react";
import "./dialog.css";
import {Button} from "../../../index";
import Body from "../body/body";
export default class Dialog extends Component {
constructor(props){
super(props);
this.dialog = React.createRef();
this.actions = [];
this.actions = this.props.actions.map((el, index) => {
return (
<Button {...el} key={index} onClick={this.actionButtonClick.bind(this, el.onClick)}/>
)
});
this.onClose = this.onClose.bind(this);
this.actionButtonClick = this.actionButtonClick.bind(this);
}
actionButtonClick(cb){
if (typeof cb === 'function') cb();
if (this.props.actionClickClose) this.props.onClose();
}
onClose(){
this.props.onClose();
}
render(){
const {open, title, closeButton, modal, overlayColor, overlayAlpha, speed, cls, clsTitle, clsContent, clsActions, height, width, contentHeight} = this.props;
return (
<Body>
{modal && open && (
<div className={'overlay'} style={{backgroundColor: overlayColor, opacity: overlayAlpha}}>{''}</div>
)}
<div className={'dialog-wrapper'} style={{
transition: `transform ${speed}s, opacity ${speed}s`,
transform: open ? 'translateY(0vh)' : 'translateY(-100vh)',
opacity: open ? 1 : 0,
}}>
<div className={'dialog ' + cls} ref={this.dialog} style={{
height: height,
width: width,
}}>
{closeButton && (
<Button cls={'square closer'} onClick={this.onClose}/>
)}
<div className={'dialog-title ' + clsTitle}>{title}</div>
<div className={'dialog-content ' + clsContent} style={{height: contentHeight}}>{this.props.children}</div>
{this.actions.length > 0 && (
<div className={'dialog-actions ' + clsActions}>{this.actions}</div>
)}
</div>
</div>
</Body>
)
}
}
Dialog.defaultProps = {
closeButton: true,
open: false,
title: "",
actions: [],
actionClickClose: true,
modal: true,
overlayColor: "#ffffff",
overlayAlpha: 1,
speed: .4,
width: "auto",
height: "auto",
contentHeight: "auto",
cls: "",
clsTitle: "",
clsContent: "",
clsActions: ""
};