Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add md breackpoint to cta-block #45

Merged
merged 6 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 16 additions & 45 deletions src/blocks/CTA/CTA.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,33 @@ $block: '.#{$namespace}cta';
flex-direction: column;
flex-grow: 1;
padding: $indentM;
}

&__button {
display: flex;
padding-bottom: $indentXS;
width: calc((100% / 3) - (#{$indentM} / 2));
}

&__content {
display: flex;
flex-direction: column;
flex-flow: row wrap;
gap: $indentXS;
}

@media (min-width: map-get($gridBreakpoints, 'sm')) {
@media (max-width: map-get($gridBreakpoints, 'md')) {
&__content {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}

&__button {
padding-bottom: 0px;

&_layout {
width: 100%;
max-width: 100%;
margin-right: 0px;

&_2 {
width: calc((100% / 2) - (#{$indentXS} / 2));
max-width: 50%;
margin-right: $indentXS;
}

&_2:nth-child(2n) {
margin-right: 0px;
}

&_3 {
width: calc((100% / 3) - (#{$indentM} / 3));
$max-width: 50%;
margin-right: $indentXS;
}

&_3:nth-child(3n) {
margin-right: 0px;
}
&__card {
width: calc((100% / 2) - #{$indentXS});
flex-grow: 1;
}
}

&_4 {
width: calc((100% / 4) - (#{$indentL} / 4));
max-width: 50%;
margin-right: $indentXS;
}
@media (max-width: map-get($gridBreakpoints, 'sm')) {
&__content {
flex-direction: column;
}

&_4:nth-child(4n) {
margin-right: 0px;
}
}
&__card {
width: 100%;
}
}
}
26 changes: 3 additions & 23 deletions src/blocks/CTA/CTA.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,7 @@ import './CTA.scss';

const b = block('cta');

const MAX_COLUMN_COUNT = 4,
MIN_COLUMN_COUNT = 2,
DEFAULT_COLUMN_COUNT = 3;

export const CTA: React.FC<CTAProps> = ({items, paddingTop, paddingBottom}) => {
let count = items ? items.length : DEFAULT_COLUMN_COUNT;

if (count < MIN_COLUMN_COUNT) {
count = MIN_COLUMN_COUNT;
} else if (count > MAX_COLUMN_COUNT) {
count = MAX_COLUMN_COUNT;
}

/**
* @deprecated Metrika will be deleted after launch of analyticsEvents
*/
Expand All @@ -43,7 +31,7 @@ export const CTA: React.FC<CTAProps> = ({items, paddingTop, paddingBottom}) => {
className={b('content')}
dataQa="blog-cta-content"
>
{items.slice(0, count).map((content: ContentBlockProps, index: number) => {
{items.map((content: ContentBlockProps, index: number) => {
const contentData = updateContentSizes(content);

contentData.links?.forEach((link) => {
Expand All @@ -52,16 +40,8 @@ export const CTA: React.FC<CTAProps> = ({items, paddingTop, paddingBottom}) => {
});

return (
<div
key={index}
className={b('button', {
['layout']: count,
})}
data-qa="blog-cta-card"
>
<div className={b('card')}>
<Content {...contentData} />
</div>
<div key={index} className={b('card')} data-qa="blog-cta-card">
<Content {...contentData} />
</div>
);
})}
Expand Down
37 changes: 36 additions & 1 deletion src/blocks/CTA/__stories__/CTA.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,44 @@ const DefaultTemplate: Story<CTAModel> = (args) => (
);

export const Default = DefaultTemplate.bind({});
export const OneItem = DefaultTemplate.bind({});
export const TwoItems = DefaultTemplate.bind({});
export const FourItems = DefaultTemplate.bind({});
export const FiveItems = DefaultTemplate.bind({});
export const SixItems = DefaultTemplate.bind({});

Default.args = {
type: BlockType.CTA,
...getDefaultStoryArgs(),
items: contentBlocks,
items: contentBlocks.slice(0, 3),
};

OneItem.args = {
type: BlockType.CTA,
...getDefaultStoryArgs(),
items: contentBlocks.slice(0, 1),
};

TwoItems.args = {
type: BlockType.CTA,
...getDefaultStoryArgs(),
items: contentBlocks.slice(0, 2),
};

FourItems.args = {
type: BlockType.CTA,
...getDefaultStoryArgs(),
items: contentBlocks.slice(0, 4),
};

FiveItems.args = {
type: BlockType.CTA,
...getDefaultStoryArgs(),
items: contentBlocks.slice(0, 5),
};

SixItems.args = {
type: BlockType.CTA,
...getDefaultStoryArgs(),
items: contentBlocks.slice(0, 6),
};