Skip to content

Commit

Permalink
fix: image card storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
qradle-yndx committed Feb 12, 2024
1 parent c275709 commit 12b0d29
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 11 deletions.
28 changes: 20 additions & 8 deletions src/sub-blocks/ImageCard/ImageCard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ $paddingS: 4px;
@include card();
min-height: 1px;
border-radius: $indentSM;
$image: #{&}__image;
$content: #{&}__content;

&__content {
padding: $indentSM $indentM $indentM $indentM;
#{$content} {
padding: $indentM;
}

$image: #{&}__image;

#{$image} {
&_inner {
width: 100%;
Expand All @@ -38,12 +38,24 @@ $paddingS: 4px;
}

&_with-content {
#{$image}_direction_direct {
padding-bottom: 0;
&#{$block}_direction_direct {
#{$image} {
padding-bottom: 0;
}

#{$content} {
padding-top: $indentSM;
}
}

#{$image}_direction_reverse {
padding-top: 0;
&#{$block}_direction_reverse {
#{$image} {
padding-top: 0;
}

#{$content} {
padding-bottom: $indentSM;
}
}
}
}
7 changes: 5 additions & 2 deletions src/sub-blocks/ImageCard/ImageCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ const ImageCard = (props: ImageCardProps) => {
const renderImage = () => {
const imageProps = getMediaImage(image);
return (
<div className={b('image', {margins, direction})}>
<div className={b('image', {margins})}>
<Image className={b('image_inner')} {...imageProps} />
</div>
);
};

return (
<div className={b({border, 'with-content': hasContent})} style={{backgroundColor}}>
<div
className={b({border, 'with-content': hasContent, direction})}
style={{backgroundColor}}
>
{direction === ImageCardDirection.Direct && (
<React.Fragment>
{renderImage()}
Expand Down
25 changes: 24 additions & 1 deletion src/sub-blocks/ImageCard/__stories__/ImageCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,34 @@ const ContentTemplate: StoryFn<ImageCardProps> = (args) => (
</div>
);

const MultipleContentTemplate: StoryFn<ImageCardProps> = (args) => (
<div>
<ContentTemplate {...args} {...(data.margins.none as Partial<ImageCardProps>)} />
<ContentTemplate {...args} {...(data.margins.small as Partial<ImageCardProps>)} />
<ContentTemplate {...args} {...(data.margins.medium as Partial<ImageCardProps>)} />
</div>
);

const BorderTemplate: StoryFn<ImageCardProps> = (args) => (
<div style={{display: 'flex', flexWrap: 'wrap', flexDirection: 'row'}}>
<div style={{width: 400, margin: 20}}>
<ImageCard {...args} {...(data.border.shadow as Partial<ImageCardProps>)} />
</div>
<div style={{width: 400, margin: 20}}>
<ImageCard {...args} {...(data.border.line as Partial<ImageCardProps>)} />
</div>
<div style={{width: 400, margin: 20}}>
<ImageCard {...args} {...(data.border.none as Partial<ImageCardProps>)} />
</div>
</div>
);

export const Default = DefaultTemplate.bind({});
export const Margins = MultipleTemplate.bind({});
export const DirectionReverse = MultipleTemplate.bind({});
export const Content = ContentTemplate.bind({});
export const Content = MultipleContentTemplate.bind({});
export const BackgroundColor = MultipleTemplate.bind({});
export const Border = BorderTemplate.bind({});

DirectionReverse.args = {direction: 'reverse'} as Partial<ImageCardProps>;
BackgroundColor.args = {...data.backgroundColor.content};
14 changes: 14 additions & 0 deletions src/sub-blocks/ImageCard/__stories__/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@
"direction": "reverse"
}
},
"border": {
"shadow": {
"border": "shadow (default)",
"title": "border: 'shadow'"
},
"line": {
"border": "line",
"title": "border: 'line'"
},
"none": {
"border": "none",
"title": "border: 'none'"
}
},
"backgroundColor": {
"content": {
"backgroundColor": "#ccf0d2"
Expand Down

0 comments on commit 12b0d29

Please sign in to comment.