-
-
Notifications
You must be signed in to change notification settings - Fork 227
/
ActionSheet.jsx
67 lines (61 loc) · 1.84 KB
/
ActionSheet.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
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Popup from '../Popup';
class ActionSheet extends PureComponent {
render() {
const { prefixCls, className, shape, visible, onMaskClick, actions, cancelText, onCancel } = this.props;
const cls = classnames({
[`${prefixCls}`]: true,
[className]: !!className,
[`shape-${shape}`]: !!shape,
});
return (
<Popup visible={visible} onMaskClick={onMaskClick}>
<div className={cls}>
<div className={`${prefixCls}-actions`}>
{
actions.map((action, index) => {
const actionCls = classnames({
[`${prefixCls}-btn`]: true,
[`theme-${action.theme}`]: !!action.theme,
});
return <a key={+index} className={actionCls} onClick={action.onClick}>{action.text}</a>;
})
}
</div>
{
typeof onCancel === 'function'
? (
<div className={`${prefixCls}-cancel`}>
<a className={`${prefixCls}-btn`} onClick={onCancel}>{cancelText}</a>
</div>
)
: null
}
</div>
</Popup>
);
}
}
ActionSheet.propTypes = {
prefixCls: PropTypes.string,
className: PropTypes.string,
shape: PropTypes.oneOf(['radius']),
visible: PropTypes.bool,
actions: PropTypes.arrayOf(PropTypes.object),
onMaskClick: Popup.propTypes.onMaskClick,
onCancel: PropTypes.func,
cancelText: PropTypes.string,
};
ActionSheet.defaultProps = {
prefixCls: 'za-actionsheet',
className: null,
shape: 'radius',
visible: false,
actions: [],
onMaskClick: Popup.defaultProps.onMaskClick,
onCancel: null,
cancelText: '取消',
};
export default ActionSheet;