@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
@@ -1,50 +1,69 @@
1
- import { Card, PolymorphicRef } from '@cloud-ru/ds-card';
2
- import { PromoTag, PromoTagProps } from '@cloud-ru/ds-promo-tag';
3
- import { Favourite } from '@cloud-ru/ds-toggles';
1
+ import { PolymorphicRef } from '@cloud-ru/ds-card';
2
+ import { useThemeClassnames } from '@cloud-ru/ds-theme';
3
+ import { TooltipProps } from '@cloud-ru/ds-tooltip';
4
4
  import { TruncateString } from '@cloud-ru/ds-truncate-string';
5
5
  import { Typography } from '@cloud-ru/ds-typography';
6
- import { useUncontrolledProp, withInnerRefSupport } from '@cloud-ru/ds-utils';
6
+ import { useValueControl, withInnerRefSupport } from '@cloud-ru/ds-utils';
7
7
  import cn from 'classnames';
8
8
  import mergeRefs from 'merge-refs';
9
9
  import {
10
10
  ComponentPropsWithoutRef,
11
11
  ElementType,
12
12
  KeyboardEventHandler,
13
+ MouseEvent,
13
14
  MouseEventHandler,
14
15
  ReactElement,
15
- useCallback,
16
16
  useRef,
17
+ useState,
17
18
  } from 'react';
18
19
 
19
- import { TEST_IDS, VISIBILITY_STRATEGY } from '../../constants';
20
- import { FavoriteProps } from '../../types';
20
+ import { TEST_IDS, TOOLTIP_HOVER_DELAY_OPEN_MS, VISIBILITY_STRATEGY } from '../../constants';
21
+ import {
22
+ CardActionsSurface,
23
+ CardActionsSurfaceProps,
24
+ CardPromoTag,
25
+ createCardActionsKeyDownHandler,
26
+ } from '../../helperComponents';
27
+ import { CardPromoTagProps, FavoriteProps, VisibilityStrategy } from '../../types';
21
28
  import styles from './styles.module.scss';
22
29
 
23
- type BaseCardServiceLightProps = {
30
+ const TARGET_BLANK = '_blank';
31
+
32
+ type BaseCardServiceLightProps = Pick<CardActionsSurfaceProps, 'actionsSize'> & {
24
33
  /** Иконка сервиса */
25
34
  icon?: ReactElement;
26
35
  /** Заголовок карточки */
27
36
  title: string;
28
37
  /** Настройки promo tag. При отсутствии не отображается */
29
- promoTag?: PromoTagProps;
38
+ promoTag?: CardPromoTagProps;
30
39
  /** Настройки обрезки текста заголовка */
31
40
  truncate?: {
32
41
  /** Максимальное количество строк заголовка */
33
42
  title?: number;
34
43
  };
35
- /** Неактивное состояние */
36
- disabled?: boolean;
44
+ /**
45
+ * Формат отображения дополнительных действий: всегда или при наведении и фокусе
46
+ * @default 'hover'
47
+ */
48
+ actionsVisibility?: VisibilityStrategy;
49
+ /** Подсказка с иконкой «?» рядом с заголовком */
50
+ tooltip?: Omit<TooltipProps, 'trigger' | 'size'>;
37
51
  /**
38
52
  * Настройки кнопки «Избранное».
39
- * Keyboard: ArrowRight на карточке → фокус на Favourite; ArrowLeft на Favourite → фокус на карточку.
53
+ * Keyboard: ArrowRight на карточке → tooltip (если есть) → Favorite; ArrowLeft — в обратном порядке.
40
54
  */
41
55
  favorite?: FavoriteProps;
42
- /** Колбэк нажатия клавиши клавиатуры на карточке */
43
- onKeyDown?: KeyboardEventHandler<HTMLElement>;
56
+ /** Неактивное состояние */
57
+ disabled?: boolean;
44
58
  /** CSS-класс корневого элемента */
45
59
  className?: string;
46
60
  /** Support prop для тестов */
47
61
  'data-test-id'?: string;
62
+ /** Настройки кнопки раскрытия */
63
+ expandable?: {
64
+ value: boolean;
65
+ onClick(): void;
66
+ };
48
67
  };
49
68
 
50
69
  export type CardServiceLightProps<T extends ElementType = 'button'> = BaseCardServiceLightProps & {
@@ -55,67 +74,114 @@ export type CardServiceLightProps<T extends ElementType = 'button'> = BaseCardSe
55
74
  } & Omit<ComponentPropsWithoutRef<T>, keyof BaseCardServiceLightProps | 'as' | 'ref'>;
56
75
 
57
76
  export function CardServiceLight<T extends ElementType = 'button'>({
77
+ as,
78
+ innerRef,
58
79
  icon,
59
80
  title,
60
81
  promoTag,
61
82
  truncate,
62
- disabled,
83
+ actionsVisibility: actionsVisibilityProp,
63
84
  favorite,
64
- onKeyDown: onKeyDownProp,
85
+ tooltip,
86
+ actionsSize,
65
87
  className,
66
- as,
67
- innerRef,
88
+ disabled = false,
89
+ expandable,
68
90
  'data-test-id': dataTestId,
69
91
  ...rest
70
92
  }: CardServiceLightProps<T>): ReactElement | null {
71
- const [isFavourite, setIsFavourite] = useUncontrolledProp(favorite?.checked, false, favorite?.onChange);
93
+ const Component: ElementType = as ?? 'button';
72
94
  const cardRef = useRef<HTMLElement>(null);
73
- const favouriteRef = useRef<HTMLInputElement>(null);
74
-
75
- const handleKeyDown: KeyboardEventHandler<HTMLElement> = useCallback(
76
- e => {
77
- if (e.target !== cardRef.current) {
78
- onKeyDownProp?.(e);
79
- return;
80
- }
81
- if (e.code === 'ArrowRight' && favorite?.enabled) {
82
- favouriteRef.current?.focus();
83
- }
84
- onKeyDownProp?.(e);
85
- },
86
- [favorite?.enabled, onKeyDownProp],
87
- );
95
+ const tooltipTriggerRef = useRef<HTMLButtonElement>(null);
96
+ const promoTagTooltipTriggerRef = useRef<HTMLElement>(null);
97
+ const favoriteRef = useRef<HTMLButtonElement>(null);
98
+ const expandButtonRef = useRef<HTMLButtonElement>(null);
88
99
 
89
- const handleFavouriteKeyUp: KeyboardEventHandler<HTMLSpanElement> = useCallback(
90
- e => {
91
- if (e.code === 'ArrowLeft') {
92
- e.preventDefault();
93
- cardRef.current?.focus();
94
- }
95
- if (e.code === 'Space' || e.code === 'Enter') {
96
- e.preventDefault();
97
- setIsFavourite(!isFavourite);
98
- }
99
- },
100
- [isFavourite, setIsFavourite],
101
- );
100
+ const compactThemeClassName = useThemeClassnames({ density: 'compact' });
101
+
102
+ const actionsVisibility = actionsVisibilityProp ?? VISIBILITY_STRATEGY.hover;
103
+
104
+ const [isFavorite, setIsFavorite] = useValueControl<boolean>({
105
+ value: favorite?.checked,
106
+ defaultValue: false,
107
+ onChange: favorite?.onChange,
108
+ });
109
+ const [isTooltipOpen, setIsTooltipOpen] = useState<boolean>(false);
110
+
111
+ const tooltipTrigger = actionsVisibility === VISIBILITY_STRATEGY.hover ? 'hoverAndFocusVisible' : 'click';
112
+
113
+ const { onKeyDown: onKeyDownProp, ...restWithoutKeyDown } = rest as ComponentPropsWithoutRef<T> & {
114
+ onKeyDown?: KeyboardEventHandler<HTMLElement>;
115
+ };
102
116
 
103
- const handleFavouriteClick: MouseEventHandler<HTMLSpanElement> = useCallback(e => {
104
- e.stopPropagation();
105
- favouriteRef.current?.blur();
106
- }, []);
117
+ const handleKeyDown = createCardActionsKeyDownHandler({
118
+ disabled,
119
+ cardRef,
120
+ onKeyDown: onKeyDownProp,
121
+ items: [
122
+ promoTag && { ref: promoTagTooltipTriggerRef },
123
+ tooltip && { ref: tooltipTriggerRef },
124
+ favorite?.enabled && {
125
+ ref: favoriteRef,
126
+ onActivate: () => setIsFavorite(!isFavorite),
127
+ },
128
+ expandable && {
129
+ ref: expandButtonRef,
130
+ onActivate: () => expandable.onClick(),
131
+ },
132
+ ],
133
+ });
134
+
135
+ let polymorphicProps: Record<string, unknown>;
136
+ if (Component === 'a') {
137
+ const { href, target, onClick, ...anchorRest } = restWithoutKeyDown as ComponentPropsWithoutRef<'a'>;
138
+ polymorphicProps = {
139
+ ...anchorRest,
140
+ href: href ?? '#',
141
+ target,
142
+ rel: target === TARGET_BLANK ? 'noopener noreferrer' : undefined,
143
+ onClick: disabled
144
+ ? (e: MouseEvent<HTMLAnchorElement>) => {
145
+ e.preventDefault();
146
+ onClick?.(e);
147
+ }
148
+ : onClick,
149
+ };
150
+ } else if (Component === 'button') {
151
+ const { type = 'button', onClick, ...buttonRest } = restWithoutKeyDown as ComponentPropsWithoutRef<'button'>;
152
+ polymorphicProps = {
153
+ type,
154
+ disabled,
155
+ onClick: disabled ? undefined : onClick,
156
+ ...buttonRest,
157
+ };
158
+ } else {
159
+ // Кастомный компонент (роутерный Link и т.п.) нативный `disabled` не понимает: гасим переход
160
+ // тем же preventDefault, что и на анкоре — иначе disabled-карточка остаётся кликабельной.
161
+ const { onClick, ...componentRest } = restWithoutKeyDown as { onClick?: MouseEventHandler<HTMLElement> };
162
+ polymorphicProps = {
163
+ ...componentRest,
164
+ onClick: disabled
165
+ ? (e: MouseEvent<HTMLElement>) => {
166
+ e.preventDefault();
167
+ }
168
+ : onClick,
169
+ };
170
+ }
107
171
 
108
172
  return (
109
- <Card<T>
110
- as={as}
111
- innerRef={mergeRefs(innerRef, cardRef)}
112
- disabled={disabled}
113
- interactive
173
+ <Component
174
+ ref={mergeRefs(innerRef, cardRef)}
114
175
  className={cn(styles.root, className)}
115
176
  data-test-id={dataTestId ?? TEST_IDS.cardServiceLight}
116
- onKeyDown={handleKeyDown as KeyboardEventHandler<Element>}
117
- {...(rest as ComponentPropsWithoutRef<T>)}
177
+ data-disabled={disabled || undefined}
178
+ aria-disabled={Component !== 'button' && disabled ? true : undefined}
179
+ tabIndex={Component !== 'button' && disabled ? -1 : undefined}
180
+ onKeyDown={handleKeyDown}
181
+ data-tooltip-open={isTooltipOpen || undefined}
182
+ {...polymorphicProps}
118
183
  >
184
+ <span className={styles.outlineBorder} aria-hidden />
119
185
  <div className={styles.container}>
120
186
  {icon && <div className={styles.icon}>{icon}</div>}
121
187
 
@@ -130,30 +196,56 @@ export function CardServiceLight<T extends ElementType = 'button'>({
130
196
  <TruncateString text={title} maxLines={truncate?.title} variant='end' />
131
197
  </Typography>
132
198
 
133
- {promoTag && <PromoTag {...promoTag} data-test-id={TEST_IDS.cardServiceLightPromoTag} />}
134
- </div>
135
-
136
- {favorite?.enabled && (
137
- <div
138
- className={styles.favouriteWrapper}
139
- data-visibility-strategy={favorite.visibilityStrategy ?? VISIBILITY_STRATEGY.hover}
140
- data-checked={isFavourite || undefined}
141
- >
142
- <Favourite
143
- size='s'
144
- checked={isFavourite}
145
- inputRef={favouriteRef}
146
- onChange={setIsFavourite}
147
- tabIndex={-1}
148
- onKeyUp={handleFavouriteKeyUp}
149
- onClick={handleFavouriteClick}
150
- data-test-id={TEST_IDS.cardServiceLightFavorite}
151
- icon='star'
199
+ {promoTag && (
200
+ <CardPromoTag
201
+ promoTag={promoTag}
202
+ tooltipTrigger={tooltipTrigger}
203
+ innerRef={promoTagTooltipTriggerRef}
204
+ data-test-id={TEST_IDS.cardServiceLightPromoTag}
205
+ className={cn(styles.promoTag, compactThemeClassName)}
152
206
  />
153
- </div>
154
- )}
207
+ )}
208
+ </div>
155
209
  </div>
156
- </Card>
210
+
211
+ <CardActionsSurface
212
+ actionsSize={actionsSize}
213
+ actionsVisibility={actionsVisibility}
214
+ className={styles.cardActions}
215
+ tooltip={
216
+ tooltip
217
+ ? {
218
+ ...tooltip,
219
+ 'data-test-id': TEST_IDS.cardServiceLightTooltip,
220
+ buttonRef: tooltipTriggerRef,
221
+ open: isTooltipOpen,
222
+ onOpenChange: setIsTooltipOpen,
223
+ hoverDelayOpen: TOOLTIP_HOVER_DELAY_OPEN_MS,
224
+ }
225
+ : undefined
226
+ }
227
+ favorite={
228
+ favorite?.enabled
229
+ ? {
230
+ enabled: favorite.enabled,
231
+ checked: isFavorite,
232
+ onChange: setIsFavorite,
233
+ buttonRef: favoriteRef,
234
+ 'data-test-id': TEST_IDS.cardServiceLightFavorite,
235
+ }
236
+ : undefined
237
+ }
238
+ expandable={
239
+ expandable
240
+ ? {
241
+ value: expandable.value,
242
+ onClick: expandable.onClick,
243
+ buttonRef: expandButtonRef,
244
+ }
245
+ : undefined
246
+ }
247
+ />
248
+ </Component>
157
249
  );
158
250
  }
159
251
 
@@ -1,57 +1,60 @@
1
1
  @use '@cloud-ru/ds-figma-variables/build/scss/styles/styles.module' as base;
2
2
 
3
- .favouriteWrapper {
3
+ .root {
4
+ cursor: pointer;
5
+
4
6
  position: relative;
5
7
 
6
8
  display: flex;
7
- flex-shrink: 0;
9
+ flex: 1 0 0;
10
+ align-items: center;
8
11
 
9
- border-radius: base.$sn-density-radius-2xs;
12
+ width: 100%;
13
+ min-width: 228px;
14
+ padding: 0;
15
+ border: none;
16
+ border-radius: base.$sn-density-radius-3xs;
10
17
 
11
- background-color: base.$sn-theme-color-neutral-background1Level;
12
- box-shadow: base.$sn-boxShadow-elevation-level1;
18
+ font: inherit;
19
+ color: inherit;
20
+ text-decoration: none;
13
21
 
14
- // Стратегия `hover`: кнопка вынута из потока (position: absolute) и скрыта.
15
- // Так текст заголовка занимает всю ширину и не сжимается под зарезервированное
16
- // место кнопки. При наведении/фокусе кнопка проявляется поверх контента, а в
17
- // checked-состоянии возвращается в поток (см. `.root:hover`), раздвигая контент.
18
- &[data-visibility-strategy='hover'] {
19
- position: absolute;
20
- top: 50%;
21
- right: base.$sn-primitive-dimension-4;
22
- transform: translateY(-50%);
22
+ background-color: transparent;
23
23
 
24
- visibility: hidden;
24
+ &[data-disabled] {
25
+ pointer-events: none;
26
+ cursor: default;
27
+ opacity: base.$sn-theme-effect-opacity-disabled;
25
28
  }
26
29
 
27
- &[data-visibility-strategy='always'] {
28
- visibility: visible;
30
+ &:focus-visible {
31
+ outline: base.$sn-theme-color-primary-accent solid base.$sn-primitive-strokeWeight-strokeSemiBold;
32
+ outline-offset: 0;
29
33
  }
30
- }
31
34
 
32
- .root {
33
- cursor: pointer;
34
- box-sizing: border-box;
35
- text-decoration: none;
35
+ &:not([data-disabled]):focus-visible {
36
+ background-color: base.$sn-theme-color-material-stateLayer-darkOnAccent-hovered-filled;
37
+ }
36
38
 
37
- &:hover,
38
- &:focus-within {
39
- .favouriteWrapper[data-visibility-strategy='hover'] {
39
+ &:not([data-disabled]):hover,
40
+ &:not([data-disabled]):focus-visible,
41
+ &:not([data-disabled])[data-tooltip-open],
42
+ &:not([data-disabled]):has(*:focus-visible) {
43
+ .cardActions {
44
+ position: relative;
45
+ transform: translateX(0);
40
46
  visibility: visible;
47
+ }
48
+ }
41
49
 
42
- &[data-checked] {
43
- position: relative;
44
- top: auto;
45
- right: auto;
46
- transform: none;
47
- }
50
+ @media (hover: hover) {
51
+ &:not([data-disabled]):hover {
52
+ background-color: base.$sn-theme-color-material-stateLayer-darkOnAccent-hovered-filled;
48
53
  }
49
54
  }
50
55
  }
51
56
 
52
57
  .container {
53
- position: relative;
54
-
55
58
  display: flex;
56
59
  gap: base.$sn-primitive-dimension-8;
57
60
  align-items: center;
@@ -60,6 +63,7 @@
60
63
  width: 100%;
61
64
  min-width: 0;
62
65
  padding: base.$sn-primitive-dimension-4;
66
+ border-radius: inherit;
63
67
  }
64
68
 
65
69
  .icon {
@@ -3,7 +3,7 @@ import { PromoTag, PromoTagProps } from '@cloud-ru/ds-promo-tag';
3
3
  import { Favourite } from '@cloud-ru/ds-toggles';
4
4
  import { TruncateString } from '@cloud-ru/ds-truncate-string';
5
5
  import { Typography } from '@cloud-ru/ds-typography';
6
- import { useUncontrolledProp, withInnerRefSupport } from '@cloud-ru/ds-utils';
6
+ import { useValueControl, withInnerRefSupport } from '@cloud-ru/ds-utils';
7
7
  import cn from 'classnames';
8
8
  import mergeRefs from 'merge-refs';
9
9
  import {
@@ -18,7 +18,7 @@ import {
18
18
  } from 'react';
19
19
 
20
20
  import { TEST_IDS, VISIBILITY_STRATEGY } from '../../constants';
21
- import { FavoriteProps } from '../../types';
21
+ import { FavoriteProps, VisibilityStrategy } from '../../types';
22
22
  import styles from './styles.module.scss';
23
23
 
24
24
  type BaseCardServiceSmallProps = {
@@ -44,10 +44,13 @@ type BaseCardServiceSmallProps = {
44
44
  * Промо-тег (бейдж). Тип — `PromoTagProps` из `@cloud-ru/ds-promo-tag`.
45
45
  */
46
46
  promoBadge?: PromoTagProps;
47
+ /** Настройки кнопки «Избранное» */
48
+ favorite?: FavoriteProps;
47
49
  /**
48
- * Настройки кнопки «Избранное». `visibilityStrategy` обязателен.
50
+ * Формат отображения кнопки «Избранное»: всегда или при наведении и фокусе
51
+ * @default 'hover'
49
52
  */
50
- favorite?: FavoriteProps & { visibilityStrategy: 'always' | 'hover' };
53
+ actionsVisibility?: VisibilityStrategy;
51
54
  /** CSS-класс корневого элемента */
52
55
  className?: string;
53
56
  /** Support prop для тестов */
@@ -76,13 +79,18 @@ export function CardServiceSmall<T extends ElementType = 'div'>({
76
79
  outline,
77
80
  promoBadge,
78
81
  favorite,
82
+ actionsVisibility,
79
83
  className,
80
84
  as,
81
85
  innerRef,
82
86
  'data-test-id': dataTestId,
83
87
  ...rest
84
88
  }: CardServiceSmallProps<T>): ReactElement | null {
85
- const [isFavourite, setIsFavourite] = useUncontrolledProp(favorite?.checked, false, favorite?.onChange);
89
+ const [isFavourite, setIsFavourite] = useValueControl<boolean>({
90
+ value: favorite?.checked,
91
+ defaultValue: false,
92
+ onChange: favorite?.onChange,
93
+ });
86
94
  const cardRef = useRef<HTMLElement>(null);
87
95
  const favouriteRef = useRef<HTMLInputElement>(null);
88
96
 
@@ -149,7 +157,7 @@ export function CardServiceSmall<T extends ElementType = 'div'>({
149
157
  {favorite?.enabled && (
150
158
  <div
151
159
  className={styles.favouriteWrapper}
152
- data-visibility-strategy={favorite.visibilityStrategy ?? VISIBILITY_STRATEGY.hover}
160
+ data-actions-visibility={actionsVisibility ?? VISIBILITY_STRATEGY.hover}
153
161
  >
154
162
  <Favourite
155
163
  size='s'
@@ -10,11 +10,11 @@
10
10
  .favouriteWrapper {
11
11
  flex-shrink: 0;
12
12
 
13
- &[data-visibility-strategy='hover'] {
13
+ &[data-actions-visibility='hover'] {
14
14
  display: none;
15
15
  }
16
16
 
17
- &[data-visibility-strategy='always'] {
17
+ &[data-actions-visibility='always'] {
18
18
  display: flex;
19
19
  }
20
20
  }
@@ -24,7 +24,7 @@
24
24
 
25
25
  &:hover,
26
26
  &:focus-within {
27
- .favouriteWrapper[data-visibility-strategy='hover'] {
27
+ .favouriteWrapper[data-actions-visibility='hover'] {
28
28
  display: flex;
29
29
  }
30
30
  }
@@ -1,6 +1,7 @@
1
1
  export * from './CardBanner';
2
2
  export * from './CardService';
3
3
  export * from './CardServiceLight';
4
+ export * from './CardServiceInfo';
4
5
  export * from './CardServiceSmall';
5
6
  export * from './CardSuggest';
6
7
  export * from './CardCustom';
package/src/constants.ts CHANGED
@@ -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',
@@ -32,3 +40,5 @@ export const CARD_SIZE = {
32
40
  S: 's',
33
41
  M: 'm',
34
42
  } as const;
43
+
44
+ export const TOOLTIP_HOVER_DELAY_OPEN_MS = 300;
@@ -0,0 +1,136 @@
1
+ import { Button } from '@cloud-ru/ds-button';
2
+ import { InfoOutlineSVG } from '@cloud-ru/ds-icons/interface/product';
3
+ import { CollapseVerticalSVG, ExpandVerticalSVG, StarFilledSVG, StarSVG } from '@cloud-ru/ds-icons/interface/system';
4
+ import { Tooltip, TooltipProps, TRIGGER } from '@cloud-ru/ds-tooltip';
5
+ import { preventEventDefault, preventEventDefaultAndPropagation } from '@cloud-ru/ds-utils';
6
+ import cn from 'classnames';
7
+ import { MouseEvent, ReactElement, RefObject } from 'react';
8
+
9
+ import { VISIBILITY_STRATEGY } from '../../constants';
10
+ import { cardPredefinedLocale } from '../../locale';
11
+ import { CardSize, FavoriteProps, VisibilityStrategy } from '../../types';
12
+ import styles from './styles.module.scss';
13
+
14
+ export type CardActionsSurfaceProps = {
15
+ /**
16
+ * Формат отображения действий: всегда или при наведении и фокусе
17
+ * @default 'hover'
18
+ */
19
+ actionsVisibility?: VisibilityStrategy;
20
+ /** Кнопка info с тултипом */
21
+ tooltip?: Omit<TooltipProps, 'children'> & {
22
+ buttonRef?: RefObject<HTMLButtonElement>;
23
+ 'data-test-id'?: string;
24
+ };
25
+ /** Кнопка «Избранное» */
26
+ favorite?: FavoriteProps & {
27
+ buttonRef?: RefObject<HTMLButtonElement>;
28
+ 'data-test-id'?: string;
29
+ };
30
+ /** Кнопка раскрытия */
31
+ expandable?: {
32
+ value: boolean;
33
+ onClick(): void;
34
+ buttonRef?: RefObject<HTMLButtonElement>;
35
+ };
36
+ /** Размер кнопок действий, для мобильного вида предполагается использовать `s` */
37
+ actionsSize?: CardSize;
38
+ /** CSS-класс корневого элемента */
39
+ className?: string;
40
+ };
41
+
42
+ export function CardActionsSurface({
43
+ actionsVisibility = VISIBILITY_STRATEGY.hover,
44
+ tooltip,
45
+ favorite,
46
+ expandable,
47
+ actionsSize = 'm',
48
+ className,
49
+ }: CardActionsSurfaceProps): ReactElement | null {
50
+ const { t } = cardPredefinedLocale.useTranslations();
51
+
52
+ if (!tooltip && !favorite && !expandable) {
53
+ return null;
54
+ }
55
+
56
+ const tooltipTrigger =
57
+ tooltip?.trigger ??
58
+ (actionsVisibility === VISIBILITY_STRATEGY.always ? TRIGGER.Click : TRIGGER.HoverAndFocusVisible);
59
+
60
+ const handleExpandButtonClick = (e: MouseEvent<HTMLButtonElement>) => {
61
+ preventEventDefaultAndPropagation(e);
62
+ expandable?.onClick();
63
+ };
64
+
65
+ const handleFavoriteClick = (e: MouseEvent<HTMLButtonElement>) => {
66
+ preventEventDefaultAndPropagation(e);
67
+ favorite?.onChange?.(!favorite.checked);
68
+ };
69
+
70
+ const { buttonRef: tooltipButtonRef, 'data-test-id': tooltipTestId, ...tooltipProps } = tooltip ?? {};
71
+
72
+ return (
73
+ // eslint-disable-next-line jsx-a11y/no-static-element-interactions
74
+ <div
75
+ onClick={preventEventDefaultAndPropagation}
76
+ className={cn(styles.root, className)}
77
+ data-actions-visibility={actionsVisibility}
78
+ >
79
+ {tooltip && (
80
+ <Tooltip {...tooltipProps} tip={tooltip.tip} trigger={tooltipTrigger} triggerClassName={styles.tooltipTrigger}>
81
+ {/* Кнопки действий — `as='span'` внутри интерактивной карточки (вложенный `<button>` невалиден),
82
+ поэтому роль и доступное имя проставляем руками. */}
83
+ <Button
84
+ as='span'
85
+ role='button'
86
+ aria-label={t('actions.info')}
87
+ size={actionsSize}
88
+ appearance='neutral'
89
+ view='simple'
90
+ icon={<InfoOutlineSVG />}
91
+ tabIndex={-1}
92
+ onClick={preventEventDefault}
93
+ innerRef={tooltipButtonRef}
94
+ data-test-id={tooltipTestId}
95
+ />
96
+ </Tooltip>
97
+ )}
98
+
99
+ {favorite?.enabled && (
100
+ <Button
101
+ as='span'
102
+ role='button'
103
+ aria-label={favorite.checked ? t('actions.favoriteRemove') : t('actions.favoriteAdd')}
104
+ aria-pressed={Boolean(favorite.checked)}
105
+ size={actionsSize}
106
+ appearance='neutral'
107
+ view='simple'
108
+ icon={favorite.checked ? <StarFilledSVG /> : <StarSVG />}
109
+ onClick={handleFavoriteClick}
110
+ className={styles.favorite}
111
+ innerRef={favorite.buttonRef}
112
+ tabIndex={-1}
113
+ data-test-id={favorite['data-test-id']}
114
+ data-checked={favorite.checked || undefined}
115
+ />
116
+ )}
117
+
118
+ {expandable && (
119
+ <Button
120
+ as='span'
121
+ role='button'
122
+ aria-label={expandable.value ? t('actions.collapse') : t('actions.expand')}
123
+ aria-expanded={expandable.value}
124
+ size={actionsSize}
125
+ appearance='neutral'
126
+ view='simple'
127
+ icon={expandable.value ? <CollapseVerticalSVG /> : <ExpandVerticalSVG />}
128
+ onClick={handleExpandButtonClick}
129
+ className={styles.expandButton}
130
+ innerRef={expandable.buttonRef}
131
+ tabIndex={-1}
132
+ />
133
+ )}
134
+ </div>
135
+ );
136
+ }
@@ -0,0 +1,2 @@
1
+ export * from './CardActionsSurface';
2
+ export * from './utils';