UNPKG

choerodon-ui

Version:

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

139 lines (120 loc) 4.56 kB
import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; 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"; var _excluded = ["prefixCls", "className", "size", "mode"]; import React, { Component } from 'react'; import classNames from 'classnames'; import { Size } from '../_util/enum'; import LocaleReceiver from '../locale-provider/LocaleReceiver'; import defaultLocale from '../locale-provider/default'; import RcSelect, { OptGroup, Option } from '../rc-components/select'; import { SelectMode } from './enum'; import ConfigContext from '../config-provider/ConfigContext'; // => It is needless to export the declaration of below two inner components. // export { Option, OptGroup }; var Select = /*#__PURE__*/function (_Component) { _inherits(Select, _Component); var _super = _createSuper(Select); function Select() { var _this; _classCallCheck(this, Select); _this = _super.apply(this, arguments); _this.saveSelect = function (node) { _this.rcSelect = node; }; _this.renderSelect = function (locale) { var _classNames; var _this$props = _this.props, customizePrefixCls = _this$props.prefixCls, _this$props$className = _this$props.className, className = _this$props$className === void 0 ? '' : _this$props$className, size = _this$props.size, mode = _this$props.mode, restProps = _objectWithoutProperties(_this$props, _excluded); var getPrefixCls = _this.context.getPrefixCls; var prefixCls = getPrefixCls('select', customizePrefixCls); var cls = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-lg"), size === Size.large), _defineProperty(_classNames, "".concat(prefixCls, "-sm"), size === Size.small), _classNames), className); var optionLabelProp = _this.props.optionLabelProp; var isCombobox = _this.isCombobox(); if (isCombobox) { // children 带 dom 结构时,无法填入输入框 optionLabelProp = optionLabelProp || 'value'; } var modeConfig = { multiple: mode === SelectMode.multiple, tags: mode === SelectMode.tags, combobox: isCombobox }; delete restProps.form; return /*#__PURE__*/React.createElement(RcSelect, _extends({}, restProps, modeConfig, { prefixCls: prefixCls, className: cls, optionLabelProp: optionLabelProp || 'children', filterPlaceholder: locale.filterPlaceholder, notFoundContent: _this.getNotFoundContent(locale), ref: _this.saveSelect })); }; return _this; } _createClass(Select, [{ key: "focus", value: function focus() { this.rcSelect.focus(); } }, { key: "blur", value: function blur() { this.rcSelect.blur(); } }, { key: "getNotFoundContent", value: function getNotFoundContent(locale) { var notFoundContent = this.props.notFoundContent; if (this.isCombobox()) { // AutoComplete don't have notFoundContent defaultly return notFoundContent === undefined ? null : notFoundContent; } return notFoundContent === undefined ? locale.notFoundContent : notFoundContent; } }, { key: "isCombobox", value: function isCombobox() { var mode = this.props.mode; return mode === 'combobox' || mode === Select.SECRET_COMBOBOX_MODE_DO_NOT_USE; } }, { key: "render", value: function render() { return /*#__PURE__*/React.createElement(LocaleReceiver, { componentName: "Select", defaultLocale: defaultLocale.Select }, this.renderSelect); } }], [{ key: "contextType", get: function get() { return ConfigContext; } }]); return Select; }(Component); export { Select as default }; Select.displayName = 'Select'; Select.Option = Option; Select.OptGroup = OptGroup; Select.SECRET_COMBOBOX_MODE_DO_NOT_USE = 'SECRET_COMBOBOX_MODE_DO_NOT_USE'; Select.defaultProps = { blurChange: true, showSearch: false, transitionName: 'slide-up', choiceTransitionName: 'zoom', filter: false, showCheckAll: true, choiceRemove: true, border: true }; //# sourceMappingURL=index.js.map