/
dialog.js
106 lines (97 loc) · 2.86 KB
/
dialog.js
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from '../../utils/classnames';
import Mask from '../mask/index';
/**
* Modals provide feedback to user
*
*/
class Dialog extends Component {
static propTypes = {
/**
* Object Arrays of buttons, `label` property is require
*
*/
buttons: PropTypes.array,
/**
* to display the dialog
*
*/
show: PropTypes.bool,
/**
* Title of dialog
*
*/
title: PropTypes.string,
/**
* Specify display style: ios/android, default is ios when autoDetect not on
*
*/
type: PropTypes.string,
};
static defaultProps = {
buttons: [],
show: false,
title: '',
type: '',
};
constructor(props){
super(props);
this.state = {
isAndroid: ''
};
}
renderButtons() {
return this.props.buttons.map((action, idx) => {
const {type, label, onClick, ...others} = action;
const className = classNames({
'weui-dialog__btn': true,
'weui-dialog__btn_default': type === 'default',
'weui-dialog__btn_primary': type === 'primary'
});
return (
<a
key={idx}
href="#"
onClick={(e) => {
if (e) {
e.preventDefault();
}
if (onClick && typeof onClick === 'function') {
onClick(e);
}
return false;
}}
{...others}
className={className}
>{label}</a>
);
});
}
render() {
const {title, show, className, children, buttons, type, autoDectect, ...others} = this.props;
const styleType = type ? type : 'ios';
const cls = classNames('weui-dialog', {
'weui-skin_android': styleType === 'android',
[className]: className
});
return (
<div style={{display: show ? 'block' : 'none'}}>
<Mask/>
<div className={cls} {...others}>
{ title ?
<div className="weui-dialog__hd">
<strong className="weui-dialog__title">{title}</strong>
</div> : false }
<div className="weui-dialog__bd">
{children}
</div>
<div className="weui-dialog__ft">
{this.renderButtons()}
</div>
</div>
</div>
);
}
}
export default Dialog;