@commercetools-uikit/selectable-search-input 0.0.0-canary-20230223135944
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +159 -0
- package/dist/commercetools-uikit-selectable-search-input.cjs.d.ts +2 -0
- package/dist/commercetools-uikit-selectable-search-input.cjs.dev.js +638 -0
- package/dist/commercetools-uikit-selectable-search-input.cjs.js +7 -0
- package/dist/commercetools-uikit-selectable-search-input.cjs.prod.js +579 -0
- package/dist/commercetools-uikit-selectable-search-input.esm.js +613 -0
- package/dist/declarations/src/index.d.ts +2 -0
- package/dist/declarations/src/selectable-search-input.d.ts +62 -0
- package/dist/declarations/src/selectable-search-input.styles.d.ts +425 -0
- package/dist/declarations/src/selectable-select.d.ts +13 -0
- package/dist/declarations/src/version.d.ts +2 -0
- package/package.json +54 -0
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
6
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
7
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
8
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
9
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
10
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
11
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
12
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
13
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
14
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
15
|
+
var _styled = require('@emotion/styled/base');
|
|
16
|
+
require('prop-types');
|
|
17
|
+
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
18
|
+
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
19
|
+
var react$1 = require('react');
|
|
20
|
+
var has = require('lodash/has');
|
|
21
|
+
var flatMap = require('lodash/flatMap');
|
|
22
|
+
var SecondaryIconButton = require('@commercetools-uikit/secondary-icon-button');
|
|
23
|
+
var Constraints = require('@commercetools-uikit/constraints');
|
|
24
|
+
var icons = require('@commercetools-uikit/icons');
|
|
25
|
+
var utils = require('@commercetools-uikit/utils');
|
|
26
|
+
var react = require('@emotion/react');
|
|
27
|
+
var inputUtils = require('@commercetools-uikit/input-utils');
|
|
28
|
+
var designSystem = require('@commercetools-uikit/design-system');
|
|
29
|
+
var selectUtils = require('@commercetools-uikit/select-utils');
|
|
30
|
+
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
31
|
+
var reactIntl = require('react-intl');
|
|
32
|
+
var Select = require('react-select');
|
|
33
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
34
|
+
var hooks = require('@commercetools-uikit/hooks');
|
|
35
|
+
|
|
36
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
37
|
+
|
|
38
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
39
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
40
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
41
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
42
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
43
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
44
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
45
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
46
|
+
var _styled__default = /*#__PURE__*/_interopDefault(_styled);
|
|
47
|
+
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
48
|
+
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
49
|
+
var has__default = /*#__PURE__*/_interopDefault(has);
|
|
50
|
+
var flatMap__default = /*#__PURE__*/_interopDefault(flatMap);
|
|
51
|
+
var SecondaryIconButton__default = /*#__PURE__*/_interopDefault(SecondaryIconButton);
|
|
52
|
+
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
53
|
+
var Select__default = /*#__PURE__*/_interopDefault(Select);
|
|
54
|
+
|
|
55
|
+
function ownKeys$2(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
56
|
+
|
|
57
|
+
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$2(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
58
|
+
|
|
59
|
+
var getInputContainerBorderColor = function getInputContainerBorderColor(props) {
|
|
60
|
+
var defaultColor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : designSystem.designTokens.borderColorForInput;
|
|
61
|
+
|
|
62
|
+
if (props.hasError) {
|
|
63
|
+
return designSystem.designTokens.borderColorForInputWhenError;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (props.hasWarning) {
|
|
67
|
+
return designSystem.designTokens.borderColorForInputWhenWarning;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (props.isDisabled) {
|
|
71
|
+
return designSystem.designTokens.borderColorForInputWhenDisabled;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (props.isReadOnly) {
|
|
75
|
+
return designSystem.designTokens.borderColorForInputWhenReadonly;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return defaultColor;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
var getInputFontColor = function getInputFontColor(props) {
|
|
82
|
+
if (props.hasError) {
|
|
83
|
+
return designSystem.designTokens.fontColorForInputWhenError;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (props.hasWarning) {
|
|
87
|
+
return designSystem.designTokens.fontColorForInputWhenWarning;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (props.isDisabled) {
|
|
91
|
+
return designSystem.designTokens.fontColorForInputWhenDisabled;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (props.isReadOnly) {
|
|
95
|
+
return designSystem.designTokens.fontColorForInputWhenReadonly;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return designSystem.designTokens.fontColorForInput;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
var getInputBoxShadow = function getInputBoxShadow(props) {
|
|
102
|
+
if (props.hasError) {
|
|
103
|
+
return designSystem.designTokens.shadowForInputWhenError;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (props.hasWarning) {
|
|
107
|
+
return designSystem.designTokens.shadowForInputWhenWarning;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return designSystem.designTokens.shadowForInput;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
var getSelectableSearchInputStyles = function getSelectableSearchInputStyles(props) {
|
|
114
|
+
return [inputUtils.getInputStyles(props), /*#__PURE__*/react.css("border:none;background:none;&,&:focus{box-shadow:none;}&:focus,&:hover{background-color:transparent!important;}width:100%;color:", getInputFontColor(props), ";" + ("" ), "" )];
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
var getButtonStyles = function getButtonStyles() {
|
|
118
|
+
return /*#__PURE__*/react.css("border:none;background:none;height:100%;border-top-right-radius:", designSystem.designTokens.borderRadiusForInput, ";border-bottom-right-radius:", designSystem.designTokens.borderRadiusForInput, ";border-left:none;align-items:center;transition:border-color ", designSystem.designTokens.transitionStandard, ",background-color ", designSystem.designTokens.transitionStandard, ";transition:border-color ", designSystem.designTokens.transitionStandard, ",box-shadow ", designSystem.designTokens.transitionStandard, ";margin-right:", designSystem.designTokens.marginRightForClearInputIcon, ";" + ("" ), "" );
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
var getIconColor = function getIconColor(props, defaultColor) {
|
|
122
|
+
if (props.isDisabled) {
|
|
123
|
+
return designSystem.designTokens.fontColorForInputWhenDisabled;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (props.isReadOnly) {
|
|
127
|
+
return designSystem.designTokens.fontColorForSearchInputIconWhenReadonly;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return defaultColor;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
var getClearIconButtonStyles = function getClearIconButtonStyles(props) {
|
|
134
|
+
return [getButtonStyles(), /*#__PURE__*/react.css("fill:", getIconColor(props, designSystem.designTokens.fontColorForClearInputIcon), ";&:hover{fill:", getIconColor(props, designSystem.designTokens.fontColorForClearInputIconWhenHovered), ";}" + ("" ), "" )];
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
var getSearchIconButtonStyles = function getSearchIconButtonStyles(props) {
|
|
138
|
+
return [getButtonStyles(), /*#__PURE__*/react.css("margin-right:", designSystem.designTokens.marginRightForSearchInputIcon, ";fill:", getIconColor(props, designSystem.designTokens.fontColorForSearchInputIcon), ";&:hover{fill:", getIconColor(props, designSystem.designTokens.fontColorForSearchInputIconWhenHovered), ";}" + ("" ), "" )];
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
var getBackgroundColor = function getBackgroundColor(props, defaultColor) {
|
|
142
|
+
if (props.isDisabled) {
|
|
143
|
+
return designSystem.designTokens.backgroundColorForInputWhenDisabled;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (props.isReadOnly) {
|
|
147
|
+
return designSystem.designTokens.backgroundColorForInputWhenReadonly;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return defaultColor;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
var getSelectableSearchInputContainerStyles = function getSelectableSearchInputContainerStyles(props) {
|
|
154
|
+
return [/*#__PURE__*/react.css("display:flex;align-items:center;background-color:", getBackgroundColor(props, designSystem.designTokens.backgroundColorForInput), ";border:1px solid ", getInputContainerBorderColor(props), ";border-radius:", designSystem.designTokens.borderRadiusForInput, ";box-shadow:", getInputBoxShadow(props), ";height:", designSystem.designTokens.heightForInput, ";box-sizing:border-box;border-top-left-radius:0;border-bottom-left-radius:0;margin-left:0;width:100%;transition:border-color ", designSystem.designTokens.transitionStandard, ",background-color ", designSystem.designTokens.transitionStandard, ";&::placeholder{color:", designSystem.designTokens.placeholderFontColorForInput, ";}&:hover{border-color:", getInputContainerBorderColor(props, designSystem.designTokens.borderColorForInputWhenHovered), ";background-color:", getBackgroundColor(props, designSystem.designTokens.backgroundColorForInputWhenHovered), ";}&:focus-within{border-color:", designSystem.designTokens.borderColorForInputWhenFocused, ";box-shadow:", designSystem.designTokens.boxShadowForDatetimeInputWhenHovered, " ", designSystem.designTokens.borderColorForInputWhenFocused, ";}&:focus{border-color:", designSystem.designTokens.borderColorForInputWhenFocused, ";}" + ("" ), "" )];
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
var createSelectableSelectStyles = function createSelectableSelectStyles(_ref) {
|
|
158
|
+
var hasWarning = _ref.hasWarning,
|
|
159
|
+
hasError = _ref.hasError,
|
|
160
|
+
isDisabled = _ref.isDisabled,
|
|
161
|
+
isReadOnly = _ref.isReadOnly,
|
|
162
|
+
menuPortalZIndex = _ref.menuPortalZIndex,
|
|
163
|
+
isNewTheme = _ref.isNewTheme,
|
|
164
|
+
dropdownHasFocus = _ref.dropdownHasFocus,
|
|
165
|
+
textInputHasFocus = _ref.textInputHasFocus;
|
|
166
|
+
var selectStyles = selectUtils.createSelectStyles({
|
|
167
|
+
hasWarning: hasWarning,
|
|
168
|
+
hasError: hasError,
|
|
169
|
+
menuPortalZIndex: menuPortalZIndex,
|
|
170
|
+
isNewTheme: isNewTheme
|
|
171
|
+
});
|
|
172
|
+
return _objectSpread$2(_objectSpread$2({}, selectStyles), {}, {
|
|
173
|
+
control: function control(base, state) {
|
|
174
|
+
return _objectSpread$2(_objectSpread$2({}, selectStyles.control(base, state)), {}, {
|
|
175
|
+
padding: designSystem.designTokens.paddingForSelectableSearchInputDropdown,
|
|
176
|
+
borderTopRightRadius: '0',
|
|
177
|
+
borderBottomRightRadius: '0',
|
|
178
|
+
borderRight: '0',
|
|
179
|
+
height: '100%',
|
|
180
|
+
borderColor: function () {
|
|
181
|
+
if (hasError) return designSystem.designTokens.borderColorForInputWhenError;
|
|
182
|
+
if (hasWarning) return designSystem.designTokens.borderColorForInputWhenWarning;
|
|
183
|
+
if (isDisabled) return "".concat(designSystem.designTokens.borderColorForInputWhenDisabled, " !important");
|
|
184
|
+
|
|
185
|
+
if (textInputHasFocus && !isNewTheme) {
|
|
186
|
+
return designSystem.designTokens.borderColorForInputWhenFocused;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (dropdownHasFocus) {
|
|
190
|
+
return designSystem.designTokens.borderColorForInputWhenFocused;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (isReadOnly) return "".concat(designSystem.designTokens.borderColorForInputWhenReadonly, " !important");
|
|
194
|
+
return designSystem.designTokens.borderColorForInput;
|
|
195
|
+
}(),
|
|
196
|
+
cursor: function () {
|
|
197
|
+
if (isDisabled) return 'not-allowed';
|
|
198
|
+
if (isReadOnly) return "default";
|
|
199
|
+
return 'pointer';
|
|
200
|
+
}(),
|
|
201
|
+
backgroundColor: getBackgroundColor({
|
|
202
|
+
isDisabled: isDisabled,
|
|
203
|
+
isReadOnly: isReadOnly
|
|
204
|
+
}, base.backgroundColor || ''),
|
|
205
|
+
'&:hover': {
|
|
206
|
+
backgroundColor: getBackgroundColor({
|
|
207
|
+
isDisabled: isDisabled,
|
|
208
|
+
isReadOnly: isReadOnly
|
|
209
|
+
}, designSystem.designTokens.backgroundColorForInputWhenHovered)
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
},
|
|
213
|
+
singleValue: function singleValue(base) {
|
|
214
|
+
return _objectSpread$2(_objectSpread$2({}, base), {}, {
|
|
215
|
+
marginLeft: 0,
|
|
216
|
+
maxWidth: 'initial',
|
|
217
|
+
color: getInputFontColor({
|
|
218
|
+
hasWarning: hasWarning,
|
|
219
|
+
hasError: hasError,
|
|
220
|
+
isDisabled: isDisabled,
|
|
221
|
+
isReadOnly: isReadOnly
|
|
222
|
+
})
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
dropdownIndicator: function dropdownIndicator() {
|
|
226
|
+
return {
|
|
227
|
+
fill: isReadOnly ? designSystem.designTokens.fontColorForInputWhenDisabled : designSystem.designTokens.fontColorForSelectInputIcon
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
var _excluded = ["id"];
|
|
234
|
+
|
|
235
|
+
function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
236
|
+
|
|
237
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
238
|
+
|
|
239
|
+
var _SingleValue = function SingleValue(_ref) {
|
|
240
|
+
var id = _ref.id,
|
|
241
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
242
|
+
|
|
243
|
+
return jsxRuntime.jsx(Select.components.SingleValue, _objectSpread$1(_objectSpread$1({}, props), {}, {
|
|
244
|
+
children: jsxRuntime.jsx("label", {
|
|
245
|
+
htmlFor: id,
|
|
246
|
+
children: props.children
|
|
247
|
+
})
|
|
248
|
+
}));
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
_SingleValue.propTypes = {};
|
|
252
|
+
|
|
253
|
+
var SelectableSelect = function SelectableSelect(props) {
|
|
254
|
+
var intl = reactIntl.useIntl();
|
|
255
|
+
|
|
256
|
+
var _useTheme = designSystem.useTheme(),
|
|
257
|
+
isNewTheme = _useTheme.isNewTheme;
|
|
258
|
+
|
|
259
|
+
var dropdownStyles = createSelectableSelectStyles({
|
|
260
|
+
hasWarning: props.hasWarning,
|
|
261
|
+
hasError: props.hasError,
|
|
262
|
+
isDisabled: props.isDisabled,
|
|
263
|
+
isReadOnly: props.isReadOnly,
|
|
264
|
+
menuPortalZIndex: props.menuPortalZIndex,
|
|
265
|
+
isNewTheme: isNewTheme,
|
|
266
|
+
dropdownHasFocus: props.dropdownHasFocus,
|
|
267
|
+
textInputHasFocus: props.textInputHasFocus
|
|
268
|
+
});
|
|
269
|
+
var onChange = props.onChange,
|
|
270
|
+
name = props.name,
|
|
271
|
+
id = props.id,
|
|
272
|
+
textInputRef = props.textInputRef;
|
|
273
|
+
var handleDropdownChange = react$1.useCallback(function (nextSelectedOptions) {
|
|
274
|
+
var _textInputRef$current;
|
|
275
|
+
|
|
276
|
+
if (onChange) {
|
|
277
|
+
onChange({
|
|
278
|
+
target: {
|
|
279
|
+
id: id,
|
|
280
|
+
name: name,
|
|
281
|
+
value: nextSelectedOptions.value
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
(_textInputRef$current = textInputRef.current) === null || _textInputRef$current === void 0 ? void 0 : _textInputRef$current.focus();
|
|
287
|
+
}, [onChange, id, name, textInputRef]);
|
|
288
|
+
return jsxRuntime.jsx(Select__default["default"], {
|
|
289
|
+
inputId: props.id,
|
|
290
|
+
name: props.name,
|
|
291
|
+
value: props.selectedOption,
|
|
292
|
+
isDisabled: props.isDisabled,
|
|
293
|
+
isSearchable: props.isReadOnly ? false : props.isMenuSearchable,
|
|
294
|
+
maxMenuHeight: props.maxMenuHeight,
|
|
295
|
+
closeMenuOnSelect: props.closeMenuOnSelect,
|
|
296
|
+
components: {
|
|
297
|
+
SingleValue: function SingleValue(innerProps) {
|
|
298
|
+
return jsxRuntime.jsx(_SingleValue, _objectSpread$1(_objectSpread$1({}, innerProps), {}, {
|
|
299
|
+
id: props.id
|
|
300
|
+
}));
|
|
301
|
+
},
|
|
302
|
+
DropdownIndicator: selectUtils.DropdownIndicator
|
|
303
|
+
},
|
|
304
|
+
options: props.options,
|
|
305
|
+
menuIsOpen: props.isReadOnly ? false : undefined,
|
|
306
|
+
placeholder: "",
|
|
307
|
+
styles: dropdownStyles,
|
|
308
|
+
onFocus: props.handleDropdownFocus,
|
|
309
|
+
menuPortalTarget: props.menuPortalTarget,
|
|
310
|
+
menuShouldBlockScroll: props.menuShouldBlockScroll,
|
|
311
|
+
onBlur: props.handleDropdownBlur,
|
|
312
|
+
onChange: handleDropdownChange,
|
|
313
|
+
onInputChange: props.onMenuInputChange,
|
|
314
|
+
noOptionsMessage: props.noMenuOptionsMessage || function (_ref2) {
|
|
315
|
+
var inputValue = _ref2.inputValue;
|
|
316
|
+
return !inputValue || inputValue === '' ? intl.formatMessage(selectUtils.messages.noOptionsMessageWithoutInputValue) : intl.formatMessage(selectUtils.messages.noOptionsMessageWithInputValue, {
|
|
317
|
+
inputValue: inputValue
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
SelectableSelect.propTypes = {};
|
|
324
|
+
var SelectableSelect$1 = SelectableSelect;
|
|
325
|
+
|
|
326
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
327
|
+
|
|
328
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
329
|
+
|
|
330
|
+
var Container = /*#__PURE__*/_styled__default["default"]("div", {
|
|
331
|
+
target: "encv1cf0"
|
|
332
|
+
} )({
|
|
333
|
+
name: "zjik7",
|
|
334
|
+
styles: "display:flex"
|
|
335
|
+
} );
|
|
336
|
+
|
|
337
|
+
var getTextInputName = function getTextInputName(name) {
|
|
338
|
+
return name ? "".concat(name, ".textInput") : undefined;
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
var getDropdownName = function getDropdownName(name) {
|
|
342
|
+
return name ? "".concat(name, ".dropdown") : undefined;
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
var defaultProps = {
|
|
346
|
+
horizontalConstraint: 'scale',
|
|
347
|
+
isClearable: true,
|
|
348
|
+
menuHorizontalConstraint: 3,
|
|
349
|
+
showSubmitButton: true
|
|
350
|
+
};
|
|
351
|
+
var selectableSearchInputSequentialId = utils.createSequentialId('selectable-search-input-');
|
|
352
|
+
|
|
353
|
+
var SelectableSearchInput = function SelectableSearchInput(props) {
|
|
354
|
+
var _useToggleState = hooks.useToggleState(false),
|
|
355
|
+
_useToggleState2 = _slicedToArray(_useToggleState, 2),
|
|
356
|
+
textInputHasFocus = _useToggleState2[0],
|
|
357
|
+
toggleTextInputHasFocus = _useToggleState2[1];
|
|
358
|
+
|
|
359
|
+
var _useToggleState3 = hooks.useToggleState(false),
|
|
360
|
+
_useToggleState4 = _slicedToArray(_useToggleState3, 2),
|
|
361
|
+
dropdownHasFocus = _useToggleState4[0],
|
|
362
|
+
toggleDropdownHasFocus = _useToggleState4[1];
|
|
363
|
+
|
|
364
|
+
var _useState = react$1.useState(props.value.text || ''),
|
|
365
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
366
|
+
searchValue = _useState2[0],
|
|
367
|
+
setSearchValue = _useState2[1];
|
|
368
|
+
|
|
369
|
+
var containerRef = react$1.useRef(null);
|
|
370
|
+
var textInputRef = react$1.useRef(null);
|
|
371
|
+
|
|
372
|
+
var _useTheme = designSystem.useTheme(),
|
|
373
|
+
isNewTheme = _useTheme.isNewTheme;
|
|
374
|
+
|
|
375
|
+
var optionsWithoutGroups = flatMap__default["default"](props.options, function (option) {
|
|
376
|
+
return has__default["default"](option, 'value') ? option : option.options;
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
var selectedOption = _findInstanceProperty__default["default"](optionsWithoutGroups).call(optionsWithoutGroups, function (option) {
|
|
380
|
+
return has__default["default"](option, 'value') && option.value === props.value.option;
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
var selectablSearchInputId = hooks.useFieldId(props.id, selectableSearchInputSequentialId);
|
|
384
|
+
|
|
385
|
+
if (!props.isReadOnly) ;
|
|
386
|
+
|
|
387
|
+
var onFocus = props.onFocus,
|
|
388
|
+
onBlur = props.onBlur,
|
|
389
|
+
name = props.name;
|
|
390
|
+
var handleTextInputFocus = react$1.useCallback(function () {
|
|
391
|
+
if (onFocus) {
|
|
392
|
+
onFocus({
|
|
393
|
+
target: {
|
|
394
|
+
id: SelectableSearchInput.getTextInputId(selectablSearchInputId),
|
|
395
|
+
name: getTextInputName(name)
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
toggleTextInputHasFocus(true);
|
|
401
|
+
}, [toggleTextInputHasFocus, onFocus, selectablSearchInputId, name]);
|
|
402
|
+
var handleTextInputBlur = react$1.useCallback(function () {
|
|
403
|
+
if (onBlur) {
|
|
404
|
+
onBlur({
|
|
405
|
+
target: {
|
|
406
|
+
id: SelectableSearchInput.getTextInputId(selectablSearchInputId),
|
|
407
|
+
name: getTextInputName(name)
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
toggleTextInputHasFocus(false);
|
|
413
|
+
}, [toggleTextInputHasFocus, onBlur, selectablSearchInputId, name]);
|
|
414
|
+
|
|
415
|
+
var handleClear = function handleClear() {
|
|
416
|
+
setSearchValue('');
|
|
417
|
+
|
|
418
|
+
if (props.onReset) {
|
|
419
|
+
props.onReset();
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
var handleChange = function handleChange(event) {
|
|
424
|
+
setSearchValue(event.target.value);
|
|
425
|
+
|
|
426
|
+
if (props.onChange) {
|
|
427
|
+
props.onChange({
|
|
428
|
+
target: {
|
|
429
|
+
id: SelectableSearchInput.getTextInputId(selectablSearchInputId),
|
|
430
|
+
name: getTextInputName(props.name),
|
|
431
|
+
value: event.target.value
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
var handleSubmit = function handleSubmit(event) {
|
|
438
|
+
event.preventDefault();
|
|
439
|
+
|
|
440
|
+
if (props.onSubmit) {
|
|
441
|
+
props.onSubmit({
|
|
442
|
+
text: searchValue,
|
|
443
|
+
option: selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.value
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
var dropdownName = getDropdownName(props.name);
|
|
449
|
+
var dropdownId = SelectableSearchInput.getDropdownId(selectablSearchInputId);
|
|
450
|
+
var handleDropdownFocus = react$1.useCallback(function () {
|
|
451
|
+
if (onFocus) {
|
|
452
|
+
onFocus({
|
|
453
|
+
target: {
|
|
454
|
+
id: dropdownId,
|
|
455
|
+
name: dropdownName
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
toggleDropdownHasFocus(true);
|
|
461
|
+
}, [onFocus, toggleDropdownHasFocus, dropdownName, dropdownId]);
|
|
462
|
+
var handleDropdownBlur = react$1.useCallback(function () {
|
|
463
|
+
if (onBlur) {
|
|
464
|
+
onBlur({
|
|
465
|
+
target: {
|
|
466
|
+
id: dropdownId,
|
|
467
|
+
name: dropdownName
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
toggleDropdownHasFocus(false);
|
|
473
|
+
}, [toggleDropdownHasFocus, onBlur, dropdownName, dropdownId]);
|
|
474
|
+
var handleContainerBlur = react$1.useCallback(function (event) {
|
|
475
|
+
var _containerRef$current;
|
|
476
|
+
|
|
477
|
+
// ensures that both fields are marked as touched when one of them
|
|
478
|
+
// is blurred
|
|
479
|
+
if (typeof onBlur === 'function' && !((_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 && _containerRef$current.contains(event.relatedTarget))) {
|
|
480
|
+
onBlur({
|
|
481
|
+
target: {
|
|
482
|
+
id: SelectableSearchInput.getDropdownId(selectablSearchInputId),
|
|
483
|
+
name: getDropdownName(name)
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
onBlur({
|
|
487
|
+
target: {
|
|
488
|
+
id: SelectableSearchInput.getTextInputId(selectablSearchInputId),
|
|
489
|
+
name: getTextInputName(name)
|
|
490
|
+
}
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}, [onBlur, selectablSearchInputId, name]);
|
|
494
|
+
return jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
495
|
+
max: props.horizontalConstraint,
|
|
496
|
+
children: jsxRuntime.jsxs(Container, {
|
|
497
|
+
ref: containerRef,
|
|
498
|
+
onBlur: handleContainerBlur,
|
|
499
|
+
"data-testid": "selectable-search-input-container",
|
|
500
|
+
children: [jsxRuntime.jsx(Constraints__default["default"].Horizontal, {
|
|
501
|
+
max: props.menuHorizontalConstraint,
|
|
502
|
+
children: jsxRuntime.jsx(SelectableSelect$1, _objectSpread(_objectSpread({}, props), {}, {
|
|
503
|
+
id: SelectableSearchInput.getDropdownId(selectablSearchInputId),
|
|
504
|
+
name: getDropdownName(props.name),
|
|
505
|
+
textInputHasFocus: textInputHasFocus,
|
|
506
|
+
dropdownHasFocus: dropdownHasFocus,
|
|
507
|
+
handleDropdownFocus: handleDropdownFocus,
|
|
508
|
+
handleDropdownBlur: handleDropdownBlur,
|
|
509
|
+
isNewTheme: isNewTheme,
|
|
510
|
+
textInputRef: textInputRef,
|
|
511
|
+
selectedOption: selectedOption
|
|
512
|
+
}))
|
|
513
|
+
}), jsxRuntime.jsxs("div", {
|
|
514
|
+
css: [getSelectableSearchInputContainerStyles(props), dropdownHasFocus && isNewTheme && /*#__PURE__*/react.css("border-left-color:", designSystem.designTokens.borderColorForInputWhenFocused, ";&:hover{border-left-color:", designSystem.designTokens.borderColorForInputWhenFocused, ";}" + ("" ), "" ), "" , "" ],
|
|
515
|
+
children: [jsxRuntime.jsx("input", _objectSpread(_objectSpread({
|
|
516
|
+
ref: textInputRef,
|
|
517
|
+
id: SelectableSearchInput.getTextInputId(selectablSearchInputId),
|
|
518
|
+
name: getTextInputName(props.name),
|
|
519
|
+
type: "text",
|
|
520
|
+
value: searchValue,
|
|
521
|
+
onChange: handleChange,
|
|
522
|
+
onBlur: handleTextInputBlur,
|
|
523
|
+
onFocus: handleTextInputFocus,
|
|
524
|
+
disabled: props.isDisabled,
|
|
525
|
+
placeholder: props.placeholder,
|
|
526
|
+
readOnly: props.isReadOnly,
|
|
527
|
+
autoFocus: props.isAutofocussed,
|
|
528
|
+
autoComplete: props.autoComplete,
|
|
529
|
+
"aria-readonly": props.isReadOnly,
|
|
530
|
+
contentEditable: !props.isReadOnly,
|
|
531
|
+
css: getSelectableSearchInputStyles(props)
|
|
532
|
+
}, utils.filterDataAttributes(props)), {}, {
|
|
533
|
+
/* ARIA */
|
|
534
|
+
"aria-invalid": props['aria-invalid'],
|
|
535
|
+
"aria-errormessage": props['aria-errormessage'],
|
|
536
|
+
"data-testid": "selectable-input",
|
|
537
|
+
onKeyDown: function onKeyDown(event) {
|
|
538
|
+
if (!props.isReadOnly && event.key === 'Enter') {
|
|
539
|
+
handleSubmit(event);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
})), props.isClearable && searchValue && !props.isDisabled && !props.isReadOnly && jsxRuntime.jsx(SecondaryIconButton__default["default"], {
|
|
543
|
+
icon: jsxRuntime.jsx(icons.CloseIcon, {
|
|
544
|
+
size: "medium"
|
|
545
|
+
}),
|
|
546
|
+
label: 'clear-button',
|
|
547
|
+
onClick: handleClear,
|
|
548
|
+
css: getClearIconButtonStyles(props)
|
|
549
|
+
}), props.showSubmitButton && jsxRuntime.jsx(SecondaryIconButton__default["default"], {
|
|
550
|
+
icon: jsxRuntime.jsx(icons.SearchIcon, {}),
|
|
551
|
+
label: 'search-button',
|
|
552
|
+
onClick: handleSubmit,
|
|
553
|
+
css: getSearchIconButtonStyles(props),
|
|
554
|
+
isDisabled: props.isDisabled
|
|
555
|
+
})]
|
|
556
|
+
})]
|
|
557
|
+
})
|
|
558
|
+
});
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
SelectableSearchInput.propTypes = {};
|
|
562
|
+
SelectableSearchInput.displayName = 'SelectableSearchInput';
|
|
563
|
+
SelectableSearchInput.defaultProps = defaultProps;
|
|
564
|
+
|
|
565
|
+
SelectableSearchInput.isEmpty = function (formValue) {
|
|
566
|
+
var _context;
|
|
567
|
+
|
|
568
|
+
return !formValue || _trimInstanceProperty__default["default"](_context = formValue.text).call(_context) === '';
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
SelectableSearchInput.getTextInputId = getTextInputName;
|
|
572
|
+
SelectableSearchInput.getDropdownId = getDropdownName;
|
|
573
|
+
var SelectableSearchInput$1 = SelectableSearchInput;
|
|
574
|
+
|
|
575
|
+
// NOTE: This string will be replaced on build time with the package version.
|
|
576
|
+
var version = "15.12.0";
|
|
577
|
+
|
|
578
|
+
exports["default"] = SelectableSearchInput$1;
|
|
579
|
+
exports.version = version;
|