choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
179 lines (152 loc) • 4.99 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _extends from "@babel/runtime/helpers/extends";
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";
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 PropTypes from 'prop-types';
import classNames from 'classnames';
import { getPrefixCls } from '../configure';
function generator(_ref) {
var displayName = _ref.displayName,
suffixCls = _ref.suffixCls;
return function (BasicComponent) {
var _a;
return _a =
/*#__PURE__*/
function (_Component) {
_inherits(Adapter, _Component);
var _super = _createSuper(Adapter);
function Adapter() {
_classCallCheck(this, Adapter);
return _super.apply(this, arguments);
}
_createClass(Adapter, [{
key: "render",
value: function render() {
var customizePrefixCls = this.props.prefixCls;
return React.createElement(BasicComponent, _extends({}, this.props, {
prefixCls: getPrefixCls(suffixCls, customizePrefixCls)
}));
}
}]);
return Adapter;
}(Component), _a.displayName = displayName, _a;
};
}
function Basic(props) {
var prefixCls = props.prefixCls,
className = props.className,
children = props.children,
others = _objectWithoutProperties(props, ["prefixCls", "className", "children"]);
var divCls = classNames(className, prefixCls);
return React.createElement("div", _extends({
className: divCls
}, others), children);
}
var BasicLayout =
/*#__PURE__*/
function (_Component2) {
_inherits(BasicLayout, _Component2);
var _super2 = _createSuper(BasicLayout);
function BasicLayout() {
var _this;
_classCallCheck(this, BasicLayout);
_this = _super2.apply(this, arguments);
_this.state = {
siders: []
};
return _this;
}
_createClass(BasicLayout, [{
key: "getChildContext",
value: function getChildContext() {
var _this2 = this;
var siders = this.state.siders;
return {
siderHook: {
addSider: function addSider(id) {
_this2.setState({
siders: [].concat(_toConsumableArray(siders), [id])
});
},
removeSider: function removeSider(id) {
_this2.setState({
siders: siders.filter(function (currentId) {
return currentId !== id;
})
});
}
}
};
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
prefixCls = _this$props.prefixCls,
className = _this$props.className,
children = _this$props.children,
hasSider = _this$props.hasSider,
others = _objectWithoutProperties(_this$props, ["prefixCls", "className", "children", "hasSider"]);
var siders = this.state.siders;
var divCls = classNames(className, prefixCls, _defineProperty({}, "".concat(prefixCls, "-has-sider"), hasSider || siders.length > 0));
return React.createElement("div", _extends({
className: divCls
}, others), children);
}
}]);
return BasicLayout;
}(Component);
BasicLayout.childContextTypes = {
siderHook: PropTypes.object
};
var Layout = generator({
suffixCls: 'layout',
displayName: 'Layout'
})(BasicLayout);
var Header = generator({
suffixCls: 'layout-header',
displayName: 'Header'
})(Basic);
var Footer = generator({
suffixCls: 'layout-footer',
displayName: 'Footer'
})(Basic);
var Content = generator({
suffixCls: 'layout-content',
displayName: 'Content'
})(Basic);
Layout.Header = Header;
Layout.Footer = Footer;
Layout.Content = Content;
export default Layout;
//# sourceMappingURL=layout.js.map