@snack-uikit/chips 0.11.10-preview-778a0ef6.0 → 0.12.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 +11 -0
- package/dist/components/ChipChoice/components/ChipChoiceCustom/ChipChoiceCustom.js +1 -1
- package/dist/components/ChipChoice/components/ChipChoiceDate.js +4 -2
- package/dist/components/ChipChoice/components/ChipChoiceDateRange.js +7 -3
- package/dist/components/ChipChoice/components/ChipChoiceSingle.js +7 -3
- package/dist/components/ChipChoice/utils.d.ts +5 -0
- package/dist/components/ChipChoice/utils.js +4 -0
- package/package.json +3 -3
- package/src/components/ChipChoice/components/ChipChoiceCustom/ChipChoiceCustom.tsx +1 -1
- package/src/components/ChipChoice/components/ChipChoiceDate.tsx +5 -2
- package/src/components/ChipChoice/components/ChipChoiceDateRange.tsx +13 -3
- package/src/components/ChipChoice/components/ChipChoiceSingle.tsx +8 -3
- package/src/components/ChipChoice/utils.ts +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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.12.0 (2024-02-26)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
* **FF-4324:** change default label formattes ([ecccf01](https://github.com/cloud-ru-tech/snack-uikit/commit/ecccf01237bc58ed68e84bb2522fb4fcfd6a33e9))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 0.11.9 (2024-02-23)
|
|
7
18
|
|
|
8
19
|
### Only dependencies have been changed
|
|
@@ -71,5 +71,5 @@ export function ChipChoiceCustom(_a) {
|
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
const showClearButton = showClearButtonProp && (value instanceof Date || Boolean(value === null || value === void 0 ? void 0 : value.length));
|
|
74
|
-
return (_jsx(Droplist, { trigger: 'click', open: isDroplistOpened, firstElementRefCallback: firstElementRefCallback, onOpenChange: onOpenChangeHandler, onFocusLeave: handleDroplistFocusLeave, triggerClassName: styles.triggerClassName, widthStrategy: widthStrategy, placement: placement, size: DROPLIST_SIZE_MAP[size], "data-test-id": CHIP_CHOICE_TEST_IDS.droplist, triggerElement: _jsxs("div", Object.assign({}, extractSupportProps(rest), { role: 'button', ref: triggerElementRef, className: cn(styles.choiceChip, className), "data-size": size, "data-variant": variant, "data-loading": loading || undefined, "data-test-id": testId || undefined, "data-disabled": (!loading && disabled) || undefined, onClick: handleChipClick, onKeyDown: handleChipKeyDown, tabIndex: tabIndex, children: [variant === VARIANT.IconBefore && (_jsx("span", { className: styles.icon, "data-test-id": CHIP_CHOICE_TEST_IDS.icon, children: icon })), _jsxs("span", { className: styles.labelLayout, children: [label && (_jsx("span", { className: styles.label, "data-test-id": CHIP_CHOICE_TEST_IDS.label, children: label })), loading ? (_jsx("span", { className: styles.spinner, "data-test-id": CHIP_CHOICE_TEST_IDS.spinner, children: _jsx(Sun, { size: spinnerSize }) })) : (_jsx("span", { className: styles.value, "data-test-id": CHIP_CHOICE_TEST_IDS.value, children: valueToRender }))] }), !disabled && !loading && showClearButton && (_jsx(ButtonClearValue, { size: BUTTON_CLEAR_VALUE_SIZE_MAP[size], onClick: handleClearButtonClick, "data-test-id": CHIP_CHOICE_TEST_IDS.clearButton, onKeyDown: handleClearButtonKeyDown, ref: clearButtonRef }))] })), children: typeof children === 'function' ? children({ handleDroplistItemKeyDown, closeDroplist }) : children }));
|
|
74
|
+
return (_jsx(Droplist, { trigger: 'click', open: isDroplistOpened, firstElementRefCallback: firstElementRefCallback, onOpenChange: onOpenChangeHandler, onFocusLeave: handleDroplistFocusLeave, triggerClassName: styles.triggerClassName, widthStrategy: widthStrategy, placement: placement, size: DROPLIST_SIZE_MAP[size], "data-test-id": CHIP_CHOICE_TEST_IDS.droplist, triggerElement: _jsxs("div", Object.assign({}, extractSupportProps(rest), { role: 'button', ref: triggerElementRef, className: cn(styles.choiceChip, className), "data-size": size, "data-variant": variant, "data-loading": loading || undefined, "data-test-id": testId || undefined, "data-disabled": (!loading && disabled) || undefined, onClick: handleChipClick, onKeyDown: handleChipKeyDown, tabIndex: tabIndex, children: [variant === VARIANT.IconBefore && (_jsx("span", { className: styles.icon, "data-test-id": CHIP_CHOICE_TEST_IDS.icon, children: icon })), _jsxs("span", { className: styles.labelLayout, children: [label && (_jsx("span", { className: styles.label, "data-test-id": CHIP_CHOICE_TEST_IDS.label, children: label + ': ' })), loading ? (_jsx("span", { className: styles.spinner, "data-test-id": CHIP_CHOICE_TEST_IDS.spinner, children: _jsx(Sun, { size: spinnerSize }) })) : (_jsx("span", { className: styles.value, "data-test-id": CHIP_CHOICE_TEST_IDS.value, children: valueToRender }))] }), !disabled && !loading && showClearButton && (_jsx(ButtonClearValue, { size: BUTTON_CLEAR_VALUE_SIZE_MAP[size], onClick: handleClearButtonClick, "data-test-id": CHIP_CHOICE_TEST_IDS.clearButton, onKeyDown: handleClearButtonKeyDown, ref: clearButtonRef }))] })), children: typeof children === 'function' ? children({ handleDroplistItemKeyDown, closeDroplist }) : children }));
|
|
75
75
|
}
|
|
@@ -12,15 +12,17 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
14
14
|
import { Calendar } from '@snack-uikit/calendar';
|
|
15
|
-
import {
|
|
15
|
+
import { useLocale } from '@snack-uikit/locale';
|
|
16
|
+
import { SIZE } from '../../../constants';
|
|
16
17
|
import { CALENDAR_SIZE_MAP } from '../constants';
|
|
17
18
|
import { ChipChoiceCustom } from './ChipChoiceCustom';
|
|
18
19
|
export function ChipChoiceDate(_a) {
|
|
19
20
|
var { size = SIZE.S, value, defaultValue, onChange, valueFormatter } = _a, rest = __rest(_a, ["size", "value", "defaultValue", "onChange", "valueFormatter"]);
|
|
20
21
|
const [selectedValue, setSelectedValue] = useUncontrolledProp(value, defaultValue, onChange);
|
|
22
|
+
const { t } = useLocale('Chips');
|
|
21
23
|
const valueToRender = valueFormatter
|
|
22
24
|
? valueFormatter(selectedValue)
|
|
23
|
-
: (selectedValue && new Date(selectedValue).toLocaleDateString()) ||
|
|
25
|
+
: (selectedValue && new Date(selectedValue).toLocaleDateString()) || t('allLabel');
|
|
24
26
|
const clearValue = () => setSelectedValue(undefined);
|
|
25
27
|
return (_jsx(ChipChoiceCustom, Object.assign({ onClearButtonClick: clearValue, value: selectedValue, valueToRender: valueToRender, size: size }, rest, { children: ({ closeDroplist }) => (_jsx(Calendar, { mode: 'date', size: CALENDAR_SIZE_MAP[size], value: selectedValue, onChangeValue: value => {
|
|
26
28
|
setSelectedValue(value);
|
|
@@ -12,19 +12,23 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
14
14
|
import { Calendar } from '@snack-uikit/calendar';
|
|
15
|
+
import { useLocale } from '@snack-uikit/locale';
|
|
15
16
|
import { DEFAULT_EMPTY_VALUE, SIZE } from '../../../constants';
|
|
16
17
|
import { CALENDAR_SIZE_MAP } from '../constants';
|
|
17
18
|
import { ChipChoiceCustom } from './ChipChoiceCustom';
|
|
18
|
-
function defaultRangeFormatter(value) {
|
|
19
|
+
function defaultRangeFormatter({ value, allLabel }) {
|
|
19
20
|
if (!value || !value.length)
|
|
20
|
-
return
|
|
21
|
+
return allLabel;
|
|
21
22
|
const [from, to] = value;
|
|
22
23
|
return `${from.toLocaleDateString()} ${DEFAULT_EMPTY_VALUE} ${to.toLocaleDateString()}`;
|
|
23
24
|
}
|
|
24
25
|
export function ChipChoiceDateRange(_a) {
|
|
25
26
|
var { size = SIZE.S, value, defaultValue, onChange, valueFormatter } = _a, rest = __rest(_a, ["size", "value", "defaultValue", "onChange", "valueFormatter"]);
|
|
26
27
|
const [selectedValue, setSelectedValue] = useUncontrolledProp(value, defaultValue, onChange);
|
|
27
|
-
const
|
|
28
|
+
const { t } = useLocale('Chips');
|
|
29
|
+
const valueToRender = valueFormatter
|
|
30
|
+
? valueFormatter(selectedValue)
|
|
31
|
+
: defaultRangeFormatter({ value: selectedValue, allLabel: t('allLabel') });
|
|
28
32
|
const clearValue = () => setSelectedValue(undefined);
|
|
29
33
|
return (_jsx(ChipChoiceCustom, Object.assign({ value: selectedValue, valueToRender: valueToRender, onClearButtonClick: clearValue, size: size }, rest, { children: ({ closeDroplist }) => (_jsx(Calendar, { mode: 'range', size: CALENDAR_SIZE_MAP[size], value: selectedValue, onChangeValue: range => {
|
|
30
34
|
setSelectedValue(range);
|
|
@@ -14,14 +14,18 @@ import { createElement as _createElement } from "react";
|
|
|
14
14
|
import { useMemo } from 'react';
|
|
15
15
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
16
16
|
import { Droplist } from '@snack-uikit/droplist';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
17
|
+
import { useLocale } from '@snack-uikit/locale';
|
|
18
|
+
import { SIZE } from '../../../constants';
|
|
19
|
+
import { defaultSingleValueFormatter, normalizeValueForSingleChoice } from '../utils';
|
|
19
20
|
import { ChipChoiceCustom } from './ChipChoiceCustom';
|
|
20
21
|
export function ChipChoiceSingle(_a) {
|
|
21
22
|
var { value, defaultValue, options, onChange, valueFormatter, size = SIZE.S, 'data-test-id': dataTestId } = _a, rest = __rest(_a, ["value", "defaultValue", "options", "onChange", "valueFormatter", "size", 'data-test-id']);
|
|
22
23
|
const [selectedValue, setSelectedValue] = useUncontrolledProp(normalizeValueForSingleChoice(options, value), normalizeValueForSingleChoice(options, defaultValue), onChange);
|
|
24
|
+
const { t } = useLocale('Chips');
|
|
23
25
|
const selectedOption = useMemo(() => options.find(({ value }) => value === selectedValue), [options, selectedValue]);
|
|
24
|
-
const valueToRender = valueFormatter
|
|
26
|
+
const valueToRender = valueFormatter
|
|
27
|
+
? valueFormatter(selectedOption)
|
|
28
|
+
: defaultSingleValueFormatter({ value: selectedOption, allLabel: t('allLabel') });
|
|
25
29
|
const clearValue = () => setSelectedValue(undefined);
|
|
26
30
|
return (_jsx(ChipChoiceCustom, Object.assign({ onClearButtonClick: clearValue, value: selectedValue, valueToRender: valueToRender, "data-test-id": dataTestId, size: size }, rest, { children: ({ handleDroplistItemKeyDown, closeDroplist }) => options.map((_a) => {
|
|
27
31
|
var { label, value } = _a, rest = __rest(_a, ["label", "value"]);
|
|
@@ -2,3 +2,8 @@ import { FilterOption } from './types';
|
|
|
2
2
|
export declare const normalizeValueForMultiChoice: (options: FilterOption[], value?: string[]) => string[] | undefined;
|
|
3
3
|
export declare const normalizeValueForSingleChoice: (options: FilterOption[], value?: string) => string | undefined;
|
|
4
4
|
export declare const defaultMultiValueLabelFormatter: (value: FilterOption[], total: number) => string;
|
|
5
|
+
export type ChipChoiceSingleValueFormatterProps = {
|
|
6
|
+
value?: FilterOption;
|
|
7
|
+
allLabel?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function defaultSingleValueFormatter({ value, allLabel }: ChipChoiceSingleValueFormatterProps): string | undefined;
|
|
@@ -12,3 +12,7 @@ export const normalizeValueForSingleChoice = (options, value) => {
|
|
|
12
12
|
return (_a = options.find(option => value === option.value)) === null || _a === void 0 ? void 0 : _a.value;
|
|
13
13
|
};
|
|
14
14
|
export const defaultMultiValueLabelFormatter = (value, total) => `${value.length.toString()}/${total}`;
|
|
15
|
+
export function defaultSingleValueFormatter({ value, allLabel }) {
|
|
16
|
+
var _a;
|
|
17
|
+
return (_a = value === null || value === void 0 ? void 0 : value.label) !== null && _a !== void 0 ? _a : allLabel;
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Chips",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.12.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -34,7 +34,7 @@
|
|
|
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.8
|
|
37
|
+
"@snack-uikit/droplist": "0.13.8",
|
|
38
38
|
"@snack-uikit/icons": "0.20.1",
|
|
39
39
|
"@snack-uikit/loaders": "0.5.1",
|
|
40
40
|
"@snack-uikit/utils": "3.2.0",
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@snack-uikit/locale": "*"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "eca9622fe5915bb18e60c4eb7a195ebc04f19f9c"
|
|
48
48
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
2
2
|
|
|
3
3
|
import { Calendar } from '@snack-uikit/calendar';
|
|
4
|
+
import { useLocale } from '@snack-uikit/locale';
|
|
4
5
|
|
|
5
|
-
import {
|
|
6
|
+
import { SIZE } from '../../../constants';
|
|
6
7
|
import { CALENDAR_SIZE_MAP } from '../constants';
|
|
7
8
|
import { ChipChoiceCommonProps } from '../types';
|
|
8
9
|
import { ChipChoiceCustom } from './ChipChoiceCustom';
|
|
@@ -28,9 +29,11 @@ export function ChipChoiceDate({
|
|
|
28
29
|
}: ChipChoiceDateProps) {
|
|
29
30
|
const [selectedValue, setSelectedValue] = useUncontrolledProp<Date>(value, defaultValue, onChange);
|
|
30
31
|
|
|
32
|
+
const { t } = useLocale('Chips');
|
|
33
|
+
|
|
31
34
|
const valueToRender = valueFormatter
|
|
32
35
|
? valueFormatter(selectedValue)
|
|
33
|
-
: (selectedValue && new Date(selectedValue).toLocaleDateString()) ||
|
|
36
|
+
: (selectedValue && new Date(selectedValue).toLocaleDateString()) || t('allLabel');
|
|
34
37
|
|
|
35
38
|
const clearValue = () => setSelectedValue(undefined);
|
|
36
39
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
2
2
|
|
|
3
3
|
import { Calendar } from '@snack-uikit/calendar';
|
|
4
|
+
import { useLocale } from '@snack-uikit/locale';
|
|
4
5
|
|
|
5
6
|
import { DEFAULT_EMPTY_VALUE, SIZE } from '../../../constants';
|
|
6
7
|
import { CALENDAR_SIZE_MAP } from '../constants';
|
|
@@ -20,8 +21,13 @@ export type ChipChoiceDateRangeProps = ChipChoiceCommonProps & {
|
|
|
20
21
|
valueFormatter?(value?: Range): string;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
type DefaultRangeFormatterProps = {
|
|
25
|
+
value?: Range;
|
|
26
|
+
allLabel?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function defaultRangeFormatter({ value, allLabel }: DefaultRangeFormatterProps) {
|
|
30
|
+
if (!value || !value.length) return allLabel;
|
|
25
31
|
|
|
26
32
|
const [from, to] = value;
|
|
27
33
|
|
|
@@ -38,7 +44,11 @@ export function ChipChoiceDateRange({
|
|
|
38
44
|
}: ChipChoiceDateRangeProps) {
|
|
39
45
|
const [selectedValue, setSelectedValue] = useUncontrolledProp<Range>(value, defaultValue, onChange);
|
|
40
46
|
|
|
41
|
-
const
|
|
47
|
+
const { t } = useLocale('Chips');
|
|
48
|
+
|
|
49
|
+
const valueToRender = valueFormatter
|
|
50
|
+
? valueFormatter(selectedValue)
|
|
51
|
+
: defaultRangeFormatter({ value: selectedValue, allLabel: t('allLabel') });
|
|
42
52
|
|
|
43
53
|
const clearValue = () => setSelectedValue(undefined);
|
|
44
54
|
|
|
@@ -2,10 +2,11 @@ import { useMemo } from 'react';
|
|
|
2
2
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
3
3
|
|
|
4
4
|
import { Droplist } from '@snack-uikit/droplist';
|
|
5
|
+
import { useLocale } from '@snack-uikit/locale';
|
|
5
6
|
|
|
6
|
-
import {
|
|
7
|
+
import { SIZE } from '../../../constants';
|
|
7
8
|
import { ChipChoiceCommonProps, FilterOption } from '../types';
|
|
8
|
-
import { normalizeValueForSingleChoice } from '../utils';
|
|
9
|
+
import { defaultSingleValueFormatter, normalizeValueForSingleChoice } from '../utils';
|
|
9
10
|
import { ChipChoiceCustom } from './ChipChoiceCustom';
|
|
10
11
|
|
|
11
12
|
export type ChipChoiceSingleProps = ChipChoiceCommonProps & {
|
|
@@ -37,9 +38,13 @@ export function ChipChoiceSingle({
|
|
|
37
38
|
onChange,
|
|
38
39
|
);
|
|
39
40
|
|
|
41
|
+
const { t } = useLocale('Chips');
|
|
42
|
+
|
|
40
43
|
const selectedOption = useMemo(() => options.find(({ value }) => value === selectedValue), [options, selectedValue]);
|
|
41
44
|
|
|
42
|
-
const valueToRender = valueFormatter
|
|
45
|
+
const valueToRender = valueFormatter
|
|
46
|
+
? valueFormatter(selectedOption)
|
|
47
|
+
: defaultSingleValueFormatter({ value: selectedOption, allLabel: t('allLabel') });
|
|
43
48
|
|
|
44
49
|
const clearValue = () => setSelectedValue(undefined);
|
|
45
50
|
|
|
@@ -18,3 +18,12 @@ export const normalizeValueForSingleChoice = (options: FilterOption[], value?: s
|
|
|
18
18
|
|
|
19
19
|
export const defaultMultiValueLabelFormatter = (value: FilterOption[], total: number): string =>
|
|
20
20
|
`${value.length.toString()}/${total}`;
|
|
21
|
+
|
|
22
|
+
export type ChipChoiceSingleValueFormatterProps = {
|
|
23
|
+
value?: FilterOption;
|
|
24
|
+
allLabel?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export function defaultSingleValueFormatter({ value, allLabel }: ChipChoiceSingleValueFormatterProps) {
|
|
28
|
+
return value?.label ?? allLabel;
|
|
29
|
+
}
|