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/dist/index.d.ts +2 -0
- package/dist/index.js +41 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +477 -477
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/select/asyncPaginate.tsx +125 -49
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
354
|
-
<
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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
|
-
|
|
391
|
-
|
|
392
|
-
|
|
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
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
};
|