Skip to content

Commit 659df2d

Browse files
Valent1325Maksim Malofeev
andauthored
feat: add background color hover property for BasicCard (#1324)
Co-authored-by: Maksim Malofeev <[email protected]>
1 parent dad7300 commit 659df2d

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

src/components/CardBase/CardBase.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ a#{$block} {
6060
@include reset-link-style();
6161
@include reset-link-hover();
6262
@include card($hover: true);
63+
@include background-hover();
6364
}

src/models/constructor-items/sub-blocks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export interface BasicCardProps
166166
gravityIcon?: ThemeSupporting<GravityIconProps>;
167167
target?: string;
168168
iconPosition?: IconPosition;
169+
hoverBackgroundColor?: string;
169170
}
170171

171172
export interface BannerCardProps {

src/sub-blocks/BasicCard/BasicCard.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const BasicCard = (props: BasicCardProps) => {
2424
controlPosition = 'content',
2525
size = 's',
2626
gravityIcon,
27+
hoverBackgroundColor,
2728
...cardParams
2829
} = props;
2930
const titleId = useUniqId();
@@ -38,7 +39,15 @@ const BasicCard = (props: BasicCardProps) => {
3839
className={b()}
3940
contentClassName={b('content')}
4041
{...cardParams}
41-
extraProps={{'aria-describedby': descriptionId, 'aria-labelledby': titleId}}
42+
extraProps={{
43+
'aria-describedby': descriptionId,
44+
'aria-labelledby': titleId,
45+
...(hoverBackgroundColor && {
46+
style: {
47+
'--hover-background-color': hoverBackgroundColor,
48+
} as React.CSSProperties,
49+
}),
50+
}}
4251
>
4352
<CardBase.Content>
4453
<IconWrapper

src/sub-blocks/BasicCard/__stories__/BasicCard.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export const WithContentList = WithContentListTemplate.bind({});
123123
export const ControlPosition = ControlPositionTemplate.bind({});
124124
export const Sizes = VariousTemplate.bind([]);
125125
export const GravityIcons = VariousTemplate.bind([]);
126+
export const HoverEffects = ListTemplate.bind({});
126127

127128
const DefaultArgs = data.default as BasicCardModel;
128129

@@ -254,3 +255,10 @@ GravityIcons.parameters = {
254255
include: Object.keys(GravityIcons.args),
255256
},
256257
};
258+
259+
HoverEffects.args = data.hoverEffects as BasicCardModel[];
260+
HoverEffects.parameters = {
261+
controls: {
262+
include: Object.keys(HoverEffects.args),
263+
},
264+
};

src/sub-blocks/BasicCard/__stories__/data.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,5 +382,30 @@
382382
}
383383
]
384384
}
385+
],
386+
"hoverEffects": [
387+
{
388+
"type": "basic-card",
389+
"title": "Hover: Gradient Background",
390+
"text": "Hover over this card to see gradient background effect",
391+
"url": "/test",
392+
"urlTitle": "Opens in a new tab",
393+
"hoverBackgroundColor": "linear-gradient(180deg, rgba(255, 255, 255, 0.00) 36%, #DCC7FF 100%)"
394+
},
395+
{
396+
"type": "basic-card",
397+
"title": "Hover: Solid Color",
398+
"text": "Hover over this card to see solid color background effect",
399+
"url": "/test",
400+
"urlTitle": "Opens in a new tab",
401+
"hoverBackgroundColor": "#DCC7FF"
402+
},
403+
{
404+
"type": "basic-card",
405+
"title": "No Hover Effect",
406+
"text": "This card has no hover background effect",
407+
"url": "/test",
408+
"urlTitle": "Opens in a new tab"
409+
}
385410
]
386411
}

styles/mixins.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@
247247
}
248248
}
249249

250+
@mixin background-hover($property: background) {
251+
&:hover {
252+
#{$property}: var(--hover-background-color);
253+
}
254+
}
255+
250256
@mixin image-shadow() {
251257
box-shadow:
252258
0 2px 8px var(--pc-color-sfx-shadow),

0 commit comments

Comments
 (0)