choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
186 lines (161 loc) • 6.01 kB
JavaScript
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 _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 { 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 { getPrefixCls } from '../configure'; // => 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, ["prefixCls", "className", "size", "mode"]);
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 = mode === SelectMode.combobox;
if (isCombobox) {
// children 带 dom 结构时,无法填入输入框
optionLabelProp = optionLabelProp || 'value';
}
var modeConfig = {
multiple: mode === SelectMode.multiple,
tags: mode === SelectMode.tags,
combobox: isCombobox
};
return 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 _this$props2 = this.props,
notFoundContent = _this$props2.notFoundContent,
mode = _this$props2.mode;
var isCombobox = mode === SelectMode.combobox;
if (isCombobox) {
// AutoComplete don't have notFoundContent defaultly
return notFoundContent === undefined ? null : notFoundContent;
}
return notFoundContent === undefined ? locale.notFoundContent : notFoundContent;
}
}, {
key: "render",
value: function render() {
return React.createElement(LocaleReceiver, {
componentName: "Select",
defaultLocale: defaultLocale.Select
}, this.renderSelect);
}
}]);
return Select;
}(Component);
export { Select as default };
Select.displayName = 'Select';
Select.Option = Option;
Select.OptGroup = OptGroup;
Select.defaultProps = {
blurChange: true,
showSearch: false,
transitionName: 'slide-up',
choiceTransitionName: 'zoom',
filter: false,
showCheckAll: true,
choiceRemove: true,
border: true
};
Select.propTypes = {
prefixCls: PropTypes.string,
className: PropTypes.string,
size: PropTypes.oneOf([Size["default"], Size.large, Size.small]),
combobox: PropTypes.bool,
notFoundContent: PropTypes.any,
showSearch: PropTypes.bool,
optionLabelProp: PropTypes.string,
transitionName: PropTypes.string,
choiceTransitionName: PropTypes.string,
showNotFindInputItem: PropTypes.bool,
showNotFindSelectedItem: PropTypes.bool,
filter: PropTypes.bool,
showCheckAll: PropTypes.bool,
footer: PropTypes.oneOfType([PropTypes.node, PropTypes.string]),
choiceRender: PropTypes.func,
loading: PropTypes.oneOfType([PropTypes.bool, PropTypes.object]),
filterValue: PropTypes.string,
onFilterChange: PropTypes.func,
choiceRemove: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
onChoiceRemove: PropTypes.func,
onClear: PropTypes.func,
border: PropTypes.bool,
blurChange: PropTypes.bool
};
//# sourceMappingURL=index.js.map