@snack-uikit/fields 0.16.1-preview-da21d728.0 → 0.17.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/CHANGELOG.md +27 -0
- package/dist/components/FieldSelect/FieldSelectMultiple.js +3 -2
- package/dist/components/FieldSelect/types.d.ts +2 -1
- package/dist/components/FieldSelect/utils.d.ts +2 -0
- package/dist/components/FieldSelect/utils.js +18 -0
- package/dist/components/FieldSlider/helpers/generateAllowedValues.js +1 -1
- package/package.json +5 -5
- package/src/components/FieldSelect/FieldSelectMultiple.tsx +10 -1
- package/src/components/FieldSelect/types.ts +2 -1
- package/src/components/FieldSelect/utils.ts +29 -0
- package/src/components/FieldSlider/helpers/generateAllowedValues.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,33 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 0.17.0 (2024-02-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **FF-4324:** fix infinite response in actocomplete mode ([ad19e0c](https://github.com/cloud-ru-tech/snack-uikit/commit/ad19e0cb6e91b4dda12bc34a3f55fe823f508602))
|
|
12
|
+
* **FF-4324:** fix value dec value as value === max ([a8bb974](https://github.com/cloud-ru-tech/snack-uikit/commit/a8bb9747f31864ea616fef6b9e2166047faceae7))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **FF-4323:** add not found items from value ([a924867](https://github.com/cloud-ru-tech/snack-uikit/commit/a92486740ce4de274ff7331fd9dbf67a9f1a39da))
|
|
18
|
+
* **FF-4324:** add appearance to tags view in muliple select ([1ce6b81](https://github.com/cloud-ru-tech/snack-uikit/commit/1ce6b817714bf6fb35e394338ab0083fa92ca44f))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## 0.16.1 (2024-02-27)
|
|
25
|
+
|
|
26
|
+
### Only dependencies have been changed
|
|
27
|
+
* [@snack-uikit/list@0.5.0](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/list/CHANGELOG.md)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
6
33
|
# 0.16.0 (2024-02-26)
|
|
7
34
|
|
|
8
35
|
|
|
@@ -23,7 +23,7 @@ import { FieldDecorator } from '../FieldDecorator';
|
|
|
23
23
|
import { extractFieldDecoratorProps } from '../FieldDecorator/utils';
|
|
24
24
|
import { useButtons, useHandleDeleteItem, useHandleOnKeyDown, useSearchInput } from './hooks';
|
|
25
25
|
import styles from './styles.module.css';
|
|
26
|
-
import { extractListProps, findSelectedOptions, getArrowIcon, transformOptionsToItems } from './utils';
|
|
26
|
+
import { extractListProps, findSelectedOptions, getArrowIcon, mapOptionToAppearance, transformOptionsToItems, } from './utils';
|
|
27
27
|
const BASE_MIN_WIDTH = 4;
|
|
28
28
|
export const FieldSelectMultiple = forwardRef((_a, ref) => {
|
|
29
29
|
var _b, _c, _d;
|
|
@@ -33,6 +33,7 @@ export const FieldSelectMultiple = forwardRef((_a, ref) => {
|
|
|
33
33
|
const contentRef = useRef(null);
|
|
34
34
|
const [open = false, setOpen] = useValueControl({ value: openProp, onChange: onOpenChange });
|
|
35
35
|
const items = useMemo(() => transformOptionsToItems(options), [options]);
|
|
36
|
+
const mapItemsToTagAppearance = useMemo(() => mapOptionToAppearance(options), [options]);
|
|
36
37
|
const [value, setValue] = useValueControl({
|
|
37
38
|
value: valueProp,
|
|
38
39
|
defaultValue,
|
|
@@ -139,7 +140,7 @@ export const FieldSelectMultiple = forwardRef((_a, ref) => {
|
|
|
139
140
|
}, dataFiltered: (_d = rest.dataFiltered) !== null && _d !== void 0 ? _d : Boolean(inputValue.length), size: size, open: !disabled && !readonly && open, onOpenChange: handleOpenChange, children: ({ onKeyDown }) => {
|
|
140
141
|
var _a, _b, _c, _d;
|
|
141
142
|
return (_jsx(FieldContainerPrivate, { className: cn(styles.container, styles.tagContainer), validationState: validationState, disabled: disabled, readonly: readonly, focused: open, variant: 'single-line-container', inputRef: localRef, size: size, prefix: prefixIcon, children: _jsxs(_Fragment, { children: [_jsxs("div", { className: styles.contentWrapper, ref: contentRef, children: [selected &&
|
|
142
|
-
selected.map(option => (_jsx(Tag, { size: size === 'l' ? 's' : 'xs', tabIndex: -1, label: String(option.content.option), onDelete: !option.disabled && !disabled && !readonly ? handleItemDelete(option) : undefined }, option.id))), _jsx("div", { className: styles.inputWrapper, style: {
|
|
143
|
+
selected.map(option => (_jsx(Tag, { size: size === 'l' ? 's' : 'xs', tabIndex: -1, label: String(option.content.option), appearance: option.id ? mapItemsToTagAppearance[option === null || option === void 0 ? void 0 : option.id] : 'neutral', onDelete: !option.disabled && !disabled && !readonly ? handleItemDelete(option) : undefined }, option.id))), _jsx("div", { className: styles.inputWrapper, style: {
|
|
143
144
|
minWidth: value
|
|
144
145
|
? Math.min((_b = (_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) !== null && _b !== void 0 ? _b : BASE_MIN_WIDTH, (_d = (_c = inputPlugRef.current) === null || _c === void 0 ? void 0 : _c.clientWidth) !== null && _d !== void 0 ? _d : BASE_MIN_WIDTH)
|
|
145
146
|
: '100%',
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { InputPrivateProps } from '@snack-uikit/input-private';
|
|
3
3
|
import { AccordionItemProps, BaseItemProps, GroupItemProps, ListProps, NextListItemProps, SelectionMultipleState, SelectionSingleState } from '@snack-uikit/list';
|
|
4
|
+
import { TagProps } from '@snack-uikit/tag';
|
|
4
5
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
5
6
|
import { FieldDecoratorProps } from '../FieldDecorator';
|
|
6
7
|
export type OptionProps = BaseOptionProps | AccordionOptionProps | GroupOptionProps | NestListOptionProps;
|
|
7
8
|
export type OptionWithoutGroup = BaseOptionProps | AccordionOptionProps | NestListOptionProps;
|
|
8
9
|
export type BaseOptionProps = Pick<BaseItemProps, 'beforeContent' | 'afterContent' | 'disabled'> & BaseItemProps['content'] & {
|
|
9
10
|
value: string | number;
|
|
10
|
-
}
|
|
11
|
+
} & Pick<TagProps, 'appearance'>;
|
|
11
12
|
export type AccordionOptionProps = Pick<AccordionItemProps, 'type'> & BaseOptionProps & {
|
|
12
13
|
options: OptionProps[];
|
|
13
14
|
};
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Size } from '@snack-uikit/input-private';
|
|
2
2
|
import { DroplistProps, ItemProps, SelectionSingleValueType } from '@snack-uikit/list';
|
|
3
|
+
import { TagProps } from '@snack-uikit/tag';
|
|
3
4
|
import { AccordionOptionProps, BaseOptionProps, FieldSelectMultipleProps, FieldSelectProps, FieldSelectSingleProps, GroupOptionProps, ItemWithId, NestListOptionProps, OptionProps } from './types';
|
|
4
5
|
export declare function isBaseOptionProps(option: any): option is BaseOptionProps;
|
|
5
6
|
export declare function isAccordionOptionProps(option: any): option is AccordionOptionProps;
|
|
6
7
|
export declare function isNextListOptionProps(option: any): option is NestListOptionProps;
|
|
7
8
|
export declare function isGroupOptionProps(option: any): option is GroupOptionProps;
|
|
9
|
+
export declare function mapOptionToAppearance(options: OptionProps[]): Record<string | number, TagProps['appearance'] | undefined>;
|
|
8
10
|
export declare function transformOptionsToItems(options: OptionProps[]): ItemProps[];
|
|
9
11
|
export declare function findSelectedOption(items: ItemProps[], value: SelectionSingleValueType): [ItemWithId | undefined, ItemWithId | undefined];
|
|
10
12
|
export declare function findSelectedOptions(items: ItemProps[], value: SelectionSingleValueType[] | undefined): [ItemWithId[] | undefined, ItemWithId[] | undefined];
|
|
@@ -28,6 +28,24 @@ export function isNextListOptionProps(option) {
|
|
|
28
28
|
export function isGroupOptionProps(option) {
|
|
29
29
|
return 'options' in option && option['type'] === undefined;
|
|
30
30
|
}
|
|
31
|
+
export function mapOptionToAppearance(options) {
|
|
32
|
+
let mapOption2Appearance = {};
|
|
33
|
+
options.forEach(option => {
|
|
34
|
+
if (isAccordionOptionProps(option) || isNextListOptionProps(option)) {
|
|
35
|
+
const { options, value, appearance } = option;
|
|
36
|
+
mapOption2Appearance = Object.assign(Object.assign(Object.assign({}, mapOption2Appearance), { [value]: appearance }), mapOptionToAppearance(options));
|
|
37
|
+
}
|
|
38
|
+
if (isGroupOptionProps(option)) {
|
|
39
|
+
const { options } = option;
|
|
40
|
+
mapOption2Appearance = Object.assign(Object.assign({}, mapOption2Appearance), mapOptionToAppearance(options));
|
|
41
|
+
}
|
|
42
|
+
const { value, appearance } = option;
|
|
43
|
+
if (value !== undefined) {
|
|
44
|
+
mapOption2Appearance = Object.assign(Object.assign({}, mapOption2Appearance), { [value]: appearance });
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return mapOption2Appearance;
|
|
48
|
+
}
|
|
31
49
|
export function transformOptionsToItems(options) {
|
|
32
50
|
return options.map(option => {
|
|
33
51
|
if (isAccordionOptionProps(option) || isNextListOptionProps(option)) {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Fields",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.17.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -34,13 +34,13 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@snack-uikit/button": "0.16.1",
|
|
36
36
|
"@snack-uikit/calendar": "0.7.6",
|
|
37
|
-
"@snack-uikit/droplist": "0.13.9
|
|
37
|
+
"@snack-uikit/droplist": "0.13.9",
|
|
38
38
|
"@snack-uikit/icons": "0.20.1",
|
|
39
39
|
"@snack-uikit/input-private": "3.1.1",
|
|
40
|
-
"@snack-uikit/list": "0.
|
|
40
|
+
"@snack-uikit/list": "0.6.0",
|
|
41
41
|
"@snack-uikit/scroll": "0.5.2",
|
|
42
42
|
"@snack-uikit/slider": "0.1.4",
|
|
43
|
-
"@snack-uikit/tag": "0.8.1
|
|
43
|
+
"@snack-uikit/tag": "0.8.1",
|
|
44
44
|
"@snack-uikit/tooltip": "0.12.1",
|
|
45
45
|
"@snack-uikit/truncate-string": "0.4.9",
|
|
46
46
|
"@snack-uikit/utils": "3.2.0",
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"@snack-uikit/locale": "*"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "559f1542bf57e8a3be174390e4bd1f2b8f799946"
|
|
60
60
|
}
|
|
@@ -14,7 +14,13 @@ import { extractFieldDecoratorProps } from '../FieldDecorator/utils';
|
|
|
14
14
|
import { useButtons, useHandleDeleteItem, useHandleOnKeyDown, useSearchInput } from './hooks';
|
|
15
15
|
import styles from './styles.module.scss';
|
|
16
16
|
import { FieldSelectMultipleProps, ItemWithId } from './types';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
extractListProps,
|
|
19
|
+
findSelectedOptions,
|
|
20
|
+
getArrowIcon,
|
|
21
|
+
mapOptionToAppearance,
|
|
22
|
+
transformOptionsToItems,
|
|
23
|
+
} from './utils';
|
|
18
24
|
|
|
19
25
|
const BASE_MIN_WIDTH = 4;
|
|
20
26
|
|
|
@@ -52,6 +58,8 @@ export const FieldSelectMultiple = forwardRef<HTMLInputElement, FieldSelectMulti
|
|
|
52
58
|
|
|
53
59
|
const [open = false, setOpen] = useValueControl<boolean>({ value: openProp, onChange: onOpenChange });
|
|
54
60
|
const items = useMemo(() => transformOptionsToItems(options), [options]);
|
|
61
|
+
const mapItemsToTagAppearance = useMemo(() => mapOptionToAppearance(options), [options]);
|
|
62
|
+
|
|
55
63
|
const [value, setValue] = useValueControl<SelectionSingleValueType[]>({
|
|
56
64
|
value: valueProp,
|
|
57
65
|
defaultValue,
|
|
@@ -225,6 +233,7 @@ export const FieldSelectMultiple = forwardRef<HTMLInputElement, FieldSelectMulti
|
|
|
225
233
|
tabIndex={-1}
|
|
226
234
|
label={String(option.content.option)}
|
|
227
235
|
key={option.id}
|
|
236
|
+
appearance={option.id ? mapItemsToTagAppearance[option?.id] : 'neutral'}
|
|
228
237
|
onDelete={!option.disabled && !disabled && !readonly ? handleItemDelete(option) : undefined}
|
|
229
238
|
/>
|
|
230
239
|
))}
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
SelectionMultipleState,
|
|
11
11
|
SelectionSingleState,
|
|
12
12
|
} from '@snack-uikit/list';
|
|
13
|
+
import { TagProps } from '@snack-uikit/tag';
|
|
13
14
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
14
15
|
|
|
15
16
|
import { FieldDecoratorProps } from '../FieldDecorator';
|
|
@@ -21,7 +22,7 @@ export type OptionProps = BaseOptionProps | AccordionOptionProps | GroupOptionPr
|
|
|
21
22
|
export type OptionWithoutGroup = BaseOptionProps | AccordionOptionProps | NestListOptionProps;
|
|
22
23
|
|
|
23
24
|
export type BaseOptionProps = Pick<BaseItemProps, 'beforeContent' | 'afterContent' | 'disabled'> &
|
|
24
|
-
BaseItemProps['content'] & { value: string | number }
|
|
25
|
+
BaseItemProps['content'] & { value: string | number } & Pick<TagProps, 'appearance'>;
|
|
25
26
|
|
|
26
27
|
export type AccordionOptionProps = Pick<AccordionItemProps, 'type'> & BaseOptionProps & { options: OptionProps[] };
|
|
27
28
|
export type GroupOptionProps = Omit<GroupItemProps, 'items' | 'id'> & { options: OptionProps[] };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ChevronDownSVG, ChevronUpSVG } from '@snack-uikit/icons';
|
|
2
2
|
import { ICON_SIZE, SIZE, Size } from '@snack-uikit/input-private';
|
|
3
3
|
import { DroplistProps, flattenItems, ItemProps, SelectionSingleValueType } from '@snack-uikit/list';
|
|
4
|
+
import { TagProps } from '@snack-uikit/tag';
|
|
4
5
|
|
|
5
6
|
import {
|
|
6
7
|
AccordionOptionProps,
|
|
@@ -34,6 +35,34 @@ export function isGroupOptionProps(option: any): option is GroupOptionProps {
|
|
|
34
35
|
return 'options' in option && option['type'] === undefined;
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
export function mapOptionToAppearance(
|
|
39
|
+
options: OptionProps[],
|
|
40
|
+
): Record<string | number, TagProps['appearance'] | undefined> {
|
|
41
|
+
let mapOption2Appearance: Record<string | number, TagProps['appearance'] | undefined> = {};
|
|
42
|
+
|
|
43
|
+
options.forEach(option => {
|
|
44
|
+
if (isAccordionOptionProps(option) || isNextListOptionProps(option)) {
|
|
45
|
+
const { options, value, appearance } = option;
|
|
46
|
+
|
|
47
|
+
mapOption2Appearance = { ...mapOption2Appearance, [value]: appearance, ...mapOptionToAppearance(options) };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (isGroupOptionProps(option)) {
|
|
51
|
+
const { options } = option;
|
|
52
|
+
|
|
53
|
+
mapOption2Appearance = { ...mapOption2Appearance, ...mapOptionToAppearance(options) };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const { value, appearance } = option as BaseOptionProps;
|
|
57
|
+
|
|
58
|
+
if (value !== undefined) {
|
|
59
|
+
mapOption2Appearance = { ...mapOption2Appearance, [value]: appearance };
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return mapOption2Appearance;
|
|
64
|
+
}
|
|
65
|
+
|
|
37
66
|
export function transformOptionsToItems(options: OptionProps[]): ItemProps[] {
|
|
38
67
|
return options.map(option => {
|
|
39
68
|
if (isAccordionOptionProps(option) || isNextListOptionProps(option)) {
|