@snack-uikit/card 0.20.7 → 0.20.9-preview-13d3b71d.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 CHANGED
@@ -3,6 +3,16 @@
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
+ ## <small>0.20.8 (2025-11-14)</small>
7
+
8
+ ### Only dependencies have been changed
9
+ * [@snack-uikit/list@0.32.7](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/list/CHANGELOG.md)
10
+ * [@snack-uikit/truncate-string@0.7.4](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/truncate-string/CHANGELOG.md)
11
+
12
+
13
+
14
+
15
+
6
16
  ## <small>0.20.7 (2025-10-28)</small>
7
17
 
8
18
  ### Only dependencies have been changed
@@ -1,9 +1,9 @@
1
1
  import { ReactElement, ReactNode } from 'react';
2
- import { BaseItemProps } from '@snack-uikit/list';
3
- type Option = {
2
+ import { DroplistProps } from '@snack-uikit/list';
3
+ type Option = DroplistProps['items'][number] & {
4
4
  tagLabel?: string;
5
5
  icon?: ReactElement;
6
- } & Pick<BaseItemProps, 'onClick' | 'content' | 'disabled'>;
6
+ };
7
7
  export type FunctionBadgeProps = {
8
8
  /** Иконка */
9
9
  icon?: ReactNode;
@@ -43,6 +43,32 @@ function FunctionBadge(_ref) {
43
43
  e.stopPropagation();
44
44
  setIsOpen(isOpen => !isOpen);
45
45
  }, []);
46
+ const items = options.map(option => {
47
+ const {
48
+ icon,
49
+ tagLabel
50
+ } = option,
51
+ item = __rest(option, ["icon", "tagLabel"]);
52
+ // GroupItem и GroupSelectItem не имеют beforeContent, afterContent, onClick
53
+ if ('type' in item && (item.type === 'group' || item.type === 'group-select')) {
54
+ return item;
55
+ }
56
+ // BaseItem, AccordionItem, NextListItem имеют beforeContent, afterContent, onClick
57
+ const baseItem = item;
58
+ const itemOnClick = baseItem.onClick;
59
+ return Object.assign(Object.assign({}, item), {
60
+ className: styles_module_scss_1.default.item,
61
+ beforeContent: icon !== null && icon !== void 0 ? icon : baseItem.beforeContent,
62
+ afterContent: tagLabel ? (0, jsx_runtime_1.jsx)(tag_1.Tag, {
63
+ label: tagLabel
64
+ }) : baseItem.afterContent,
65
+ onClick: e => {
66
+ e.stopPropagation();
67
+ setIsOpen(false);
68
+ itemOnClick === null || itemOnClick === void 0 ? void 0 : itemOnClick(e);
69
+ }
70
+ });
71
+ });
46
72
  return (0, jsx_runtime_1.jsx)("span", {
47
73
  className: styles_module_scss_1.default.wrapper,
48
74
  children: (0, jsx_runtime_1.jsx)(list_1.Droplist, {
@@ -54,26 +80,7 @@ function FunctionBadge(_ref) {
54
80
  "data-test-id": constants_1.TEST_IDS.droplist,
55
81
  placement: 'bottom-end',
56
82
  triggerElemRef: buttonRef,
57
- items: options.map(_a => {
58
- var {
59
- icon,
60
- tagLabel,
61
- onClick
62
- } = _a,
63
- item = __rest(_a, ["icon", "tagLabel", "onClick"]);
64
- return Object.assign(Object.assign({}, item), {
65
- className: styles_module_scss_1.default.item,
66
- beforeContent: icon,
67
- afterContent: tagLabel ? (0, jsx_runtime_1.jsx)(tag_1.Tag, {
68
- label: tagLabel
69
- }) : undefined,
70
- onClick: e => {
71
- e.stopPropagation();
72
- setIsOpen(false);
73
- onClick === null || onClick === void 0 ? void 0 : onClick(e);
74
- }
75
- });
76
- }),
83
+ items: items,
77
84
  children: (0, jsx_runtime_1.jsx)("button", {
78
85
  type: 'button',
79
86
  "data-test-id": constants_1.TEST_IDS.functionBadge,
@@ -1,9 +1,9 @@
1
1
  import { ReactElement, ReactNode } from 'react';
2
- import { BaseItemProps } from '@snack-uikit/list';
3
- type Option = {
2
+ import { DroplistProps } from '@snack-uikit/list';
3
+ type Option = DroplistProps['items'][number] & {
4
4
  tagLabel?: string;
5
5
  icon?: ReactElement;
6
- } & Pick<BaseItemProps, 'onClick' | 'content' | 'disabled'>;
6
+ };
7
7
  export type FunctionBadgeProps = {
8
8
  /** Иконка */
9
9
  icon?: ReactNode;
@@ -29,12 +29,20 @@ export function FunctionBadge({ icon, options }) {
29
29
  e.stopPropagation();
30
30
  setIsOpen(isOpen => !isOpen);
31
31
  }, []);
32
- return (_jsx("span", { className: styles.wrapper, children: _jsx(Droplist, { trigger: 'clickAndFocusVisible', open: isOpen, onOpenChange: setIsOpen, widthStrategy: 'gte', scroll: true, "data-test-id": TEST_IDS.droplist, placement: 'bottom-end', triggerElemRef: buttonRef, items: options.map((_a) => {
33
- var { icon, tagLabel, onClick } = _a, item = __rest(_a, ["icon", "tagLabel", "onClick"]);
34
- return (Object.assign(Object.assign({}, item), { className: styles.item, beforeContent: icon, afterContent: tagLabel ? _jsx(Tag, { label: tagLabel }) : undefined, onClick: e => {
35
- e.stopPropagation();
36
- setIsOpen(false);
37
- onClick === null || onClick === void 0 ? void 0 : onClick(e);
38
- } }));
39
- }), children: _jsx("button", { type: 'button', "data-test-id": TEST_IDS.functionBadge, className: styles.button, onClick: onClick, ref: buttonRef, children: icon || _jsx(KebabSVG, {}) }) }) }));
32
+ const items = options.map(option => {
33
+ const { icon, tagLabel } = option, item = __rest(option, ["icon", "tagLabel"]);
34
+ // GroupItem и GroupSelectItem не имеют beforeContent, afterContent, onClick
35
+ if ('type' in item && (item.type === 'group' || item.type === 'group-select')) {
36
+ return item;
37
+ }
38
+ // BaseItem, AccordionItem, NextListItem имеют beforeContent, afterContent, onClick
39
+ const baseItem = item;
40
+ const itemOnClick = baseItem.onClick;
41
+ return Object.assign(Object.assign({}, item), { className: styles.item, beforeContent: icon !== null && icon !== void 0 ? icon : baseItem.beforeContent, afterContent: tagLabel ? _jsx(Tag, { label: tagLabel }) : baseItem.afterContent, onClick: (e) => {
42
+ e.stopPropagation();
43
+ setIsOpen(false);
44
+ itemOnClick === null || itemOnClick === void 0 ? void 0 : itemOnClick(e);
45
+ } });
46
+ });
47
+ return (_jsx("span", { className: styles.wrapper, children: _jsx(Droplist, { trigger: 'clickAndFocusVisible', open: isOpen, onOpenChange: setIsOpen, widthStrategy: 'gte', scroll: true, "data-test-id": TEST_IDS.droplist, placement: 'bottom-end', triggerElemRef: buttonRef, items: items, children: _jsx("button", { type: 'button', "data-test-id": TEST_IDS.functionBadge, className: styles.button, onClick: onClick, ref: buttonRef, children: icon || _jsx(KebabSVG, {}) }) }) }));
40
48
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Card",
7
- "version": "0.20.7",
7
+ "version": "0.20.9-preview-13d3b71d.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -39,14 +39,14 @@
39
39
  "@snack-uikit/button": "0.19.16",
40
40
  "@snack-uikit/icon-predefined": "0.7.10",
41
41
  "@snack-uikit/icons": "0.27.3",
42
- "@snack-uikit/list": "0.32.6",
42
+ "@snack-uikit/list": "0.32.7",
43
43
  "@snack-uikit/promo-tag": "0.7.8",
44
44
  "@snack-uikit/tag": "0.15.10",
45
- "@snack-uikit/truncate-string": "0.7.3",
45
+ "@snack-uikit/truncate-string": "0.7.4",
46
46
  "@snack-uikit/typography": "0.8.11",
47
47
  "@snack-uikit/utils": "4.0.0",
48
48
  "classnames": "2.5.1",
49
49
  "merge-refs": "1.3.0"
50
50
  },
51
- "gitHead": "4b590b25862e58fae2addec0ca0ddbb56d6d39f5"
51
+ "gitHead": "e79e04521872644030a51b61e594a42c957682f5"
52
52
  }
@@ -1,7 +1,7 @@
1
1
  import { MouseEvent, ReactElement, ReactNode, useCallback, useContext, useRef, useState } from 'react';
2
2
 
3
3
  import { KebabSVG } from '@snack-uikit/icons';
4
- import { BaseItemProps, Droplist } from '@snack-uikit/list';
4
+ import { Droplist, DroplistProps } from '@snack-uikit/list';
5
5
  import { Tag } from '@snack-uikit/tag';
6
6
  import { useLayoutEffect } from '@snack-uikit/utils';
7
7
 
@@ -9,10 +9,10 @@ import { TEST_IDS } from '../../constants';
9
9
  import { FunctionBadgeContext } from '../../context';
10
10
  import styles from './styles.module.scss';
11
11
 
12
- type Option = {
12
+ type Option = DroplistProps['items'][number] & {
13
13
  tagLabel?: string;
14
14
  icon?: ReactElement;
15
- } & Pick<BaseItemProps, 'onClick' | 'content' | 'disabled'>;
15
+ };
16
16
 
17
17
  export type FunctionBadgeProps = {
18
18
  /** Иконка */
@@ -36,6 +36,35 @@ export function FunctionBadge({ icon, options }: FunctionBadgeProps) {
36
36
  setIsOpen(isOpen => !isOpen);
37
37
  }, []);
38
38
 
39
+ const items = options.map(option => {
40
+ const { icon, tagLabel, ...item } = option;
41
+
42
+ // GroupItem и GroupSelectItem не имеют beforeContent, afterContent, onClick
43
+ if ('type' in item && (item.type === 'group' || item.type === 'group-select')) {
44
+ return item;
45
+ }
46
+
47
+ // BaseItem, AccordionItem, NextListItem имеют beforeContent, afterContent, onClick
48
+ const baseItem = item as {
49
+ beforeContent?: ReactNode;
50
+ afterContent?: ReactNode;
51
+ onClick?: (e: MouseEvent<HTMLElement>) => void;
52
+ };
53
+ const itemOnClick = baseItem.onClick;
54
+
55
+ return {
56
+ ...item,
57
+ className: styles.item,
58
+ beforeContent: icon ?? baseItem.beforeContent,
59
+ afterContent: tagLabel ? <Tag label={tagLabel} /> : baseItem.afterContent,
60
+ onClick: (e: MouseEvent<HTMLElement>) => {
61
+ e.stopPropagation();
62
+ setIsOpen(false);
63
+ itemOnClick?.(e);
64
+ },
65
+ };
66
+ });
67
+
39
68
  return (
40
69
  <span className={styles.wrapper}>
41
70
  <Droplist
@@ -47,17 +76,7 @@ export function FunctionBadge({ icon, options }: FunctionBadgeProps) {
47
76
  data-test-id={TEST_IDS.droplist}
48
77
  placement='bottom-end'
49
78
  triggerElemRef={buttonRef}
50
- items={options.map(({ icon, tagLabel, onClick, ...item }) => ({
51
- ...item,
52
- className: styles.item,
53
- beforeContent: icon,
54
- afterContent: tagLabel ? <Tag label={tagLabel} /> : undefined,
55
- onClick: e => {
56
- e.stopPropagation();
57
- setIsOpen(false);
58
- onClick?.(e);
59
- },
60
- }))}
79
+ items={items}
61
80
  >
62
81
  <button
63
82
  type='button'