@snack-uikit/fields 0.18.0 → 0.18.1-preview-69abc1d3.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.
- package/README.md +5 -5
- package/dist/components/FieldSelect/FieldSelectMultiple.d.ts +3 -1
- package/dist/components/FieldSelect/FieldSelectMultiple.js +4 -1
- package/dist/components/FieldSelect/FieldSelectSingle.d.ts +3 -1
- package/dist/components/FieldSelect/FieldSelectSingle.js +10 -2
- package/dist/components/FieldSelect/hooks.js +4 -1
- package/dist/components/FieldSelect/types.d.ts +6 -3
- package/dist/components/FieldSelect/utils/extractListProps.d.ts +1 -1
- package/dist/components/FieldSelect/utils/extractListProps.js +1 -3
- package/dist/components/FieldSelect/utils/typeGuards.js +1 -1
- package/dist/components/FieldSelect/utils/updateItems.d.ts +6 -5
- package/dist/components/FieldSelect/utils/updateItems.js +5 -2
- package/package.json +13 -13
- package/src/components/FieldSelect/FieldSelectMultiple.tsx +4 -1
- package/src/components/FieldSelect/FieldSelectSingle.tsx +8 -1
- package/src/components/FieldSelect/hooks.ts +9 -1
- package/src/components/FieldSelect/types.ts +29 -12
- package/src/components/FieldSelect/utils/extractListProps.ts +0 -4
- package/src/components/FieldSelect/utils/typeGuards.ts +1 -1
- package/src/components/FieldSelect/utils/updateItems.ts +6 -3
package/README.md
CHANGED
|
@@ -312,6 +312,8 @@ const [isOpen, setIsOpen] = useState(false);
|
|
|
312
312
|
### Props
|
|
313
313
|
| name | type | default value | description |
|
|
314
314
|
|------|------|---------------|-------------|
|
|
315
|
+
| pinBottom* | `OptionProps[]` | - | |
|
|
316
|
+
| pinTop* | `OptionProps[]` | - | |
|
|
315
317
|
| options* | `OptionProps[]` | - | |
|
|
316
318
|
| disabled | `boolean` | false | Является ли поле деактивированным |
|
|
317
319
|
| readonly | `boolean` | false false | Является ли поле доступным только для чтения |
|
|
@@ -332,9 +334,9 @@ const [isOpen, setIsOpen] = useState(false);
|
|
|
332
334
|
| validationState | enum ValidationState: `"default"`, `"error"`, `"warning"`, `"success"` | - | Состояние валидации |
|
|
333
335
|
| showHintIcon | `boolean` | - | Отображать иконку подсказки |
|
|
334
336
|
| loading | `boolean` | - | |
|
|
335
|
-
| value | `
|
|
336
|
-
| onChange | `
|
|
337
|
-
| defaultValue | `
|
|
337
|
+
| value | `ItemId \| ItemId[]` | - | Controlled состояние |
|
|
338
|
+
| onChange | `OnChangeHandler<any, any>` | - | Controlled обработчик измения состояния |
|
|
339
|
+
| defaultValue | `ItemId \| ItemId[]` | - | Начальное состояние |
|
|
338
340
|
| searchable | `boolean` | - | |
|
|
339
341
|
| showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
|
|
340
342
|
| showClearButton | `boolean` | true | Отображение кнопки очистки поля |
|
|
@@ -350,8 +352,6 @@ const [isOpen, setIsOpen] = useState(false);
|
|
|
350
352
|
| noDataState | `EmptyStateProps` | - | Экран при отстутствии данных |
|
|
351
353
|
| noResultsState | `EmptyStateProps` | - | Экран при отстутствии результатов поиска или фильтров |
|
|
352
354
|
| errorDataState | `EmptyStateProps` | - | Экран при ошибке запроса |
|
|
353
|
-
| pinTop | `ItemProps[]` | - | Элементы списка, закрепленные сверху |
|
|
354
|
-
| pinBottom | `ItemProps[]` | - | Элементы списка, закрепленные снизу |
|
|
355
355
|
| dataFiltered | `boolean` | - | |
|
|
356
356
|
| selection | "single" \| "multiple" | - | |
|
|
357
357
|
| ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
|
|
@@ -9,6 +9,8 @@ export declare const FieldSelectMultiple: import("react").ForwardRefExoticCompon
|
|
|
9
9
|
'data-test-id'?: string | undefined;
|
|
10
10
|
} & import("react").AriaAttributes & {
|
|
11
11
|
options: import("./types").OptionProps[];
|
|
12
|
+
pinTop: import("./types").OptionProps[];
|
|
13
|
+
pinBottom: import("./types").OptionProps[];
|
|
12
14
|
searchable?: boolean | undefined;
|
|
13
15
|
showCopyButton?: boolean | undefined;
|
|
14
16
|
showClearButton?: boolean | undefined;
|
|
@@ -21,4 +23,4 @@ export declare const FieldSelectMultiple: import("react").ForwardRefExoticCompon
|
|
|
21
23
|
open?: boolean | undefined;
|
|
22
24
|
onOpenChange?(open: boolean): void;
|
|
23
25
|
selectedOptionFormatter?: SelectedOptionFormatter | undefined;
|
|
24
|
-
} & Pick<import("@snack-uikit/list").ListProps, "dataError" | "
|
|
26
|
+
} & Pick<import("@snack-uikit/list").ListProps, "dataError" | "dataFiltered" | "noDataState" | "noResultsState" | "errorDataState">, "showCopyButton"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -25,7 +25,10 @@ import { useButtons, useHandleDeleteItem, useHandleOnKeyDown, useSearchInput } f
|
|
|
25
25
|
import styles from './styles.module.css';
|
|
26
26
|
import { extractListProps, getArrowIcon, updateMultipleItems } from './utils';
|
|
27
27
|
const BASE_MIN_WIDTH = 4;
|
|
28
|
-
const defaultSelectedOptionFormatter = item =>
|
|
28
|
+
const defaultSelectedOptionFormatter = item =>
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
30
|
+
// @ts-expect-error
|
|
31
|
+
(item === null || item === void 0 ? void 0 : item.content.option) || '';
|
|
29
32
|
export const FieldSelectMultiple = forwardRef((_a, ref) => {
|
|
30
33
|
var _b;
|
|
31
34
|
var { id, name, placeholder, size = 's', options, value: valueProp, defaultValue, onChange: onChangeProp, disabled = false, readonly = false, searchable = true, showClearButton = true, onKeyDown: onInputKeyDownProp, validationState = 'default', search, autocomplete = false, prefixIcon, removeByBackspace = false, addOptionByEnter = false, open: openProp, onOpenChange, selectedOptionFormatter = defaultSelectedOptionFormatter } = _a, rest = __rest(_a, ["id", "name", "placeholder", "size", "options", "value", "defaultValue", "onChange", "disabled", "readonly", "searchable", "showClearButton", "onKeyDown", "validationState", "search", "autocomplete", "prefixIcon", "removeByBackspace", "addOptionByEnter", "open", "onOpenChange", "selectedOptionFormatter"]);
|
|
@@ -7,6 +7,8 @@ export declare const FieldSelectSingle: import("react").ForwardRefExoticComponen
|
|
|
7
7
|
'data-test-id'?: string | undefined;
|
|
8
8
|
} & import("react").AriaAttributes & {
|
|
9
9
|
options: import("./types").OptionProps[];
|
|
10
|
+
pinTop: import("./types").OptionProps[];
|
|
11
|
+
pinBottom: import("./types").OptionProps[];
|
|
10
12
|
searchable?: boolean | undefined;
|
|
11
13
|
showCopyButton?: boolean | undefined;
|
|
12
14
|
showClearButton?: boolean | undefined;
|
|
@@ -19,4 +21,4 @@ export declare const FieldSelectSingle: import("react").ForwardRefExoticComponen
|
|
|
19
21
|
open?: boolean | undefined;
|
|
20
22
|
onOpenChange?(open: boolean): void;
|
|
21
23
|
selectedOptionFormatter?: SelectedOptionFormatter | undefined;
|
|
22
|
-
} & Pick<import("@snack-uikit/list").ListProps, "dataError" | "
|
|
24
|
+
} & Pick<import("@snack-uikit/list").ListProps, "dataError" | "dataFiltered" | "noDataState" | "noResultsState" | "errorDataState"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -23,7 +23,10 @@ import { extractFieldDecoratorProps } from '../FieldDecorator/utils';
|
|
|
23
23
|
import { useButtons, useHandleOnKeyDown, useSearchInput } from './hooks';
|
|
24
24
|
import styles from './styles.module.css';
|
|
25
25
|
import { extractListProps, getArrowIcon, updateItems } from './utils';
|
|
26
|
-
const defaultSelectedOptionFormatter = item =>
|
|
26
|
+
const defaultSelectedOptionFormatter = item =>
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
|
+
// @ts-expect-error
|
|
29
|
+
(item === null || item === void 0 ? void 0 : item.content.option) || '';
|
|
27
30
|
export const FieldSelectSingle = forwardRef((_a, ref) => {
|
|
28
31
|
var _b;
|
|
29
32
|
var { id, name, placeholder, size = 's', options, value: valueProp, defaultValue, onChange: onChangeProp, disabled = false, readonly = false, searchable = true, showCopyButton = true, showClearButton = true, onKeyDown: onInputKeyDownProp, required = false, validationState = 'default', search, autocomplete = false, prefixIcon, addOptionByEnter = false, open: openProp, onOpenChange, selectedOptionFormatter = defaultSelectedOptionFormatter } = _a, rest = __rest(_a, ["id", "name", "placeholder", "size", "options", "value", "defaultValue", "onChange", "disabled", "readonly", "searchable", "showCopyButton", "showClearButton", "onKeyDown", "required", "validationState", "search", "autocomplete", "prefixIcon", "addOptionByEnter", "open", "onOpenChange", "selectedOptionFormatter"]);
|
|
@@ -35,7 +38,10 @@ export const FieldSelectSingle = forwardRef((_a, ref) => {
|
|
|
35
38
|
onChange: onChangeProp,
|
|
36
39
|
});
|
|
37
40
|
const [{ selectedItem, items = [] }, setItems] = useState(() => updateItems({ options, value, currentItems: [], selectedItem: undefined }));
|
|
38
|
-
const { inputValue, setInputValue, prevInputValue, updateInputValue } = useSearchInput(Object.assign(Object.assign({}, search), {
|
|
41
|
+
const { inputValue, setInputValue, prevInputValue, updateInputValue } = useSearchInput(Object.assign(Object.assign({}, search), {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
43
|
+
// @ts-expect-error
|
|
44
|
+
defaultValue: (_b = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.content.option) !== null && _b !== void 0 ? _b : '', selectedOptionFormatter }));
|
|
39
45
|
const prevSelectedItem = useRef(selectedItem);
|
|
40
46
|
useLayoutEffect(() => {
|
|
41
47
|
setItems(({ selectedItem }) => updateItems({ options, value, selectedItem }));
|
|
@@ -43,6 +49,8 @@ export const FieldSelectSingle = forwardRef((_a, ref) => {
|
|
|
43
49
|
useEffect(() => {
|
|
44
50
|
if (prevSelectedItem.current &&
|
|
45
51
|
prevSelectedItem.current.id === (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id) &&
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
53
|
+
// @ts-expect-error
|
|
46
54
|
prevSelectedItem.current.content.option === (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.content.option)) {
|
|
47
55
|
return;
|
|
48
56
|
}
|
|
@@ -74,7 +74,10 @@ export function useHandleDeleteItem(setValue) {
|
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
76
|
if (isBaseOptionProps(item)) {
|
|
77
|
-
setValue((value) => value === null || value === void 0 ? void 0 : value.filter(v =>
|
|
77
|
+
setValue((value) => value === null || value === void 0 ? void 0 : value.filter(v =>
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
79
|
+
// @ts-expect-error
|
|
80
|
+
v !== item.id));
|
|
78
81
|
}
|
|
79
82
|
}, [setValue]);
|
|
80
83
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { InputPrivateProps } from '@snack-uikit/input-private';
|
|
3
|
-
import { AccordionItemProps, BaseItemProps, GroupItemProps, ListProps, NextListItemProps, SelectionMultipleState, SelectionSingleState } from '@snack-uikit/list';
|
|
3
|
+
import { AccordionItemProps, BaseItemProps, GroupItemProps, ItemContentProps, ListProps, NextListItemProps, SelectionMultipleState, SelectionSingleState } from '@snack-uikit/list';
|
|
4
4
|
import { TagProps } from '@snack-uikit/tag';
|
|
5
5
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
6
6
|
import { FieldDecoratorProps } from '../FieldDecorator';
|
|
7
|
+
export type AnyType = any;
|
|
7
8
|
export type OptionProps = BaseOptionProps | AccordionOptionProps | GroupOptionProps | NestListOptionProps;
|
|
8
9
|
export type OptionWithoutGroup = BaseOptionProps | AccordionOptionProps | NestListOptionProps;
|
|
9
|
-
export type BaseOptionProps = Pick<BaseItemProps, 'beforeContent' | 'afterContent' | 'disabled'> &
|
|
10
|
+
export type BaseOptionProps = Pick<BaseItemProps, 'beforeContent' | 'afterContent' | 'disabled'> & Pick<ItemContentProps, 'option' | 'caption' | 'description'> & {
|
|
10
11
|
value: string | number;
|
|
11
12
|
} & Pick<TagProps, 'appearance'>;
|
|
12
13
|
export type AccordionOptionProps = Pick<AccordionItemProps, 'type'> & BaseOptionProps & {
|
|
@@ -37,6 +38,8 @@ export type FieldSelectPrivateProps = InputProps & WrapperProps & {
|
|
|
37
38
|
};
|
|
38
39
|
type FiledSelectCommonProps = WithSupportProps<{
|
|
39
40
|
options: OptionProps[];
|
|
41
|
+
pinTop: OptionProps[];
|
|
42
|
+
pinBottom: OptionProps[];
|
|
40
43
|
searchable?: boolean;
|
|
41
44
|
/** Отображение кнопки Копировать для поля (актуально только для `readonly = true`) */
|
|
42
45
|
showCopyButton?: boolean;
|
|
@@ -59,7 +62,7 @@ type FiledSelectCommonProps = WithSupportProps<{
|
|
|
59
62
|
open?: boolean;
|
|
60
63
|
onOpenChange?(open: boolean): void;
|
|
61
64
|
selectedOptionFormatter?: SelectedOptionFormatter;
|
|
62
|
-
}> & Pick<ListProps, 'dataError' | 'noDataState' | 'noResultsState' | 'errorDataState' | '
|
|
65
|
+
}> & Pick<ListProps, 'dataError' | 'noDataState' | 'noResultsState' | 'errorDataState' | 'dataFiltered'>;
|
|
63
66
|
export type FieldSelectSingleProps = FieldSelectPrivateProps & Omit<SelectionSingleState, 'mode'> & WrapperProps & FiledSelectCommonProps;
|
|
64
67
|
export type FieldSelectMultipleProps = FieldSelectPrivateProps & {
|
|
65
68
|
removeByBackspace?: boolean;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DroplistProps } from '@snack-uikit/list';
|
|
2
2
|
import { FieldSelectProps } from '../types';
|
|
3
|
-
export declare function extractListProps({ dataError, noDataState, noResultsState, errorDataState,
|
|
3
|
+
export declare function extractListProps({ dataError, noDataState, noResultsState, errorDataState, dataFiltered, loading, }: Partial<FieldSelectProps>): Partial<DroplistProps>;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
export function extractListProps({ dataError, noDataState, noResultsState, errorDataState,
|
|
1
|
+
export function extractListProps({ dataError, noDataState, noResultsState, errorDataState, dataFiltered, loading, }) {
|
|
2
2
|
return {
|
|
3
3
|
dataError,
|
|
4
4
|
noDataState,
|
|
5
5
|
noResultsState,
|
|
6
6
|
errorDataState,
|
|
7
|
-
pinTop,
|
|
8
|
-
pinBottom,
|
|
9
7
|
dataFiltered,
|
|
10
8
|
loading,
|
|
11
9
|
trigger: 'clickAndFocusVisible',
|
|
@@ -12,7 +12,7 @@ export function isNextListOptionProps(option) {
|
|
|
12
12
|
}
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
14
|
export function isGroupOptionProps(option) {
|
|
15
|
-
return 'options' in option && option['type'] ===
|
|
15
|
+
return 'options' in option && option['type'] === 'group';
|
|
16
16
|
}
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
18
|
export function isFieldSelectMultipleProps(props) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ItemProps, SelectionSingleValueType } from '@snack-uikit/list';
|
|
2
|
+
import { ItemId } from '@snack-uikit/list/dist/components/Items';
|
|
2
3
|
import { ItemWithId, OptionProps } from '../types';
|
|
3
4
|
export declare function createPlaceholderItem(value: SelectionSingleValueType): {
|
|
4
|
-
id:
|
|
5
|
+
id: ItemId;
|
|
5
6
|
content: {
|
|
6
7
|
option: string;
|
|
7
8
|
};
|
|
@@ -9,12 +10,12 @@ export declare function createPlaceholderItem(value: SelectionSingleValueType):
|
|
|
9
10
|
};
|
|
10
11
|
export declare function updateItems({ options, value, selectedItem, }: {
|
|
11
12
|
options: OptionProps[];
|
|
12
|
-
value
|
|
13
|
+
value?: ItemId;
|
|
13
14
|
selectedItem?: ItemWithId;
|
|
14
15
|
currentItems?: ItemProps[];
|
|
15
16
|
}): {
|
|
16
17
|
selectedItem: ItemWithId | undefined;
|
|
17
|
-
items:
|
|
18
|
+
items: import("@snack-uikit/list/dist/components/Items").Item[];
|
|
18
19
|
};
|
|
19
20
|
export declare function updateMultipleItems({ options, value, selectedItems, }: {
|
|
20
21
|
options: OptionProps[];
|
|
@@ -23,10 +24,10 @@ export declare function updateMultipleItems({ options, value, selectedItems, }:
|
|
|
23
24
|
currentItems?: ItemProps[];
|
|
24
25
|
}): {
|
|
25
26
|
selectedItems: undefined;
|
|
26
|
-
items: (
|
|
27
|
+
items: (import("@snack-uikit/list/dist/components/Items").Item & {
|
|
27
28
|
appearance?: import("@snack-uikit/tag/dist/types").Appearance | undefined;
|
|
28
29
|
})[];
|
|
29
30
|
} | {
|
|
30
31
|
selectedItems: ItemWithId[];
|
|
31
|
-
items:
|
|
32
|
+
items: import("@snack-uikit/list/dist/components/Items").Item[];
|
|
32
33
|
};
|
|
@@ -42,8 +42,11 @@ export function updateMultipleItems({ options, value, selectedItems, }) {
|
|
|
42
42
|
let newItems = originalItems;
|
|
43
43
|
let newSelectedItems = selectedItems;
|
|
44
44
|
const flattenOriginalItems = flattenItems(originalItems);
|
|
45
|
-
|
|
46
|
-
const
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
const foundItems = flattenOriginalItems.filter((item) => value.includes(item.id));
|
|
47
|
+
const nonFoundValues = value.filter(
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
value => !flattenOriginalItems.find((item) => item.id === value));
|
|
47
50
|
if (nonFoundValues.length) {
|
|
48
51
|
const nonFoundItems = nonFoundValues.map(value => (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.find(selectedItem => selectedItem.id === value)) || createPlaceholderItem(value));
|
|
49
52
|
newSelectedItems = [...foundItems, ...nonFoundItems];
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Fields",
|
|
7
|
-
"version": "0.18.0",
|
|
7
|
+
"version": "0.18.1-preview-69abc1d3.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -32,18 +32,18 @@
|
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@snack-uikit/button": "0.17.0",
|
|
36
|
-
"@snack-uikit/calendar": "0.7.
|
|
37
|
-
"@snack-uikit/droplist": "0.13.
|
|
35
|
+
"@snack-uikit/button": "0.17.1-preview-69abc1d3.0",
|
|
36
|
+
"@snack-uikit/calendar": "0.7.7-preview-69abc1d3.0",
|
|
37
|
+
"@snack-uikit/droplist": "0.13.15-preview-69abc1d3.0",
|
|
38
38
|
"@snack-uikit/icons": "0.20.1",
|
|
39
|
-
"@snack-uikit/input-private": "3.1.
|
|
40
|
-
"@snack-uikit/list": "0.10.0",
|
|
41
|
-
"@snack-uikit/scroll": "0.5.
|
|
42
|
-
"@snack-uikit/slider": "0.1.
|
|
43
|
-
"@snack-uikit/tag": "0.8.
|
|
44
|
-
"@snack-uikit/tooltip": "0.13.
|
|
45
|
-
"@snack-uikit/truncate-string": "0.4.
|
|
46
|
-
"@snack-uikit/utils": "3.2.0",
|
|
39
|
+
"@snack-uikit/input-private": "3.1.2-preview-69abc1d3.0",
|
|
40
|
+
"@snack-uikit/list": "0.10.1-preview-69abc1d3.0",
|
|
41
|
+
"@snack-uikit/scroll": "0.5.3-preview-69abc1d3.0",
|
|
42
|
+
"@snack-uikit/slider": "0.1.8-preview-69abc1d3.0",
|
|
43
|
+
"@snack-uikit/tag": "0.8.3-preview-69abc1d3.0",
|
|
44
|
+
"@snack-uikit/tooltip": "0.13.2-preview-69abc1d3.0",
|
|
45
|
+
"@snack-uikit/truncate-string": "0.4.13-preview-69abc1d3.0",
|
|
46
|
+
"@snack-uikit/utils": "3.2.1-preview-69abc1d3.0",
|
|
47
47
|
"classnames": "2.3.2",
|
|
48
48
|
"copy-to-clipboard": "3.3.3",
|
|
49
49
|
"merge-refs": "1.2.2",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@snack-uikit/locale": "*"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "f1afde301bcd6ae86662d45c89041e7a14cc7b98"
|
|
60
60
|
}
|
|
@@ -18,7 +18,10 @@ import { extractListProps, getArrowIcon, updateMultipleItems } from './utils';
|
|
|
18
18
|
|
|
19
19
|
const BASE_MIN_WIDTH = 4;
|
|
20
20
|
|
|
21
|
-
const defaultSelectedOptionFormatter: SelectedOptionFormatter = item =>
|
|
21
|
+
const defaultSelectedOptionFormatter: SelectedOptionFormatter = item =>
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
|
+
// @ts-expect-error
|
|
24
|
+
item?.content.option || '';
|
|
22
25
|
|
|
23
26
|
export const FieldSelectMultiple = forwardRef<HTMLInputElement, FieldSelectMultipleProps>(
|
|
24
27
|
(
|
|
@@ -25,7 +25,10 @@ import styles from './styles.module.scss';
|
|
|
25
25
|
import { FieldSelectSingleProps, ItemWithId, SelectedOptionFormatter } from './types';
|
|
26
26
|
import { extractListProps, getArrowIcon, updateItems } from './utils';
|
|
27
27
|
|
|
28
|
-
const defaultSelectedOptionFormatter: SelectedOptionFormatter = item =>
|
|
28
|
+
const defaultSelectedOptionFormatter: SelectedOptionFormatter = item =>
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
30
|
+
// @ts-expect-error
|
|
31
|
+
item?.content.option || '';
|
|
29
32
|
|
|
30
33
|
export const FieldSelectSingle = forwardRef<HTMLInputElement, FieldSelectSingleProps>(
|
|
31
34
|
(
|
|
@@ -72,6 +75,8 @@ export const FieldSelectSingle = forwardRef<HTMLInputElement, FieldSelectSingleP
|
|
|
72
75
|
|
|
73
76
|
const { inputValue, setInputValue, prevInputValue, updateInputValue } = useSearchInput({
|
|
74
77
|
...search,
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
79
|
+
// @ts-expect-error
|
|
75
80
|
defaultValue: selectedItem?.content.option ?? '',
|
|
76
81
|
selectedOptionFormatter,
|
|
77
82
|
});
|
|
@@ -86,6 +91,8 @@ export const FieldSelectSingle = forwardRef<HTMLInputElement, FieldSelectSingleP
|
|
|
86
91
|
if (
|
|
87
92
|
prevSelectedItem.current &&
|
|
88
93
|
prevSelectedItem.current.id === selectedItem?.id &&
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
95
|
+
// @ts-expect-error
|
|
89
96
|
prevSelectedItem.current.content.option === selectedItem?.content.option
|
|
90
97
|
) {
|
|
91
98
|
return;
|
|
@@ -136,7 +136,15 @@ export function useHandleDeleteItem(setValue: Handler) {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
if (isBaseOptionProps(item)) {
|
|
139
|
-
setValue(
|
|
139
|
+
setValue(
|
|
140
|
+
(value: SelectionSingleValueType[]) =>
|
|
141
|
+
value?.filter(
|
|
142
|
+
v =>
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
144
|
+
// @ts-expect-error
|
|
145
|
+
v !== item.id,
|
|
146
|
+
),
|
|
147
|
+
);
|
|
140
148
|
}
|
|
141
149
|
},
|
|
142
150
|
[setValue],
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
AccordionItemProps,
|
|
6
6
|
BaseItemProps,
|
|
7
7
|
GroupItemProps,
|
|
8
|
+
ItemContentProps,
|
|
8
9
|
ListProps,
|
|
9
10
|
NextListItemProps,
|
|
10
11
|
SelectionMultipleState,
|
|
@@ -15,17 +16,33 @@ import { WithSupportProps } from '@snack-uikit/utils';
|
|
|
15
16
|
|
|
16
17
|
import { FieldDecoratorProps } from '../FieldDecorator';
|
|
17
18
|
|
|
18
|
-
// eslint-disable-next-line no-
|
|
19
|
-
export type
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
export type AnyType = any;
|
|
21
|
+
|
|
22
|
+
export type OptionProps =
|
|
23
|
+
// eslint-disable-next-line no-use-before-define
|
|
24
|
+
| BaseOptionProps
|
|
25
|
+
// eslint-disable-next-line no-use-before-define
|
|
26
|
+
| AccordionOptionProps
|
|
27
|
+
// eslint-disable-next-line no-use-before-define
|
|
28
|
+
| GroupOptionProps
|
|
29
|
+
// eslint-disable-next-line no-use-before-define
|
|
30
|
+
| NestListOptionProps;
|
|
20
31
|
|
|
21
32
|
// eslint-disable-next-line no-use-before-define
|
|
22
33
|
export type OptionWithoutGroup = BaseOptionProps | AccordionOptionProps | NestListOptionProps;
|
|
23
34
|
|
|
24
35
|
export type BaseOptionProps = Pick<BaseItemProps, 'beforeContent' | 'afterContent' | 'disabled'> &
|
|
25
|
-
|
|
36
|
+
Pick<ItemContentProps, 'option' | 'caption' | 'description'> & { value: string | number } & Pick<
|
|
37
|
+
TagProps,
|
|
38
|
+
'appearance'
|
|
39
|
+
>;
|
|
26
40
|
|
|
27
41
|
export type AccordionOptionProps = Pick<AccordionItemProps, 'type'> & BaseOptionProps & { options: OptionProps[] };
|
|
28
|
-
|
|
42
|
+
|
|
43
|
+
export type GroupOptionProps = Omit<GroupItemProps, 'items' | 'id'> & {
|
|
44
|
+
options: OptionProps[];
|
|
45
|
+
};
|
|
29
46
|
export type NestListOptionProps = Pick<NextListItemProps, 'type' | 'onSublistOpenChanged' | 'id'> &
|
|
30
47
|
BaseOptionProps & { options: OptionProps[] };
|
|
31
48
|
|
|
@@ -66,6 +83,10 @@ export type FieldSelectPrivateProps = InputProps & WrapperProps & { options: Opt
|
|
|
66
83
|
|
|
67
84
|
type FiledSelectCommonProps = WithSupportProps<{
|
|
68
85
|
options: OptionProps[];
|
|
86
|
+
|
|
87
|
+
pinTop: OptionProps[];
|
|
88
|
+
pinBottom: OptionProps[];
|
|
89
|
+
|
|
69
90
|
searchable?: boolean;
|
|
70
91
|
/** Отображение кнопки Копировать для поля (актуально только для `readonly = true`) */
|
|
71
92
|
showCopyButton?: boolean;
|
|
@@ -97,20 +118,16 @@ type FiledSelectCommonProps = WithSupportProps<{
|
|
|
97
118
|
|
|
98
119
|
selectedOptionFormatter?: SelectedOptionFormatter;
|
|
99
120
|
}> &
|
|
100
|
-
Pick<
|
|
101
|
-
ListProps,
|
|
102
|
-
'dataError' | 'noDataState' | 'noResultsState' | 'errorDataState' | 'pinTop' | 'pinBottom' | 'dataFiltered'
|
|
103
|
-
>;
|
|
121
|
+
Pick<ListProps, 'dataError' | 'noDataState' | 'noResultsState' | 'errorDataState' | 'dataFiltered'>;
|
|
104
122
|
|
|
105
123
|
export type FieldSelectSingleProps = FieldSelectPrivateProps &
|
|
106
124
|
Omit<SelectionSingleState, 'mode'> &
|
|
107
125
|
WrapperProps &
|
|
108
126
|
FiledSelectCommonProps;
|
|
109
127
|
|
|
110
|
-
export type FieldSelectMultipleProps = FieldSelectPrivateProps & {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
> &
|
|
128
|
+
export type FieldSelectMultipleProps = FieldSelectPrivateProps & {
|
|
129
|
+
removeByBackspace?: boolean;
|
|
130
|
+
} & Omit<SelectionMultipleState, 'mode'> &
|
|
114
131
|
Omit<FiledSelectCommonProps, 'showCopyButton'>;
|
|
115
132
|
|
|
116
133
|
export type FieldSelectProps =
|
|
@@ -7,8 +7,6 @@ export function extractListProps({
|
|
|
7
7
|
noDataState,
|
|
8
8
|
noResultsState,
|
|
9
9
|
errorDataState,
|
|
10
|
-
pinTop,
|
|
11
|
-
pinBottom,
|
|
12
10
|
dataFiltered,
|
|
13
11
|
loading,
|
|
14
12
|
}: Partial<FieldSelectProps>): Partial<DroplistProps> {
|
|
@@ -17,8 +15,6 @@ export function extractListProps({
|
|
|
17
15
|
noDataState,
|
|
18
16
|
noResultsState,
|
|
19
17
|
errorDataState,
|
|
20
|
-
pinTop,
|
|
21
|
-
pinBottom,
|
|
22
18
|
dataFiltered,
|
|
23
19
|
loading,
|
|
24
20
|
trigger: 'clickAndFocusVisible',
|
|
@@ -24,7 +24,7 @@ export function isNextListOptionProps(option: any): option is NestListOptionProp
|
|
|
24
24
|
|
|
25
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
26
|
export function isGroupOptionProps(option: any): option is GroupOptionProps {
|
|
27
|
-
return 'options' in option && option['type'] ===
|
|
27
|
+
return 'options' in option && option['type'] === 'group';
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { flattenItems, ItemProps, SelectionSingleValueType } from '@snack-uikit/list';
|
|
2
|
+
import { ItemId } from '@snack-uikit/list/dist/components/Items';
|
|
2
3
|
|
|
3
4
|
import { ItemWithId, OptionProps } from '../types';
|
|
4
5
|
import { transformOptionsToItems } from './options';
|
|
@@ -13,7 +14,7 @@ export function updateItems({
|
|
|
13
14
|
selectedItem,
|
|
14
15
|
}: {
|
|
15
16
|
options: OptionProps[];
|
|
16
|
-
value
|
|
17
|
+
value?: ItemId;
|
|
17
18
|
selectedItem?: ItemWithId;
|
|
18
19
|
currentItems?: ItemProps[];
|
|
19
20
|
}) {
|
|
@@ -72,9 +73,11 @@ export function updateMultipleItems({
|
|
|
72
73
|
|
|
73
74
|
const flattenOriginalItems = flattenItems(originalItems);
|
|
74
75
|
|
|
75
|
-
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
|
+
const foundItems: ItemWithId[] = flattenOriginalItems.filter((item: any) => value.includes(item.id));
|
|
76
78
|
const nonFoundValues: SelectionSingleValueType[] = value.filter(
|
|
77
|
-
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
+
value => !flattenOriginalItems.find((item: any) => item.id === value),
|
|
78
81
|
);
|
|
79
82
|
|
|
80
83
|
if (nonFoundValues.length) {
|