@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.
Files changed (31) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +3 -3
  3. package/dist/components/Tag/Tag.d.ts +1 -5
  4. package/dist/components/Tag/Tag.js +4 -6
  5. package/dist/components/Tag/constants.d.ts +1 -1
  6. package/dist/components/Tag/constants.js +4 -4
  7. package/dist/components/TagRow/TagRow.d.ts +1 -6
  8. package/dist/components/TagRow/TagRow.js +2 -4
  9. package/dist/components/TagRow/utils.js +2 -2
  10. package/dist/constants.d.ts +15 -15
  11. package/dist/constants.js +15 -17
  12. package/dist/helperComponents/TagList/TagList.d.ts +1 -2
  13. package/dist/helperComponents/TagList/TagList.js +3 -3
  14. package/dist/helperComponents/TagMore/TagMore.d.ts +1 -2
  15. package/dist/helperComponents/TagMore/TagMore.js +3 -3
  16. package/dist/helperComponents/TagRowSimple/TagRowSimple.d.ts +1 -2
  17. package/dist/helperComponents/TagRowSimple/TagRowSimple.js +1 -1
  18. package/dist/helperComponents/TagRowTruncated/TagRowTruncated.d.ts +1 -2
  19. package/dist/helperComponents/TagRowTruncated/TagRowTruncated.js +1 -1
  20. package/dist/types.d.ts +4 -1
  21. package/package.json +6 -6
  22. package/src/components/Tag/Tag.tsx +8 -10
  23. package/src/components/Tag/constants.ts +4 -4
  24. package/src/components/TagRow/TagRow.tsx +3 -6
  25. package/src/components/TagRow/utils.ts +2 -2
  26. package/src/constants.ts +15 -15
  27. package/src/helperComponents/TagList/TagList.tsx +3 -3
  28. package/src/helperComponents/TagMore/TagMore.tsx +6 -11
  29. package/src/helperComponents/TagRowSimple/TagRowSimple.tsx +1 -2
  30. package/src/helperComponents/TagRowTruncated/TagRowTruncated.tsx +1 -2
  31. 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"` | Size.Xs | Размер |
16
- | appearance | enum Appearance: `"neutral"`, `"primary"`, `"red"`, `"orange"`, `"yellow"`, `"green"`, `"blue"`, `"violet"`, `"pink"` | Appearance.Neutral | Внешний вид |
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"` | Size.Xs | Размер |
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 '../../constants';
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 { Appearance, Size } from '../../constants';
17
- import { IconSize } from './constants';
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 = 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", Object.assign({ className: styles.label }, { children: label })), onDelete && (_jsx("button", Object.assign({ type: 'button', className: styles.tagButton, onClick: onDelete, "data-test-id": 'tag-remove-button' }, { children: size === Size.Xs ? (_jsx(CrossSVG, { size: IconSize[size], className: styles.icon })) : (_jsx(CrossSVG, { size: IconSize[size], className: styles.icon })) })))] })));
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,4 +1,4 @@
1
- export declare const IconSize: {
1
+ export declare const ICON_SIZE: {
2
2
  xs: number;
3
3
  s: number;
4
4
  };
@@ -1,5 +1,5 @@
1
- import { Size } from '../../constants';
2
- export const IconSize = {
3
- [Size.Xs]: 16,
4
- [Size.S]: 24,
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 { Appearance, Size } from '../../constants';
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 { Appearance, Size } from '../../constants';
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 = Size.Xs } = _a, props = __rest(_a, ["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 { Appearance } from '../../constants';
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: Appearance.Neutral,
11
+ color: APPEARANCE.Neutral,
12
12
  };
13
13
  };
@@ -1,15 +1,15 @@
1
- export declare enum 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 declare enum Size {
13
- Xs = "xs",
14
- S = "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 var Appearance;
2
- (function (Appearance) {
3
- Appearance["Neutral"] = "neutral";
4
- Appearance["Primary"] = "primary";
5
- Appearance["Red"] = "red";
6
- Appearance["Orange"] = "orange";
7
- Appearance["Yellow"] = "yellow";
8
- Appearance["Green"] = "green";
9
- Appearance["Blue"] = "blue";
10
- Appearance["Violet"] = "violet";
11
- Appearance["Pink"] = "pink";
12
- })(Appearance || (Appearance = {}));
13
- export var Size;
14
- (function (Size) {
15
- Size["Xs"] = "xs";
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 '../../constants';
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 { Size } from '../../constants';
3
+ import { SIZE } from '../../constants';
4
4
  function renderTag(size, handleRemoveItem, setRef) {
5
5
  return function TagRowItem(item, index) {
6
- return (_jsx("div", Object.assign({ 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));
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 = Size.Xs, onItemRemove, setTagRef }) {
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
  }
@@ -1,6 +1,5 @@
1
1
  import { Ref } from 'react';
2
- import { Size } from '../../constants';
3
- import { TagRowItemInner } from '../../types';
2
+ import { Size, TagRowItemInner } from '../../types';
4
3
  type TagMoreProps = {
5
4
  items: TagRowItemInner[];
6
5
  size: Size;
@@ -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 { Size } from '../../constants';
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 = Size.Xs, buttonRef, onItemRemove }) {
9
- return (_jsx(PopoverPrivate, Object.assign({ placement: PopoverPrivate.placements.BottomEnd, trigger: PopoverPrivate.triggers.HoverAndFocusVisible, triggerClassName: styles.triggerClassName, popoverContent: _jsx("div", Object.assign({ className: styles.tagRowDroplistContainer, "data-size": size }, { children: _jsx(Scroll, Object.assign({ className: styles.tagRowDroplistScroll, size: Scroll.sizes.S, barHideStrategy: Scroll.barHideStrategies.Move, resize: Scroll.resizes.None }, { children: _jsx(TagRowSimple, { items: items, size: size, onItemRemove: onItemRemove, "data-test-id": TAG_ROW_TEST_IDS.droplistTagsWrapper }) })) })), hasArrow: false }, { children: _jsx("button", Object.assign({ type: 'button', className: styles.button, ref: buttonRef, "data-size": size, "data-test-id": TAG_ROW_TEST_IDS.moreButton }, { children: `${text}${items.length}` })) })));
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
  }
@@ -1,6 +1,5 @@
1
1
  import { Ref } from 'react';
2
- import { Size } from '../../constants';
3
- import { TagRowItemInner } from '../../types';
2
+ import { Size, TagRowItemInner } from '../../types';
4
3
  type TagRowSimpleProps = {
5
4
  items: TagRowItemInner[];
6
5
  size: Size;
@@ -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 }, { children: _jsx(TagList, { items: items, size: size, onItemRemove: onItemRemove, setTagRef: setTagRef }) })));
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 '../../constants';
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 }, { children: [_jsx("div", Object.assign({ className: styles.hiddenRow, ref: hiddenRowElementRef, "data-size": size }, { children: _jsx(TagList, { items: items, size: size, onItemRemove: onItemRemove, setTagRef: setTagElement }) })), _jsx("div", Object.assign({ className: styles.hiddenMoreButton, ref: hiddenMoreButtonWrapperRef }, { children: _jsx(TagMore, { items: items, text: moreButtonLabel, size: size, buttonRef: hiddenMoreButtonRef }) })), _jsxs("div", Object.assign({ 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 }))] }))] })));
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 { Appearance } from './constants';
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.5.1",
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.0",
36
- "@snack-uikit/popover-private": "0.11.1",
37
- "@snack-uikit/scroll": "0.4.1",
38
- "@snack-uikit/utils": "3.1.0",
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": "76a159dde7baccf49dc7b11e1fd7abc31424b42f"
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 { Appearance, Size } from '../../constants';
8
- import { IconSize } from './constants';
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 = Size.Xs,
27
- appearance = Appearance.Neutral,
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 === Size.Xs ? (
44
- <CrossSVG size={IconSize[size]} className={styles.icon} />
44
+ {size === SIZE.Xs ? (
45
+ <CrossSVG size={ICON_SIZE[size]} className={styles.icon} />
45
46
  ) : (
46
- <CrossSVG size={IconSize[size]} className={styles.icon} />
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,6 +1,6 @@
1
- import { Size } from '../../constants';
1
+ import { SIZE } from '../../constants';
2
2
 
3
- export const IconSize = {
4
- [Size.Xs]: 16,
5
- [Size.S]: 24,
3
+ export const ICON_SIZE = {
4
+ [SIZE.Xs]: 16,
5
+ [SIZE.S]: 24,
6
6
  };
@@ -1,8 +1,8 @@
1
1
  import { WithSupportProps } from '@snack-uikit/utils';
2
2
 
3
- import { Appearance, Size } from '../../constants';
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 = Size.Xs, ...props }: TagRowProps) {
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 { Appearance } from '../../constants';
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: Appearance.Neutral,
14
+ color: APPEARANCE.Neutral,
15
15
  };
16
16
  };
package/src/constants.ts CHANGED
@@ -1,16 +1,16 @@
1
- export enum 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
- }
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 enum Size {
14
- Xs = 'xs',
15
- S = '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 { Size } from '../../constants';
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 = Size.Xs, onItemRemove, setTagRef }: TagListProps) {
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 { Size } from '../../constants';
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 = Size.Xs, buttonRef, onItemRemove }: TagMoreProps) {
20
+ export function TagMore({ items, text = '', size = SIZE.Xs, buttonRef, onItemRemove }: TagMoreProps) {
21
21
  return (
22
22
  <PopoverPrivate
23
- placement={PopoverPrivate.placements.BottomEnd}
24
- trigger={PopoverPrivate.triggers.HoverAndFocusVisible}
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 '../../constants';
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 '../../constants';
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 { Appearance } from './constants';
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;