@aimake/nanod
Version:
## 设计模式 NANO DESIGN 是面向于企业级中台化应用的解决方案。服务于 ToB 和 ToE 类型的单页应用,应用于各产品中从而产出了一套设计及前端规范。
326 lines (275 loc) • 11.5 kB
JavaScript
;
var _typeof3 = require("babel-runtime/helpers/typeof");
var _typeof4 = _interopRequireDefault2(_typeof3);
function _interopRequireDefault2(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var React = _interopRequireWildcard(require("react"));
var PropTypes = _interopRequireWildcard(require("prop-types"));
var _rcSelect = _interopRequireWildcard(require("rc-select"));
var _classnames = _interopRequireDefault(require("classnames"));
var _configProvider = require("../config-provider");
var _omit = _interopRequireDefault(require("omit.js"));
var _warning = _interopRequireDefault(require("warning"));
var _icon = _interopRequireDefault(require("../icon"));
var _type = require("../_util/type");
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { "default": obj };
}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
return obj;
} else {
var newObj = {};if (obj != null) {
for (var key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};if (desc.get || desc.set) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
}newObj["default"] = obj;return newObj;
}
}
function _typeof(obj) {
if (typeof Symbol === "function" && (0, _typeof4["default"])(Symbol.iterator) === "symbol") {
_typeof = function _typeof(obj) {
return typeof obj === "undefined" ? "undefined" : (0, _typeof4["default"])(obj);
};
} else {
_typeof = function _typeof(obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj === "undefined" ? "undefined" : (0, _typeof4["default"])(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 = void 0 && (void 0).__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) t[p[i]] = s[p[i]];
}
return t;
};
var SelectSizes = (0, _type.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,
restProps = __rest(_a, ["prefixCls", "className", "size", "mode", "getPopupContainer", "removeIcon", "clearIcon", "menuItemSelectedIcon"]);
var rest = (0, _omit["default"])(restProps, ['inputIcon']);
var prefixCls = getPrefixCls('select', customizePrefixCls);
var cls = (0, _classnames["default"])((_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-lg"), size === 'large'), _defineProperty(_classNames, "".concat(prefixCls, "-sm"), size === 'small'), _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: (0, _classnames["default"])(removeIcon.props.className, "".concat(prefixCls, "-remove-icon"))
}) : removeIcon) || React.createElement(_icon["default"], {
type: "close",
className: "".concat(prefixCls, "-remove-icon")
});
var finalClearIcon = clearIcon && (React.isValidElement(clearIcon) ? React.cloneElement(clearIcon, {
className: (0, _classnames["default"])(clearIcon.props.className, "".concat(prefixCls, "-clear-icon"))
}) : clearIcon) || React.createElement(_icon["default"], {
type: "close-circle",
theme: "filled",
className: "".concat(prefixCls, "-clear-icon")
});
var finalMenuItemSelectedIcon = menuItemSelectedIcon && (React.isValidElement(menuItemSelectedIcon) ? React.cloneElement(menuItemSelectedIcon, {
className: (0, _classnames["default"])(menuItemSelectedIcon.props.className, "".concat(prefixCls, "-selected-icon"))
}) : menuItemSelectedIcon) || React.createElement(_icon["default"], {
type: "check",
className: "".concat(prefixCls, "-selected-icon")
});
return React.createElement(_rcSelect["default"], _extends({
inputIcon: _this.renderSuffixIcon(prefixCls),
removeIcon: finalRemoveIcon,
clearIcon: finalClearIcon,
menuItemSelectedIcon: finalMenuItemSelectedIcon
}, rest, modeConfig, {
prefixCls: prefixCls,
className: cls,
optionLabelProp: optionLabelProp || 'children',
notFoundContent: _this.getNotFoundContent(renderEmpty),
getPopupContainer: getPopupContainer || getContextPopupContainer,
ref: _this.saveSelect
}));
};
(0, _warning["default"])(props.mode !== 'combobox', 'The combobox mode of Select is deprecated, ' + 'it will be removed in next major version, ' + 'please use AutoComplete instead');
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(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: "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: (0, _classnames["default"])(suffixIcon.props.className, "".concat(prefixCls, "-arrow-icon"))
}) : suffixIcon;
}
if (loading) {
return React.createElement(_icon["default"], {
type: "loading"
});
}
return React.createElement(_icon["default"], {
type: "down",
className: "".concat(prefixCls, "-arrow-icon")
});
}
}, {
key: "render",
value: function render() {
return React.createElement(_configProvider.ConfigConsumer, null, this.renderSelect);
}
}]);
return Select;
}(React.Component);
exports["default"] = Select;
Select.Option = _rcSelect.Option;
Select.OptGroup = _rcSelect.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;