@cloud-ru/ds-uikit-product-card-predefined 1.0.4 → 2.0.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.
Files changed (92) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +251 -34
  3. package/dist/cjs/components/CardServiceInfo/CardServiceInfo.d.ts +43 -0
  4. package/dist/cjs/components/CardServiceInfo/CardServiceInfo.js +66 -0
  5. package/dist/cjs/components/CardServiceInfo/index.d.ts +1 -0
  6. package/dist/cjs/components/CardServiceInfo/index.js +17 -0
  7. package/dist/cjs/components/CardServiceInfo/styles.module.css +102 -0
  8. package/dist/cjs/components/CardServiceLight/CardServiceLight.d.ts +22 -11
  9. package/dist/cjs/components/CardServiceLight/CardServiceLight.js +98 -31
  10. package/dist/cjs/components/CardServiceLight/styles.module.css +30 -25
  11. package/dist/cjs/components/CardServiceSmall/CardServiceSmall.d.ts +7 -6
  12. package/dist/cjs/components/CardServiceSmall/CardServiceSmall.js +7 -3
  13. package/dist/cjs/components/CardServiceSmall/styles.module.css +3 -3
  14. package/dist/cjs/components/index.d.ts +1 -0
  15. package/dist/cjs/components/index.js +1 -0
  16. package/dist/cjs/constants.d.ts +9 -0
  17. package/dist/cjs/constants.js +10 -1
  18. package/dist/cjs/helperComponents/CardActionsSurface/CardActionsSurface.d.ts +31 -0
  19. package/dist/cjs/helperComponents/CardActionsSurface/CardActionsSurface.js +36 -0
  20. package/dist/cjs/helperComponents/CardActionsSurface/index.d.ts +2 -0
  21. package/dist/cjs/helperComponents/CardActionsSurface/index.js +18 -0
  22. package/dist/cjs/helperComponents/CardActionsSurface/styles.module.css +36 -0
  23. package/dist/cjs/helperComponents/CardActionsSurface/utils.d.ts +22 -0
  24. package/dist/cjs/helperComponents/CardActionsSurface/utils.js +43 -0
  25. package/dist/cjs/helperComponents/CardPromoTag/CardPromoTag.d.ts +16 -0
  26. package/dist/cjs/helperComponents/CardPromoTag/CardPromoTag.js +24 -0
  27. package/dist/cjs/helperComponents/CardPromoTag/index.d.ts +1 -0
  28. package/dist/cjs/helperComponents/CardPromoTag/index.js +17 -0
  29. package/dist/cjs/helperComponents/index.d.ts +2 -0
  30. package/dist/cjs/helperComponents/index.js +2 -0
  31. package/dist/cjs/index.d.ts +2 -0
  32. package/dist/cjs/index.js +2 -0
  33. package/dist/cjs/locale/index.d.ts +43 -0
  34. package/dist/cjs/locale/index.js +26 -0
  35. package/dist/cjs/style.css +166 -23
  36. package/dist/cjs/types.d.ts +12 -5
  37. package/dist/esm/components/CardServiceInfo/CardServiceInfo.d.ts +43 -0
  38. package/dist/esm/components/CardServiceInfo/CardServiceInfo.js +60 -0
  39. package/dist/esm/components/CardServiceInfo/index.d.ts +1 -0
  40. package/dist/esm/components/CardServiceInfo/index.js +1 -0
  41. package/dist/esm/components/CardServiceInfo/styles.module.css +102 -0
  42. package/dist/esm/components/CardServiceLight/CardServiceLight.d.ts +22 -11
  43. package/dist/esm/components/CardServiceLight/CardServiceLight.js +101 -34
  44. package/dist/esm/components/CardServiceLight/styles.module.css +30 -25
  45. package/dist/esm/components/CardServiceSmall/CardServiceSmall.d.ts +7 -6
  46. package/dist/esm/components/CardServiceSmall/CardServiceSmall.js +8 -4
  47. package/dist/esm/components/CardServiceSmall/styles.module.css +3 -3
  48. package/dist/esm/components/index.d.ts +1 -0
  49. package/dist/esm/components/index.js +1 -0
  50. package/dist/esm/constants.d.ts +9 -0
  51. package/dist/esm/constants.js +9 -0
  52. package/dist/esm/helperComponents/CardActionsSurface/CardActionsSurface.d.ts +31 -0
  53. package/dist/esm/helperComponents/CardActionsSurface/CardActionsSurface.js +30 -0
  54. package/dist/esm/helperComponents/CardActionsSurface/index.d.ts +2 -0
  55. package/dist/esm/helperComponents/CardActionsSurface/index.js +2 -0
  56. package/dist/esm/helperComponents/CardActionsSurface/styles.module.css +36 -0
  57. package/dist/esm/helperComponents/CardActionsSurface/utils.d.ts +22 -0
  58. package/dist/esm/helperComponents/CardActionsSurface/utils.js +40 -0
  59. package/dist/esm/helperComponents/CardPromoTag/CardPromoTag.d.ts +16 -0
  60. package/dist/esm/helperComponents/CardPromoTag/CardPromoTag.js +21 -0
  61. package/dist/esm/helperComponents/CardPromoTag/index.d.ts +1 -0
  62. package/dist/esm/helperComponents/CardPromoTag/index.js +1 -0
  63. package/dist/esm/helperComponents/index.d.ts +2 -0
  64. package/dist/esm/helperComponents/index.js +2 -0
  65. package/dist/esm/index.d.ts +2 -0
  66. package/dist/esm/index.js +2 -0
  67. package/dist/esm/locale/index.d.ts +43 -0
  68. package/dist/esm/locale/index.js +23 -0
  69. package/dist/esm/style.css +166 -23
  70. package/dist/esm/types.d.ts +12 -5
  71. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  72. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  73. package/package.json +21 -11
  74. package/src/components/CardServiceInfo/CardServiceInfo.tsx +203 -0
  75. package/src/components/CardServiceInfo/index.ts +1 -0
  76. package/src/components/CardServiceInfo/styles.module.scss +124 -0
  77. package/src/components/CardServiceLight/CardServiceLight.tsx +172 -80
  78. package/src/components/CardServiceLight/styles.module.scss +37 -33
  79. package/src/components/CardServiceSmall/CardServiceSmall.tsx +14 -6
  80. package/src/components/CardServiceSmall/styles.module.scss +3 -3
  81. package/src/components/index.ts +1 -0
  82. package/src/constants.ts +10 -0
  83. package/src/helperComponents/CardActionsSurface/CardActionsSurface.tsx +136 -0
  84. package/src/helperComponents/CardActionsSurface/index.ts +2 -0
  85. package/src/helperComponents/CardActionsSurface/styles.module.scss +50 -0
  86. package/src/helperComponents/CardActionsSurface/utils.ts +76 -0
  87. package/src/helperComponents/CardPromoTag/CardPromoTag.tsx +46 -0
  88. package/src/helperComponents/CardPromoTag/index.ts +1 -0
  89. package/src/helperComponents/index.ts +2 -0
  90. package/src/index.ts +2 -0
  91. package/src/locale/index.ts +27 -0
  92. package/src/types.ts +10 -5
@@ -0,0 +1,102 @@
1
+ .actions{
2
+ --card-actions-surface-inset-top:var(--sn-primitive-dimension-4, 4px);
3
+ --card-actions-surface-inset-right:var(--sn-primitive-dimension-4, 4px);
4
+ }
5
+
6
+ .titleContainer{
7
+ display:flex;
8
+ gap:var(--sn-primitive-dimension-4, 4px);
9
+ align-items:center;
10
+ width:100%;
11
+ min-width:0;
12
+ }
13
+ .titleContainer[data-actions-visibility=always][data-actions-size=s][data-visible-actions="1"]{
14
+ padding-right:calc(1 * var(--sn-button-anatomy-size-s-container-iconOnly-minWidth, var(--sn-density-size-s, var(--sn-primitive-dimension-48, 48px))));
15
+ }
16
+ .titleContainer[data-actions-visibility=always][data-actions-size=s][data-visible-actions="2"]{
17
+ padding-right:calc(2 * var(--sn-button-anatomy-size-s-container-iconOnly-minWidth, var(--sn-density-size-s, var(--sn-primitive-dimension-48, 48px))));
18
+ }
19
+ .titleContainer[data-actions-visibility=always][data-actions-size=m][data-visible-actions="1"]{
20
+ padding-right:calc(1 * var(--sn-button-anatomy-size-m-container-iconOnly-minWidth, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px))));
21
+ }
22
+ .titleContainer[data-actions-visibility=always][data-actions-size=m][data-visible-actions="2"]{
23
+ padding-right:calc(2 * var(--sn-button-anatomy-size-m-container-iconOnly-minWidth, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px))));
24
+ }
25
+
26
+ .root{
27
+ cursor:pointer;
28
+ position:relative;
29
+ box-sizing:border-box;
30
+ width:100%;
31
+ padding:0;
32
+ border:none;
33
+ font:inherit;
34
+ color:inherit;
35
+ text-decoration:none;
36
+ background-color:transparent;
37
+ outline:none;
38
+ }
39
+ .root:hover .actions, .root:focus-visible .actions, .root:has(*:focus-visible) .actions{
40
+ transform:translateX(0);
41
+ visibility:visible;
42
+ }
43
+ .root:hover .titleContainer[data-actions-size=s][data-visible-actions="1"], .root:focus-visible .titleContainer[data-actions-size=s][data-visible-actions="1"], .root:has(*:focus-visible) .titleContainer[data-actions-size=s][data-visible-actions="1"]{
44
+ padding-right:calc(1 * var(--sn-button-anatomy-size-s-container-iconOnly-minWidth, var(--sn-density-size-s, var(--sn-primitive-dimension-48, 48px))));
45
+ }
46
+ .root:hover .titleContainer[data-actions-size=s][data-visible-actions="2"], .root:focus-visible .titleContainer[data-actions-size=s][data-visible-actions="2"], .root:has(*:focus-visible) .titleContainer[data-actions-size=s][data-visible-actions="2"]{
47
+ padding-right:calc(2 * var(--sn-button-anatomy-size-s-container-iconOnly-minWidth, var(--sn-density-size-s, var(--sn-primitive-dimension-48, 48px))));
48
+ }
49
+ .root:hover .titleContainer[data-actions-size=m][data-visible-actions="1"], .root:focus-visible .titleContainer[data-actions-size=m][data-visible-actions="1"], .root:has(*:focus-visible) .titleContainer[data-actions-size=m][data-visible-actions="1"]{
50
+ padding-right:calc(1 * var(--sn-button-anatomy-size-m-container-iconOnly-minWidth, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px))));
51
+ }
52
+ .root:hover .titleContainer[data-actions-size=m][data-visible-actions="2"], .root:focus-visible .titleContainer[data-actions-size=m][data-visible-actions="2"], .root:has(*:focus-visible) .titleContainer[data-actions-size=m][data-visible-actions="2"]{
53
+ padding-right:calc(2 * var(--sn-button-anatomy-size-m-container-iconOnly-minWidth, var(--sn-density-size-m, var(--sn-primitive-dimension-56, 56px))));
54
+ }
55
+
56
+ .container{
57
+ display:flex;
58
+ gap:var(--sn-primitive-dimension-4, 4px);
59
+ align-items:flex-start;
60
+ box-sizing:border-box;
61
+ width:100%;
62
+ min-width:0;
63
+ padding:var(--sn-density-spacing-interval-s, var(--sn-primitive-dimension-8, 8px));
64
+ }
65
+
66
+ .icon{
67
+ flex-shrink:0;
68
+ width:var(--sn-density-size-icon-s, var(--sn-primitive-dimension-24, 24px));
69
+ height:var(--sn-density-size-icon-s, var(--sn-primitive-dimension-24, 24px));
70
+ color:var(--sn-theme-color-available-version-textTertiary, var(--sn-brand-color-text-version-tertiary, rgba(65, 66, 78, 0.5490196078)));
71
+ }
72
+
73
+ .textContent{
74
+ display:flex;
75
+ flex:1;
76
+ flex-direction:column;
77
+ align-items:flex-start;
78
+ min-width:0;
79
+ text-align:left;
80
+ }
81
+
82
+ .titleRow{
83
+ display:flex;
84
+ gap:var(--sn-primitive-dimension-4, 4px);
85
+ align-items:center;
86
+ justify-content:space-between;
87
+ width:100%;
88
+ min-height:var(--sn-primitive-dimension-24, 24px);
89
+ }
90
+
91
+ .title{
92
+ overflow:hidden;
93
+ display:block;
94
+ flex-shrink:1;
95
+ min-width:0;
96
+ color:var(--sn-theme-color-available-version-textMain, var(--sn-brand-color-text-version-main, #41424e));
97
+ }
98
+
99
+ .description{
100
+ width:100%;
101
+ color:var(--sn-theme-color-available-version-textTertiary, var(--sn-brand-color-text-version-tertiary, rgba(65, 66, 78, 0.5490196078)));
102
+ }
@@ -1,32 +1,43 @@
1
1
  import { PolymorphicRef } from '@cloud-ru/ds-card';
2
- import { PromoTagProps } from '@cloud-ru/ds-promo-tag';
3
- import { ComponentPropsWithoutRef, ElementType, KeyboardEventHandler, ReactElement } from 'react';
4
- import { FavoriteProps } from '../../types.js';
5
- type BaseCardServiceLightProps = {
2
+ import { TooltipProps } from '@cloud-ru/ds-tooltip';
3
+ import { ComponentPropsWithoutRef, ElementType, ReactElement } from 'react';
4
+ import { CardActionsSurfaceProps } from '../../helperComponents/index.js';
5
+ import { CardPromoTagProps, FavoriteProps, VisibilityStrategy } from '../../types.js';
6
+ type BaseCardServiceLightProps = Pick<CardActionsSurfaceProps, 'actionsSize'> & {
6
7
  /** Иконка сервиса */
7
8
  icon?: ReactElement;
8
9
  /** Заголовок карточки */
9
10
  title: string;
10
11
  /** Настройки promo tag. При отсутствии не отображается */
11
- promoTag?: PromoTagProps;
12
+ promoTag?: CardPromoTagProps;
12
13
  /** Настройки обрезки текста заголовка */
13
14
  truncate?: {
14
15
  /** Максимальное количество строк заголовка */
15
16
  title?: number;
16
17
  };
17
- /** Неактивное состояние */
18
- disabled?: boolean;
18
+ /**
19
+ * Формат отображения дополнительных действий: всегда или при наведении и фокусе
20
+ * @default 'hover'
21
+ */
22
+ actionsVisibility?: VisibilityStrategy;
23
+ /** Подсказка с иконкой «?» рядом с заголовком */
24
+ tooltip?: Omit<TooltipProps, 'trigger' | 'size'>;
19
25
  /**
20
26
  * Настройки кнопки «Избранное».
21
- * Keyboard: ArrowRight на карточке → фокус на Favourite; ArrowLeft на Favourite → фокус на карточку.
27
+ * Keyboard: ArrowRight на карточке → tooltip (если есть) → Favorite; ArrowLeft — в обратном порядке.
22
28
  */
23
29
  favorite?: FavoriteProps;
24
- /** Колбэк нажатия клавиши клавиатуры на карточке */
25
- onKeyDown?: KeyboardEventHandler<HTMLElement>;
30
+ /** Неактивное состояние */
31
+ disabled?: boolean;
26
32
  /** CSS-класс корневого элемента */
27
33
  className?: string;
28
34
  /** Support prop для тестов */
29
35
  'data-test-id'?: string;
36
+ /** Настройки кнопки раскрытия */
37
+ expandable?: {
38
+ value: boolean;
39
+ onClick(): void;
40
+ };
30
41
  };
31
42
  export type CardServiceLightProps<T extends ElementType = 'button'> = BaseCardServiceLightProps & {
32
43
  /** Полиморфный элемент: `'button'`, `'a'`, `{Link}` и т.д. */
@@ -34,5 +45,5 @@ export type CardServiceLightProps<T extends ElementType = 'button'> = BaseCardSe
34
45
  /** Ref на реальный DOM-элемент / инстанс */
35
46
  innerRef?: PolymorphicRef<T>;
36
47
  } & Omit<ComponentPropsWithoutRef<T>, keyof BaseCardServiceLightProps | 'as' | 'ref'>;
37
- export declare function CardServiceLight<T extends ElementType = 'button'>({ icon, title, promoTag, truncate, disabled, favorite, onKeyDown: onKeyDownProp, className, as, innerRef, 'data-test-id': dataTestId, ...rest }: CardServiceLightProps<T>): ReactElement | null;
48
+ export declare function CardServiceLight<T extends ElementType = 'button'>({ as, innerRef, icon, title, promoTag, truncate, actionsVisibility: actionsVisibilityProp, favorite, tooltip, actionsSize, className, disabled, expandable, 'data-test-id': dataTestId, ...rest }: CardServiceLightProps<T>): ReactElement | null;
38
49
  export {};
@@ -1,43 +1,110 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Card } from '@cloud-ru/ds-card';
3
- import { PromoTag } from '@cloud-ru/ds-promo-tag';
4
- import { Favourite } from '@cloud-ru/ds-toggles';
2
+ import { useThemeClassnames } from '@cloud-ru/ds-theme';
5
3
  import { TruncateString } from '@cloud-ru/ds-truncate-string';
6
4
  import { Typography } from '@cloud-ru/ds-typography';
7
- import { useUncontrolledProp, withInnerRefSupport } from '@cloud-ru/ds-utils';
5
+ import { useValueControl, withInnerRefSupport } from '@cloud-ru/ds-utils';
8
6
  import cn from 'classnames';
9
7
  import mergeRefs from 'merge-refs';
10
- import { useCallback, useRef, } from 'react';
11
- import { TEST_IDS, VISIBILITY_STRATEGY } from '../../constants.js';
8
+ import { useRef, useState, } from 'react';
9
+ import { TEST_IDS, TOOLTIP_HOVER_DELAY_OPEN_MS, VISIBILITY_STRATEGY } from '../../constants.js';
10
+ import { CardActionsSurface, CardPromoTag, createCardActionsKeyDownHandler, } from '../../helperComponents/index.js';
12
11
  import styles from './styles.module.css';
13
- export function CardServiceLight({ icon, title, promoTag, truncate, disabled, favorite, onKeyDown: onKeyDownProp, className, as, innerRef, 'data-test-id': dataTestId, ...rest }) {
14
- const [isFavourite, setIsFavourite] = useUncontrolledProp(favorite?.checked, false, favorite?.onChange);
12
+ const TARGET_BLANK = '_blank';
13
+ export function CardServiceLight({ as, innerRef, icon, title, promoTag, truncate, actionsVisibility: actionsVisibilityProp, favorite, tooltip, actionsSize, className, disabled = false, expandable, 'data-test-id': dataTestId, ...rest }) {
14
+ const Component = as ?? 'button';
15
15
  const cardRef = useRef(null);
16
- const favouriteRef = useRef(null);
17
- const handleKeyDown = useCallback(e => {
18
- if (e.target !== cardRef.current) {
19
- onKeyDownProp?.(e);
20
- return;
21
- }
22
- if (e.code === 'ArrowRight' && favorite?.enabled) {
23
- favouriteRef.current?.focus();
24
- }
25
- onKeyDownProp?.(e);
26
- }, [favorite?.enabled, onKeyDownProp]);
27
- const handleFavouriteKeyUp = useCallback(e => {
28
- if (e.code === 'ArrowLeft') {
29
- e.preventDefault();
30
- cardRef.current?.focus();
31
- }
32
- if (e.code === 'Space' || e.code === 'Enter') {
33
- e.preventDefault();
34
- setIsFavourite(!isFavourite);
35
- }
36
- }, [isFavourite, setIsFavourite]);
37
- const handleFavouriteClick = useCallback(e => {
38
- e.stopPropagation();
39
- favouriteRef.current?.blur();
40
- }, []);
41
- return (_jsx(Card, { as: as, innerRef: mergeRefs(innerRef, cardRef), disabled: disabled, interactive: true, className: cn(styles.root, className), "data-test-id": dataTestId ?? TEST_IDS.cardServiceLight, onKeyDown: handleKeyDown, ...rest, children: _jsxs("div", { className: styles.container, children: [icon && _jsx("div", { className: styles.icon, children: icon }), _jsxs("div", { className: styles.content, children: [_jsx(Typography, { as: 'span', variant: 'body', size: 'm', className: styles.title, "data-test-id": TEST_IDS.cardServiceLightTitle, children: _jsx(TruncateString, { text: title, maxLines: truncate?.title, variant: 'end' }) }), promoTag && _jsx(PromoTag, { ...promoTag, "data-test-id": TEST_IDS.cardServiceLightPromoTag })] }), favorite?.enabled && (_jsx("div", { className: styles.favouriteWrapper, "data-visibility-strategy": favorite.visibilityStrategy ?? VISIBILITY_STRATEGY.hover, "data-checked": isFavourite || undefined, children: _jsx(Favourite, { size: 's', checked: isFavourite, inputRef: favouriteRef, onChange: setIsFavourite, tabIndex: -1, onKeyUp: handleFavouriteKeyUp, onClick: handleFavouriteClick, "data-test-id": TEST_IDS.cardServiceLightFavorite, icon: 'star' }) }))] }) }));
16
+ const tooltipTriggerRef = useRef(null);
17
+ const promoTagTooltipTriggerRef = useRef(null);
18
+ const favoriteRef = useRef(null);
19
+ const expandButtonRef = useRef(null);
20
+ const compactThemeClassName = useThemeClassnames({ density: 'compact' });
21
+ const actionsVisibility = actionsVisibilityProp ?? VISIBILITY_STRATEGY.hover;
22
+ const [isFavorite, setIsFavorite] = useValueControl({
23
+ value: favorite?.checked,
24
+ defaultValue: false,
25
+ onChange: favorite?.onChange,
26
+ });
27
+ const [isTooltipOpen, setIsTooltipOpen] = useState(false);
28
+ const tooltipTrigger = actionsVisibility === VISIBILITY_STRATEGY.hover ? 'hoverAndFocusVisible' : 'click';
29
+ const { onKeyDown: onKeyDownProp, ...restWithoutKeyDown } = rest;
30
+ const handleKeyDown = createCardActionsKeyDownHandler({
31
+ disabled,
32
+ cardRef,
33
+ onKeyDown: onKeyDownProp,
34
+ items: [
35
+ promoTag && { ref: promoTagTooltipTriggerRef },
36
+ tooltip && { ref: tooltipTriggerRef },
37
+ favorite?.enabled && {
38
+ ref: favoriteRef,
39
+ onActivate: () => setIsFavorite(!isFavorite),
40
+ },
41
+ expandable && {
42
+ ref: expandButtonRef,
43
+ onActivate: () => expandable.onClick(),
44
+ },
45
+ ],
46
+ });
47
+ let polymorphicProps;
48
+ if (Component === 'a') {
49
+ const { href, target, onClick, ...anchorRest } = restWithoutKeyDown;
50
+ polymorphicProps = {
51
+ ...anchorRest,
52
+ href: href ?? '#',
53
+ target,
54
+ rel: target === TARGET_BLANK ? 'noopener noreferrer' : undefined,
55
+ onClick: disabled
56
+ ? (e) => {
57
+ e.preventDefault();
58
+ onClick?.(e);
59
+ }
60
+ : onClick,
61
+ };
62
+ }
63
+ else if (Component === 'button') {
64
+ const { type = 'button', onClick, ...buttonRest } = restWithoutKeyDown;
65
+ polymorphicProps = {
66
+ type,
67
+ disabled,
68
+ onClick: disabled ? undefined : onClick,
69
+ ...buttonRest,
70
+ };
71
+ }
72
+ else {
73
+ // Кастомный компонент (роутерный Link и т.п.) нативный `disabled` не понимает: гасим переход
74
+ // тем же preventDefault, что и на анкоре — иначе disabled-карточка остаётся кликабельной.
75
+ const { onClick, ...componentRest } = restWithoutKeyDown;
76
+ polymorphicProps = {
77
+ ...componentRest,
78
+ onClick: disabled
79
+ ? (e) => {
80
+ e.preventDefault();
81
+ }
82
+ : onClick,
83
+ };
84
+ }
85
+ return (_jsxs(Component, { ref: mergeRefs(innerRef, cardRef), className: cn(styles.root, className), "data-test-id": dataTestId ?? TEST_IDS.cardServiceLight, "data-disabled": disabled || undefined, "aria-disabled": Component !== 'button' && disabled ? true : undefined, tabIndex: Component !== 'button' && disabled ? -1 : undefined, onKeyDown: handleKeyDown, "data-tooltip-open": isTooltipOpen || undefined, ...polymorphicProps, children: [_jsx("span", { className: styles.outlineBorder, "aria-hidden": true }), _jsxs("div", { className: styles.container, children: [icon && _jsx("div", { className: styles.icon, children: icon }), _jsxs("div", { className: styles.content, children: [_jsx(Typography, { as: 'span', variant: 'body', size: 'm', className: styles.title, "data-test-id": TEST_IDS.cardServiceLightTitle, children: _jsx(TruncateString, { text: title, maxLines: truncate?.title, variant: 'end' }) }), promoTag && (_jsx(CardPromoTag, { promoTag: promoTag, tooltipTrigger: tooltipTrigger, innerRef: promoTagTooltipTriggerRef, "data-test-id": TEST_IDS.cardServiceLightPromoTag, className: cn(styles.promoTag, compactThemeClassName) }))] })] }), _jsx(CardActionsSurface, { actionsSize: actionsSize, actionsVisibility: actionsVisibility, className: styles.cardActions, tooltip: tooltip
86
+ ? {
87
+ ...tooltip,
88
+ 'data-test-id': TEST_IDS.cardServiceLightTooltip,
89
+ buttonRef: tooltipTriggerRef,
90
+ open: isTooltipOpen,
91
+ onOpenChange: setIsTooltipOpen,
92
+ hoverDelayOpen: TOOLTIP_HOVER_DELAY_OPEN_MS,
93
+ }
94
+ : undefined, favorite: favorite?.enabled
95
+ ? {
96
+ enabled: favorite.enabled,
97
+ checked: isFavorite,
98
+ onChange: setIsFavorite,
99
+ buttonRef: favoriteRef,
100
+ 'data-test-id': TEST_IDS.cardServiceLightFavorite,
101
+ }
102
+ : undefined, expandable: expandable
103
+ ? {
104
+ value: expandable.value,
105
+ onClick: expandable.onClick,
106
+ buttonRef: expandButtonRef,
107
+ }
108
+ : undefined })] }));
42
109
  }
43
110
  withInnerRefSupport(CardServiceLight);
@@ -1,39 +1,43 @@
1
- .favouriteWrapper{
1
+ .root{
2
+ cursor:pointer;
2
3
  position:relative;
3
4
  display:flex;
4
- flex-shrink:0;
5
- border-radius:var(--sn-density-radius-2xs, var(--sn-primitive-dimension-4, 4px));
6
- background-color:var(--sn-theme-color-neutral-background1Level, var(--sn-brand-color-neutral-95, var(--sn-primitive-color-gray-95, #fdfdfd)));
7
- box-shadow:var(--sn-boxShadow-elevation-level1, var(--sn-theme-effect-shadow-level1-layer1-positionX, 0) var(--sn-theme-effect-shadow-level1-layer1-positionY, 0) var(--sn-theme-effect-shadow-level1-layer1-blur, 4px) var(--sn-theme-effect-shadow-level1-layer1-speed, 0) var(--sn-theme-effect-shadow-layer1Color, rgba(0, 0, 0, 0.0784313725)), var(--sn-theme-effect-shadow-level1-layer2-positionX, 0) var(--sn-theme-effect-shadow-level1-layer2-positionY, 2px) var(--sn-theme-effect-shadow-level1-layer2-blur, 4px) var(--sn-theme-effect-shadow-level1-layer2-speed, 1px) var(--sn-theme-effect-shadow-layer2Color, rgba(0, 0, 0, 0.0784313725)));
5
+ flex:1 0 0;
6
+ align-items:center;
7
+ width:100%;
8
+ min-width:228px;
9
+ padding:0;
10
+ border:none;
11
+ border-radius:var(--sn-density-radius-3xs, var(--sn-primitive-dimension-2, 2px));
12
+ font:inherit;
13
+ color:inherit;
14
+ text-decoration:none;
15
+ background-color:transparent;
8
16
  }
9
- .favouriteWrapper[data-visibility-strategy=hover]{
10
- position:absolute;
11
- top:50%;
12
- right:var(--sn-primitive-dimension-4, 4px);
13
- transform:translateY(-50%);
14
- visibility:hidden;
17
+ .root[data-disabled]{
18
+ pointer-events:none;
19
+ cursor:default;
20
+ opacity:var(--sn-theme-effect-opacity-disabled, 0.4);
15
21
  }
16
- .favouriteWrapper[data-visibility-strategy=always]{
17
- visibility:visible;
22
+ .root:focus-visible{
23
+ outline:var(--sn-theme-color-primary-accent, var(--sn-brand-color-primary-55, var(--sn-brandRole-color-brandA-55, var(--sn-primitive-color-brandA-55, #389f74)))) solid var(--sn-primitive-strokeWeight-strokeSemiBold, 2px);
24
+ outline-offset:0;
18
25
  }
19
-
20
- .root{
21
- cursor:pointer;
22
- box-sizing:border-box;
23
- text-decoration:none;
26
+ .root:not([data-disabled]):focus-visible{
27
+ background-color:var(--sn-theme-color-material-stateLayer-darkOnAccent-hovered-filled, rgba(0, 0, 0, 0.0588235294));
24
28
  }
25
- .root:hover .favouriteWrapper[data-visibility-strategy=hover], .root:focus-within .favouriteWrapper[data-visibility-strategy=hover]{
29
+ .root:not([data-disabled]):hover .cardActions, .root:not([data-disabled]):focus-visible .cardActions, .root:not([data-disabled])[data-tooltip-open] .cardActions, .root:not([data-disabled]):has(*:focus-visible) .cardActions{
30
+ position:relative;
31
+ transform:translateX(0);
26
32
  visibility:visible;
27
33
  }
28
- .root:hover .favouriteWrapper[data-visibility-strategy=hover][data-checked], .root:focus-within .favouriteWrapper[data-visibility-strategy=hover][data-checked]{
29
- position:relative;
30
- top:auto;
31
- right:auto;
32
- transform:none;
34
+ @media (hover: hover){
35
+ .root:not([data-disabled]):hover{
36
+ background-color:var(--sn-theme-color-material-stateLayer-darkOnAccent-hovered-filled, rgba(0, 0, 0, 0.0588235294));
37
+ }
33
38
  }
34
39
 
35
40
  .container{
36
- position:relative;
37
41
  display:flex;
38
42
  gap:var(--sn-primitive-dimension-8, 8px);
39
43
  align-items:center;
@@ -41,6 +45,7 @@
41
45
  width:100%;
42
46
  min-width:0;
43
47
  padding:var(--sn-primitive-dimension-4, 4px);
48
+ border-radius:inherit;
44
49
  }
45
50
 
46
51
  .icon{
@@ -1,7 +1,7 @@
1
1
  import { PolymorphicRef } from '@cloud-ru/ds-card';
2
2
  import { PromoTagProps } from '@cloud-ru/ds-promo-tag';
3
3
  import { ComponentPropsWithoutRef, ElementType, JSXElementConstructor, ReactElement } from 'react';
4
- import { FavoriteProps } from '../../types.js';
4
+ import { FavoriteProps, VisibilityStrategy } from '../../types.js';
5
5
  type BaseCardServiceSmallProps = {
6
6
  /** Заголовок карточки */
7
7
  title: string;
@@ -30,12 +30,13 @@ type BaseCardServiceSmallProps = {
30
30
  * Промо-тег (бейдж). Тип — `PromoTagProps` из `@cloud-ru/ds-promo-tag`.
31
31
  */
32
32
  promoBadge?: PromoTagProps;
33
+ /** Настройки кнопки «Избранное» */
34
+ favorite?: FavoriteProps;
33
35
  /**
34
- * Настройки кнопки «Избранное». `visibilityStrategy` обязателен.
36
+ * Формат отображения кнопки «Избранное»: всегда или при наведении и фокусе
37
+ * @default 'hover'
35
38
  */
36
- favorite?: FavoriteProps & {
37
- visibilityStrategy: 'always' | 'hover';
38
- };
39
+ actionsVisibility?: VisibilityStrategy;
39
40
  /** CSS-класс корневого элемента */
40
41
  className?: string;
41
42
  /** Support prop для тестов */
@@ -47,5 +48,5 @@ export type CardServiceSmallProps<T extends ElementType = 'div'> = BaseCardServi
47
48
  /** Ref на реальный DOM-элемент / инстанс */
48
49
  innerRef?: PolymorphicRef<T>;
49
50
  } & Omit<ComponentPropsWithoutRef<T>, keyof BaseCardServiceSmallProps | 'as' | 'ref'>;
50
- export declare function CardServiceSmall<T extends ElementType = 'div'>({ title, emblem, truncate, checked, disabled, outline, promoBadge, favorite, className, as, innerRef, 'data-test-id': dataTestId, ...rest }: CardServiceSmallProps<T>): ReactElement | null;
51
+ export declare function CardServiceSmall<T extends ElementType = 'div'>({ title, emblem, truncate, checked, disabled, outline, promoBadge, favorite, actionsVisibility, className, as, innerRef, 'data-test-id': dataTestId, ...rest }: CardServiceSmallProps<T>): ReactElement | null;
51
52
  export {};
@@ -4,7 +4,7 @@ import { PromoTag } from '@cloud-ru/ds-promo-tag';
4
4
  import { Favourite } from '@cloud-ru/ds-toggles';
5
5
  import { TruncateString } from '@cloud-ru/ds-truncate-string';
6
6
  import { Typography } from '@cloud-ru/ds-typography';
7
- import { useUncontrolledProp, withInnerRefSupport } from '@cloud-ru/ds-utils';
7
+ import { useValueControl, withInnerRefSupport } from '@cloud-ru/ds-utils';
8
8
  import cn from 'classnames';
9
9
  import mergeRefs from 'merge-refs';
10
10
  import { useCallback, useRef, } from 'react';
@@ -13,8 +13,12 @@ import styles from './styles.module.css';
13
13
  function isIconEmblem(emblem) {
14
14
  return 'icon' in emblem;
15
15
  }
16
- export function CardServiceSmall({ title, emblem, truncate, checked, disabled, outline, promoBadge, favorite, className, as, innerRef, 'data-test-id': dataTestId, ...rest }) {
17
- const [isFavourite, setIsFavourite] = useUncontrolledProp(favorite?.checked, false, favorite?.onChange);
16
+ export function CardServiceSmall({ title, emblem, truncate, checked, disabled, outline, promoBadge, favorite, actionsVisibility, className, as, innerRef, 'data-test-id': dataTestId, ...rest }) {
17
+ const [isFavourite, setIsFavourite] = useValueControl({
18
+ value: favorite?.checked,
19
+ defaultValue: false,
20
+ onChange: favorite?.onChange,
21
+ });
18
22
  const cardRef = useRef(null);
19
23
  const favouriteRef = useRef(null);
20
24
  const handleCardKeyDown = useCallback(e => {
@@ -37,6 +41,6 @@ export function CardServiceSmall({ title, emblem, truncate, checked, disabled, o
37
41
  favouriteRef.current?.blur();
38
42
  }, []);
39
43
  const IconComponent = isIconEmblem(emblem) ? emblem.icon : null;
40
- return (_jsxs("div", { className: cn(styles.wrapper, className), children: [_jsx(Card, { as: as, innerRef: mergeRefs(innerRef, cardRef), disabled: disabled, interactive: true, checked: checked, view: outline ? 'outline' : undefined, className: styles.card, "data-test-id": dataTestId ?? TEST_IDS.cardServiceSmall, onKeyDown: handleCardKeyDown, ...rest, children: _jsxs("div", { className: styles.contentWrapper, children: [IconComponent ? (_jsx(IconComponent, { className: styles.icon, size: 24 })) : (!isIconEmblem(emblem) && _jsx("div", { className: styles.icon, children: emblem })), _jsx("div", { className: styles.contentLayout, children: _jsx(Typography, { as: 'span', variant: 'title', size: 's', className: styles.title, "data-test-id": TEST_IDS.cardServiceSmallTitle, children: _jsx(TruncateString, { text: title, maxLines: truncate?.title, variant: 'end' }) }) }), favorite?.enabled && (_jsx("div", { className: styles.favouriteWrapper, "data-visibility-strategy": favorite.visibilityStrategy ?? VISIBILITY_STRATEGY.hover, children: _jsx(Favourite, { size: 's', checked: isFavourite, inputRef: favouriteRef, onChange: setIsFavourite, tabIndex: -1, onKeyUp: handleFavouriteKeyUp, onClick: handleFavouriteClick, "data-test-id": TEST_IDS.cardServiceSmallFavorite, icon: 'star' }) }))] }) }), promoBadge && (_jsx("div", { className: styles.promoTagWrapper, children: _jsx(PromoTag, { ...promoBadge, "data-test-id": TEST_IDS.cardServiceSmallPromoBadge }) }))] }));
44
+ return (_jsxs("div", { className: cn(styles.wrapper, className), children: [_jsx(Card, { as: as, innerRef: mergeRefs(innerRef, cardRef), disabled: disabled, interactive: true, checked: checked, view: outline ? 'outline' : undefined, className: styles.card, "data-test-id": dataTestId ?? TEST_IDS.cardServiceSmall, onKeyDown: handleCardKeyDown, ...rest, children: _jsxs("div", { className: styles.contentWrapper, children: [IconComponent ? (_jsx(IconComponent, { className: styles.icon, size: 24 })) : (!isIconEmblem(emblem) && _jsx("div", { className: styles.icon, children: emblem })), _jsx("div", { className: styles.contentLayout, children: _jsx(Typography, { as: 'span', variant: 'title', size: 's', className: styles.title, "data-test-id": TEST_IDS.cardServiceSmallTitle, children: _jsx(TruncateString, { text: title, maxLines: truncate?.title, variant: 'end' }) }) }), favorite?.enabled && (_jsx("div", { className: styles.favouriteWrapper, "data-actions-visibility": actionsVisibility ?? VISIBILITY_STRATEGY.hover, children: _jsx(Favourite, { size: 's', checked: isFavourite, inputRef: favouriteRef, onChange: setIsFavourite, tabIndex: -1, onKeyUp: handleFavouriteKeyUp, onClick: handleFavouriteClick, "data-test-id": TEST_IDS.cardServiceSmallFavorite, icon: 'star' }) }))] }) }), promoBadge && (_jsx("div", { className: styles.promoTagWrapper, children: _jsx(PromoTag, { ...promoBadge, "data-test-id": TEST_IDS.cardServiceSmallPromoBadge }) }))] }));
41
45
  }
42
46
  withInnerRefSupport(CardServiceSmall);
@@ -8,17 +8,17 @@
8
8
  .favouriteWrapper{
9
9
  flex-shrink:0;
10
10
  }
11
- .favouriteWrapper[data-visibility-strategy=hover]{
11
+ .favouriteWrapper[data-actions-visibility=hover]{
12
12
  display:none;
13
13
  }
14
- .favouriteWrapper[data-visibility-strategy=always]{
14
+ .favouriteWrapper[data-actions-visibility=always]{
15
15
  display:flex;
16
16
  }
17
17
 
18
18
  .wrapper{
19
19
  position:relative;
20
20
  }
21
- .wrapper:hover .favouriteWrapper[data-visibility-strategy=hover], .wrapper:focus-within .favouriteWrapper[data-visibility-strategy=hover]{
21
+ .wrapper:hover .favouriteWrapper[data-actions-visibility=hover], .wrapper:focus-within .favouriteWrapper[data-actions-visibility=hover]{
22
22
  display:flex;
23
23
  }
24
24
 
@@ -1,6 +1,7 @@
1
1
  export * from './CardBanner/index.js';
2
2
  export * from './CardService/index.js';
3
3
  export * from './CardServiceLight/index.js';
4
+ export * from './CardServiceInfo/index.js';
4
5
  export * from './CardServiceSmall/index.js';
5
6
  export * from './CardSuggest/index.js';
6
7
  export * from './CardCustom/index.js';
@@ -1,6 +1,7 @@
1
1
  export * from './CardBanner/index.js';
2
2
  export * from './CardService/index.js';
3
3
  export * from './CardServiceLight/index.js';
4
+ export * from './CardServiceInfo/index.js';
4
5
  export * from './CardServiceSmall/index.js';
5
6
  export * from './CardSuggest/index.js';
6
7
  export * from './CardCustom/index.js';
@@ -12,7 +12,15 @@ export declare const TEST_IDS: {
12
12
  readonly cardServiceLight: "card-service-light";
13
13
  readonly cardServiceLightTitle: "card-service-light__title";
14
14
  readonly cardServiceLightPromoTag: "card-service-light__promo-tag";
15
+ readonly cardServiceLightPromoTagTooltip: "card-service-light__promo-tag__tooltip";
15
16
  readonly cardServiceLightFavorite: "card-service-light__favorite";
17
+ readonly cardServiceLightTooltip: "card-service-light__tooltip";
18
+ readonly cardServiceInfo: "card-service-info";
19
+ readonly cardServiceInfoTitle: "card-service-info__title";
20
+ readonly cardServiceInfoDescription: "card-service-info__description";
21
+ readonly cardServiceInfoPromoTag: "card-service-info__promo-tag";
22
+ readonly cardServiceInfoPromoTagTooltip: "card-service-info__promo-tag__tooltip";
23
+ readonly cardServiceInfoFavorite: "card-service-info__favorite";
16
24
  readonly cardSuggest: "card-suggest";
17
25
  readonly cardSuggestContent: "card-suggest__content";
18
26
  readonly cardSuggestPromoBadge: "card-suggest__promo-badge";
@@ -29,3 +37,4 @@ export declare const CARD_SIZE: {
29
37
  readonly S: "s";
30
38
  readonly M: "m";
31
39
  };
40
+ export declare const TOOLTIP_HOVER_DELAY_OPEN_MS = 300;
@@ -12,7 +12,15 @@ export const TEST_IDS = {
12
12
  cardServiceLight: 'card-service-light',
13
13
  cardServiceLightTitle: 'card-service-light__title',
14
14
  cardServiceLightPromoTag: 'card-service-light__promo-tag',
15
+ cardServiceLightPromoTagTooltip: 'card-service-light__promo-tag__tooltip',
15
16
  cardServiceLightFavorite: 'card-service-light__favorite',
17
+ cardServiceLightTooltip: 'card-service-light__tooltip',
18
+ cardServiceInfo: 'card-service-info',
19
+ cardServiceInfoTitle: 'card-service-info__title',
20
+ cardServiceInfoDescription: 'card-service-info__description',
21
+ cardServiceInfoPromoTag: 'card-service-info__promo-tag',
22
+ cardServiceInfoPromoTagTooltip: 'card-service-info__promo-tag__tooltip',
23
+ cardServiceInfoFavorite: 'card-service-info__favorite',
16
24
  cardSuggest: 'card-suggest',
17
25
  cardSuggestContent: 'card-suggest__content',
18
26
  cardSuggestPromoBadge: 'card-suggest__promo-badge',
@@ -29,3 +37,4 @@ export const CARD_SIZE = {
29
37
  S: 's',
30
38
  M: 'm',
31
39
  };
40
+ export const TOOLTIP_HOVER_DELAY_OPEN_MS = 300;
@@ -0,0 +1,31 @@
1
+ import { TooltipProps } from '@cloud-ru/ds-tooltip';
2
+ import { ReactElement, RefObject } from 'react';
3
+ import { CardSize, FavoriteProps, VisibilityStrategy } from '../../types.js';
4
+ export type CardActionsSurfaceProps = {
5
+ /**
6
+ * Формат отображения действий: всегда или при наведении и фокусе
7
+ * @default 'hover'
8
+ */
9
+ actionsVisibility?: 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?: CardSize;
28
+ /** CSS-класс корневого элемента */
29
+ className?: string;
30
+ };
31
+ export declare function CardActionsSurface({ actionsVisibility, tooltip, favorite, expandable, actionsSize, className, }: CardActionsSurfaceProps): ReactElement | null;
@@ -0,0 +1,30 @@
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 { cardPredefinedLocale } from '../../locale/index.js';
10
+ import styles from './styles.module.css';
11
+ export function CardActionsSurface({ actionsVisibility = VISIBILITY_STRATEGY.hover, tooltip, favorite, expandable, actionsSize = 'm', className, }) {
12
+ const { t } = cardPredefinedLocale.useTranslations();
13
+ if (!tooltip && !favorite && !expandable) {
14
+ return null;
15
+ }
16
+ const tooltipTrigger = tooltip?.trigger ??
17
+ (actionsVisibility === VISIBILITY_STRATEGY.always ? TRIGGER.Click : TRIGGER.HoverAndFocusVisible);
18
+ const handleExpandButtonClick = (e) => {
19
+ preventEventDefaultAndPropagation(e);
20
+ expandable?.onClick();
21
+ };
22
+ const handleFavoriteClick = (e) => {
23
+ preventEventDefaultAndPropagation(e);
24
+ favorite?.onChange?.(!favorite.checked);
25
+ };
26
+ const { buttonRef: tooltipButtonRef, 'data-test-id': tooltipTestId, ...tooltipProps } = tooltip ?? {};
27
+ return (
28
+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions
29
+ _jsxs("div", { onClick: preventEventDefaultAndPropagation, className: cn(styles.root, className), "data-actions-visibility": actionsVisibility, children: [tooltip && (_jsx(Tooltip, { ...tooltipProps, tip: tooltip.tip, trigger: tooltipTrigger, triggerClassName: styles.tooltipTrigger, children: _jsx(Button, { as: 'span', role: 'button', "aria-label": t('actions.info'), 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', role: 'button', "aria-label": favorite.checked ? t('actions.favoriteRemove') : t('actions.favoriteAdd'), "aria-pressed": Boolean(favorite.checked), 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', role: 'button', "aria-label": expandable.value ? t('actions.collapse') : t('actions.expand'), "aria-expanded": expandable.value, size: actionsSize, appearance: 'neutral', view: 'simple', icon: expandable.value ? _jsx(CollapseVerticalSVG, {}) : _jsx(ExpandVerticalSVG, {}), onClick: handleExpandButtonClick, className: styles.expandButton, innerRef: expandable.buttonRef, tabIndex: -1 }))] }));
30
+ }
@@ -0,0 +1,2 @@
1
+ export * from './CardActionsSurface.js';
2
+ export * from './utils.js';
@@ -0,0 +1,2 @@
1
+ export * from './CardActionsSurface.js';
2
+ export * from './utils.js';