choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
186 lines (155 loc) • 5.32 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _typeof from "@babel/runtime/helpers/typeof";
function _createSuper(Derived) {
function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true;
} catch (e) {
return false;
}
}
return function () {
var Super = _getPrototypeOf(Derived),
result;
if (isNativeReflectConstruct()) {
var NewTarget = _getPrototypeOf(this).constructor;
result = Reflect.construct(Super, arguments, NewTarget);
} else {
result = Super.apply(this, arguments);
}
return _possibleConstructorReturn(this, result);
};
}
import React, { Component } from 'react';
import classNames from 'classnames';
import Dialog from './Modal';
import Button from '../button';
import { getConfirmLocale } from './locale';
import { getPrefixCls as _getPrefixCls } from '../configure';
function isFixedWidth(width) {
switch (_typeof(width)) {
case 'undefined':
return false;
case 'number':
return true;
case 'string':
// width: 100%不是固定宽度
return width.indexOf('%') === -1;
default:
return false;
}
}
var Sidebar =
/*#__PURE__*/
function (_Component) {
_inherits(Sidebar, _Component);
var _super = _createSuper(Sidebar);
function Sidebar(props) {
var _this;
_classCallCheck(this, Sidebar);
_this = _super.call(this, props);
_this.handleCancel = function (e) {
var onCancel = _this.props.onCancel;
if (onCancel) {
onCancel(e);
}
};
_this.handleOk = function (e) {
var onOk = _this.props.onOk;
if (onOk) {
onOk(e);
}
};
_this.renderFooter = function () {
var props = _this.props;
var onCancel = props.onCancel,
onOk = props.onOk,
okType = props.okType,
funcType = props.funcType,
confirmLoading = props.confirmLoading,
alwaysCanCancel = props.alwaysCanCancel;
var prefixCls = _this.getPrefixCls();
var okCancel = 'okCancel' in props ? props.okCancel : true;
var runtimeLocale = getConfirmLocale();
var okText = props.okText || (okCancel ? runtimeLocale.okText : runtimeLocale.justOkText);
var cancelText = props.cancelText || runtimeLocale.cancelText;
var cancalBtn = okCancel ? React.createElement(Button, {
className: "".concat(prefixCls, "-btn-cancel"),
disabled: !alwaysCanCancel && confirmLoading,
funcType: funcType,
onClick: onCancel
}, cancelText) : null;
return React.createElement("div", {
className: "".concat(prefixCls, "-btns")
}, React.createElement(Button, {
className: "".concat(prefixCls, "-btn-ok"),
loading: confirmLoading,
funcType: funcType,
type: okType,
onClick: onOk
}, okText), cancalBtn);
};
_this.handleStatus = function () {
var open = _this.state.open;
_this.setState({
open: !open
});
};
_this.state = {
open: false
};
return _this;
}
_createClass(Sidebar, [{
key: "getPrefixCls",
value: function getPrefixCls() {
var prefixCls = this.props.prefixCls;
return _getPrefixCls('modal', prefixCls);
}
}, {
key: "render",
value: function render() {
var _classNames;
var props = this.props;
var _props$footer = props.footer,
footer = _props$footer === void 0 ? this.renderFooter() : _props$footer,
width = props.width,
className = props.className;
var prefixCls = this.getPrefixCls();
var open = this.state.open;
var fixedWidth = isFixedWidth(width);
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);
return React.createElement(Dialog, _extends({}, props, {
prefixCls: prefixCls,
animationEnd: this.handleStatus,
className: classString,
footer: footer,
closable: 'closable' in props ? props.closable : false
}));
}
}]);
return Sidebar;
}(Component);
export { Sidebar as default };
Sidebar.displayName = 'Sidebar';
Sidebar.defaultProps = {
width: '100%',
transitionName: 'slide-right',
maskTransitionName: 'fade',
confirmLoading: false,
alwaysCanCancel: false,
visible: false,
okType: 'primary',
funcType: 'raised'
};
//# sourceMappingURL=Sidebar.js.map