@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.
- package/CHANGELOG.md +6 -0
- package/README.md +251 -34
- package/dist/cjs/components/CardServiceInfo/CardServiceInfo.d.ts +43 -0
- package/dist/cjs/components/CardServiceInfo/CardServiceInfo.js +66 -0
- package/dist/cjs/components/CardServiceInfo/index.d.ts +1 -0
- package/dist/cjs/components/CardServiceInfo/index.js +17 -0
- package/dist/cjs/components/CardServiceInfo/styles.module.css +102 -0
- package/dist/cjs/components/CardServiceLight/CardServiceLight.d.ts +22 -11
- package/dist/cjs/components/CardServiceLight/CardServiceLight.js +98 -31
- package/dist/cjs/components/CardServiceLight/styles.module.css +30 -25
- package/dist/cjs/components/CardServiceSmall/CardServiceSmall.d.ts +7 -6
- package/dist/cjs/components/CardServiceSmall/CardServiceSmall.js +7 -3
- package/dist/cjs/components/CardServiceSmall/styles.module.css +3 -3
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/constants.d.ts +9 -0
- package/dist/cjs/constants.js +10 -1
- package/dist/cjs/helperComponents/CardActionsSurface/CardActionsSurface.d.ts +31 -0
- package/dist/cjs/helperComponents/CardActionsSurface/CardActionsSurface.js +36 -0
- package/dist/cjs/helperComponents/CardActionsSurface/index.d.ts +2 -0
- package/dist/cjs/helperComponents/CardActionsSurface/index.js +18 -0
- package/dist/cjs/helperComponents/CardActionsSurface/styles.module.css +36 -0
- package/dist/cjs/helperComponents/CardActionsSurface/utils.d.ts +22 -0
- package/dist/cjs/helperComponents/CardActionsSurface/utils.js +43 -0
- package/dist/cjs/helperComponents/CardPromoTag/CardPromoTag.d.ts +16 -0
- package/dist/cjs/helperComponents/CardPromoTag/CardPromoTag.js +24 -0
- package/dist/cjs/helperComponents/CardPromoTag/index.d.ts +1 -0
- package/dist/cjs/helperComponents/CardPromoTag/index.js +17 -0
- package/dist/cjs/helperComponents/index.d.ts +2 -0
- package/dist/cjs/helperComponents/index.js +2 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/locale/index.d.ts +43 -0
- package/dist/cjs/locale/index.js +26 -0
- package/dist/cjs/style.css +166 -23
- package/dist/cjs/types.d.ts +12 -5
- package/dist/esm/components/CardServiceInfo/CardServiceInfo.d.ts +43 -0
- package/dist/esm/components/CardServiceInfo/CardServiceInfo.js +60 -0
- package/dist/esm/components/CardServiceInfo/index.d.ts +1 -0
- package/dist/esm/components/CardServiceInfo/index.js +1 -0
- package/dist/esm/components/CardServiceInfo/styles.module.css +102 -0
- package/dist/esm/components/CardServiceLight/CardServiceLight.d.ts +22 -11
- package/dist/esm/components/CardServiceLight/CardServiceLight.js +101 -34
- package/dist/esm/components/CardServiceLight/styles.module.css +30 -25
- package/dist/esm/components/CardServiceSmall/CardServiceSmall.d.ts +7 -6
- package/dist/esm/components/CardServiceSmall/CardServiceSmall.js +8 -4
- package/dist/esm/components/CardServiceSmall/styles.module.css +3 -3
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/constants.d.ts +9 -0
- package/dist/esm/constants.js +9 -0
- package/dist/esm/helperComponents/CardActionsSurface/CardActionsSurface.d.ts +31 -0
- package/dist/esm/helperComponents/CardActionsSurface/CardActionsSurface.js +30 -0
- package/dist/esm/helperComponents/CardActionsSurface/index.d.ts +2 -0
- package/dist/esm/helperComponents/CardActionsSurface/index.js +2 -0
- package/dist/esm/helperComponents/CardActionsSurface/styles.module.css +36 -0
- package/dist/esm/helperComponents/CardActionsSurface/utils.d.ts +22 -0
- package/dist/esm/helperComponents/CardActionsSurface/utils.js +40 -0
- package/dist/esm/helperComponents/CardPromoTag/CardPromoTag.d.ts +16 -0
- package/dist/esm/helperComponents/CardPromoTag/CardPromoTag.js +21 -0
- package/dist/esm/helperComponents/CardPromoTag/index.d.ts +1 -0
- package/dist/esm/helperComponents/CardPromoTag/index.js +1 -0
- package/dist/esm/helperComponents/index.d.ts +2 -0
- package/dist/esm/helperComponents/index.js +2 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/locale/index.d.ts +43 -0
- package/dist/esm/locale/index.js +23 -0
- package/dist/esm/style.css +166 -23
- package/dist/esm/types.d.ts +12 -5
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +21 -11
- package/src/components/CardServiceInfo/CardServiceInfo.tsx +203 -0
- package/src/components/CardServiceInfo/index.ts +1 -0
- package/src/components/CardServiceInfo/styles.module.scss +124 -0
- package/src/components/CardServiceLight/CardServiceLight.tsx +172 -80
- package/src/components/CardServiceLight/styles.module.scss +37 -33
- package/src/components/CardServiceSmall/CardServiceSmall.tsx +14 -6
- package/src/components/CardServiceSmall/styles.module.scss +3 -3
- package/src/components/index.ts +1 -0
- package/src/constants.ts +10 -0
- package/src/helperComponents/CardActionsSurface/CardActionsSurface.tsx +136 -0
- package/src/helperComponents/CardActionsSurface/index.ts +2 -0
- package/src/helperComponents/CardActionsSurface/styles.module.scss +50 -0
- package/src/helperComponents/CardActionsSurface/utils.ts +76 -0
- package/src/helperComponents/CardPromoTag/CardPromoTag.tsx +46 -0
- package/src/helperComponents/CardPromoTag/index.ts +1 -0
- package/src/helperComponents/index.ts +2 -0
- package/src/index.ts +2 -0
- package/src/locale/index.ts +27 -0
- package/src/types.ts +10 -5
|
@@ -1,50 +1,69 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
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?:
|
|
38
|
+
promoTag?: CardPromoTagProps;
|
|
30
39
|
/** Настройки обрезки текста заголовка */
|
|
31
40
|
truncate?: {
|
|
32
41
|
/** Максимальное количество строк заголовка */
|
|
33
42
|
title?: number;
|
|
34
43
|
};
|
|
35
|
-
/**
|
|
36
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Формат отображения дополнительных действий: всегда или при наведении и фокусе
|
|
46
|
+
* @default 'hover'
|
|
47
|
+
*/
|
|
48
|
+
actionsVisibility?: VisibilityStrategy;
|
|
49
|
+
/** Подсказка с иконкой «?» рядом с заголовком */
|
|
50
|
+
tooltip?: Omit<TooltipProps, 'trigger' | 'size'>;
|
|
37
51
|
/**
|
|
38
52
|
* Настройки кнопки «Избранное».
|
|
39
|
-
* Keyboard: ArrowRight на карточке →
|
|
53
|
+
* Keyboard: ArrowRight на карточке → tooltip (если есть) → Favorite; ArrowLeft — в обратном порядке.
|
|
40
54
|
*/
|
|
41
55
|
favorite?: FavoriteProps;
|
|
42
|
-
/**
|
|
43
|
-
|
|
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
|
-
|
|
83
|
+
actionsVisibility: actionsVisibilityProp,
|
|
63
84
|
favorite,
|
|
64
|
-
|
|
85
|
+
tooltip,
|
|
86
|
+
actionsSize,
|
|
65
87
|
className,
|
|
66
|
-
|
|
67
|
-
|
|
88
|
+
disabled = false,
|
|
89
|
+
expandable,
|
|
68
90
|
'data-test-id': dataTestId,
|
|
69
91
|
...rest
|
|
70
92
|
}: CardServiceLightProps<T>): ReactElement | null {
|
|
71
|
-
const
|
|
93
|
+
const Component: ElementType = as ?? 'button';
|
|
72
94
|
const cardRef = useRef<HTMLElement>(null);
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
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
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
<
|
|
110
|
-
|
|
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
|
-
|
|
117
|
-
{
|
|
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 &&
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
154
|
-
|
|
207
|
+
)}
|
|
208
|
+
</div>
|
|
155
209
|
</div>
|
|
156
|
-
|
|
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
|
-
.
|
|
3
|
+
.root {
|
|
4
|
+
cursor: pointer;
|
|
5
|
+
|
|
4
6
|
position: relative;
|
|
5
7
|
|
|
6
8
|
display: flex;
|
|
7
|
-
flex
|
|
9
|
+
flex: 1 0 0;
|
|
10
|
+
align-items: center;
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
width: 100%;
|
|
13
|
+
min-width: 228px;
|
|
14
|
+
padding: 0;
|
|
15
|
+
border: none;
|
|
16
|
+
border-radius: base.$sn-density-radius-3xs;
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
font: inherit;
|
|
19
|
+
color: inherit;
|
|
20
|
+
text-decoration: none;
|
|
13
21
|
|
|
14
|
-
|
|
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
|
-
|
|
24
|
+
&[data-disabled] {
|
|
25
|
+
pointer-events: none;
|
|
26
|
+
cursor: default;
|
|
27
|
+
opacity: base.$sn-theme-effect-opacity-disabled;
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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-
|
|
39
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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 {
|
|
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
|
-
*
|
|
50
|
+
* Формат отображения кнопки «Избранное»: всегда или при наведении и фокусе
|
|
51
|
+
* @default 'hover'
|
|
49
52
|
*/
|
|
50
|
-
|
|
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] =
|
|
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
|
|
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
|
|
13
|
+
&[data-actions-visibility='hover'] {
|
|
14
14
|
display: none;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
&[data-visibility
|
|
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
|
|
27
|
+
.favouriteWrapper[data-actions-visibility='hover'] {
|
|
28
28
|
display: flex;
|
|
29
29
|
}
|
|
30
30
|
}
|
package/src/components/index.ts
CHANGED
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
|
+
}
|