forstok-ui-lib 8.8.1 → 8.8.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "forstok-ui-lib",
3
- "version": "8.8.1",
3
+ "version": "8.8.3",
4
4
  "description": "Forstok UI Components Library",
5
5
  "path": "dist",
6
6
  "main": "dist/index.js",
@@ -1,5 +1,7 @@
1
1
  import { useCallback, useEffect, useRef, useState } from "react";
2
2
  import { AsyncPaginate } from "react-select-async-paginate";
3
+ import AsyncCreatableSelect from "react-select/async-creatable";
4
+
3
5
  import type { LoadOptions } from "react-select-async-paginate";
4
6
  import {
5
7
  SingleValueProps,
@@ -49,6 +51,8 @@ type TSelect = {
49
51
  ) => void;
50
52
  id?: string;
51
53
  isDisabled?: boolean;
54
+ isCreateable?: boolean;
55
+ evCreate?: (value: string) => void;
52
56
  };
53
57
 
54
58
  const SelectAsyncPaginateComponent = ({ loadOptions, ...props }: TSelect) => {
@@ -61,7 +65,7 @@ const SelectAsyncPaginateComponent = ({ loadOptions, ...props }: TSelect) => {
61
65
  MenuList,
62
66
  defaultValue,
63
67
  // reset,
64
- // setReset,
68
+ setReset,
65
69
  evChange,
66
70
  isForceUpdate,
67
71
  setForceUpdate,
@@ -76,6 +80,8 @@ const SelectAsyncPaginateComponent = ({ loadOptions, ...props }: TSelect) => {
76
80
  setMenuIsOpen,
77
81
  id,
78
82
  evChangeOnMenuClose,
83
+ isCreateable = false,
84
+ evCreate,
79
85
  ...rest
80
86
  } = props;
81
87
 
@@ -132,6 +138,21 @@ const SelectAsyncPaginateComponent = ({ loadOptions, ...props }: TSelect) => {
132
138
  evChange && evChange(newValue, actionMeta);
133
139
  };
134
140
 
141
+ const handleCreate = (inputValue: string) => {
142
+ setReset?.(false);
143
+ if (isMulti) {
144
+ !Array.isArray(valueSelect)
145
+ ? setValueSelect([{ value: inputValue, label: inputValue }])
146
+ : setValueSelect([
147
+ ...valueSelect,
148
+ { value: inputValue, label: inputValue },
149
+ ]);
150
+ } else {
151
+ setValueSelect({ value: inputValue, label: inputValue });
152
+ }
153
+ evCreate?.(inputValue);
154
+ };
155
+
135
156
  const customStyles: StylesConfig<TOption, boolean> = {
136
157
  container: (provided: CSSObject) =>
137
158
  ({
@@ -350,57 +371,112 @@ const SelectAsyncPaginateComponent = ({ loadOptions, ...props }: TSelect) => {
350
371
  evToogleSelect();
351
372
  };
352
373
 
353
- return (
354
- <div className="_refContainer" style={{ width: "100%", minWidth: 0 }}>
355
- <AsyncPaginate
356
- isSearchable={isSearchable}
357
- placeholder={placeholder}
358
- debounceTimeout={500}
359
- styles={customStyles}
360
- loadOptions={loadOptions}
361
- menuPortalTarget={document.body}
362
- menuPosition="fixed"
363
- menuPlacement="auto"
364
- value={valueSelect}
365
- onChange={handleChange}
366
- loadOptionsOnMenuOpen={loadOptionsOnMenuOpen}
367
- noOptionsMessage={noOptionsMessage}
368
- menuIsOpen={isMenuOpen}
369
- {...(id && { id: id })}
370
- {...(mode === "multi-select" && {
371
- closeMenuOnSelect: false,
372
- inputValue: inputValue,
373
- onInputChange: (value, action) => {
374
- if (action.action === "input-change") {
375
- setInputValue(value);
376
- setTime(new Date());
377
- return value;
378
- }
379
-
374
+ let SelectEl = isCreateable ? (
375
+ <AsyncCreatableSelect
376
+ isSearchable={isSearchable}
377
+ placeholder={placeholder}
378
+ debounceTimeout={500}
379
+ styles={customStyles}
380
+ loadOptions={loadOptions}
381
+ menuPortalTarget={document.body}
382
+ menuPosition="fixed"
383
+ menuPlacement="auto"
384
+ value={valueSelect}
385
+ onChange={handleChange}
386
+ onCreateOption={handleCreate}
387
+ loadOptionsOnMenuOpen={loadOptionsOnMenuOpen}
388
+ noOptionsMessage={noOptionsMessage}
389
+ menuIsOpen={isMenuOpen}
390
+ {...(id && { id: id })}
391
+ {...(mode === "multi-select" && {
392
+ closeMenuOnSelect: false,
393
+ inputValue: inputValue,
394
+ onInputChange: (value, action) => {
395
+ if (action.action === "input-change") {
396
+ setInputValue(value);
397
+ setTime(new Date());
380
398
  return value;
381
- },
382
- onMenuClose: () => {
383
- setInputValue("");
384
- evChangeOnMenuClose?.(valueSelect);
385
- },
386
- onMenuOpen: () => evReToogleSelect(),
387
- cacheUniqs: [_time],
388
- selectRef: selectRef,
399
+ }
400
+
401
+ return value;
402
+ },
403
+ onMenuClose: () => {
404
+ setInputValue("");
405
+ evChangeOnMenuClose?.(valueSelect);
406
+ },
407
+ onMenuOpen: () => evReToogleSelect(),
408
+ cacheUniqs: [_time],
409
+ selectRef: selectRef,
410
+ })}
411
+ {...(mode !== "multi-select" && {
412
+ onMenuOpen: onMenuOpen,
413
+ onMenuClose: onMenuClose,
414
+ })}
415
+ {...(customLabel && { components: { SingleValue: customLabel } })}
416
+ {...(customOption && { components: { Option: customOption } })}
417
+ {...(customLabel &&
418
+ customOption && {
419
+ components: { SingleValue: customLabel, Option: customOption },
389
420
  })}
390
- {...(mode !== "multi-select" && {
391
- onMenuOpen: onMenuOpen,
392
- onMenuClose: onMenuClose,
421
+ {...(MenuList && { components: { MenuList } })}
422
+ {...(isMulti && { isMulti: true })}
423
+ {...rest}
424
+ />
425
+ ) : (
426
+ <AsyncPaginate
427
+ isSearchable={isSearchable}
428
+ placeholder={placeholder}
429
+ debounceTimeout={500}
430
+ styles={customStyles}
431
+ loadOptions={loadOptions}
432
+ menuPortalTarget={document.body}
433
+ menuPosition="fixed"
434
+ menuPlacement="auto"
435
+ value={valueSelect}
436
+ onChange={handleChange}
437
+ loadOptionsOnMenuOpen={loadOptionsOnMenuOpen}
438
+ noOptionsMessage={noOptionsMessage}
439
+ menuIsOpen={isMenuOpen}
440
+ {...(id && { id: id })}
441
+ {...(mode === "multi-select" && {
442
+ closeMenuOnSelect: false,
443
+ inputValue: inputValue,
444
+ onInputChange: (value, action) => {
445
+ if (action.action === "input-change") {
446
+ setInputValue(value);
447
+ setTime(new Date());
448
+ return value;
449
+ }
450
+
451
+ return value;
452
+ },
453
+ onMenuClose: () => {
454
+ setInputValue("");
455
+ evChangeOnMenuClose?.(valueSelect);
456
+ },
457
+ onMenuOpen: () => evReToogleSelect(),
458
+ cacheUniqs: [_time],
459
+ selectRef: selectRef,
460
+ })}
461
+ {...(mode !== "multi-select" && {
462
+ onMenuOpen: onMenuOpen,
463
+ onMenuClose: onMenuClose,
464
+ })}
465
+ {...(customLabel && { components: { SingleValue: customLabel } })}
466
+ {...(customOption && { components: { Option: customOption } })}
467
+ {...(customLabel &&
468
+ customOption && {
469
+ components: { SingleValue: customLabel, Option: customOption },
393
470
  })}
394
- {...(customLabel && { components: { SingleValue: customLabel } })}
395
- {...(customOption && { components: { Option: customOption } })}
396
- {...(customLabel &&
397
- customOption && {
398
- components: { SingleValue: customLabel, Option: customOption },
399
- })}
400
- {...(MenuList && { components: { MenuList } })}
401
- {...(isMulti && { isMulti: true })}
402
- {...rest}
403
- />
471
+ {...(MenuList && { components: { MenuList } })}
472
+ {...(isMulti && { isMulti: true })}
473
+ {...rest}
474
+ />
475
+ );
476
+
477
+ return (
478
+ <div className="_refContainer" style={{ width: "100%", minWidth: 0 }}>
479
+ {SelectEl}
404
480
  </div>
405
481
  );
406
482
  };