acud
Version:
acg react 组件库
95 lines (94 loc) • 4.54 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var React = _interopRequireWildcard(require("react"));
var _pickAttrs = _interopRequireDefault(require("rc-util/lib/pickAttrs"));
var _LocaleReceiver = require("../../../locale-provider/LocaleReceiver");
var _Input = _interopRequireDefault(require("./Input"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var SingleSelector = function SingleSelector(props) {
var inputElement = props.inputElement,
prefixCls = props.prefixCls,
id = props.id,
inputRef = props.inputRef,
disabled = props.disabled,
autoFocus = props.autoFocus,
autoComplete = props.autoComplete,
accessibilityIndex = props.accessibilityIndex,
mode = props.mode,
open = props.open,
values = props.values,
placeholder = props.placeholder,
tabIndex = props.tabIndex,
showSearch = props.showSearch,
searchValue = props.searchValue,
activeValue = props.activeValue,
maxLength = props.maxLength,
onInputKeyDown = props.onInputKeyDown,
onInputMouseDown = props.onInputMouseDown,
onInputChange = props.onInputChange,
onInputPaste = props.onInputPaste,
onInputCompositionStart = props.onInputCompositionStart,
onInputCompositionEnd = props.onInputCompositionEnd;
var _useLocaleReceiver = (0, _LocaleReceiver.useLocaleReceiver)('Select'),
_useLocaleReceiver2 = (0, _slicedToArray2["default"])(_useLocaleReceiver, 1),
selectLocale = _useLocaleReceiver2[0];
var placeholderLocale = placeholder || selectLocale.placeholder;
var _React$useState = React.useState(false),
_React$useState2 = (0, _slicedToArray2["default"])(_React$useState, 2),
inputChanged = _React$useState2[0],
setInputChanged = _React$useState2[1];
var combobox = mode === 'combobox';
var inputEditable = combobox || showSearch;
var item = values[0];
var inputValue = searchValue || '';
if (combobox && activeValue && !inputChanged) {
inputValue = activeValue;
}
React.useEffect(function () {
if (combobox) {
setInputChanged(false);
}
}, [combobox, activeValue]);
// Not show text when closed expect combobox mode
var hasTextInput = mode !== 'combobox' && !open ? false : !!inputValue;
var title = item && (typeof item.label === 'string' || typeof item.label === 'number') ? item.label.toString() : undefined;
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-selection-search")
}, /*#__PURE__*/React.createElement(_Input["default"], {
ref: inputRef,
prefixCls: prefixCls,
id: id,
open: open,
inputElement: inputElement,
disabled: disabled,
autoFocus: autoFocus,
autoComplete: autoComplete,
editable: inputEditable,
accessibilityIndex: accessibilityIndex,
value: inputValue,
onKeyDown: onInputKeyDown,
onMouseDown: onInputMouseDown,
onChange: function onChange(e) {
setInputChanged(true);
onInputChange(e);
},
onPaste: onInputPaste,
onCompositionStart: onInputCompositionStart,
onCompositionEnd: onInputCompositionEnd,
tabIndex: tabIndex,
attrs: (0, _pickAttrs["default"])(props, true),
maxLength: combobox ? maxLength : undefined
})), !combobox && item && !hasTextInput && /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-selection-item"),
title: title
}, item.label), !item && !hasTextInput && /*#__PURE__*/React.createElement("span", {
className: "".concat(prefixCls, "-selection-placeholder")
}, placeholderLocale));
};
var _default = exports["default"] = SingleSelector;