@automattic/vip-design-system 0.30.2 → 0.32.0

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.
@@ -9,93 +9,153 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
9
9
 
10
10
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
11
 
12
- var _react = _interopRequireDefault(require("react"));
12
+ var _react = _interopRequireWildcard(require("react"));
13
13
 
14
14
  var _propTypes = _interopRequireDefault(require("prop-types"));
15
15
 
16
- var RadioGroupPrimitive = _interopRequireWildcard(require("@radix-ui/react-radio-group"));
17
-
18
- var _md = require("react-icons/md");
19
-
20
- var _ = require("../");
16
+ var _ScreenReaderText = _interopRequireDefault(require("../ScreenReaderText"));
21
17
 
22
18
  var _jsxRuntime = require("theme-ui/jsx-runtime");
23
19
 
24
- var _excluded = ["onChange", "groupLabel", "value", "options"];
20
+ var _excluded = ["id", "value", "className", "label", "description", "labelProps"],
21
+ _excluded2 = ["optionWidth", "name", "onChange", "groupLabel", "defaultValue", "options", "disabled"];
25
22
 
26
23
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
24
 
28
25
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
26
 
30
- var RadioBoxGroup = /*#__PURE__*/_react["default"].forwardRef(function (_ref, forwardRef) {
31
- var onChange = _ref.onChange,
32
- groupLabel = _ref.groupLabel,
33
- value = _ref.value,
34
- options = _ref.options,
35
- props = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
36
- return (0, _jsxRuntime.jsx)(RadioGroupPrimitive.Root, (0, _extends2["default"])({
37
- onValueChange: onChange,
27
+ /**
28
+ * Internal dependencies
29
+ */
30
+ var RadioOption = function RadioOption(_ref) {
31
+ var width = _ref.width,
32
+ disabled = _ref.disabled,
33
+ defaultValue = _ref.defaultValue,
34
+ _ref$option = _ref.option,
35
+ id = _ref$option.id,
36
+ value = _ref$option.value,
37
+ className = _ref$option.className,
38
+ label = _ref$option.label,
39
+ description = _ref$option.description,
40
+ _ref$option$labelProp = _ref$option.labelProps,
41
+ labelProps = _ref$option$labelProp === void 0 ? {} : _ref$option$labelProp,
42
+ restOption = (0, _objectWithoutPropertiesLoose2["default"])(_ref$option, _excluded),
43
+ name = _ref.name,
44
+ onChangeHandler = _ref.onChangeHandler;
45
+ var forLabel = id || value;
46
+ return (0, _jsxRuntime.jsxs)("div", {
38
47
  value: value,
39
- "aria-label": groupLabel,
40
- sx: {
48
+ id: "o" + forLabel,
49
+ sx: (0, _extends2["default"])({
50
+ width: width,
41
51
  display: 'flex',
42
- gap: 2
43
- },
44
- ref: forwardRef
45
- }, props, {
46
- children: options.map(function (option, index) {
47
- return (0, _jsxRuntime.jsxs)(RadioGroupPrimitive.Item, {
48
- value: option.value,
49
- id: "o" + index,
50
- sx: {
51
- p: 3,
52
- backgroundColor: 'input.radio-box.background.default',
53
- cursor: 'pointer',
54
- borderRadius: 2,
55
- textAlign: 'left',
56
- border: '1px solid',
57
- borderColor: 'input.radio-box.border.default',
58
- position: 'relative',
59
- '&:hover': {
60
- backgroundColor: 'input.radio-box.background.hover',
61
- borderColor: 'input.radio-box.border.default'
62
- },
63
- '&[data-state=checked]': {
64
- borderColor: 'input.radio-box.border.active'
65
- },
66
- '&[data-state=disabled]': {
67
- borderColor: 'input.radio-box.border.disabled'
68
- }
69
- },
70
- children: [(0, _jsxRuntime.jsx)(RadioGroupPrimitive.Indicator, {
71
- children: (0, _jsxRuntime.jsx)(_md.MdCheckCircle, {
72
- size: 16,
73
- sx: {
74
- position: 'absolute',
75
- top: 2,
76
- right: 2,
77
- color: 'icon.primary'
78
- }
79
- })
80
- }), (0, _jsxRuntime.jsx)(_.Heading, {
81
- variant: "h4",
82
- as: "label",
83
- htmlFor: "o" + index,
84
- sx: {
85
- mb: 0,
86
- color: 'input.radio-box.label.primary.default'
87
- },
88
- children: option.label
89
- }), (0, _jsxRuntime.jsx)(_.Text, {
52
+ flexDirection: 'row-reverse',
53
+ alignItems: 'flex-start',
54
+ backgroundColor: 'input.radio-box.background.default',
55
+ cursor: 'pointer',
56
+ borderRadius: 2,
57
+ textAlign: 'left',
58
+ border: '1px solid',
59
+ borderColor: 'input.radio-box.border.default',
60
+ position: 'relative',
61
+ '&:hover': {
62
+ backgroundColor: 'input.radio-box.background.hover',
63
+ borderColor: 'input.radio-box.border.default'
64
+ }
65
+ }, "" + defaultValue === "" + value && {
66
+ borderColor: 'input.radio-box.border.active'
67
+ }, disabled && {
68
+ borderColor: 'input.radio-box.border.disabled'
69
+ }),
70
+ children: [(0, _jsxRuntime.jsx)("input", (0, _extends2["default"])({
71
+ checked: "" + defaultValue === "" + value,
72
+ type: "radio",
73
+ name: name,
74
+ id: forLabel,
75
+ onChange: onChangeHandler,
76
+ value: "" + value,
77
+ sx: {
78
+ mr: 3,
79
+ mt: 3
80
+ }
81
+ }, restOption)), (0, _jsxRuntime.jsxs)("label", (0, _extends2["default"])({
82
+ htmlFor: forLabel,
83
+ sx: {
84
+ mb: 0,
85
+ color: 'input.radio-box.label.primary.default',
86
+ p: 3,
87
+ pr: 0,
88
+ flex: 'auto'
89
+ }
90
+ }, labelProps, {
91
+ children: [label, description && (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
92
+ children: [(0, _jsxRuntime.jsx)(_ScreenReaderText["default"], {
93
+ children: "."
94
+ }), (0, _jsxRuntime.jsx)("span", {
90
95
  sx: {
91
96
  color: 'input.radio-box.label.secondary.default',
92
97
  mb: 0,
93
- fontSize: 1
98
+ fontSize: 1,
99
+ display: 'block'
94
100
  },
95
- children: option.description
101
+ children: description
96
102
  })]
97
- }, option.value);
98
- })
103
+ })]
104
+ }))]
105
+ }, value);
106
+ };
107
+
108
+ RadioOption.propTypes = {
109
+ defaultValue: _propTypes["default"].string,
110
+ option: _propTypes["default"].object,
111
+ name: _propTypes["default"].string,
112
+ onChangeHandler: _propTypes["default"].func,
113
+ checked: _propTypes["default"].bool,
114
+ disabled: _propTypes["default"].bool,
115
+ width: _propTypes["default"].string
116
+ };
117
+
118
+ var RadioBoxGroup = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, forwardRef) {
119
+ var _ref2$optionWidth = _ref2.optionWidth,
120
+ optionWidth = _ref2$optionWidth === void 0 ? 'auto' : _ref2$optionWidth,
121
+ _ref2$name = _ref2.name,
122
+ name = _ref2$name === void 0 ? '' : _ref2$name,
123
+ onChange = _ref2.onChange,
124
+ groupLabel = _ref2.groupLabel,
125
+ defaultValue = _ref2.defaultValue,
126
+ options = _ref2.options,
127
+ disabled = _ref2.disabled,
128
+ props = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, _excluded2);
129
+ var onChangeHandler = (0, _react.useCallback)(function (e) {
130
+ var optionTriggered = options.find(function (option) {
131
+ return "" + option.value === "" + e.target.value;
132
+ });
133
+ onChange(e, optionTriggered);
134
+ }, [onChange]);
135
+ var renderedOptions = options.map(function (option) {
136
+ return (0, _jsxRuntime.jsx)(RadioOption, {
137
+ defaultValue: defaultValue,
138
+ disabled: disabled,
139
+ name: name,
140
+ option: option,
141
+ onChangeHandler: onChangeHandler,
142
+ width: optionWidth
143
+ }, (option == null ? void 0 : option.id) || (option == null ? void 0 : option.value));
144
+ });
145
+ return (0, _jsxRuntime.jsxs)("fieldset", (0, _extends2["default"])({
146
+ sx: {
147
+ display: 'flex',
148
+ gap: 2,
149
+ border: 0,
150
+ padding: 0
151
+ },
152
+ ref: forwardRef
153
+ }, props, {
154
+ children: [groupLabel ? (0, _jsxRuntime.jsx)("legend", {
155
+ children: groupLabel
156
+ }) : (0, _jsxRuntime.jsx)(_ScreenReaderText["default"], {
157
+ children: "Choose an option"
158
+ }), renderedOptions]
99
159
  }));
100
160
  });
101
161
 
@@ -104,6 +164,9 @@ RadioBoxGroup.displayName = 'RadioBoxGroup';
104
164
  RadioBoxGroup.propTypes = {
105
165
  onChange: _propTypes["default"].func,
106
166
  options: _propTypes["default"].array,
107
- value: _propTypes["default"].string,
108
- groupLabel: _propTypes["default"].string
167
+ defaultValue: _propTypes["default"].string,
168
+ name: _propTypes["default"].string,
169
+ disabled: _propTypes["default"].bool,
170
+ groupLabel: _propTypes["default"].string,
171
+ optionWidth: _propTypes["default"].string
109
172
  };
@@ -41,12 +41,12 @@ var Default = function Default() {
41
41
  setValue = _useState[1];
42
42
 
43
43
  return (0, _jsxRuntime.jsx)(_.RadioBoxGroup, {
44
- value: value,
45
- onChange: function onChange(newValue) {
46
- return setValue(newValue);
44
+ defaultValue: value,
45
+ onChange: function onChange(e) {
46
+ return setValue(e.target.value);
47
47
  },
48
- groupLabel: "group",
49
- options: options
48
+ options: options,
49
+ optionWidth: "350px"
50
50
  });
51
51
  };
52
52
 
@@ -37,7 +37,7 @@ var _Form = require("../Form");
37
37
 
38
38
  var _jsxRuntime = require("theme-ui/jsx-runtime");
39
39
 
40
- var _excluded = ["autoFilter", "className", "debounce", "displayMenu", "dropdownArrow", "errorMessage", "forLabel", "getOptionLabel", "getOptionValue", "hasError", "isInline", "label", "loading", "minLength", "noOptionsMessage", "onChange", "onInputChange", "options", "required", "searchIcon", "showAllValues", "source", "value"];
40
+ var _excluded = ["autoFilter", "className", "debounce", "displayMenu", "dropdownArrow", "errorMessage", "forLabel", "getOptionLabel", "getOptionValue", "hasError", "isInline", "label", "loading", "minLength", "noOptionsMessage", "onChange", "onInputChange", "options", "required", "searchIcon", "showAllValues", "resetOnBlur", "source", "value"];
41
41
 
42
42
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
43
43
 
@@ -171,6 +171,8 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
171
171
  searchIcon = _ref.searchIcon,
172
172
  _ref$showAllValues = _ref.showAllValues,
173
173
  showAllValues = _ref$showAllValues === void 0 ? false : _ref$showAllValues,
174
+ _ref$resetOnBlur = _ref.resetOnBlur,
175
+ resetOnBlur = _ref$resetOnBlur === void 0 ? false : _ref$resetOnBlur,
174
176
  source = _ref.source,
175
177
  value = _ref.value,
176
178
  props = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
@@ -179,8 +181,20 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
179
181
  isDirty = _useState[0],
180
182
  setIsDirty = _useState[1];
181
183
 
184
+ var _useState2 = (0, _react.useState)(value || ''),
185
+ selectedValue = _useState2[0],
186
+ setSelectedValue = _useState2[1];
187
+
188
+ var _useState3 = (0, _react.useState)(value),
189
+ inputQuery = _useState3[0],
190
+ setInputQuery = _useState3[1];
191
+
182
192
  var debounceTimeout;
183
193
 
194
+ if (!forwardRef) {
195
+ forwardRef = /*#__PURE__*/_react["default"].createRef();
196
+ }
197
+
184
198
  var SelectLabel = function SelectLabel() {
185
199
  return (0, _jsxRuntime.jsx)(_Label.Label, {
186
200
  required: required,
@@ -209,11 +223,43 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
209
223
  return "" + optionLabel(option) === "" + inputValue;
210
224
  });
211
225
  }, [getAllOptions, optionLabel]);
226
+ /**
227
+ * Reset the underlying component state to show the selected value
228
+ */
229
+
230
+ var resetInputState = (0, _react.useCallback)(function () {
231
+ var _forwardRef;
232
+
233
+ if (resetOnBlur && (_forwardRef = forwardRef) != null && _forwardRef.current && inputQuery !== selectedValue) {
234
+ // resets the input field to the selected value or the empty string
235
+ forwardRef.current.setState((0, _extends2["default"])({}, forwardRef.current.state, {
236
+ query: inputQuery && inputQuery !== '' ? selectedValue != null ? selectedValue : '' : '' // selected value should not be null or the component will crash
237
+
238
+ }));
239
+ }
240
+ }, [forwardRef]); // sets the internal state variables and calls the onChange callback
241
+
242
+ var setAutocompleteState = function setAutocompleteState(inputValue) {
243
+ setInputQuery(inputValue);
244
+ setSelectedValue(inputValue);
245
+ onChange(getOptionByLabel(inputValue), inputValue);
246
+ setIsDirty(false);
247
+ }; // this method gets called when we confirm the selection via click/enter
248
+
249
+
212
250
  var onValueChange = (0, _react.useCallback)(function (inputValue) {
213
251
  if (inputValue) {
214
- onChange(getOptionByLabel(inputValue), inputValue);
252
+ setAutocompleteState(inputValue);
253
+ } else if (resetOnBlur && inputQuery !== selectedValue) {
254
+ if (inputQuery && inputQuery !== '') {
255
+ // reset the content to the selected value
256
+ setAutocompleteState(selectedValue);
257
+ } else {
258
+ // reset the content to empty if there's no match
259
+ setAutocompleteState(null);
260
+ }
215
261
  }
216
- }, [onChange, getOptionByLabel]);
262
+ }, [onChange, getOptionByLabel, setAutocompleteState]);
217
263
  var handleTypeChange = (0, _react.useCallback)(function (query) {
218
264
  return options.filter(function (option) {
219
265
  return optionLabel(option).toLowerCase().indexOf(query.toLowerCase()) >= 0;
@@ -248,7 +294,18 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
248
294
  populateResults((_data = data) == null ? void 0 : _data.map(function (option) {
249
295
  return optionLabel(option);
250
296
  }));
251
- }, [autoFilter, isDirty, onInputChange, options]);
297
+ }, [autoFilter, isDirty, onInputChange, options]); // internal function to save the inputQuery
298
+
299
+ var handleSource = function handleSource(query, populateResults) {
300
+ setInputQuery(query); // user function to fetch the results has the precedence
301
+
302
+ if (source) {
303
+ return source(query, populateResults);
304
+ }
305
+
306
+ return suggest(query, populateResults);
307
+ };
308
+
252
309
  (0, _react.useEffect)(function () {
253
310
  global.document.querySelector('.autocomplete__input').setAttribute('aria-activedescendant', '');
254
311
  }, []);
@@ -265,8 +322,13 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
265
322
  input.setAttribute('aria-required', required);
266
323
  }, [required]);
267
324
  (0, _react.useEffect)(function () {
268
- global.document.querySelector("#" + forLabel).addEventListener('keydown', function () {
269
- setIsDirty(true);
325
+ global.document.querySelector("#" + forLabel).addEventListener('keydown', function (e) {
326
+ // pressed escape, we want to reset the status
327
+ if (e.keyCode === 27 && resetOnBlur) {
328
+ resetInputState();
329
+ } else {
330
+ setIsDirty(true);
331
+ }
270
332
  });
271
333
  }, [setIsDirty]); // For accessibility, we need to add the error message to the aria-describedby attribute
272
334
 
@@ -274,6 +336,11 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
274
336
  var input = global.document.querySelector("#" + forLabel);
275
337
  input == null ? void 0 : input.setAttribute('aria-describedby', "describe-" + forLabel + "-validation " + input.getAttribute('aria-describedby'));
276
338
  }, []);
339
+ (0, _react.useEffect)(function () {
340
+ global.document.querySelector("#" + forLabel).addEventListener('blur', function () {
341
+ resetInputState();
342
+ });
343
+ }, [forwardRef]);
277
344
  return (0, _jsxRuntime.jsxs)("div", {
278
345
  className: (0, _classnames["default"])('vip-form-autocomplete-component', className),
279
346
  children: [label && !isInline && (0, _jsxRuntime.jsx)(SelectLabel, {}), (0, _jsxRuntime.jsx)("div", {
@@ -286,7 +353,7 @@ var FormAutocomplete = /*#__PURE__*/_react["default"].forwardRef(function (_ref,
286
353
  "aria-busy": loading,
287
354
  showAllValues: showAllValues,
288
355
  ref: forwardRef,
289
- source: source || suggest,
356
+ source: handleSource,
290
357
  defaultValue: value,
291
358
  displayMenu: displayMenu,
292
359
  onConfirm: onValueChange,
@@ -331,6 +398,7 @@ FormAutocomplete.propTypes = {
331
398
  required: _propTypes["default"].bool,
332
399
  searchIcon: _propTypes["default"].bool,
333
400
  showAllValues: _propTypes["default"].bool,
401
+ resetOnBlur: _propTypes["default"].bool,
334
402
  source: _propTypes["default"].func,
335
403
  value: _propTypes["default"].string,
336
404
  dropdownArrow: _propTypes["default"].node
@@ -3,7 +3,11 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
5
  exports.__esModule = true;
6
- exports["default"] = exports.WithSearchIcon = exports.WithLoading = exports.WithErrors = exports.WithDefaultValue = exports.WithDebounce = exports.WithCustomMessages = exports.WithCustomArrow = exports.WithArrow = exports.Inline = exports.Default = void 0;
6
+ exports["default"] = exports.WithSlowSearch = exports.WithSearchIcon = exports.WithLoading = exports.WithErrors = exports.WithDefaultValue = exports.WithDebounce = exports.WithCustomMessages = exports.WithCustomArrow = exports.WithArrow = exports.Inline = exports.Default = void 0;
7
+
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
7
11
 
8
12
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
13
 
@@ -41,6 +45,12 @@ var _default = {
41
45
  control: {
42
46
  type: 'text'
43
47
  }
48
+ },
49
+ resetOnBlur: {
50
+ options: [false, true],
51
+ control: {
52
+ type: 'boolean'
53
+ }
44
54
  }
45
55
  }
46
56
  };
@@ -57,7 +67,9 @@ var options = [{
57
67
  }];
58
68
  var args = {
59
69
  label: 'Label',
60
- options: options
70
+ options: options,
71
+ resetOnBlur: false,
72
+ placeholder: 'Start typing...'
61
73
  }; // eslint-disable-next-line react/prop-types
62
74
 
63
75
  var DefaultComponent = function DefaultComponent(_ref) {
@@ -94,62 +106,30 @@ var DefaultComponent = function DefaultComponent(_ref) {
94
106
  });
95
107
  };
96
108
 
97
- var Default = function Default() {
98
- return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
99
- children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({
100
- required: true
101
- }, args, {
102
- placeholder: "Start typing..."
103
- }))
104
- });
105
- };
106
-
109
+ var Default = DefaultComponent.bind({});
107
110
  exports.Default = Default;
108
-
109
- var Inline = function Inline() {
110
- var customArgs = (0, _extends2["default"])({}, args, {
111
- isInline: true
112
- });
113
- return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
114
- children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({}, customArgs))
115
- });
116
- };
117
-
111
+ Default.args = args;
112
+ var Inline = DefaultComponent.bind({});
118
113
  exports.Inline = Inline;
119
-
120
- var WithDefaultValue = function WithDefaultValue() {
121
- var customArgs = (0, _extends2["default"])({}, args, {
122
- value: 'Chocolate'
123
- });
124
- return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
125
- children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({}, customArgs))
126
- });
127
- };
128
-
114
+ Inline.args = (0, _extends2["default"])({}, Default.args, {
115
+ isInline: true
116
+ });
117
+ var WithDefaultValue = DefaultComponent.bind({});
129
118
  exports.WithDefaultValue = WithDefaultValue;
130
-
131
- var WithSearchIcon = function WithSearchIcon() {
132
- var customArgs = (0, _extends2["default"])({}, args, {
133
- searchIcon: true,
134
- placeholder: 'Type to search'
135
- });
136
- return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
137
- children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({}, customArgs))
138
- });
139
- };
140
-
119
+ WithDefaultValue.args = (0, _extends2["default"])({}, Default.args, {
120
+ value: 'Chocolate'
121
+ });
122
+ var WithSearchIcon = DefaultComponent.bind({});
141
123
  exports.WithSearchIcon = WithSearchIcon;
142
-
143
- var WithLoading = function WithLoading() {
144
- var customArgs = (0, _extends2["default"])({}, args, {
145
- loading: true
146
- });
147
- return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
148
- children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({}, customArgs))
149
- });
150
- };
151
-
124
+ WithSearchIcon.args = (0, _extends2["default"])({}, Default.args, {
125
+ searchIcon: true,
126
+ placeholder: 'Type to search'
127
+ });
128
+ var WithLoading = DefaultComponent.bind({});
152
129
  exports.WithLoading = WithLoading;
130
+ WithLoading.args = (0, _extends2["default"])({}, Default.args, {
131
+ loading: true
132
+ });
153
133
 
154
134
  var WithDebounce = function WithDebounce() {
155
135
  var _useState2 = (0, _react.useState)(null),
@@ -169,65 +149,80 @@ var WithDebounce = function WithDebounce() {
169
149
  };
170
150
 
171
151
  exports.WithDebounce = WithDebounce;
152
+ var WithSlowSearch = DefaultComponent.bind({});
153
+ exports.WithSlowSearch = WithSlowSearch;
154
+ WithSlowSearch.args = (0, _extends2["default"])({}, Default.args, {
155
+ label: 'Label',
156
+ autoFilter: false,
157
+ minLength: 3,
158
+ required: true,
159
+ source: function () {
160
+ var _source = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(query, populateResults) {
161
+ return _regenerator["default"].wrap(function _callee$(_context) {
162
+ while (1) {
163
+ switch (_context.prev = _context.next) {
164
+ case 0:
165
+ if (!query || query.length >= 3) {
166
+ setTimeout(function () {
167
+ var filteredResults = args.options.map(function (option) {
168
+ return option.label;
169
+ }).filter(function (result) {
170
+ return result.toLowerCase().indexOf(query == null ? void 0 : query.toLowerCase()) !== -1;
171
+ });
172
+ populateResults(filteredResults);
173
+ }, 1000);
174
+ }
175
+
176
+ case 1:
177
+ case "end":
178
+ return _context.stop();
179
+ }
180
+ }
181
+ }, _callee);
182
+ }));
172
183
 
173
- var WithCustomMessages = function WithCustomMessages() {
174
- var customArgs = (0, _extends2["default"])({}, args, {
175
- noOptionsMessage: function noOptionsMessage() {
176
- return 'No data';
177
- },
178
- placeholder: 'Type to search'
179
- });
180
- return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
181
- children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({}, customArgs))
182
- });
183
- };
184
+ function source(_x, _x2) {
185
+ return _source.apply(this, arguments);
186
+ }
184
187
 
188
+ return source;
189
+ }()
190
+ });
191
+ var WithCustomMessages = DefaultComponent.bind({});
185
192
  exports.WithCustomMessages = WithCustomMessages;
186
-
187
- var WithErrors = function WithErrors() {
188
- var customArgs = (0, _extends2["default"])({}, args, {
189
- hasError: true,
190
- errorMessage: 'Please select a value.',
191
- required: true
192
- });
193
- return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
194
- children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({}, customArgs))
195
- });
196
- };
197
-
193
+ WithCustomMessages.args = (0, _extends2["default"])({}, Default.args, {
194
+ noOptionsMessage: function noOptionsMessage() {
195
+ return 'No data';
196
+ },
197
+ placeholder: 'Type to search'
198
+ });
199
+ var WithErrors = DefaultComponent.bind({});
198
200
  exports.WithErrors = WithErrors;
199
-
200
- var WithArrow = function WithArrow() {
201
- var customArgs = (0, _extends2["default"])({}, args, {
202
- showAllValues: true
203
- });
204
- return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
205
- children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({}, customArgs))
206
- });
207
- };
208
-
201
+ WithErrors.args = (0, _extends2["default"])({}, Default.args, {
202
+ hasError: true,
203
+ errorMessage: 'Please select a value.',
204
+ required: true
205
+ });
206
+ var WithArrow = DefaultComponent.bind({});
209
207
  exports.WithArrow = WithArrow;
210
-
211
- var WithCustomArrow = function WithCustomArrow() {
212
- var customArgs = (0, _extends2["default"])({}, args, {
213
- showAllValues: true,
214
- // eslint-disable-next-line react/display-name
215
- dropdownArrow: function dropdownArrow() {
216
- return (0, _jsxRuntime.jsx)("span", {
217
- sx: {
218
- position: 'absolute',
219
- top: '2px',
220
- right: '10px',
221
- pointerEvents: 'none'
222
- },
223
- children: "\uD83D\uDC47"
224
- });
225
- }
226
- });
227
- return (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
228
- children: (0, _jsxRuntime.jsx)(DefaultComponent, (0, _extends2["default"])({}, customArgs))
229
- });
230
- };
231
-
208
+ WithArrow.args = (0, _extends2["default"])({}, Default.args, {
209
+ showAllValues: true
210
+ });
211
+ var WithCustomArrow = DefaultComponent.bind({});
232
212
  exports.WithCustomArrow = WithCustomArrow;
213
+ WithCustomArrow.args = (0, _extends2["default"])({}, Default.args, {
214
+ showAllValues: true,
215
+ // eslint-disable-next-line react/display-name
216
+ dropdownArrow: function dropdownArrow() {
217
+ return (0, _jsxRuntime.jsx)("span", {
218
+ sx: {
219
+ position: 'absolute',
220
+ top: '2px',
221
+ right: '10px',
222
+ pointerEvents: 'none'
223
+ },
224
+ children: "\uD83D\uDC47"
225
+ });
226
+ }
227
+ });
233
228
  WithCustomArrow.displayName = 'WithCustomArrow';