choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
157 lines (134 loc) • 6.4 kB
JavaScript
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
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";
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 animation from '../_util/openAnimation';
import CollapsePanel from './CollapsePanel';
import RcCollapse from '../rc-components/collapse';
import { getPrefixCls, getConfig } from '../configure';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale-provider/default';
var Collapse =
/*#__PURE__*/
function (_Component) {
_inherits(Collapse, _Component);
var _super = _createSuper(Collapse);
function Collapse() {
var _this;
_classCallCheck(this, Collapse);
_this = _super.apply(this, arguments);
_this.renderExpandIcon = function () {
var panelProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var expandIcon = _this.props.expandIcon;
return expandIcon ? expandIcon(panelProps) : null;
};
_this.renderExpandTextContent = function () {
var _classNames;
var panelProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var locale = arguments.length > 1 ? arguments[1] : undefined;
var localeCode = arguments.length > 2 ? arguments[2] : undefined;
var expandIconPositionCof = arguments.length > 3 ? arguments[3] : undefined;
var customizePrefixCls = _this.props.prefixCls;
var prefixCls = getPrefixCls('collapse', customizePrefixCls);
var iconCls = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-expand-icon"), true), _defineProperty(_classNames, "".concat(prefixCls, "-expanded"), panelProps.isActive), _defineProperty(_classNames, "".concat(prefixCls, "-collapsed"), !panelProps.isActive), _classNames));
var icon = React.createElement("i", {
className: iconCls
});
return React.createElement(React.Fragment, null, expandIconPositionCof === 'left' && icon, panelProps.isActive ? React.createElement("span", {
className: "".concat(prefixCls, "-expand-text"),
style: {
minWidth: localeCode === 'zh-cn' ? '0.38rem' : '0.52rem'
}
}, locale.fold) : React.createElement("span", {
className: "".concat(prefixCls, "-expand-text"),
style: {
minWidth: localeCode === 'zh-cn' ? '0.38rem' : '0.52rem'
}
}, locale.unfold), expandIconPositionCof === 'right' && icon);
};
return _this;
}
_createClass(Collapse, [{
key: "render",
value: function render() {
var _classNames2,
_this2 = this;
var _this$props = this.props,
customizePrefixCls = _this$props.prefixCls,
_this$props$className = _this$props.className,
className = _this$props$className === void 0 ? '' : _this$props$className,
expandIcon = _this$props.expandIcon,
bordered = _this$props.bordered,
expandIconPosition = _this$props.expandIconPosition,
trigger = _this$props.trigger,
ghost = _this$props.ghost;
var prefixCls = getPrefixCls('collapse', customizePrefixCls);
var expandIconPositionCof = expandIconPosition || getConfig('collapseExpandIconPosition');
var expandIconCof = expandIcon || getConfig('collapseExpandIcon');
var triggerCof = trigger || getConfig('collapseTrigger');
var collapseClassName = classNames((_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-borderless"), !bordered), _defineProperty(_classNames2, "".concat(prefixCls, "-text-action"), expandIconCof === 'text' && expandIconPositionCof === 'left'), _defineProperty(_classNames2, "".concat(prefixCls, "-trigger"), triggerCof === 'header'), _defineProperty(_classNames2, "".concat(prefixCls, "-ghost"), ghost), _defineProperty(_classNames2, "".concat(prefixCls, "-icon-position-").concat(expandIconPositionCof), true), _classNames2), className);
var expandIconContent;
if (typeof expandIconCof === 'function') {
expandIconContent = function expandIconContent(panelProps) {
return _this2.renderExpandIcon(panelProps);
};
} else if (expandIconCof === 'text') {
expandIconContent = function expandIconContent(panelProps) {
return React.createElement(LocaleReceiver, {
componentName: "Collapse",
defaultLocale: defaultLocale.Collapse
}, function (locale, localeCode) {
return _this2.renderExpandTextContent(panelProps, locale, localeCode, expandIconPositionCof);
});
};
}
return React.createElement(RcCollapse, _extends({}, this.props, {
expandIcon: expandIconContent,
expandIconPosition: expandIconPositionCof,
prefixCls: prefixCls,
className: collapseClassName
}));
}
}]);
return Collapse;
}(Component);
export { Collapse as default };
Collapse.displayName = 'Collapse';
Collapse.Panel = CollapsePanel;
Collapse.defaultProps = {
bordered: true,
openAnimation: _objectSpread({}, animation, {
appear: function appear() {}
})
};
//# sourceMappingURL=Collapse.js.map