Skip to content

Commit ecf0fca

Browse files
niktverdNikitaCG
andauthored
feat: add analyticsEvents to BackgroundCard & add link animation for cards without shadow (#559)
* feat: add link animation for cards without shadow (#513) * feat: add analyticsEvents to BackgroundCard (#556) --------- Co-authored-by: Nikita Gorin <[email protected]>
1 parent f2b321c commit ecf0fca

File tree

16 files changed

+142
-14
lines changed

16 files changed

+142
-14
lines changed

src/models/constructor-items/common.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ export interface PriceDetailsProps {
375375
items?: PriceDetailsSettingsProps[] | PriceDetailsListProps[];
376376
}
377377

378-
export interface PriceItemProps extends PriceDetailsProps, PriceDescriptionProps {}
378+
export interface PriceItemProps
379+
extends PriceDetailsProps,
380+
PriceDescriptionProps,
381+
AnalyticsEventsBase {}
379382

380383
export interface PriceFoldableDetailsProps {
381384
title: string;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export interface QuoteProps extends Themable, CardBaseProps {
100100

101101
export interface BackgroundCardProps
102102
extends CardBaseProps,
103+
AnalyticsEventsBase,
103104
Omit<ContentBlockProps, 'colSizes' | 'centered'> {
104105
url?: string;
105106
background?: ThemeSupporting<ImageObjectProps>;
@@ -109,6 +110,7 @@ export interface BackgroundCardProps
109110

110111
export interface BasicCardProps
111112
extends CardBaseProps,
113+
AnalyticsEventsBase,
112114
Omit<ContentBlockProps, 'colSizes' | 'centered' | 'size' | 'theme'> {
113115
url: string;
114116
icon?: ImageProps;
@@ -126,9 +128,9 @@ export interface BannerCardProps {
126128
button: Pick<ButtonProps, 'text' | 'url' | 'target'>;
127129
}
128130

129-
export interface MediaCardProps extends MediaProps, CardBaseProps {}
131+
export interface MediaCardProps extends MediaProps, AnalyticsEventsBase, CardBaseProps {}
130132

131-
export interface LayoutItemProps extends ClassNameProps {
133+
export interface LayoutItemProps extends ClassNameProps, AnalyticsEventsBase {
132134
content: Omit<ContentBlockProps, 'colSizes' | 'centered' | 'size'>;
133135
media: MediaProps;
134136
metaInfo?: string[];

src/sub-blocks/BackgroundCard/BackgroundCard.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@ const BackgroundCard = (props: BackgroundCardProps) => {
2323
theme: cardTheme = 'default',
2424
links,
2525
buttons,
26+
analyticsEvents,
2627
} = props;
2728

2829
const {themeValue: theme} = useContext(ThemeValueContext);
2930
const hasBackgroundColor = backgroundColor || cardTheme !== 'default';
30-
const link = hasBackgroundColor || border === 'line' ? undefined : url;
3131
const borderType = hasBackgroundColor ? 'none' : border;
3232

3333
return (
3434
<CardBase
3535
className={b({padding: paddingBottom, theme: cardTheme})}
36-
url={link}
36+
url={url}
3737
border={borderType}
38+
analyticsEvents={analyticsEvents}
3839
>
3940
<CardBase.Content>
4041
<BackgroundImage

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,23 @@ const BackgroundColorTemplate: StoryFn<BackgroundCardProps> = (args) => (
8585
</div>
8686
);
8787

88+
const WithUrlTemplate: StoryFn<{items: BackgroundCardProps[]}> = (args) => (
89+
<div style={{display: 'flex'}}>
90+
{args.items.map((item, i) => (
91+
<div style={{maxWidth: '400px', padding: '0 8px'}} key={i}>
92+
<BackgroundCard {...item} />
93+
</div>
94+
))}
95+
</div>
96+
);
97+
8898
export const Default = DefaultTemplate.bind({});
8999
export const WithBackgroundImage = DefaultTemplate.bind({});
90100
export const Paddings = PaddingsTemplate.bind({});
91101
export const CardThemes = CardThemesTemplate.bind([]);
92102
export const BorderLine = DefaultTemplate.bind({});
93103
export const BackgroundColor = BackgroundColorTemplate.bind({});
104+
export const WithUrl = WithUrlTemplate.bind({});
94105

95106
const DefaultArgs = {
96107
title: data.common.title,
@@ -128,3 +139,17 @@ BackgroundColor.args = {
128139
...DefaultArgs,
129140
...data.backgroundColor.content,
130141
} as BackgroundCardProps;
142+
143+
WithUrl.args = {
144+
items: [
145+
data.cardThemes.content[1],
146+
data.withBackgroundImage.content,
147+
data.borderLine.content,
148+
data.backgroundColor.content,
149+
data.borderNone.content,
150+
].map((item) => ({
151+
...DefaultArgs,
152+
...item,
153+
url: data.url,
154+
})) as BackgroundCardProps[],
155+
};

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@
5555
"border": "line"
5656
}
5757
},
58+
"borderNone": {
59+
"content": {
60+
"border": "none"
61+
}
62+
},
63+
"url": "https://example.com",
5864
"paddings": {
5965
"title": "Padding Bottom = {{padding}}"
6066
},

src/sub-blocks/BackgroundCard/schema.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import _ from 'lodash';
22

33
import {ImageObjectProps} from '../../components/Image/schema';
44
import {BaseProps, CardBase, withTheme} from '../../schema/validators/common';
5+
import {AnalyticsEventSchema} from '../../schema/validators/event';
56
import {ContentBase} from '../Content/schema';
67

78
const BackgroundCardContentProps = _.omit(ContentBase, ['size']);
@@ -25,6 +26,19 @@ export const BackgroundCard = {
2526
type: 'string',
2627
enum: ['s', 'm', 'l', 'xl'],
2728
},
29+
analyticsEvents: {
30+
oneOf: [
31+
{
32+
...AnalyticsEventSchema,
33+
optionName: 'single',
34+
},
35+
{
36+
type: 'array',
37+
items: AnalyticsEventSchema,
38+
optionName: 'list',
39+
},
40+
],
41+
},
2842
},
2943
},
3044
};

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,24 @@ const WithBorderTemplate: StoryFn<BasicCardProps> = (args) => (
6060
</div>
6161
);
6262

63+
const WithUrlTemplate: StoryFn<BasicCardProps> = (args) => (
64+
<div style={{display: 'flex', padding: '40px 0'}}>
65+
<div style={{maxWidth: '400px', padding: '0 8px'}}>
66+
<BasicCard {...args} title={getCardWithBorderTitle('shadow')} />
67+
</div>
68+
<div style={{maxWidth: '400px', padding: '0 8px'}}>
69+
<BasicCard {...args} border="line" title={getCardWithBorderTitle('line')} />
70+
</div>
71+
<div style={{maxWidth: '400px', padding: '0 8px'}}>
72+
<BasicCard {...args} border="none" title={getCardWithBorderTitle('none')} />
73+
</div>
74+
</div>
75+
);
76+
6377
export const Default = DefaultTemplate.bind({});
6478
export const WithIcon = WithIconTemplate.bind({});
6579
export const WithBorder = WithBorderTemplate.bind({});
80+
export const WithUrl = WithUrlTemplate.bind({});
6681

6782
const DefaultArgs = {
6883
...data.default.content,
@@ -75,3 +90,7 @@ Default.args = {
7590
} as BasicCardProps;
7691
WithIcon.args = DefaultArgs as BasicCardProps;
7792
WithBorder.args = DefaultArgs as BasicCardProps;
93+
WithUrl.args = {
94+
url: data.url,
95+
...DefaultArgs,
96+
} as BasicCardProps;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"withBorder": {
1111
"title": "Card with border {{border}}"
1212
},
13+
"url": "https://example.com",
1314
"default": {
1415
"content": {
15-
"url": "https://example.com",
1616
"title": "Lorem ipsum",
1717
"text": "**Ut enim ad minim veniam** [quis nostrud](https://example.com) exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat."
1818
}

src/sub-blocks/LayoutItem/LayoutItem.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const LayoutItem = ({
1818
border,
1919
fullscreen,
2020
className,
21+
analyticsEvents,
2122
}: LayoutItemProps) => (
2223
<div className={b(null, className)}>
2324
{fullscreen && hasFullscreen(media) ? (
@@ -31,11 +32,12 @@ const LayoutItem = ({
3132
{...media}
3233
{...fullscreenMediaProps}
3334
className={b('media', {border}, mediaClassName)}
35+
analyticsEvents={analyticsEvents}
3436
/>
3537
)}
3638
</FullscreenMedia>
3739
) : (
38-
<Media {...media} className={b('media', {border})} />
40+
<Media {...media} className={b('media', {border})} analyticsEvents={analyticsEvents} />
3941
)}
4042
{metaInfo && <MetaInfo items={metaInfo} className={b('meta-info')} />}
4143
<div className={b('content')}>

src/sub-blocks/LayoutItem/schema.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {omit} from 'lodash';
22

33
import metaInfo from '../../components/MetaInfo/schema';
44
import {BaseProps, MediaProps} from '../../schema/validators/common';
5+
import {AnalyticsEventSchema} from '../../schema/validators/event';
56
import {ContentBase} from '../../sub-blocks/Content/schema';
67

78
export const LayoutItem = {
@@ -19,5 +20,18 @@ export const LayoutItem = {
1920
fullscreen: {
2021
type: 'boolean',
2122
},
23+
analyticsEvents: {
24+
oneOf: [
25+
{
26+
...AnalyticsEventSchema,
27+
optionName: 'single',
28+
},
29+
{
30+
type: 'array',
31+
items: AnalyticsEventSchema,
32+
optionName: 'list',
33+
},
34+
],
35+
},
2236
},
2337
};

0 commit comments

Comments
 (0)