@cloud-ru/ds-uikit-product-card-predefined 1.0.0 → 1.0.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 (24) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  3. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  4. package/package.json +7 -7
  5. package/dist/cjs/components/CardServiceInfo/CardServiceInfo.d.ts +0 -43
  6. package/dist/cjs/components/CardServiceInfo/CardServiceInfo.js +0 -70
  7. package/dist/cjs/components/CardServiceInfo/index.d.ts +0 -1
  8. package/dist/cjs/components/CardServiceInfo/index.js +0 -17
  9. package/dist/cjs/helperComponents/CardActionsSurface/CardActionsSurface.d.ts +0 -31
  10. package/dist/cjs/helperComponents/CardActionsSurface/CardActionsSurface.js +0 -34
  11. package/dist/cjs/helperComponents/CardActionsSurface/index.d.ts +0 -2
  12. package/dist/cjs/helperComponents/CardActionsSurface/index.js +0 -18
  13. package/dist/cjs/helperComponents/CardActionsSurface/utils.d.ts +0 -23
  14. package/dist/cjs/helperComponents/CardActionsSurface/utils.js +0 -45
  15. package/dist/esm/components/CardServiceInfo/CardServiceInfo.d.ts +0 -43
  16. package/dist/esm/components/CardServiceInfo/CardServiceInfo.js +0 -64
  17. package/dist/esm/components/CardServiceInfo/index.d.ts +0 -1
  18. package/dist/esm/components/CardServiceInfo/index.js +0 -1
  19. package/dist/esm/helperComponents/CardActionsSurface/CardActionsSurface.d.ts +0 -31
  20. package/dist/esm/helperComponents/CardActionsSurface/CardActionsSurface.js +0 -28
  21. package/dist/esm/helperComponents/CardActionsSurface/index.d.ts +0 -2
  22. package/dist/esm/helperComponents/CardActionsSurface/index.js +0 -2
  23. package/dist/esm/helperComponents/CardActionsSurface/utils.d.ts +0 -23
  24. package/dist/esm/helperComponents/CardActionsSurface/utils.js +0 -42
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud-ru/ds-uikit-product-card-predefined",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Пресеты карточек Product UI Kit — CardBanner, CardService, CardServiceLight, CardServiceSmall, CardSuggest, CardCustom.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,17 +35,17 @@
35
35
  "dependencies": {
36
36
  "classnames": "^2.5.1",
37
37
  "merge-refs": "^2.0.0",
38
- "@cloud-ru/ds-button": "^1.0.0",
39
38
  "@cloud-ru/ds-card": "^1.0.0",
39
+ "@cloud-ru/ds-button": "^1.0.0",
40
40
  "@cloud-ru/ds-icons": "^1.0.0",
41
- "@cloud-ru/ds-icon-predefined": "^1.0.0",
42
- "@cloud-ru/ds-list": "^1.0.0",
43
- "@cloud-ru/ds-tag": "^1.0.0",
41
+ "@cloud-ru/ds-list": "^1.1.0",
44
42
  "@cloud-ru/ds-promo-tag": "^1.0.0",
43
+ "@cloud-ru/ds-tag": "^1.0.0",
44
+ "@cloud-ru/ds-icon-predefined": "^1.0.0",
45
45
  "@cloud-ru/ds-toggles": "^1.0.0",
46
- "@cloud-ru/ds-truncate-string": "^1.0.0",
47
46
  "@cloud-ru/ds-typography": "^1.0.0",
48
- "@cloud-ru/ds-utils": "^1.0.0"
47
+ "@cloud-ru/ds-utils": "^1.0.0",
48
+ "@cloud-ru/ds-truncate-string": "^1.0.0"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"
@@ -1,43 +0,0 @@
1
- import { PolymorphicRef } from '@cloud-ru/ds-card';
2
- import { PromoTagPredefinedProps } from '@cloud-ru/ds-uikit-product-promo-tag-predefined';
3
- import { ComponentPropsWithoutRef, ElementType, ReactElement } from 'react';
4
- import { CardActionsSurfaceProps } from '../../helperComponents';
5
- import { FavoriteProps, VisibilityStrategy } from '../../types';
6
- type BaseCardServiceInfoProps = Pick<CardActionsSurfaceProps, 'actionsSize'> & {
7
- /** Иконка сервиса */
8
- icon?: ReactElement;
9
- /** Заголовок карточки */
10
- title: string;
11
- /** Описание сервиса */
12
- description: string;
13
- /** Настройки promo tag. При отсутствии не отображается */
14
- promoTag?: Omit<PromoTagPredefinedProps, 'trigger' | 'as' | 'innerRef'>;
15
- /**
16
- * Формат отображения дополнительных действий: всегда или при наведении и фокусе
17
- * @default 'hover'
18
- */
19
- actionsVisibility?: VisibilityStrategy;
20
- /**
21
- * Настройки кнопки «Избранное».
22
- * Keyboard: ArrowRight на карточке → Favorite → expand; ArrowLeft — в обратном порядке.
23
- */
24
- favorite?: FavoriteProps;
25
- /** Неактивное состояние */
26
- disabled?: boolean;
27
- /** CSS-класс корневого элемента */
28
- className?: string;
29
- /** Support prop для тестов */
30
- 'data-test-id'?: string;
31
- expandable?: {
32
- value: boolean;
33
- onClick(): void;
34
- };
35
- };
36
- export type CardServiceInfoProps<T extends ElementType = 'button'> = BaseCardServiceInfoProps & {
37
- /** Полиморфный элемент: `'button'`, `'a'`, `{Link}` и т.д. */
38
- as?: T;
39
- /** Ref на реальный DOM-элемент / инстанс */
40
- innerRef?: PolymorphicRef<T>;
41
- } & Omit<ComponentPropsWithoutRef<T>, keyof BaseCardServiceInfoProps | 'as' | 'ref'>;
42
- export declare function CardServiceInfo<T extends ElementType = 'button'>({ as, innerRef, icon, title, description, promoTag, actionsVisibility, favorite, actionsSize, className, disabled, expandable, 'data-test-id': dataTestId, ...rest }: CardServiceInfoProps<T>): ReactElement | null;
43
- export {};
@@ -1,70 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CardServiceInfo = CardServiceInfo;
7
- const jsx_runtime_1 = require("react/jsx-runtime");
8
- const card_1 = require("@cloud-ru/ds-card");
9
- const theme_1 = require("@cloud-ru/ds-theme");
10
- const truncate_string_1 = require("@cloud-ru/ds-truncate-string");
11
- const typography_1 = require("@cloud-ru/ds-typography");
12
- const uikit_product_promo_tag_predefined_1 = require("@cloud-ru/ds-uikit-product-promo-tag-predefined");
13
- const utils_1 = require("@cloud-ru/ds-utils");
14
- const classnames_1 = __importDefault(require("classnames"));
15
- const merge_refs_1 = __importDefault(require("merge-refs"));
16
- const react_1 = require("react");
17
- const constants_1 = require("../../constants");
18
- const helperComponents_1 = require("../../helperComponents");
19
- const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
20
- function CardServiceInfo({ as, innerRef, icon, title, description, promoTag, actionsVisibility = constants_1.VISIBILITY_STRATEGY.hover, favorite, actionsSize, className, disabled, expandable, 'data-test-id': dataTestId, ...rest }) {
21
- const cardRef = (0, react_1.useRef)(null);
22
- const favoriteRef = (0, react_1.useRef)(null);
23
- const expandButtonRef = (0, react_1.useRef)(null);
24
- const promoTagTooltipTriggerRef = (0, react_1.useRef)(null);
25
- const compactThemeClassName = (0, theme_1.useThemeClassnames)({ density: 'compact' });
26
- const visibleActions = [favorite?.enabled, expandable].filter(Boolean);
27
- const [isFavorite, setIsFavorite] = (0, utils_1.useValueControl)({
28
- value: favorite?.checked,
29
- defaultValue: false,
30
- onChange: favorite?.onChange,
31
- });
32
- const tooltipTrigger = actionsVisibility === constants_1.VISIBILITY_STRATEGY.hover ? 'hoverAndFocusVisible' : 'click';
33
- const { onKeyDown: onKeyDownProp, ...restWithoutKeyDown } = rest;
34
- const handleKeyDown = (0, helperComponents_1.createCardActionsKeyDownHandler)({
35
- disabled,
36
- cardRef,
37
- onKeyDown: onKeyDownProp,
38
- items: [
39
- promoTag && { ref: promoTagTooltipTriggerRef },
40
- favorite?.enabled && {
41
- ref: favoriteRef,
42
- onActivate: () => setIsFavorite(!isFavorite),
43
- },
44
- expandable && {
45
- ref: expandButtonRef,
46
- onActivate: () => expandable.onClick(),
47
- },
48
- ],
49
- });
50
- return ((0, jsx_runtime_1.jsx)(card_1.Card, { as: (as ?? 'button'), innerRef: (0, merge_refs_1.default)(innerRef, cardRef), disabled: disabled, interactive: true, radius: 's', view: 'outline', backgroundPredefined: 'neutralBackground1Level', className: (0, classnames_1.default)(styles_module_scss_1.default.root, className), "data-test-id": dataTestId ?? constants_1.TEST_IDS.cardServiceInfo, onKeyDown: handleKeyDown, ...restWithoutKeyDown, children: (0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.container, children: [icon && (0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.icon, children: icon }), (0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.textContent, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.titleRow, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.titleContainer, "data-actions-visibility": actionsVisibility, "data-visible-actions": visibleActions.length, children: [(0, jsx_runtime_1.jsx)(typography_1.Typography, { as: 'span', variant: 'body', size: 'm', className: styles_module_scss_1.default.title, "data-test-id": constants_1.TEST_IDS.cardServiceInfoTitle, children: (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, { text: title, maxLines: 1, variant: 'end' }) }), promoTag && ((0, jsx_runtime_1.jsx)(uikit_product_promo_tag_predefined_1.PromoTagPredefined, { ...promoTag, variant: promoTag.variant, as: 'span', tabIndex: -1, tooltip: {
51
- ...promoTag.tooltip,
52
- trigger: tooltipTrigger,
53
- 'data-test-id': constants_1.TEST_IDS.cardServiceInfoPromoTagTooltip,
54
- }, innerRef: promoTagTooltipTriggerRef, "data-test-id": constants_1.TEST_IDS.cardServiceInfoPromoTag, className: (0, classnames_1.default)(styles_module_scss_1.default.promoTag, compactThemeClassName) }))] }), (0, jsx_runtime_1.jsx)(helperComponents_1.CardActionsSurface, { actionsSize: actionsSize, visibilityStrategy: actionsVisibility, className: styles_module_scss_1.default.actions, favorite: favorite?.enabled
55
- ? {
56
- enabled: favorite.enabled,
57
- checked: isFavorite,
58
- onChange: setIsFavorite,
59
- buttonRef: favoriteRef,
60
- 'data-test-id': constants_1.TEST_IDS.cardServiceInfoFavorite,
61
- }
62
- : undefined, expandable: expandable
63
- ? {
64
- value: expandable.value,
65
- onClick: expandable.onClick,
66
- buttonRef: expandButtonRef,
67
- }
68
- : undefined })] }), (0, jsx_runtime_1.jsx)(typography_1.Typography, { as: 'p', variant: 'body', size: 's', className: styles_module_scss_1.default.description, "data-test-id": constants_1.TEST_IDS.cardServiceInfoDescription, children: (0, jsx_runtime_1.jsx)(truncate_string_1.TruncateString, { text: description, maxLines: 2, variant: 'end' }) })] })] }) }));
69
- }
70
- (0, utils_1.withInnerRefSupport)(CardServiceInfo);
@@ -1 +0,0 @@
1
- export * from './CardServiceInfo';
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./CardServiceInfo"), exports);
@@ -1,31 +0,0 @@
1
- import { TooltipProps } from '@cloud-ru/ds-tooltip';
2
- import { ReactElement, RefObject } from 'react';
3
- import { FavoriteProps, VisibilityStrategy } from '../../types';
4
- export type CardActionsSurfaceProps = {
5
- /**
6
- * Формат отображения: всегда или при наведении и фокусе
7
- * @default 'hover'
8
- */
9
- visibilityStrategy?: VisibilityStrategy;
10
- /** Кнопка info с тултипом */
11
- tooltip?: Omit<TooltipProps, 'children'> & {
12
- buttonRef?: RefObject<HTMLButtonElement>;
13
- 'data-test-id'?: string;
14
- };
15
- /** Кнопка «Избранное» */
16
- favorite?: FavoriteProps & {
17
- buttonRef?: RefObject<HTMLButtonElement>;
18
- 'data-test-id'?: string;
19
- };
20
- /** Кнопка раскрытия */
21
- expandable?: {
22
- value: boolean;
23
- onClick(): void;
24
- buttonRef?: RefObject<HTMLButtonElement>;
25
- };
26
- /** Размер кнопок действий, для мобильного вида предполагается использовать `s` */
27
- actionsSize?: 's' | 'm';
28
- /** CSS-класс корневого элемента */
29
- className?: string;
30
- };
31
- export declare function CardActionsSurface({ visibilityStrategy, tooltip, favorite, expandable, actionsSize, className, }: CardActionsSurfaceProps): ReactElement | null;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CardActionsSurface = CardActionsSurface;
7
- const jsx_runtime_1 = require("react/jsx-runtime");
8
- const button_1 = require("@cloud-ru/ds-button");
9
- const product_1 = require("@cloud-ru/ds-icons/interface/product");
10
- const system_1 = require("@cloud-ru/ds-icons/interface/system");
11
- const tooltip_1 = require("@cloud-ru/ds-tooltip");
12
- const utils_1 = require("@cloud-ru/ds-utils");
13
- const classnames_1 = __importDefault(require("classnames"));
14
- const constants_1 = require("../../constants");
15
- const styles_module_scss_1 = __importDefault(require('./styles.module.css'));
16
- function CardActionsSurface({ visibilityStrategy = constants_1.VISIBILITY_STRATEGY.hover, tooltip, favorite, expandable, actionsSize = 'm', className, }) {
17
- if (!tooltip && !favorite && !expandable) {
18
- return null;
19
- }
20
- const tooltipTrigger = tooltip?.trigger ??
21
- (visibilityStrategy === constants_1.VISIBILITY_STRATEGY.always ? tooltip_1.TRIGGER.Click : tooltip_1.TRIGGER.HoverAndFocusVisible);
22
- const handleExpandButtonClick = (e) => {
23
- (0, utils_1.preventEventDefaultAndPropagation)(e);
24
- expandable?.onClick();
25
- };
26
- const handleFavoriteClick = (e) => {
27
- (0, utils_1.preventEventDefaultAndPropagation)(e);
28
- favorite?.onChange?.(!favorite.checked);
29
- };
30
- const { buttonRef: tooltipButtonRef, 'data-test-id': tooltipTestId, ...tooltipProps } = tooltip ?? {};
31
- return (
32
- // eslint-disable-next-line jsx-a11y/no-static-element-interactions
33
- (0, jsx_runtime_1.jsxs)("div", { onClick: utils_1.preventEventDefaultAndPropagation, className: (0, classnames_1.default)(styles_module_scss_1.default.root, className), "data-visibility-strategy": visibilityStrategy, children: [tooltip && ((0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { ...tooltipProps, tip: tooltip.tip, trigger: tooltipTrigger, triggerClassName: styles_module_scss_1.default.tooltipTrigger, children: (0, jsx_runtime_1.jsx)(button_1.Button, { as: 'span', size: actionsSize, appearance: 'neutral', view: 'simple', icon: (0, jsx_runtime_1.jsx)(product_1.InfoOutlineSVG, {}), tabIndex: -1, onClick: utils_1.preventEventDefault, innerRef: tooltipButtonRef, "data-test-id": tooltipTestId }) })), favorite?.enabled && ((0, jsx_runtime_1.jsx)(button_1.Button, { as: 'span', size: actionsSize, appearance: 'neutral', view: 'simple', icon: favorite.checked ? (0, jsx_runtime_1.jsx)(system_1.StarFilledSVG, {}) : (0, jsx_runtime_1.jsx)(system_1.StarSVG, {}), onClick: handleFavoriteClick, className: styles_module_scss_1.default.favorite, innerRef: favorite.buttonRef, tabIndex: -1, "data-test-id": favorite['data-test-id'], "data-checked": favorite.checked || undefined })), expandable && ((0, jsx_runtime_1.jsx)(button_1.Button, { as: 'span', size: actionsSize, appearance: 'neutral', view: 'simple', icon: expandable.value ? (0, jsx_runtime_1.jsx)(system_1.CollapseVerticalSVG, {}) : (0, jsx_runtime_1.jsx)(system_1.ExpandVerticalSVG, {}), onClick: handleExpandButtonClick, className: styles_module_scss_1.default.expandButton, innerRef: expandable.buttonRef, tabIndex: -1 }))] }));
34
- }
@@ -1,2 +0,0 @@
1
- export * from './CardActionsSurface';
2
- export * from './utils';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./CardActionsSurface"), exports);
18
- __exportStar(require("./utils"), exports);
@@ -1,23 +0,0 @@
1
- import { KeyboardEventHandler, RefObject } from 'react';
2
- export type CardActionsKeyboardItem = {
3
- ref: RefObject<HTMLElement | null>;
4
- /**
5
- * Поведение Space/Enter, когда фокус на этом элементе.
6
- * - `undefined` — проброс на клик по карточке
7
- * - `'ignore'` — ничего не делать (например, trigger тултипа)
8
- * - функция — вызвать и остановиться
9
- */
10
- onActivate?(): void;
11
- };
12
- export type CreateCardActionsKeyDownHandlerOptions = {
13
- disabled?: boolean;
14
- cardRef: RefObject<HTMLElement | null>;
15
- /** Упорядоченная цепочка фокуса после карточки: promoTag → tooltip → favorite → expand */
16
- items: Array<CardActionsKeyboardItem | false | null | undefined>;
17
- onKeyDown?: KeyboardEventHandler<HTMLElement>;
18
- };
19
- /**
20
- * Клавиатура для доп. контролов карточки сервиса:
21
- * ArrowRight/ArrowLeft — по цепочке card → items; Space/Enter — activate или клик по карточке.
22
- */
23
- export declare function createCardActionsKeyDownHandler({ disabled, cardRef, items: rawItems, onKeyDown, }: CreateCardActionsKeyDownHandlerOptions): KeyboardEventHandler<HTMLElement>;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createCardActionsKeyDownHandler = createCardActionsKeyDownHandler;
4
- /**
5
- * Клавиатура для доп. контролов карточки сервиса:
6
- * ArrowRight/ArrowLeft — по цепочке card → items; Space/Enter — activate или клик по карточке.
7
- */
8
- function createCardActionsKeyDownHandler({ disabled, cardRef, items: rawItems, onKeyDown, }) {
9
- const items = rawItems.filter(Boolean);
10
- const chain = [cardRef, ...items.map(item => item.ref)];
11
- return e => {
12
- if (disabled) {
13
- onKeyDown?.(e);
14
- return;
15
- }
16
- const currentIndex = chain.findIndex(ref => ref.current === e.target);
17
- if (e.code === 'ArrowRight') {
18
- e.preventDefault();
19
- if (currentIndex !== -1) {
20
- chain[currentIndex + 1]?.current?.focus();
21
- }
22
- }
23
- if (e.code === 'ArrowLeft') {
24
- e.preventDefault();
25
- if (currentIndex > 0) {
26
- chain[currentIndex - 1]?.current?.focus();
27
- }
28
- else {
29
- cardRef.current?.focus();
30
- }
31
- }
32
- if (e.code === 'Space' || e.code === 'Enter') {
33
- e.preventDefault();
34
- const currentItem = currentIndex > 0 ? items[currentIndex - 1] : undefined;
35
- if (e.target === currentItem?.ref.current) {
36
- if (typeof currentItem?.onActivate === 'function') {
37
- currentItem.onActivate();
38
- }
39
- return;
40
- }
41
- cardRef.current?.click();
42
- }
43
- onKeyDown?.(e);
44
- };
45
- }
@@ -1,43 +0,0 @@
1
- import { PolymorphicRef } from '@cloud-ru/ds-card';
2
- import { PromoTagPredefinedProps } from '@cloud-ru/ds-uikit-product-promo-tag-predefined';
3
- import { ComponentPropsWithoutRef, ElementType, ReactElement } from 'react';
4
- import { CardActionsSurfaceProps } from '../../helperComponents/index.js';
5
- import { FavoriteProps, VisibilityStrategy } from '../../types.js';
6
- type BaseCardServiceInfoProps = Pick<CardActionsSurfaceProps, 'actionsSize'> & {
7
- /** Иконка сервиса */
8
- icon?: ReactElement;
9
- /** Заголовок карточки */
10
- title: string;
11
- /** Описание сервиса */
12
- description: string;
13
- /** Настройки promo tag. При отсутствии не отображается */
14
- promoTag?: Omit<PromoTagPredefinedProps, 'trigger' | 'as' | 'innerRef'>;
15
- /**
16
- * Формат отображения дополнительных действий: всегда или при наведении и фокусе
17
- * @default 'hover'
18
- */
19
- actionsVisibility?: VisibilityStrategy;
20
- /**
21
- * Настройки кнопки «Избранное».
22
- * Keyboard: ArrowRight на карточке → Favorite → expand; ArrowLeft — в обратном порядке.
23
- */
24
- favorite?: FavoriteProps;
25
- /** Неактивное состояние */
26
- disabled?: boolean;
27
- /** CSS-класс корневого элемента */
28
- className?: string;
29
- /** Support prop для тестов */
30
- 'data-test-id'?: string;
31
- expandable?: {
32
- value: boolean;
33
- onClick(): void;
34
- };
35
- };
36
- export type CardServiceInfoProps<T extends ElementType = 'button'> = BaseCardServiceInfoProps & {
37
- /** Полиморфный элемент: `'button'`, `'a'`, `{Link}` и т.д. */
38
- as?: T;
39
- /** Ref на реальный DOM-элемент / инстанс */
40
- innerRef?: PolymorphicRef<T>;
41
- } & Omit<ComponentPropsWithoutRef<T>, keyof BaseCardServiceInfoProps | 'as' | 'ref'>;
42
- export declare function CardServiceInfo<T extends ElementType = 'button'>({ as, innerRef, icon, title, description, promoTag, actionsVisibility, favorite, actionsSize, className, disabled, expandable, 'data-test-id': dataTestId, ...rest }: CardServiceInfoProps<T>): ReactElement | null;
43
- export {};
@@ -1,64 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Card } from '@cloud-ru/ds-card';
3
- import { useThemeClassnames } from '@cloud-ru/ds-theme';
4
- import { TruncateString } from '@cloud-ru/ds-truncate-string';
5
- import { Typography } from '@cloud-ru/ds-typography';
6
- import { PromoTagPredefined } from '@cloud-ru/ds-uikit-product-promo-tag-predefined';
7
- import { useValueControl, withInnerRefSupport } from '@cloud-ru/ds-utils';
8
- import cn from 'classnames';
9
- import mergeRefs from 'merge-refs';
10
- import { useRef } from 'react';
11
- import { TEST_IDS, VISIBILITY_STRATEGY } from '../../constants.js';
12
- import { CardActionsSurface, createCardActionsKeyDownHandler } from '../../helperComponents/index.js';
13
- import styles from './styles.module.css';
14
- export function CardServiceInfo({ as, innerRef, icon, title, description, promoTag, actionsVisibility = VISIBILITY_STRATEGY.hover, favorite, actionsSize, className, disabled, expandable, 'data-test-id': dataTestId, ...rest }) {
15
- const cardRef = useRef(null);
16
- const favoriteRef = useRef(null);
17
- const expandButtonRef = useRef(null);
18
- const promoTagTooltipTriggerRef = useRef(null);
19
- const compactThemeClassName = useThemeClassnames({ density: 'compact' });
20
- const visibleActions = [favorite?.enabled, expandable].filter(Boolean);
21
- const [isFavorite, setIsFavorite] = useValueControl({
22
- value: favorite?.checked,
23
- defaultValue: false,
24
- onChange: favorite?.onChange,
25
- });
26
- const tooltipTrigger = actionsVisibility === VISIBILITY_STRATEGY.hover ? 'hoverAndFocusVisible' : 'click';
27
- const { onKeyDown: onKeyDownProp, ...restWithoutKeyDown } = rest;
28
- const handleKeyDown = createCardActionsKeyDownHandler({
29
- disabled,
30
- cardRef,
31
- onKeyDown: onKeyDownProp,
32
- items: [
33
- promoTag && { ref: promoTagTooltipTriggerRef },
34
- favorite?.enabled && {
35
- ref: favoriteRef,
36
- onActivate: () => setIsFavorite(!isFavorite),
37
- },
38
- expandable && {
39
- ref: expandButtonRef,
40
- onActivate: () => expandable.onClick(),
41
- },
42
- ],
43
- });
44
- return (_jsx(Card, { as: (as ?? 'button'), innerRef: mergeRefs(innerRef, cardRef), disabled: disabled, interactive: true, radius: 's', view: 'outline', backgroundPredefined: 'neutralBackground1Level', className: cn(styles.root, className), "data-test-id": dataTestId ?? TEST_IDS.cardServiceInfo, onKeyDown: handleKeyDown, ...restWithoutKeyDown, children: _jsxs("div", { className: styles.container, children: [icon && _jsx("div", { className: styles.icon, children: icon }), _jsxs("div", { className: styles.textContent, children: [_jsxs("div", { className: styles.titleRow, children: [_jsxs("div", { className: styles.titleContainer, "data-actions-visibility": actionsVisibility, "data-visible-actions": visibleActions.length, children: [_jsx(Typography, { as: 'span', variant: 'body', size: 'm', className: styles.title, "data-test-id": TEST_IDS.cardServiceInfoTitle, children: _jsx(TruncateString, { text: title, maxLines: 1, variant: 'end' }) }), promoTag && (_jsx(PromoTagPredefined, { ...promoTag, variant: promoTag.variant, as: 'span', tabIndex: -1, tooltip: {
45
- ...promoTag.tooltip,
46
- trigger: tooltipTrigger,
47
- 'data-test-id': TEST_IDS.cardServiceInfoPromoTagTooltip,
48
- }, innerRef: promoTagTooltipTriggerRef, "data-test-id": TEST_IDS.cardServiceInfoPromoTag, className: cn(styles.promoTag, compactThemeClassName) }))] }), _jsx(CardActionsSurface, { actionsSize: actionsSize, visibilityStrategy: actionsVisibility, className: styles.actions, favorite: favorite?.enabled
49
- ? {
50
- enabled: favorite.enabled,
51
- checked: isFavorite,
52
- onChange: setIsFavorite,
53
- buttonRef: favoriteRef,
54
- 'data-test-id': TEST_IDS.cardServiceInfoFavorite,
55
- }
56
- : undefined, expandable: expandable
57
- ? {
58
- value: expandable.value,
59
- onClick: expandable.onClick,
60
- buttonRef: expandButtonRef,
61
- }
62
- : undefined })] }), _jsx(Typography, { as: 'p', variant: 'body', size: 's', className: styles.description, "data-test-id": TEST_IDS.cardServiceInfoDescription, children: _jsx(TruncateString, { text: description, maxLines: 2, variant: 'end' }) })] })] }) }));
63
- }
64
- withInnerRefSupport(CardServiceInfo);
@@ -1 +0,0 @@
1
- export * from './CardServiceInfo.js';
@@ -1 +0,0 @@
1
- export * from './CardServiceInfo.js';
@@ -1,31 +0,0 @@
1
- import { TooltipProps } from '@cloud-ru/ds-tooltip';
2
- import { ReactElement, RefObject } from 'react';
3
- import { FavoriteProps, VisibilityStrategy } from '../../types.js';
4
- export type CardActionsSurfaceProps = {
5
- /**
6
- * Формат отображения: всегда или при наведении и фокусе
7
- * @default 'hover'
8
- */
9
- visibilityStrategy?: VisibilityStrategy;
10
- /** Кнопка info с тултипом */
11
- tooltip?: Omit<TooltipProps, 'children'> & {
12
- buttonRef?: RefObject<HTMLButtonElement>;
13
- 'data-test-id'?: string;
14
- };
15
- /** Кнопка «Избранное» */
16
- favorite?: FavoriteProps & {
17
- buttonRef?: RefObject<HTMLButtonElement>;
18
- 'data-test-id'?: string;
19
- };
20
- /** Кнопка раскрытия */
21
- expandable?: {
22
- value: boolean;
23
- onClick(): void;
24
- buttonRef?: RefObject<HTMLButtonElement>;
25
- };
26
- /** Размер кнопок действий, для мобильного вида предполагается использовать `s` */
27
- actionsSize?: 's' | 'm';
28
- /** CSS-класс корневого элемента */
29
- className?: string;
30
- };
31
- export declare function CardActionsSurface({ visibilityStrategy, tooltip, favorite, expandable, actionsSize, className, }: CardActionsSurfaceProps): ReactElement | null;
@@ -1,28 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button } from '@cloud-ru/ds-button';
3
- import { InfoOutlineSVG } from '@cloud-ru/ds-icons/interface/product';
4
- import { CollapseVerticalSVG, ExpandVerticalSVG, StarFilledSVG, StarSVG } from '@cloud-ru/ds-icons/interface/system';
5
- import { Tooltip, TRIGGER } from '@cloud-ru/ds-tooltip';
6
- import { preventEventDefault, preventEventDefaultAndPropagation } from '@cloud-ru/ds-utils';
7
- import cn from 'classnames';
8
- import { VISIBILITY_STRATEGY } from '../../constants.js';
9
- import styles from './styles.module.css';
10
- export function CardActionsSurface({ visibilityStrategy = VISIBILITY_STRATEGY.hover, tooltip, favorite, expandable, actionsSize = 'm', className, }) {
11
- if (!tooltip && !favorite && !expandable) {
12
- return null;
13
- }
14
- const tooltipTrigger = tooltip?.trigger ??
15
- (visibilityStrategy === VISIBILITY_STRATEGY.always ? TRIGGER.Click : TRIGGER.HoverAndFocusVisible);
16
- const handleExpandButtonClick = (e) => {
17
- preventEventDefaultAndPropagation(e);
18
- expandable?.onClick();
19
- };
20
- const handleFavoriteClick = (e) => {
21
- preventEventDefaultAndPropagation(e);
22
- favorite?.onChange?.(!favorite.checked);
23
- };
24
- const { buttonRef: tooltipButtonRef, 'data-test-id': tooltipTestId, ...tooltipProps } = tooltip ?? {};
25
- return (
26
- // eslint-disable-next-line jsx-a11y/no-static-element-interactions
27
- _jsxs("div", { onClick: preventEventDefaultAndPropagation, className: cn(styles.root, className), "data-visibility-strategy": visibilityStrategy, children: [tooltip && (_jsx(Tooltip, { ...tooltipProps, tip: tooltip.tip, trigger: tooltipTrigger, triggerClassName: styles.tooltipTrigger, children: _jsx(Button, { as: 'span', size: actionsSize, appearance: 'neutral', view: 'simple', icon: _jsx(InfoOutlineSVG, {}), tabIndex: -1, onClick: preventEventDefault, innerRef: tooltipButtonRef, "data-test-id": tooltipTestId }) })), favorite?.enabled && (_jsx(Button, { as: 'span', size: actionsSize, appearance: 'neutral', view: 'simple', icon: favorite.checked ? _jsx(StarFilledSVG, {}) : _jsx(StarSVG, {}), onClick: handleFavoriteClick, className: styles.favorite, innerRef: favorite.buttonRef, tabIndex: -1, "data-test-id": favorite['data-test-id'], "data-checked": favorite.checked || undefined })), expandable && (_jsx(Button, { as: 'span', size: actionsSize, appearance: 'neutral', view: 'simple', icon: expandable.value ? _jsx(CollapseVerticalSVG, {}) : _jsx(ExpandVerticalSVG, {}), onClick: handleExpandButtonClick, className: styles.expandButton, innerRef: expandable.buttonRef, tabIndex: -1 }))] }));
28
- }
@@ -1,2 +0,0 @@
1
- export * from './CardActionsSurface.js';
2
- export * from './utils.js';
@@ -1,2 +0,0 @@
1
- export * from './CardActionsSurface.js';
2
- export * from './utils.js';
@@ -1,23 +0,0 @@
1
- import { KeyboardEventHandler, RefObject } from 'react';
2
- export type CardActionsKeyboardItem = {
3
- ref: RefObject<HTMLElement | null>;
4
- /**
5
- * Поведение Space/Enter, когда фокус на этом элементе.
6
- * - `undefined` — проброс на клик по карточке
7
- * - `'ignore'` — ничего не делать (например, trigger тултипа)
8
- * - функция — вызвать и остановиться
9
- */
10
- onActivate?(): void;
11
- };
12
- export type CreateCardActionsKeyDownHandlerOptions = {
13
- disabled?: boolean;
14
- cardRef: RefObject<HTMLElement | null>;
15
- /** Упорядоченная цепочка фокуса после карточки: promoTag → tooltip → favorite → expand */
16
- items: Array<CardActionsKeyboardItem | false | null | undefined>;
17
- onKeyDown?: KeyboardEventHandler<HTMLElement>;
18
- };
19
- /**
20
- * Клавиатура для доп. контролов карточки сервиса:
21
- * ArrowRight/ArrowLeft — по цепочке card → items; Space/Enter — activate или клик по карточке.
22
- */
23
- export declare function createCardActionsKeyDownHandler({ disabled, cardRef, items: rawItems, onKeyDown, }: CreateCardActionsKeyDownHandlerOptions): KeyboardEventHandler<HTMLElement>;
@@ -1,42 +0,0 @@
1
- /**
2
- * Клавиатура для доп. контролов карточки сервиса:
3
- * ArrowRight/ArrowLeft — по цепочке card → items; Space/Enter — activate или клик по карточке.
4
- */
5
- export function createCardActionsKeyDownHandler({ disabled, cardRef, items: rawItems, onKeyDown, }) {
6
- const items = rawItems.filter(Boolean);
7
- const chain = [cardRef, ...items.map(item => item.ref)];
8
- return e => {
9
- if (disabled) {
10
- onKeyDown?.(e);
11
- return;
12
- }
13
- const currentIndex = chain.findIndex(ref => ref.current === e.target);
14
- if (e.code === 'ArrowRight') {
15
- e.preventDefault();
16
- if (currentIndex !== -1) {
17
- chain[currentIndex + 1]?.current?.focus();
18
- }
19
- }
20
- if (e.code === 'ArrowLeft') {
21
- e.preventDefault();
22
- if (currentIndex > 0) {
23
- chain[currentIndex - 1]?.current?.focus();
24
- }
25
- else {
26
- cardRef.current?.focus();
27
- }
28
- }
29
- if (e.code === 'Space' || e.code === 'Enter') {
30
- e.preventDefault();
31
- const currentItem = currentIndex > 0 ? items[currentIndex - 1] : undefined;
32
- if (e.target === currentItem?.ref.current) {
33
- if (typeof currentItem?.onActivate === 'function') {
34
- currentItem.onActivate();
35
- }
36
- return;
37
- }
38
- cardRef.current?.click();
39
- }
40
- onKeyDown?.(e);
41
- };
42
- }