1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 | var _typeof = require("@babel/runtime/helpers/typeof");
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.default = void 0;
|
9 | var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
10 | var React = _interopRequireWildcard(require("react"));
|
11 | var _pickAttrs = _interopRequireDefault(require("rc-util/lib/pickAttrs"));
|
12 | var _Input = _interopRequireDefault(require("./Input"));
|
13 | var _commonUtil = require("../utils/commonUtil");
|
14 | function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
15 | function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
16 | var SingleSelector = function SingleSelector(props) {
|
17 | var inputElement = props.inputElement,
|
18 | prefixCls = props.prefixCls,
|
19 | id = props.id,
|
20 | inputRef = props.inputRef,
|
21 | disabled = props.disabled,
|
22 | autoFocus = props.autoFocus,
|
23 | autoComplete = props.autoComplete,
|
24 | activeDescendantId = props.activeDescendantId,
|
25 | mode = props.mode,
|
26 | open = props.open,
|
27 | values = props.values,
|
28 | placeholder = props.placeholder,
|
29 | tabIndex = props.tabIndex,
|
30 | showSearch = props.showSearch,
|
31 | searchValue = props.searchValue,
|
32 | activeValue = props.activeValue,
|
33 | maxLength = props.maxLength,
|
34 | onInputKeyDown = props.onInputKeyDown,
|
35 | onInputMouseDown = props.onInputMouseDown,
|
36 | onInputChange = props.onInputChange,
|
37 | onInputPaste = props.onInputPaste,
|
38 | onInputCompositionStart = props.onInputCompositionStart,
|
39 | onInputCompositionEnd = props.onInputCompositionEnd,
|
40 | title = props.title;
|
41 | var _React$useState = React.useState(false),
|
42 | _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
|
43 | inputChanged = _React$useState2[0],
|
44 | setInputChanged = _React$useState2[1];
|
45 | var combobox = mode === 'combobox';
|
46 | var inputEditable = combobox || showSearch;
|
47 | var item = values[0];
|
48 | var inputValue = searchValue || '';
|
49 | if (combobox && activeValue && !inputChanged) {
|
50 | inputValue = activeValue;
|
51 | }
|
52 | React.useEffect(function () {
|
53 | if (combobox) {
|
54 | setInputChanged(false);
|
55 | }
|
56 | }, [combobox, activeValue]);
|
57 |
|
58 |
|
59 | var hasTextInput = mode !== 'combobox' && !open && !showSearch ? false : !!inputValue;
|
60 |
|
61 |
|
62 | var selectionTitle = title === undefined ? (0, _commonUtil.getTitle)(item) : title;
|
63 | var placeholderNode = React.useMemo(function () {
|
64 | if (item) {
|
65 | return null;
|
66 | }
|
67 | return React.createElement("span", {
|
68 | className: "".concat(prefixCls, "-selection-placeholder"),
|
69 | style: hasTextInput ? {
|
70 | visibility: 'hidden'
|
71 | } : undefined
|
72 | }, placeholder);
|
73 | }, [item, hasTextInput, placeholder, prefixCls]);
|
74 | return React.createElement("span", {
|
75 | className: "".concat(prefixCls, "-selection-wrap")
|
76 | }, React.createElement("span", {
|
77 | className: "".concat(prefixCls, "-selection-search")
|
78 | }, React.createElement(_Input.default, {
|
79 | ref: inputRef,
|
80 | prefixCls: prefixCls,
|
81 | id: id,
|
82 | open: open,
|
83 | inputElement: inputElement,
|
84 | disabled: disabled,
|
85 | autoFocus: autoFocus,
|
86 | autoComplete: autoComplete,
|
87 | editable: inputEditable,
|
88 | activeDescendantId: activeDescendantId,
|
89 | value: inputValue,
|
90 | onKeyDown: onInputKeyDown,
|
91 | onMouseDown: onInputMouseDown,
|
92 | onChange: function onChange(e) {
|
93 | setInputChanged(true);
|
94 | onInputChange(e);
|
95 | },
|
96 | onPaste: onInputPaste,
|
97 | onCompositionStart: onInputCompositionStart,
|
98 | onCompositionEnd: onInputCompositionEnd,
|
99 | tabIndex: tabIndex,
|
100 | attrs: (0, _pickAttrs.default)(props, true),
|
101 | maxLength: combobox ? maxLength : undefined
|
102 | })), !combobox && item ? React.createElement("span", {
|
103 | className: "".concat(prefixCls, "-selection-item"),
|
104 | title: selectionTitle
|
105 |
|
106 |
|
107 |
|
108 | ,
|
109 | style: hasTextInput ? {
|
110 | visibility: 'hidden'
|
111 | } : undefined
|
112 | }, item.label) : null, placeholderNode);
|
113 | };
|
114 | var _default = exports.default = SingleSelector; |
\ | No newline at end of file |