UNPKG

5.32 kBJavaScriptView Raw
1import _extends from "@babel/runtime/helpers/extends";
2import _defineProperty from "@babel/runtime/helpers/defineProperty";
3import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
4import _createClass from "@babel/runtime/helpers/createClass";
5import _inherits from "@babel/runtime/helpers/inherits";
6import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8import _typeof from "@babel/runtime/helpers/typeof";
9
10function _createSuper(Derived) {
11 function isNativeReflectConstruct() {
12 if (typeof Reflect === "undefined" || !Reflect.construct) return false;
13 if (Reflect.construct.sham) return false;
14 if (typeof Proxy === "function") return true;
15
16 try {
17 Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
18 return true;
19 } catch (e) {
20 return false;
21 }
22 }
23
24 return function () {
25 var Super = _getPrototypeOf(Derived),
26 result;
27
28 if (isNativeReflectConstruct()) {
29 var NewTarget = _getPrototypeOf(this).constructor;
30
31 result = Reflect.construct(Super, arguments, NewTarget);
32 } else {
33 result = Super.apply(this, arguments);
34 }
35
36 return _possibleConstructorReturn(this, result);
37 };
38}
39
40import React, { Component } from 'react';
41import classNames from 'classnames';
42import Dialog from './Modal';
43import Button from '../button';
44import { getConfirmLocale } from './locale';
45import { getPrefixCls as _getPrefixCls } from '../configure';
46
47function isFixedWidth(width) {
48 switch (_typeof(width)) {
49 case 'undefined':
50 return false;
51
52 case 'number':
53 return true;
54
55 case 'string':
56 // width: 100%不是固定宽度
57 return width.indexOf('%') === -1;
58
59 default:
60 return false;
61 }
62}
63
64var Sidebar =
65/*#__PURE__*/
66function (_Component) {
67 _inherits(Sidebar, _Component);
68
69 var _super = _createSuper(Sidebar);
70
71 function Sidebar(props) {
72 var _this;
73
74 _classCallCheck(this, Sidebar);
75
76 _this = _super.call(this, props);
77
78 _this.handleCancel = function (e) {
79 var onCancel = _this.props.onCancel;
80
81 if (onCancel) {
82 onCancel(e);
83 }
84 };
85
86 _this.handleOk = function (e) {
87 var onOk = _this.props.onOk;
88
89 if (onOk) {
90 onOk(e);
91 }
92 };
93
94 _this.renderFooter = function () {
95 var props = _this.props;
96 var onCancel = props.onCancel,
97 onOk = props.onOk,
98 okType = props.okType,
99 funcType = props.funcType,
100 confirmLoading = props.confirmLoading,
101 alwaysCanCancel = props.alwaysCanCancel;
102
103 var prefixCls = _this.getPrefixCls();
104
105 var okCancel = 'okCancel' in props ? props.okCancel : true;
106 var runtimeLocale = getConfirmLocale();
107 var okText = props.okText || (okCancel ? runtimeLocale.okText : runtimeLocale.justOkText);
108 var cancelText = props.cancelText || runtimeLocale.cancelText;
109 var cancalBtn = okCancel ? React.createElement(Button, {
110 className: "".concat(prefixCls, "-btn-cancel"),
111 disabled: !alwaysCanCancel && confirmLoading,
112 funcType: funcType,
113 onClick: onCancel
114 }, cancelText) : null;
115 return React.createElement("div", {
116 className: "".concat(prefixCls, "-btns")
117 }, React.createElement(Button, {
118 className: "".concat(prefixCls, "-btn-ok"),
119 loading: confirmLoading,
120 funcType: funcType,
121 type: okType,
122 onClick: onOk
123 }, okText), cancalBtn);
124 };
125
126 _this.handleStatus = function () {
127 var open = _this.state.open;
128
129 _this.setState({
130 open: !open
131 });
132 };
133
134 _this.state = {
135 open: false
136 };
137 return _this;
138 }
139
140 _createClass(Sidebar, [{
141 key: "getPrefixCls",
142 value: function getPrefixCls() {
143 var prefixCls = this.props.prefixCls;
144 return _getPrefixCls('modal', prefixCls);
145 }
146 }, {
147 key: "render",
148 value: function render() {
149 var _classNames;
150
151 var props = this.props;
152 var _props$footer = props.footer,
153 footer = _props$footer === void 0 ? this.renderFooter() : _props$footer,
154 width = props.width,
155 className = props.className;
156 var prefixCls = this.getPrefixCls();
157 var open = this.state.open;
158 var fixedWidth = isFixedWidth(width);
159 var classString = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-sidebar"), true), _defineProperty(_classNames, "".concat(prefixCls, "-sidebar-open"), open), _defineProperty(_classNames, "".concat(prefixCls, "-sidebar-fixed-width"), fixedWidth), _classNames), className);
160 return React.createElement(Dialog, _extends({}, props, {
161 prefixCls: prefixCls,
162 animationEnd: this.handleStatus,
163 className: classString,
164 footer: footer,
165 closable: 'closable' in props ? props.closable : false
166 }));
167 }
168 }]);
169
170 return Sidebar;
171}(Component);
172
173export { Sidebar as default };
174Sidebar.displayName = 'Sidebar';
175Sidebar.defaultProps = {
176 width: '100%',
177 transitionName: 'slide-right',
178 maskTransitionName: 'fade',
179 confirmLoading: false,
180 alwaysCanCancel: false,
181 visible: false,
182 okType: 'primary',
183 funcType: 'raised'
184};
185//# sourceMappingURL=Sidebar.js.map