UNPKG

choerodon-ui

Version:

An enterprise-class UI design language and React-based implementation

220 lines (186 loc) 7.22 kB
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 { __decorate } from "tslib"; import React, { Component } from 'react'; import isEmpty from 'lodash/isEmpty'; import isUndefined from 'lodash/isUndefined'; import sortBy from 'lodash/sortBy'; import { action, toJS } from 'mobx'; import { observer } from 'mobx-react'; import { getProPrefixCls } from '../../../es/configure/utils'; import Tag from '../../../es/tag'; import Animate from '../animate'; import Icon from '../icon'; import { $l } from '../locale-context'; export var TIMESTAMP = '__TIMESTAMP__'; export var SelectionsPosition; (function (SelectionsPosition) { SelectionsPosition["side"] = "side"; SelectionsPosition["below"] = "below"; })(SelectionsPosition || (SelectionsPosition = {})); var SelectionList = /*#__PURE__*/ function (_Component) { _inherits(SelectionList, _Component); var _super = _createSuper(SelectionList); function SelectionList() { var _this; _classCallCheck(this, SelectionList); _this = _super.apply(this, arguments); _this.prefixCls = getProPrefixCls('modal'); _this.unSelect = function (record) { var _this$props = _this.props, dataSet = _this$props.dataSet, treeFlag = _this$props.treeFlag; record.setState(TIMESTAMP, 0); if (treeFlag === 'Y') { dataSet.treeUnSelect(record); } else { dataSet.unSelect(record); } if (!isUndefined(record.parent)) { dataSet.unSelect(record.parent); } }; _this.renderBelow = function () { var _this$props2 = _this.props, dataSet = _this$props2.dataSet, treeFlag = _this$props2.treeFlag, _this$props2$valueFie = _this$props2.valueField, valueField = _this$props2$valueFie === void 0 ? '' : _this$props2$valueFie, _this$props2$textFiel = _this$props2.textField, textField = _this$props2$textFiel === void 0 ? '' : _this$props2$textFiel; var records = treeFlag === 'Y' ? dataSet.treeSelected : dataSet.selected; if (isEmpty(records)) { return null; } var classString = "".concat(_this.prefixCls, "-selection-list-below"); var animateChildren = _this.getRecords(records).map(function (record) { return React.createElement("li", { key: record.get(valueField), className: "".concat(classString, "-item") }, React.createElement(Tag, { closable: true, onClose: function onClose() { _this.unSelect(record); } }, React.createElement("span", null, record.get(textField)))); }); return React.createElement("div", { className: classString }, React.createElement("p", { className: "".concat(classString, "-intro") }, $l('Lov', 'selection_tips', { count: React.createElement("b", { key: "count" }, records.length) })), React.createElement(Animate, { className: "".concat(classString, "-list"), transitionAppear: true, transitionName: "fade", component: "ul" }, animateChildren)); }; return _this; } _createClass(SelectionList, [{ key: "getRecords", value: function getRecords(records) { return sortBy(records, function (item) { var _item$getState; return (_item$getState = item.getState(TIMESTAMP)) !== null && _item$getState !== void 0 ? _item$getState : -1; }); } }, { key: "renderSide", value: function renderSide() { var _this2 = this; var _this$props3 = this.props, dataSet = _this$props3.dataSet, treeFlag = _this$props3.treeFlag, _this$props3$valueFie = _this$props3.valueField, valueField = _this$props3$valueFie === void 0 ? '' : _this$props3$valueFie, _this$props3$textFiel = _this$props3.textField, textField = _this$props3$textFiel === void 0 ? '' : _this$props3$textFiel, _this$props3$selectio = _this$props3.selectionProps, selectionProps = _this$props3$selectio === void 0 ? {} : _this$props3$selectio; var nodeRenderer = selectionProps.nodeRenderer, placeholder = selectionProps.placeholder; var records = treeFlag === 'Y' ? dataSet.treeSelected : dataSet.selected; var isEmptyList = isEmpty(records); if (isEmptyList && !placeholder) { return null; } var classString = "".concat(this.prefixCls, "-selection-list"); var animateChildren = this.getRecords(records).map(function (record) { return React.createElement("li", { key: record.get(valueField), className: "".concat(classString, "-item") }, nodeRenderer ? toJS(nodeRenderer(record)) : React.createElement("span", null, record.get(textField)), React.createElement(Icon, { type: "cancel", onClick: function onClick() { _this2.unSelect(record); } })); }); return React.createElement("div", { className: "".concat(classString, "-container") }, React.createElement("p", { className: "".concat(classString, "-intro") }, isEmptyList ? placeholder : $l('Lov', 'selection_tips', { count: React.createElement("b", { key: "count" }, records.length) })), React.createElement(Animate, { className: "".concat(classString, "-list"), transitionAppear: true, transitionName: "slide-right", component: "ul" }, animateChildren)); } }, { key: "render", value: function render() { var selectionsPosition = this.props.selectionsPosition; if (selectionsPosition === SelectionsPosition.side) { return this.renderSide(); } if (selectionsPosition === SelectionsPosition.below) { return this.renderBelow(); } return null; } }]); return SelectionList; }(Component); __decorate([action], SelectionList.prototype, "unSelect", void 0); SelectionList = __decorate([observer], SelectionList); export default SelectionList; //# sourceMappingURL=SelectionList.js.map