Files
icehrm/web/node_modules/rc-select/es/Selector/SingleSelector.js
2020-05-20 18:47:29 +02:00

67 lines
2.2 KiB
JavaScript

import React from 'react';
import Input from './Input';
var SingleSelector = function SingleSelector(_ref) {
var inputElement = _ref.inputElement,
prefixCls = _ref.prefixCls,
id = _ref.id,
inputRef = _ref.inputRef,
disabled = _ref.disabled,
autoFocus = _ref.autoFocus,
autoComplete = _ref.autoComplete,
accessibilityIndex = _ref.accessibilityIndex,
mode = _ref.mode,
open = _ref.open,
values = _ref.values,
placeholder = _ref.placeholder,
tabIndex = _ref.tabIndex,
showSearch = _ref.showSearch,
searchValue = _ref.searchValue,
activeValue = _ref.activeValue,
onInputKeyDown = _ref.onInputKeyDown,
onInputMouseDown = _ref.onInputMouseDown,
onInputChange = _ref.onInputChange,
onInputPaste = _ref.onInputPaste;
var combobox = mode === 'combobox';
var inputEditable = combobox || showSearch && open;
var item = values[0];
var getDisplayValue = function getDisplayValue(value) {
return value === null ? '' : String(value);
};
var inputValue = searchValue;
if (combobox) {
inputValue = item ? getDisplayValue(item.value) : activeValue || searchValue;
} // Not show text when closed expect combobox mode
var hasTextInput = mode !== 'combobox' && !open ? false : !!inputValue;
return React.createElement(React.Fragment, null, React.createElement("span", {
className: "".concat(prefixCls, "-selection-search")
}, React.createElement(Input, {
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: onInputChange,
onPaste: onInputPaste,
tabIndex: tabIndex
})), !combobox && item && !hasTextInput && React.createElement("span", {
className: "".concat(prefixCls, "-selection-item")
}, item.label), !item && !hasTextInput && React.createElement("span", {
className: "".concat(prefixCls, "-selection-placeholder")
}, placeholder));
};
export default SingleSelector;