@snack-uikit/tag 0.5.1 → 0.6.1
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 +21 -0
- package/README.md +3 -3
- package/dist/components/Tag/Tag.d.ts +1 -5
- package/dist/components/Tag/Tag.js +4 -6
- package/dist/components/Tag/constants.d.ts +1 -1
- package/dist/components/Tag/constants.js +4 -4
- package/dist/components/TagRow/TagRow.d.ts +1 -6
- package/dist/components/TagRow/TagRow.js +2 -4
- package/dist/components/TagRow/utils.js +2 -2
- package/dist/constants.d.ts +15 -15
- package/dist/constants.js +15 -17
- package/dist/helperComponents/TagList/TagList.d.ts +1 -2
- package/dist/helperComponents/TagList/TagList.js +3 -3
- package/dist/helperComponents/TagMore/TagMore.d.ts +1 -2
- package/dist/helperComponents/TagMore/TagMore.js +3 -3
- package/dist/helperComponents/TagRowSimple/TagRowSimple.d.ts +1 -2
- package/dist/helperComponents/TagRowSimple/TagRowSimple.js +1 -1
- package/dist/helperComponents/TagRowTruncated/TagRowTruncated.d.ts +1 -2
- package/dist/helperComponents/TagRowTruncated/TagRowTruncated.js +1 -1
- package/dist/types.d.ts +4 -1
- package/package.json +6 -6
- package/src/components/Tag/Tag.tsx +8 -10
- package/src/components/Tag/constants.ts +4 -4
- package/src/components/TagRow/TagRow.tsx +3 -6
- package/src/components/TagRow/utils.ts +2 -2
- package/src/constants.ts +15 -15
- package/src/helperComponents/TagList/TagList.tsx +3 -3
- package/src/helperComponents/TagMore/TagMore.tsx +6 -11
- package/src/helperComponents/TagRowSimple/TagRowSimple.tsx +1 -2
- package/src/helperComponents/TagRowTruncated/TagRowTruncated.tsx +1 -2
- package/src/types.ts +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,27 @@
|
|
|
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.6.1 (2023-12-14)
|
|
7
|
+
|
|
8
|
+
### Only dependencies have been changed
|
|
9
|
+
* [@snack-uikit/icons@0.19.1](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/icons/CHANGELOG.md)
|
|
10
|
+
* [@snack-uikit/popover-private@0.12.1](https://git.sbercloud.tech/sbercloud-ui/tokens-design-system/snack-uikit/-/blob/master/packages/popover-private/CHANGELOG.md)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# 0.6.0 (2023-12-14)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### BREAKING CHANGES
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
* **FF-3729:** replace enum with unions ([910db4a](https://github.com/cloud-ru-tech/snack-uikit/commit/910db4aa8231ccbc58e538e5c5c1f461b1dec275))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
6
27
|
## 0.5.1 (2023-12-06)
|
|
7
28
|
|
|
8
29
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
| name | type | default value | description |
|
|
13
13
|
|------|------|---------------|-------------|
|
|
14
14
|
| label* | `string` | - | Текст |
|
|
15
|
-
| size | enum Size: `"xs"`, `"s"` |
|
|
16
|
-
| appearance | enum Appearance: `"neutral"`, `"primary"`, `"red"`, `"orange"`, `"yellow"`, `"green"`, `"blue"`, `"violet"`, `"pink"` |
|
|
15
|
+
| size | enum Size: `"xs"`, `"s"` | xs | Размер |
|
|
16
|
+
| appearance | enum Appearance: `"neutral"`, `"primary"`, `"red"`, `"orange"`, `"yellow"`, `"green"`, `"blue"`, `"violet"`, `"pink"` | neutral | Внешний вид |
|
|
17
17
|
| onDelete | `MouseEventHandler<HTMLButtonElement>` | - | Коллбэк на удаление |
|
|
18
18
|
| className | `string` | - | CSS-класс |
|
|
19
19
|
## TagRow
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|------|------|---------------|-------------|
|
|
23
23
|
| items* | `TagRowItem[]` | - | Массив тэгов |
|
|
24
24
|
| rowLimit | `number` | - | Лимит количества рядов тэгов. При достижении лимита тэги скрываются под кнопкой. Отсутствие лимита или значение равное нулю отобразит весь список |
|
|
25
|
-
| size | enum Size: `"xs"`, `"s"` |
|
|
25
|
+
| size | enum Size: `"xs"`, `"s"` | xs | Размер |
|
|
26
26
|
| moreButtonLabel | `string` | - | Текст кнопки, при наведении на которую отображается список скрытых тэгов |
|
|
27
27
|
| className | `string` | - | CSS-класс |
|
|
28
28
|
| onItemRemove | `(item: string) => void` | - | Коллбэк на клик по удалению тэга |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MouseEventHandler } from 'react';
|
|
2
2
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
-
import { Appearance, Size } from '../../
|
|
3
|
+
import { Appearance, Size } from '../../types';
|
|
4
4
|
export type TagProps = WithSupportProps<{
|
|
5
5
|
/** Текст */
|
|
6
6
|
label: string;
|
|
@@ -14,7 +14,3 @@ export type TagProps = WithSupportProps<{
|
|
|
14
14
|
className?: string;
|
|
15
15
|
}>;
|
|
16
16
|
export declare function Tag({ label, size, appearance, onDelete, className, ...rest }: TagProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
-
export declare namespace Tag {
|
|
18
|
-
var sizes: typeof Size;
|
|
19
|
-
var appearances: typeof Appearance;
|
|
20
|
-
}
|
|
@@ -13,12 +13,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
13
13
|
import cn from 'classnames';
|
|
14
14
|
import { CrossSVG } from '@snack-uikit/icons';
|
|
15
15
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { APPEARANCE, SIZE } from '../../constants';
|
|
17
|
+
import { ICON_SIZE } from './constants';
|
|
18
18
|
import styles from './styles.module.css';
|
|
19
19
|
export function Tag(_a) {
|
|
20
|
-
var { label, size =
|
|
21
|
-
return (_jsxs("span", Object.assign({}, extractSupportProps(rest), { className: cn(styles.tag, className), "data-size": size, "data-appearance": appearance, "data-removable": Boolean(onDelete)
|
|
20
|
+
var { label, size = SIZE.Xs, appearance = APPEARANCE.Neutral, onDelete, className } = _a, rest = __rest(_a, ["label", "size", "appearance", "onDelete", "className"]);
|
|
21
|
+
return (_jsxs("span", Object.assign({}, extractSupportProps(rest), { className: cn(styles.tag, className), "data-size": size, "data-appearance": appearance, "data-removable": Boolean(onDelete), children: [_jsx("span", { className: styles.label, children: label }), onDelete && (_jsx("button", { type: 'button', className: styles.tagButton, onClick: onDelete, "data-test-id": 'tag-remove-button', children: size === SIZE.Xs ? (_jsx(CrossSVG, { size: ICON_SIZE[size], className: styles.icon })) : (_jsx(CrossSVG, { size: ICON_SIZE[size], className: styles.icon })) }))] })));
|
|
22
22
|
}
|
|
23
|
-
Tag.sizes = Size;
|
|
24
|
-
Tag.appearances = Appearance;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const
|
|
3
|
-
[
|
|
4
|
-
[
|
|
1
|
+
import { SIZE } from '../../constants';
|
|
2
|
+
export const ICON_SIZE = {
|
|
3
|
+
[SIZE.Xs]: 16,
|
|
4
|
+
[SIZE.S]: 24,
|
|
5
5
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
2
|
-
import {
|
|
3
|
-
import { TagRowItem } from '../../types';
|
|
2
|
+
import { Size, TagRowItem } from '../../types';
|
|
4
3
|
export type TagRowProps = WithSupportProps<{
|
|
5
4
|
/** Массив тэгов */
|
|
6
5
|
items: TagRowItem[];
|
|
@@ -16,7 +15,3 @@ export type TagRowProps = WithSupportProps<{
|
|
|
16
15
|
onItemRemove?(item: string): void;
|
|
17
16
|
}>;
|
|
18
17
|
export declare function TagRow({ items, rowLimit, size, ...props }: TagRowProps): import("react/jsx-runtime").JSX.Element;
|
|
19
|
-
export declare namespace TagRow {
|
|
20
|
-
var sizes: typeof Size;
|
|
21
|
-
var appearances: typeof Appearance;
|
|
22
|
-
}
|
|
@@ -10,16 +10,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import {
|
|
13
|
+
import { SIZE } from '../../constants';
|
|
14
14
|
import { TagRowSimple, TagRowTruncated } from '../../helperComponents';
|
|
15
15
|
import { mapTagRowItem } from './utils';
|
|
16
16
|
export function TagRow(_a) {
|
|
17
|
-
var { items, rowLimit, size =
|
|
17
|
+
var { items, rowLimit, size = SIZE.Xs } = _a, props = __rest(_a, ["items", "rowLimit", "size"]);
|
|
18
18
|
const coloredItems = items.map(mapTagRowItem);
|
|
19
19
|
if (rowLimit) {
|
|
20
20
|
return _jsx(TagRowTruncated, Object.assign({ items: coloredItems, rowLimit: rowLimit, size: size }, props));
|
|
21
21
|
}
|
|
22
22
|
return _jsx(TagRowSimple, Object.assign({ items: coloredItems, size: size }, props));
|
|
23
23
|
}
|
|
24
|
-
TagRow.sizes = Size;
|
|
25
|
-
TagRow.appearances = Appearance;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { APPEARANCE } from '../../constants';
|
|
2
2
|
export const mapTagRowItem = ({ label, color }) => {
|
|
3
3
|
if (color) {
|
|
4
4
|
return {
|
|
@@ -8,6 +8,6 @@ export const mapTagRowItem = ({ label, color }) => {
|
|
|
8
8
|
}
|
|
9
9
|
return {
|
|
10
10
|
label,
|
|
11
|
-
color:
|
|
11
|
+
color: APPEARANCE.Neutral,
|
|
12
12
|
};
|
|
13
13
|
};
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
Neutral
|
|
3
|
-
Primary
|
|
4
|
-
Red
|
|
5
|
-
Orange
|
|
6
|
-
Yellow
|
|
7
|
-
Green
|
|
8
|
-
Blue
|
|
9
|
-
Violet
|
|
10
|
-
Pink
|
|
11
|
-
}
|
|
12
|
-
export declare
|
|
13
|
-
Xs
|
|
14
|
-
S
|
|
15
|
-
}
|
|
1
|
+
export declare const APPEARANCE: {
|
|
2
|
+
readonly Neutral: "neutral";
|
|
3
|
+
readonly Primary: "primary";
|
|
4
|
+
readonly Red: "red";
|
|
5
|
+
readonly Orange: "orange";
|
|
6
|
+
readonly Yellow: "yellow";
|
|
7
|
+
readonly Green: "green";
|
|
8
|
+
readonly Blue: "blue";
|
|
9
|
+
readonly Violet: "violet";
|
|
10
|
+
readonly Pink: "pink";
|
|
11
|
+
};
|
|
12
|
+
export declare const SIZE: {
|
|
13
|
+
readonly Xs: "xs";
|
|
14
|
+
readonly S: "s";
|
|
15
|
+
};
|
package/dist/constants.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Size["S"] = "s";
|
|
17
|
-
})(Size || (Size = {}));
|
|
1
|
+
export const APPEARANCE = {
|
|
2
|
+
Neutral: 'neutral',
|
|
3
|
+
Primary: 'primary',
|
|
4
|
+
Red: 'red',
|
|
5
|
+
Orange: 'orange',
|
|
6
|
+
Yellow: 'yellow',
|
|
7
|
+
Green: 'green',
|
|
8
|
+
Blue: 'blue',
|
|
9
|
+
Violet: 'violet',
|
|
10
|
+
Pink: 'pink',
|
|
11
|
+
};
|
|
12
|
+
export const SIZE = {
|
|
13
|
+
Xs: 'xs',
|
|
14
|
+
S: 's',
|
|
15
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Ref } from 'react';
|
|
2
|
-
import { Size } from '../../
|
|
3
|
-
import { TagRowItemInner } from '../../types';
|
|
2
|
+
import { Size, TagRowItemInner } from '../../types';
|
|
4
3
|
type SetTagRef = (item: TagRowItemInner, index: number) => Ref<HTMLDivElement>;
|
|
5
4
|
type TagListProps = {
|
|
6
5
|
items: TagRowItemInner[];
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { Tag } from '../../components';
|
|
3
|
-
import {
|
|
3
|
+
import { SIZE } from '../../constants';
|
|
4
4
|
function renderTag(size, handleRemoveItem, setRef) {
|
|
5
5
|
return function TagRowItem(item, index) {
|
|
6
|
-
return (_jsx("div",
|
|
6
|
+
return (_jsx("div", { ref: setRef === null || setRef === void 0 ? void 0 : setRef(item, index), children: _jsx(Tag, { label: item.label, appearance: item.color, size: size, onDelete: handleRemoveItem === null || handleRemoveItem === void 0 ? void 0 : handleRemoveItem(item) }) }, item.label));
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
export function TagList({ items, size =
|
|
9
|
+
export function TagList({ items, size = SIZE.Xs, onItemRemove, setTagRef }) {
|
|
10
10
|
const handleRemoveItem = onItemRemove ? (item) => () => onItemRemove(item.label) : undefined;
|
|
11
11
|
return _jsx(_Fragment, { children: items.map(renderTag(size, handleRemoveItem, setTagRef)) });
|
|
12
12
|
}
|
|
@@ -2,9 +2,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { PopoverPrivate } from '@snack-uikit/popover-private';
|
|
3
3
|
import { Scroll } from '@snack-uikit/scroll';
|
|
4
4
|
import { TAG_ROW_TEST_IDS } from '../../components/TagRow/constants';
|
|
5
|
-
import {
|
|
5
|
+
import { SIZE } from '../../constants';
|
|
6
6
|
import { TagRowSimple } from '../TagRowSimple';
|
|
7
7
|
import styles from './styles.module.css';
|
|
8
|
-
export function TagMore({ items, text = '', size =
|
|
9
|
-
return (_jsx(PopoverPrivate,
|
|
8
|
+
export function TagMore({ items, text = '', size = SIZE.Xs, buttonRef, onItemRemove }) {
|
|
9
|
+
return (_jsx(PopoverPrivate, { placement: 'bottom-end', trigger: 'hoverAndFocusVisible', triggerClassName: styles.triggerClassName, popoverContent: _jsx("div", { className: styles.tagRowDroplistContainer, "data-size": size, children: _jsx(Scroll, { className: styles.tagRowDroplistScroll, size: 's', barHideStrategy: 'move', resize: 'none', children: _jsx(TagRowSimple, { items: items, size: size, onItemRemove: onItemRemove, "data-test-id": TAG_ROW_TEST_IDS.droplistTagsWrapper }) }) }), hasArrow: false, children: _jsx("button", { type: 'button', className: styles.button, ref: buttonRef, "data-size": size, "data-test-id": TAG_ROW_TEST_IDS.moreButton, children: `${text}${items.length}` }) }));
|
|
10
10
|
}
|
|
@@ -16,5 +16,5 @@ import { TagList } from '../TagList';
|
|
|
16
16
|
import styles from './styles.module.css';
|
|
17
17
|
export function TagRowSimple(_a) {
|
|
18
18
|
var { items, size, onItemRemove, setTagRef, className } = _a, rest = __rest(_a, ["items", "size", "onItemRemove", "setTagRef", "className"]);
|
|
19
|
-
return (_jsx("div", Object.assign({ className: cn(styles.tagRowSimpleWrapper, className) }, extractSupportProps(rest), { "data-size": size
|
|
19
|
+
return (_jsx("div", Object.assign({ className: cn(styles.tagRowSimpleWrapper, className) }, extractSupportProps(rest), { "data-size": size, children: _jsx(TagList, { items: items, size: size, onItemRemove: onItemRemove, setTagRef: setTagRef }) })));
|
|
20
20
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
2
|
-
import { Size } from '../../
|
|
3
|
-
import { TagRowItemInner } from '../../types';
|
|
2
|
+
import { Size, TagRowItemInner } from '../../types';
|
|
4
3
|
type TagRowTruncatedProps = WithSupportProps<{
|
|
5
4
|
items: TagRowItemInner[];
|
|
6
5
|
rowLimit: number;
|
|
@@ -83,5 +83,5 @@ export function TagRowTruncated(_a) {
|
|
|
83
83
|
setVisibleTags(newVisibleTags);
|
|
84
84
|
setHiddenTags(newHiddenTags);
|
|
85
85
|
}, [items, rowLimit, maxWidth, onItemRemove, gapWidth, firstVisibleTagWidth]);
|
|
86
|
-
return (_jsxs("div", Object.assign({ className: cn(styles.wrapper, className) }, extractSupportProps(rest), { "data-size": size
|
|
86
|
+
return (_jsxs("div", Object.assign({ className: cn(styles.wrapper, className) }, extractSupportProps(rest), { "data-size": size, children: [_jsx("div", { className: styles.hiddenRow, ref: hiddenRowElementRef, "data-size": size, children: _jsx(TagList, { items: items, size: size, onItemRemove: onItemRemove, setTagRef: setTagElement }) }), _jsx("div", { className: styles.hiddenMoreButton, ref: hiddenMoreButtonWrapperRef, children: _jsx(TagMore, { items: items, text: moreButtonLabel, size: size, buttonRef: hiddenMoreButtonRef }) }), _jsxs("div", { className: styles.visibleRow, "data-size": size, "data-test-id": TAG_ROW_TEST_IDS.visibleTagsWrapper, children: [_jsx(TagList, { items: visibleTags, size: size, onItemRemove: onItemRemove }), hiddenTags.length > 0 && (_jsx(TagMore, { items: hiddenTags, text: moreButtonLabel, size: size, onItemRemove: onItemRemove }))] })] })));
|
|
87
87
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ValueOf } from '@snack-uikit/utils';
|
|
2
|
+
import { APPEARANCE, SIZE } from './constants';
|
|
3
|
+
export type Appearance = ValueOf<typeof APPEARANCE>;
|
|
4
|
+
export type Size = ValueOf<typeof SIZE>;
|
|
2
5
|
export type TagRowItem = {
|
|
3
6
|
label: string;
|
|
4
7
|
color?: Appearance;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Tag",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.6.1",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@snack-uikit/icons": "0.19.
|
|
36
|
-
"@snack-uikit/popover-private": "0.
|
|
37
|
-
"@snack-uikit/scroll": "0.
|
|
38
|
-
"@snack-uikit/utils": "3.
|
|
35
|
+
"@snack-uikit/icons": "0.19.1",
|
|
36
|
+
"@snack-uikit/popover-private": "0.12.1",
|
|
37
|
+
"@snack-uikit/scroll": "0.5.0",
|
|
38
|
+
"@snack-uikit/utils": "3.2.0",
|
|
39
39
|
"classnames": "2.3.2"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "62f43bf0cbfd611d0b746117400f67096b1790f6"
|
|
42
42
|
}
|
|
@@ -4,8 +4,9 @@ import { MouseEventHandler } from 'react';
|
|
|
4
4
|
import { CrossSVG } from '@snack-uikit/icons';
|
|
5
5
|
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { APPEARANCE, SIZE } from '../../constants';
|
|
8
|
+
import { Appearance, Size } from '../../types';
|
|
9
|
+
import { ICON_SIZE } from './constants';
|
|
9
10
|
import styles from './styles.module.scss';
|
|
10
11
|
|
|
11
12
|
export type TagProps = WithSupportProps<{
|
|
@@ -23,8 +24,8 @@ export type TagProps = WithSupportProps<{
|
|
|
23
24
|
|
|
24
25
|
export function Tag({
|
|
25
26
|
label,
|
|
26
|
-
size =
|
|
27
|
-
appearance =
|
|
27
|
+
size = SIZE.Xs,
|
|
28
|
+
appearance = APPEARANCE.Neutral,
|
|
28
29
|
onDelete,
|
|
29
30
|
className,
|
|
30
31
|
...rest
|
|
@@ -40,16 +41,13 @@ export function Tag({
|
|
|
40
41
|
<span className={styles.label}>{label}</span>
|
|
41
42
|
{onDelete && (
|
|
42
43
|
<button type='button' className={styles.tagButton} onClick={onDelete} data-test-id='tag-remove-button'>
|
|
43
|
-
{size ===
|
|
44
|
-
<CrossSVG size={
|
|
44
|
+
{size === SIZE.Xs ? (
|
|
45
|
+
<CrossSVG size={ICON_SIZE[size]} className={styles.icon} />
|
|
45
46
|
) : (
|
|
46
|
-
<CrossSVG size={
|
|
47
|
+
<CrossSVG size={ICON_SIZE[size]} className={styles.icon} />
|
|
47
48
|
)}
|
|
48
49
|
</button>
|
|
49
50
|
)}
|
|
50
51
|
</span>
|
|
51
52
|
);
|
|
52
53
|
}
|
|
53
|
-
|
|
54
|
-
Tag.sizes = Size;
|
|
55
|
-
Tag.appearances = Appearance;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { SIZE } from '../../constants';
|
|
4
4
|
import { TagRowSimple, TagRowTruncated } from '../../helperComponents';
|
|
5
|
-
import { TagRowItem } from '../../types';
|
|
5
|
+
import { Size, TagRowItem } from '../../types';
|
|
6
6
|
import { mapTagRowItem } from './utils';
|
|
7
7
|
|
|
8
8
|
export type TagRowProps = WithSupportProps<{
|
|
@@ -20,7 +20,7 @@ export type TagRowProps = WithSupportProps<{
|
|
|
20
20
|
onItemRemove?(item: string): void;
|
|
21
21
|
}>;
|
|
22
22
|
|
|
23
|
-
export function TagRow({ items, rowLimit, size =
|
|
23
|
+
export function TagRow({ items, rowLimit, size = SIZE.Xs, ...props }: TagRowProps) {
|
|
24
24
|
const coloredItems = items.map(mapTagRowItem);
|
|
25
25
|
|
|
26
26
|
if (rowLimit) {
|
|
@@ -29,6 +29,3 @@ export function TagRow({ items, rowLimit, size = Size.Xs, ...props }: TagRowProp
|
|
|
29
29
|
|
|
30
30
|
return <TagRowSimple items={coloredItems} size={size} {...props} />;
|
|
31
31
|
}
|
|
32
|
-
|
|
33
|
-
TagRow.sizes = Size;
|
|
34
|
-
TagRow.appearances = Appearance;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { APPEARANCE } from '../../constants';
|
|
2
2
|
import { TagRowItem, TagRowItemInner } from '../../types';
|
|
3
3
|
|
|
4
4
|
export const mapTagRowItem = ({ label, color }: TagRowItem): TagRowItemInner => {
|
|
@@ -11,6 +11,6 @@ export const mapTagRowItem = ({ label, color }: TagRowItem): TagRowItemInner =>
|
|
|
11
11
|
|
|
12
12
|
return {
|
|
13
13
|
label,
|
|
14
|
-
color:
|
|
14
|
+
color: APPEARANCE.Neutral,
|
|
15
15
|
};
|
|
16
16
|
};
|
package/src/constants.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export
|
|
2
|
-
Neutral
|
|
3
|
-
Primary
|
|
4
|
-
Red
|
|
5
|
-
Orange
|
|
6
|
-
Yellow
|
|
7
|
-
Green
|
|
8
|
-
Blue
|
|
9
|
-
Violet
|
|
10
|
-
Pink
|
|
11
|
-
}
|
|
1
|
+
export const APPEARANCE = {
|
|
2
|
+
Neutral: 'neutral',
|
|
3
|
+
Primary: 'primary',
|
|
4
|
+
Red: 'red',
|
|
5
|
+
Orange: 'orange',
|
|
6
|
+
Yellow: 'yellow',
|
|
7
|
+
Green: 'green',
|
|
8
|
+
Blue: 'blue',
|
|
9
|
+
Violet: 'violet',
|
|
10
|
+
Pink: 'pink',
|
|
11
|
+
} as const;
|
|
12
12
|
|
|
13
|
-
export
|
|
14
|
-
Xs
|
|
15
|
-
S
|
|
16
|
-
}
|
|
13
|
+
export const SIZE = {
|
|
14
|
+
Xs: 'xs',
|
|
15
|
+
S: 's',
|
|
16
|
+
} as const;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Ref } from 'react';
|
|
2
2
|
|
|
3
3
|
import { Tag } from '../../components';
|
|
4
|
-
import {
|
|
5
|
-
import { TagRowItemInner } from '../../types';
|
|
4
|
+
import { SIZE } from '../../constants';
|
|
5
|
+
import { Size, TagRowItemInner } from '../../types';
|
|
6
6
|
|
|
7
7
|
type SetTagRef = (item: TagRowItemInner, index: number) => Ref<HTMLDivElement>;
|
|
8
8
|
|
|
@@ -25,7 +25,7 @@ function renderTag(size: Size, handleRemoveItem?: (item: TagRowItemInner) => OnD
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export function TagList({ items, size =
|
|
28
|
+
export function TagList({ items, size = SIZE.Xs, onItemRemove, setTagRef }: TagListProps) {
|
|
29
29
|
const handleRemoveItem = onItemRemove ? (item: TagRowItemInner) => () => onItemRemove(item.label) : undefined;
|
|
30
30
|
|
|
31
31
|
return <>{items.map(renderTag(size, handleRemoveItem, setTagRef))}</>;
|
|
@@ -4,8 +4,8 @@ import { PopoverPrivate } from '@snack-uikit/popover-private';
|
|
|
4
4
|
import { Scroll } from '@snack-uikit/scroll';
|
|
5
5
|
|
|
6
6
|
import { TAG_ROW_TEST_IDS } from '../../components/TagRow/constants';
|
|
7
|
-
import {
|
|
8
|
-
import { TagRowItemInner } from '../../types';
|
|
7
|
+
import { SIZE } from '../../constants';
|
|
8
|
+
import { Size, TagRowItemInner } from '../../types';
|
|
9
9
|
import { TagRowSimple } from '../TagRowSimple';
|
|
10
10
|
import styles from './styles.module.scss';
|
|
11
11
|
|
|
@@ -17,20 +17,15 @@ type TagMoreProps = {
|
|
|
17
17
|
onItemRemove?(item: string): void;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export function TagMore({ items, text = '', size =
|
|
20
|
+
export function TagMore({ items, text = '', size = SIZE.Xs, buttonRef, onItemRemove }: TagMoreProps) {
|
|
21
21
|
return (
|
|
22
22
|
<PopoverPrivate
|
|
23
|
-
placement=
|
|
24
|
-
trigger=
|
|
23
|
+
placement='bottom-end'
|
|
24
|
+
trigger='hoverAndFocusVisible'
|
|
25
25
|
triggerClassName={styles.triggerClassName}
|
|
26
26
|
popoverContent={
|
|
27
27
|
<div className={styles.tagRowDroplistContainer} data-size={size}>
|
|
28
|
-
<Scroll
|
|
29
|
-
className={styles.tagRowDroplistScroll}
|
|
30
|
-
size={Scroll.sizes.S}
|
|
31
|
-
barHideStrategy={Scroll.barHideStrategies.Move}
|
|
32
|
-
resize={Scroll.resizes.None}
|
|
33
|
-
>
|
|
28
|
+
<Scroll className={styles.tagRowDroplistScroll} size='s' barHideStrategy='move' resize='none'>
|
|
34
29
|
<TagRowSimple
|
|
35
30
|
items={items}
|
|
36
31
|
size={size}
|
|
@@ -3,8 +3,7 @@ import { Ref } from 'react';
|
|
|
3
3
|
|
|
4
4
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
5
5
|
|
|
6
|
-
import { Size } from '../../
|
|
7
|
-
import { TagRowItemInner } from '../../types';
|
|
6
|
+
import { Size, TagRowItemInner } from '../../types';
|
|
8
7
|
import { TagList } from '../TagList';
|
|
9
8
|
import styles from './styles.module.scss';
|
|
10
9
|
|
|
@@ -4,8 +4,7 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
4
4
|
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
5
5
|
|
|
6
6
|
import { TAG_ROW_TEST_IDS } from '../../components/TagRow/constants';
|
|
7
|
-
import { Size } from '../../
|
|
8
|
-
import { TagRowItemInner } from '../../types';
|
|
7
|
+
import { Size, TagRowItemInner } from '../../types';
|
|
9
8
|
import { TagList } from '../TagList';
|
|
10
9
|
import { TagMore } from '../TagMore';
|
|
11
10
|
import { useResizeObserver } from './hooks';
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ValueOf } from '@snack-uikit/utils';
|
|
2
|
+
|
|
3
|
+
import { APPEARANCE, SIZE } from './constants';
|
|
4
|
+
|
|
5
|
+
export type Appearance = ValueOf<typeof APPEARANCE>;
|
|
6
|
+
|
|
7
|
+
export type Size = ValueOf<typeof SIZE>;
|
|
2
8
|
|
|
3
9
|
export type TagRowItem = {
|
|
4
10
|
label: string;
|