choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
132 lines (116 loc) • 5.92 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 _createSuper from "@babel/runtime/helpers/createSuper";
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 LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale-provider/default';
import ConfigContext from '../config-provider/ConfigContext';
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 getPrefixCls = _this.context.getPrefixCls;
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 = /*#__PURE__*/React.createElement("i", {
className: iconCls
});
return /*#__PURE__*/React.createElement(React.Fragment, null, expandIconPositionCof === 'left' && icon, panelProps.isActive ? /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-expand-text"),
style: {
minWidth: localeCode === 'zh-cn' ? '0.38rem' : '0.52rem'
}
}, locale.fold) : /*#__PURE__*/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 _this$context = this.context,
getPrefixCls = _this$context.getPrefixCls,
getConfig = _this$context.getConfig;
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 /*#__PURE__*/React.createElement(LocaleReceiver, {
componentName: "Collapse",
defaultLocale: defaultLocale.Collapse
}, function (locale, localeCode) {
return _this2.renderExpandTextContent(panelProps, locale, localeCode, expandIconPositionCof);
});
};
}
return /*#__PURE__*/React.createElement(RcCollapse, _extends({}, this.props, {
expandIcon: expandIconContent,
expandIconPosition: expandIconPositionCof,
prefixCls: prefixCls,
className: collapseClassName
}));
}
}], [{
key: "contextType",
get: function get() {
return ConfigContext;
}
}]);
return Collapse;
}(Component);
export { Collapse as default };
Collapse.displayName = 'Collapse';
Collapse.Panel = CollapsePanel;
Collapse.defaultProps = {
bordered: true,
openAnimation: _objectSpread(_objectSpread({}, animation), {}, {
appear: function appear() {}
})
};
//# sourceMappingURL=Collapse.js.map