165 lines
8.3 KiB
JavaScript
165 lines
8.3 KiB
JavaScript
function _typeof(obj) { "@babel/helpers - typeof"; 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 _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 _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 _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 _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); }
|
|
|
|
function _createSuper(Derived) { 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); }; }
|
|
|
|
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 _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; } }
|
|
|
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
|
|
// TODO: 4.0 - codemod should help to change `filterOption` to support node props.
|
|
import * as React from 'react';
|
|
import omit from 'omit.js';
|
|
import classNames from 'classnames';
|
|
import RcSelect, { Option, OptGroup } from 'rc-select';
|
|
import { ConfigConsumer } from '../config-provider';
|
|
import getIcons from './utils/iconUtil';
|
|
import SizeContext from '../config-provider/SizeContext'; // We still use class here since `forwardRef` not support generic in typescript
|
|
|
|
var Select = /*#__PURE__*/function (_React$Component) {
|
|
_inherits(Select, _React$Component);
|
|
|
|
var _super = _createSuper(Select);
|
|
|
|
function Select() {
|
|
var _this;
|
|
|
|
_classCallCheck(this, Select);
|
|
|
|
_this = _super.apply(this, arguments);
|
|
_this.selectRef = React.createRef();
|
|
|
|
_this.focus = function () {
|
|
if (_this.selectRef.current) {
|
|
_this.selectRef.current.focus();
|
|
}
|
|
};
|
|
|
|
_this.blur = function () {
|
|
if (_this.selectRef.current) {
|
|
_this.selectRef.current.blur();
|
|
}
|
|
};
|
|
|
|
_this.getMode = function () {
|
|
var mode = _this.props.mode;
|
|
|
|
if (mode === 'combobox') {
|
|
return undefined;
|
|
}
|
|
|
|
if (mode === Select.SECRET_COMBOBOX_MODE_DO_NOT_USE) {
|
|
return 'combobox';
|
|
}
|
|
|
|
return mode;
|
|
};
|
|
|
|
_this.renderSelect = function (_ref) {
|
|
var getContextPopupContainer = _ref.getPopupContainer,
|
|
getPrefixCls = _ref.getPrefixCls,
|
|
renderEmpty = _ref.renderEmpty,
|
|
direction = _ref.direction;
|
|
var _this$props = _this.props,
|
|
customizePrefixCls = _this$props.prefixCls,
|
|
notFoundContent = _this$props.notFoundContent,
|
|
className = _this$props.className,
|
|
customizeSize = _this$props.size,
|
|
_this$props$listHeigh = _this$props.listHeight,
|
|
listHeight = _this$props$listHeigh === void 0 ? 256 : _this$props$listHeigh,
|
|
_this$props$listItemH = _this$props.listItemHeight,
|
|
listItemHeight = _this$props$listItemH === void 0 ? 32 : _this$props$listItemH,
|
|
getPopupContainer = _this$props.getPopupContainer,
|
|
dropdownClassName = _this$props.dropdownClassName,
|
|
bordered = _this$props.bordered;
|
|
var prefixCls = getPrefixCls('select', customizePrefixCls);
|
|
|
|
var mode = _this.getMode();
|
|
|
|
var isMultiple = mode === 'multiple' || mode === 'tags'; // ===================== Empty =====================
|
|
|
|
var mergedNotFound;
|
|
|
|
if (notFoundContent !== undefined) {
|
|
mergedNotFound = notFoundContent;
|
|
} else if (mode === 'combobox') {
|
|
mergedNotFound = null;
|
|
} else {
|
|
mergedNotFound = renderEmpty('Select');
|
|
} // ===================== Icons =====================
|
|
|
|
|
|
var _getIcons = getIcons(_extends(_extends({}, _this.props), {
|
|
multiple: isMultiple
|
|
})),
|
|
suffixIcon = _getIcons.suffixIcon,
|
|
itemIcon = _getIcons.itemIcon,
|
|
removeIcon = _getIcons.removeIcon,
|
|
clearIcon = _getIcons.clearIcon;
|
|
|
|
var selectProps = omit(_this.props, ['prefixCls', 'suffixIcon', 'itemIcon', 'removeIcon', 'clearIcon', 'size', 'bordered']);
|
|
var rcSelectRtlDropDownClassName = classNames(dropdownClassName, _defineProperty({}, "".concat(prefixCls, "-dropdown-").concat(direction), direction === 'rtl'));
|
|
return /*#__PURE__*/React.createElement(SizeContext.Consumer, null, function (size) {
|
|
var _classNames2;
|
|
|
|
var mergedSize = customizeSize || size;
|
|
var mergedClassName = classNames(className, (_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-lg"), mergedSize === 'large'), _defineProperty(_classNames2, "".concat(prefixCls, "-sm"), mergedSize === 'small'), _defineProperty(_classNames2, "".concat(prefixCls, "-rtl"), direction === 'rtl'), _defineProperty(_classNames2, "".concat(prefixCls, "-borderless"), !bordered), _classNames2));
|
|
return /*#__PURE__*/React.createElement(RcSelect, _extends({
|
|
ref: _this.selectRef
|
|
}, selectProps, {
|
|
listHeight: listHeight,
|
|
listItemHeight: listItemHeight,
|
|
mode: mode,
|
|
prefixCls: prefixCls,
|
|
direction: direction,
|
|
inputIcon: suffixIcon,
|
|
menuItemSelectedIcon: itemIcon,
|
|
removeIcon: removeIcon,
|
|
clearIcon: clearIcon,
|
|
notFoundContent: mergedNotFound,
|
|
className: mergedClassName,
|
|
getPopupContainer: getPopupContainer || getContextPopupContainer,
|
|
dropdownClassName: rcSelectRtlDropDownClassName
|
|
}));
|
|
});
|
|
};
|
|
|
|
return _this;
|
|
}
|
|
|
|
_createClass(Select, [{
|
|
key: "render",
|
|
value: function render() {
|
|
return /*#__PURE__*/React.createElement(ConfigConsumer, null, this.renderSelect);
|
|
}
|
|
}]);
|
|
|
|
return Select;
|
|
}(React.Component);
|
|
|
|
Select.Option = Option;
|
|
Select.OptGroup = OptGroup;
|
|
Select.SECRET_COMBOBOX_MODE_DO_NOT_USE = 'SECRET_COMBOBOX_MODE_DO_NOT_USE';
|
|
Select.defaultProps = {
|
|
transitionName: 'slide-up',
|
|
choiceTransitionName: 'zoom',
|
|
bordered: true
|
|
};
|
|
export default Select; |