@snack-uikit/card 0.8.1 → 0.9.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 CHANGED
@@ -3,6 +3,26 @@
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.9.1 (2024-01-30)
7
+
8
+ ### Only dependencies have been changed
9
+ * [@snack-uikit/list@0.1.1](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/list/CHANGELOG.md)
10
+
11
+
12
+
13
+
14
+
15
+ # 0.9.0 (2024-01-30)
16
+
17
+
18
+ ### BREAKING CHANGES
19
+
20
+
21
+ * **FF-4075:** change usage droplist to list package ([4ce6391](https://github.com/cloud-ru-tech/snack-uikit/commit/4ce63915e838a46a3776e8e21393695a37d2fdd3))
22
+
23
+
24
+
25
+
6
26
  ## 0.8.1 (2024-01-23)
7
27
 
8
28
  ### Only dependencies have been changed
@@ -1,9 +1,14 @@
1
- import { ReactNode } from 'react';
2
- import { ItemSingleProps } from '@snack-uikit/droplist';
1
+ import { ReactElement, ReactNode } from 'react';
2
+ import { BaseItemProps } from '@snack-uikit/list';
3
+ type Option = {
4
+ tagLabel?: string;
5
+ icon?: ReactElement;
6
+ } & Pick<BaseItemProps, 'onClick' | 'content' | 'disabled'>;
3
7
  export type FunctionBadgeProps = {
4
8
  /** Иконка */
5
9
  icon?: ReactNode;
6
10
  /** Вложенные опции */
7
- options: Pick<ItemSingleProps, 'tagLabel' | 'onClick' | 'option' | 'icon' | 'disabled' | 'description' | 'caption'>[];
11
+ options: Option[];
8
12
  };
9
13
  export declare function FunctionBadge({ icon, options }: FunctionBadgeProps): import("react/jsx-runtime").JSX.Element;
14
+ export {};
@@ -1,23 +1,39 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { createElement as _createElement } from "react";
3
- import { useCallback, useContext, useLayoutEffect, useState } from 'react';
4
- import { Droplist } from '@snack-uikit/droplist';
13
+ import { useCallback, useContext, useLayoutEffect, useRef, useState } from 'react';
5
14
  import { KebabSVG } from '@snack-uikit/icons';
15
+ import { Droplist } from '@snack-uikit/list';
16
+ import { Tag } from '@snack-uikit/tag';
6
17
  import { TEST_IDS } from '../../constants';
7
18
  import { FunctionBadgeContext } from '../../context';
8
19
  import styles from './styles.module.css';
9
20
  export function FunctionBadge({ icon, options }) {
10
21
  const [isOpen, setIsOpen] = useState(false);
22
+ const buttonRef = useRef(null);
11
23
  const { setVisible } = useContext(FunctionBadgeContext);
12
24
  useLayoutEffect(() => {
13
25
  setVisible && setVisible(isOpen);
14
26
  }, [isOpen, setVisible]);
15
- const { firstElementRefCallback, triggerElementRef, handleDroplistFocusLeave, handleDroplistItemClick, handleTriggerKeyDown, handleDroplistItemKeyDown, } = Droplist.useKeyboardNavigation({ setDroplistOpen: setIsOpen });
16
27
  const onClick = useCallback((e) => {
17
28
  e.stopPropagation();
18
29
  setIsOpen(isOpen => !isOpen);
19
30
  }, []);
20
- return (_jsx("span", { className: styles.wrapper, children: _jsx(Droplist, { open: isOpen, onOpenChange: setIsOpen, firstElementRefCallback: firstElementRefCallback, widthStrategy: 'gte', useScroll: true, onFocusLeave: handleDroplistFocusLeave, "data-test-id": TEST_IDS.droplist, triggerClassName: styles.triggerClassName, placement: 'bottom-end', triggerElement: _jsx("button", { "data-test-id": TEST_IDS.functionBadge, className: styles.button, onKeyDown: handleTriggerKeyDown, onClick: onClick, ref: triggerElementRef, children: icon || _jsx(KebabSVG, {}) }), children: options.map(item => (_createElement(Droplist.ItemSingle, Object.assign({}, item, { key: item.option, className: styles.item, "data-test-id": TEST_IDS.option, onClick: e => {
21
- handleDroplistItemClick(e, item.onClick);
22
- }, onKeyDown: handleDroplistItemKeyDown })))) }) }));
31
+ 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) => {
32
+ var { icon, tagLabel, onClick } = _a, item = __rest(_a, ["icon", "tagLabel", "onClick"]);
33
+ return (Object.assign(Object.assign({}, item), { beforeContent: icon, afterContent: tagLabel ? _jsx(Tag, { label: tagLabel }) : undefined, onClick: e => {
34
+ e.stopPropagation();
35
+ setIsOpen(false);
36
+ onClick === null || onClick === void 0 ? void 0 : onClick(e);
37
+ } }));
38
+ }), children: _jsx("button", { "data-test-id": TEST_IDS.functionBadge, className: styles.button, onClick: onClick, ref: buttonRef, children: icon || _jsx(KebabSVG, {}) }) }) }));
23
39
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "Card",
7
- "version": "0.8.1",
7
+ "version": "0.9.1",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -33,14 +33,15 @@
33
33
  "scripts": {},
34
34
  "dependencies": {
35
35
  "@snack-uikit/button": "0.15.1",
36
- "@snack-uikit/droplist": "0.12.5",
37
36
  "@snack-uikit/icon-predefined": "0.4.1",
38
37
  "@snack-uikit/icons": "0.20.0",
38
+ "@snack-uikit/list": "0.1.1",
39
39
  "@snack-uikit/promo-tag": "0.4.1",
40
+ "@snack-uikit/tag": "0.6.4",
40
41
  "@snack-uikit/truncate-string": "0.4.5",
41
42
  "@snack-uikit/typography": "0.6.1",
42
43
  "@snack-uikit/utils": "3.2.0",
43
44
  "classnames": "2.3.2"
44
45
  },
45
- "gitHead": "c292f4c45173928f57cc5c9f3cb02efb26887b64"
46
+ "gitHead": "54873fdb2f34f26a771f62568d3d6fcd62ea1694"
46
47
  }
@@ -1,21 +1,28 @@
1
- import { MouseEvent, ReactNode, useCallback, useContext, useLayoutEffect, useState } from 'react';
1
+ import { MouseEvent, ReactElement, ReactNode, useCallback, useContext, useLayoutEffect, useRef, useState } from 'react';
2
2
 
3
- import { Droplist, ItemSingleProps } from '@snack-uikit/droplist';
4
3
  import { KebabSVG } from '@snack-uikit/icons';
4
+ import { BaseItemProps, Droplist } from '@snack-uikit/list';
5
+ import { Tag } from '@snack-uikit/tag';
5
6
 
6
7
  import { TEST_IDS } from '../../constants';
7
8
  import { FunctionBadgeContext } from '../../context';
8
9
  import styles from './styles.module.scss';
9
10
 
11
+ type Option = {
12
+ tagLabel?: string;
13
+ icon?: ReactElement;
14
+ } & Pick<BaseItemProps, 'onClick' | 'content' | 'disabled'>;
15
+
10
16
  export type FunctionBadgeProps = {
11
17
  /** Иконка */
12
18
  icon?: ReactNode;
13
19
  /** Вложенные опции */
14
- options: Pick<ItemSingleProps, 'tagLabel' | 'onClick' | 'option' | 'icon' | 'disabled' | 'description' | 'caption'>[];
20
+ options: Option[];
15
21
  };
16
22
 
17
23
  export function FunctionBadge({ icon, options }: FunctionBadgeProps) {
18
24
  const [isOpen, setIsOpen] = useState<boolean>(false);
25
+ const buttonRef = useRef(null);
19
26
 
20
27
  const { setVisible } = useContext(FunctionBadgeContext);
21
28
 
@@ -23,15 +30,6 @@ export function FunctionBadge({ icon, options }: FunctionBadgeProps) {
23
30
  setVisible && setVisible(isOpen);
24
31
  }, [isOpen, setVisible]);
25
32
 
26
- const {
27
- firstElementRefCallback,
28
- triggerElementRef,
29
- handleDroplistFocusLeave,
30
- handleDroplistItemClick,
31
- handleTriggerKeyDown,
32
- handleDroplistItemKeyDown,
33
- } = Droplist.useKeyboardNavigation<HTMLButtonElement>({ setDroplistOpen: setIsOpen });
34
-
35
33
  const onClick = useCallback((e: MouseEvent<HTMLButtonElement>) => {
36
34
  e.stopPropagation();
37
35
  setIsOpen(isOpen => !isOpen);
@@ -40,39 +38,28 @@ export function FunctionBadge({ icon, options }: FunctionBadgeProps) {
40
38
  return (
41
39
  <span className={styles.wrapper}>
42
40
  <Droplist
41
+ trigger='clickAndFocusVisible'
43
42
  open={isOpen}
44
43
  onOpenChange={setIsOpen}
45
- firstElementRefCallback={firstElementRefCallback}
46
44
  widthStrategy='gte'
47
- useScroll
48
- onFocusLeave={handleDroplistFocusLeave}
45
+ scroll
49
46
  data-test-id={TEST_IDS.droplist}
50
- triggerClassName={styles.triggerClassName}
51
47
  placement='bottom-end'
52
- triggerElement={
53
- <button
54
- data-test-id={TEST_IDS.functionBadge}
55
- className={styles.button}
56
- onKeyDown={handleTriggerKeyDown}
57
- onClick={onClick}
58
- ref={triggerElementRef}
59
- >
60
- {icon || <KebabSVG />}
61
- </button>
62
- }
48
+ triggerElemRef={buttonRef}
49
+ items={options.map(({ icon, tagLabel, onClick, ...item }) => ({
50
+ ...item,
51
+ beforeContent: icon,
52
+ afterContent: tagLabel ? <Tag label={tagLabel} /> : undefined,
53
+ onClick: e => {
54
+ e.stopPropagation();
55
+ setIsOpen(false);
56
+ onClick?.(e);
57
+ },
58
+ }))}
63
59
  >
64
- {options.map(item => (
65
- <Droplist.ItemSingle
66
- {...item}
67
- key={item.option}
68
- className={styles.item}
69
- data-test-id={TEST_IDS.option}
70
- onClick={e => {
71
- handleDroplistItemClick(e, item.onClick);
72
- }}
73
- onKeyDown={handleDroplistItemKeyDown}
74
- />
75
- ))}
60
+ <button data-test-id={TEST_IDS.functionBadge} className={styles.button} onClick={onClick} ref={buttonRef}>
61
+ {icon || <KebabSVG />}
62
+ </button>
76
63
  </Droplist>
77
64
  </span>
78
65
  );