@dilicorp/ui 0.2.46 → 0.2.47
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/components/form-builder/components/infinite-select.d.ts +33 -0
- package/dist/components/form-builder/components/infinite-select.js +30 -0
- package/dist/components/form-builder/form-builder-components-list.d.ts +1 -0
- package/dist/components/form-builder/form-builder-components-list.js +3 -1
- package/dist/components/form-builder/form-builder.types.d.ts +13 -1
- package/package.json +1 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FormikProps } from 'formik';
|
|
3
|
+
import { OnChangeValue } from 'react-select/dist/declarations/src/types';
|
|
4
|
+
declare type Option = {
|
|
5
|
+
label: string | number;
|
|
6
|
+
value: string | number;
|
|
7
|
+
};
|
|
8
|
+
declare type Props = {
|
|
9
|
+
name: string;
|
|
10
|
+
actions: FormikProps<any>;
|
|
11
|
+
options?: Option[];
|
|
12
|
+
defaultOptions?: Option[];
|
|
13
|
+
id?: string;
|
|
14
|
+
value?: Option | Option[];
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
isDisabled?: boolean;
|
|
17
|
+
isLoading?: boolean;
|
|
18
|
+
isClearable?: boolean;
|
|
19
|
+
isSearchable?: boolean;
|
|
20
|
+
isMulti?: boolean;
|
|
21
|
+
onChange?: (event: {
|
|
22
|
+
currentTarget: {
|
|
23
|
+
value: OnChangeValue<Option, boolean>;
|
|
24
|
+
name: string;
|
|
25
|
+
};
|
|
26
|
+
}) => void;
|
|
27
|
+
selectRef?: React.MutableRefObject<any>;
|
|
28
|
+
loadOptions?: (newValue: string) => void;
|
|
29
|
+
loadMoreOptions?: () => void;
|
|
30
|
+
};
|
|
31
|
+
export default function InfiniteSelect(props: Props): JSX.Element;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=infinite-select.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
2
|
+
import AsyncSelect from 'react-select/async';
|
|
3
|
+
export default function InfiniteSelect(props) {
|
|
4
|
+
const { actions, options = [], defaultOptions = [], name, id = name, value = null, placeholder, isDisabled = false, isLoading = false, isClearable = false, isSearchable = true, isMulti = false, selectRef, onChange, loadOptions, loadMoreOptions } = props;
|
|
5
|
+
const [currValue, setValue] = useState(value || null);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (value !== currValue) {
|
|
8
|
+
actions.setFieldValue(name, '');
|
|
9
|
+
setValue(null);
|
|
10
|
+
}
|
|
11
|
+
}, [options]);
|
|
12
|
+
const handleChange = useCallback((newValue) => {
|
|
13
|
+
if (onChange) {
|
|
14
|
+
onChange({
|
|
15
|
+
currentTarget: {
|
|
16
|
+
value: newValue,
|
|
17
|
+
name
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
actions.setFieldValue(name, JSON.stringify(newValue));
|
|
22
|
+
setValue(newValue);
|
|
23
|
+
}, [onChange, actions, name]);
|
|
24
|
+
const handleMenuScrollToBottom = useCallback(() => {
|
|
25
|
+
if (loadMoreOptions && options.length >= 100) {
|
|
26
|
+
loadMoreOptions();
|
|
27
|
+
}
|
|
28
|
+
}, [loadMoreOptions, options]);
|
|
29
|
+
return (React.createElement(AsyncSelect, { ref: selectRef, placeholder: placeholder, className: "form-builder-select", classNamePrefix: "form-builder", options: options, defaultOptions: defaultOptions, name: name, id: id, "data-testid": id, defaultValue: currValue, value: currValue, isDisabled: isDisabled, isLoading: isLoading, isClearable: isClearable, isSearchable: isSearchable, isMulti: isMulti, onChange: handleChange, loadOptions: loadOptions, onMenuScrollToBottom: handleMenuScrollToBottom }));
|
|
30
|
+
}
|
|
@@ -6,6 +6,7 @@ import Input from './components/input';
|
|
|
6
6
|
import Password from './components/password';
|
|
7
7
|
import Radio from './components/radio';
|
|
8
8
|
import Select from './components/select';
|
|
9
|
+
import InfiniteSelect from './components/infinite-select';
|
|
9
10
|
export const FormBuilderComponentsList = {
|
|
10
11
|
button: Button,
|
|
11
12
|
checkbox: Checkbox,
|
|
@@ -14,5 +15,6 @@ export const FormBuilderComponentsList = {
|
|
|
14
15
|
input: Input,
|
|
15
16
|
password: Password,
|
|
16
17
|
radio: Radio,
|
|
17
|
-
select: Select
|
|
18
|
+
select: Select,
|
|
19
|
+
infiniteSelect: InfiniteSelect
|
|
18
20
|
};
|
|
@@ -52,6 +52,18 @@ interface FormBuilderItemSelect extends Omit<FormBuilderBasicsItem, 'value'> {
|
|
|
52
52
|
isMulti?: boolean;
|
|
53
53
|
selectRef?: React.MutableRefObject<any>;
|
|
54
54
|
}
|
|
55
|
+
interface FormBuilderItemInfinitiSelect extends Omit<FormBuilderItemSelect, 'component'> {
|
|
56
|
+
component: 'infiniteSelect';
|
|
57
|
+
value?: Option | Option[];
|
|
58
|
+
options: Option[];
|
|
59
|
+
isDisabled?: boolean;
|
|
60
|
+
isLoading?: boolean;
|
|
61
|
+
isClearable?: boolean;
|
|
62
|
+
isSearchable?: boolean;
|
|
63
|
+
isMulti?: boolean;
|
|
64
|
+
selectRef?: React.MutableRefObject<any>;
|
|
65
|
+
loadMoreOptions?: () => void;
|
|
66
|
+
}
|
|
55
67
|
interface FormBuilderItemDatePicker extends FormBuilderBasicsItem {
|
|
56
68
|
component?: 'datepicker';
|
|
57
69
|
locale?: SupportedLanguages;
|
|
@@ -79,7 +91,7 @@ interface FormBuilderItemCheckbox extends Omit<FormBuilderBasicsItem, 'value'> {
|
|
|
79
91
|
value?: string[];
|
|
80
92
|
options: Option[];
|
|
81
93
|
}
|
|
82
|
-
export declare type FormBuilderItem = FormBuildItemInput | FormBuilderItemPassword | FormBuilderItemButton | FormBuilderItemSelect | FormBuilderItemDropZone | FormBuilderItemDatePicker | FormBuilderItemRadio | FormBuilderItemCheckbox;
|
|
94
|
+
export declare type FormBuilderItem = FormBuildItemInput | FormBuilderItemPassword | FormBuilderItemButton | FormBuilderItemSelect | FormBuilderItemDropZone | FormBuilderItemDatePicker | FormBuilderItemRadio | FormBuilderItemCheckbox | FormBuilderItemInfinitiSelect;
|
|
83
95
|
export declare type FormBuilderGroup = {
|
|
84
96
|
items: FormBuilderItem[];
|
|
85
97
|
name?: string;
|