antd
Version:
An enterprise-class UI design language and React components implementation
230 lines (194 loc) • 10.1 kB
JavaScript
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var __rest = this && this.__rest || function (s, e) {
var t = {};
for (var p in s) {
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
}
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
}
return t;
};
import * as React from 'react';
import * as PropTypes from 'prop-types';
import RcSelect, { Option, OptGroup } from 'rc-select';
import classNames from 'classnames';
import omit from 'omit.js';
import { ConfigConsumer } from '../config-provider';
import warning from '../_util/warning';
import Icon from '../icon';
import { tuple } from '../_util/type';
var SelectSizes = tuple('default', 'large', 'small');
var SelectPropTypes = {
prefixCls: PropTypes.string,
className: PropTypes.string,
size: PropTypes.oneOf(SelectSizes),
notFoundContent: PropTypes.any,
showSearch: PropTypes.bool,
optionLabelProp: PropTypes.string,
transitionName: PropTypes.string,
choiceTransitionName: PropTypes.string,
id: PropTypes.string
}; // => It is needless to export the declaration of below two inner components.
// export { Option, OptGroup };
var Select =
/*#__PURE__*/
function (_React$Component) {
_inherits(Select, _React$Component);
function Select(props) {
var _this;
_classCallCheck(this, Select);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Select).call(this, props));
_this.saveSelect = function (node) {
_this.rcSelect = node;
};
_this.renderSelect = function (_ref) {
var _classNames;
var getContextPopupContainer = _ref.getPopupContainer,
getPrefixCls = _ref.getPrefixCls,
renderEmpty = _ref.renderEmpty;
var _a = _this.props,
customizePrefixCls = _a.prefixCls,
_a$className = _a.className,
className = _a$className === void 0 ? '' : _a$className,
size = _a.size,
mode = _a.mode,
getPopupContainer = _a.getPopupContainer,
removeIcon = _a.removeIcon,
clearIcon = _a.clearIcon,
menuItemSelectedIcon = _a.menuItemSelectedIcon,
showArrow = _a.showArrow,
restProps = __rest(_a, ["prefixCls", "className", "size", "mode", "getPopupContainer", "removeIcon", "clearIcon", "menuItemSelectedIcon", "showArrow"]);
var rest = omit(restProps, ['inputIcon']);
var prefixCls = getPrefixCls('select', customizePrefixCls);
var cls = classNames((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-lg"), size === 'large'), _defineProperty(_classNames, "".concat(prefixCls, "-sm"), size === 'small'), _defineProperty(_classNames, "".concat(prefixCls, "-show-arrow"), showArrow), _classNames), className);
var optionLabelProp = _this.props.optionLabelProp;
if (_this.isCombobox()) {
// children 带 dom 结构时,无法填入输入框
optionLabelProp = optionLabelProp || 'value';
}
var modeConfig = {
multiple: mode === 'multiple',
tags: mode === 'tags',
combobox: _this.isCombobox()
};
var finalRemoveIcon = removeIcon && (React.isValidElement(removeIcon) ? React.cloneElement(removeIcon, {
className: classNames(removeIcon.props.className, "".concat(prefixCls, "-remove-icon"))
}) : removeIcon) || React.createElement(Icon, {
type: "close",
className: "".concat(prefixCls, "-remove-icon")
});
var finalClearIcon = clearIcon && (React.isValidElement(clearIcon) ? React.cloneElement(clearIcon, {
className: classNames(clearIcon.props.className, "".concat(prefixCls, "-clear-icon"))
}) : clearIcon) || React.createElement(Icon, {
type: "close-circle",
theme: "filled",
className: "".concat(prefixCls, "-clear-icon")
});
var finalMenuItemSelectedIcon = menuItemSelectedIcon && (React.isValidElement(menuItemSelectedIcon) ? React.cloneElement(menuItemSelectedIcon, {
className: classNames(menuItemSelectedIcon.props.className, "".concat(prefixCls, "-selected-icon"))
}) : menuItemSelectedIcon) || React.createElement(Icon, {
type: "check",
className: "".concat(prefixCls, "-selected-icon")
});
return React.createElement(RcSelect, _extends({
inputIcon: _this.renderSuffixIcon(prefixCls),
removeIcon: finalRemoveIcon,
clearIcon: finalClearIcon,
menuItemSelectedIcon: finalMenuItemSelectedIcon,
showArrow: showArrow
}, rest, modeConfig, {
prefixCls: prefixCls,
className: cls,
optionLabelProp: optionLabelProp || 'children',
notFoundContent: _this.getNotFoundContent(renderEmpty),
getPopupContainer: getPopupContainer || getContextPopupContainer,
ref: _this.saveSelect
}));
};
warning(props.mode !== 'combobox', 'Select', 'The combobox mode is deprecated, ' + 'it will be removed in next major version, ' + 'please use AutoComplete instead');
return _this;
}
_createClass(Select, [{
key: "getNotFoundContent",
value: function getNotFoundContent(renderEmpty) {
var notFoundContent = this.props.notFoundContent;
if (notFoundContent !== undefined) {
return notFoundContent;
}
if (this.isCombobox()) {
return null;
}
return renderEmpty('Select'); // if (this.isCombobox()) {
// // AutoComplete don't have notFoundContent defaultly
// return notFoundContent === undefined ? null : notFoundContent;
// }
// return renderEmpty('Select');
// // return notFoundContent === undefined ? locale.notFoundContent : notFoundContent;
}
}, {
key: "focus",
value: function focus() {
this.rcSelect.focus();
}
}, {
key: "blur",
value: function blur() {
this.rcSelect.blur();
}
}, {
key: "isCombobox",
value: function isCombobox() {
var mode = this.props.mode;
return mode === 'combobox' || mode === Select.SECRET_COMBOBOX_MODE_DO_NOT_USE;
}
}, {
key: "renderSuffixIcon",
value: function renderSuffixIcon(prefixCls) {
var _this$props = this.props,
loading = _this$props.loading,
suffixIcon = _this$props.suffixIcon;
if (suffixIcon) {
return React.isValidElement(suffixIcon) ? React.cloneElement(suffixIcon, {
className: classNames(suffixIcon.props.className, "".concat(prefixCls, "-arrow-icon"))
}) : suffixIcon;
}
if (loading) {
return React.createElement(Icon, {
type: "loading"
});
}
return React.createElement(Icon, {
type: "down",
className: "".concat(prefixCls, "-arrow-icon")
});
}
}, {
key: "render",
value: function render() {
return React.createElement(ConfigConsumer, null, this.renderSelect);
}
}]);
return Select;
}(React.Component);
export { Select as default };
Select.Option = Option;
Select.OptGroup = OptGroup;
Select.SECRET_COMBOBOX_MODE_DO_NOT_USE = 'SECRET_COMBOBOX_MODE_DO_NOT_USE';
Select.defaultProps = {
showSearch: false,
transitionName: 'slide-up',
choiceTransitionName: 'zoom'
};
Select.propTypes = SelectPropTypes;
//# sourceMappingURL=index.js.map