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