Skip to content

Commit

Permalink
fix: image card review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
qradle-yndx committed Feb 13, 2024
1 parent 1dc25a9 commit 676e3e9
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/models/constructor-items/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export type ContentSize = 's' | 'l';
export type ContentTextSize = 's' | 'm' | 'l';
export type ContentTheme = 'default' | 'dark' | 'light';
export type FileLinkType = 'vertical' | 'horizontal';
export type ImageCardMargins = 's' | 'm';

// modifiers
export interface Themable {
Expand Down
7 changes: 1 addition & 6 deletions src/models/constructor-items/sub-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CardBaseProps,
ContentTheme,
DividerSize,
ImageCardMargins,
ImageObjectProps,
ImageProps,
LinkProps,
Expand Down Expand Up @@ -58,12 +59,6 @@ export interface IconWrapperProps {
icon?: PositionedIcon;
}

export enum ImageCardMargins {
None = 'none',
Small = 's',
Medium = 'm',
}

export enum ImageCardDirection {
Direct = 'direct',
Reverse = 'reverse',
Expand Down
18 changes: 13 additions & 5 deletions src/sub-blocks/ImageCard/ImageCard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ $paddingS: 4px;
&_inner {
width: 100%;
display: block;

&_radius {
border-radius: $borderRadius;
}
}

&_margins {
&_none {
#{$image}_inner#{$image}_inner_radius {
border-radius: $borderRadius;
}
}
&_s {
padding: $paddingS;

Expand All @@ -37,11 +36,18 @@ $paddingS: 4px;

&_m {
padding: $indentM;

#{$image}_inner {
border-radius: initial;
}
}
}
}

&_with-content {
display: flex;
flex-direction: column;

&#{$block}_direction_direct {
#{$image} {
padding-bottom: 0;
Expand All @@ -53,6 +59,8 @@ $paddingS: 4px;
}

&#{$block}_direction_reverse {
flex-direction: column-reverse;

#{$image} {
padding-top: 0;
}
Expand Down
46 changes: 12 additions & 34 deletions src/sub-blocks/ImageCard/ImageCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

import {Image} from '../../components';
import {getMediaImage} from '../../components/Media/Image/utils';
import {ImageCardDirection, ImageCardMargins, ImageCardProps} from '../../models';
import {ImageCardDirection, ImageCardProps} from '../../models';
import {block} from '../../utils';
import Content from '../Content/Content';

Expand All @@ -18,50 +18,28 @@ const ImageCard = (props: ImageCardProps) => {
image,
enableImageBorderRadius = false,
direction = ImageCardDirection.Direct,
margins = ImageCardMargins.None,
margins,
backgroundColor,
} = props;

const hasContent = Boolean(text || title);
const imageProps = getMediaImage(image);

const renderContent = () => {
if (!hasContent) {
return null;
}
return (
<div className={b('content')}>
<Content title={title} text={text} colSizes={{all: 12, md: 12}} size="s" />
</div>
);
};
const renderImage = () => {
const imageProps = getMediaImage(image);
return (
return (
<div
className={b({border, 'with-content': hasContent, direction})}
style={{backgroundColor}}
>
<div className={b('image', {margins})}>
<Image
className={b('image_inner', {radius: enableImageBorderRadius})}
{...imageProps}
/>
</div>
);
};

return (
<div
className={b({border, 'with-content': hasContent, direction})}
style={{backgroundColor}}
>
{direction === ImageCardDirection.Direct && (
<React.Fragment>
{renderImage()}
{renderContent()}
</React.Fragment>
)}
{direction === ImageCardDirection.Reverse && (
<React.Fragment>
{renderContent()}
{renderImage()}
</React.Fragment>
{hasContent && (
<div className={b('content')}>
<Content title={title} text={text} colSizes={{all: 12, md: 12}} size="s" />
</div>
)}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/sub-blocks/ImageCard/__stories__/ImageCard.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as ImageCardStories from './ImageCard.stories.tsx';

`backgroundColor?: string` — Card background color.

`margins?: 'none' | 's' | 'm'` — Space between the image and the card borders.
`margins?: 's' | 'm'` — Space between the image and the card borders.

`direction?: 'direct' | 'reverse'` — Image and Content direction.

Expand Down
4 changes: 4 additions & 0 deletions src/sub-blocks/ImageCard/__stories__/ImageCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default {
title: 'Components/Cards/ImageCard',
args: data.default.content,
argTypes: {
margins: {
control: {type: 'radio'},
options: [undefined, 's', 'm'],
},
backgroundColor: {
control: {type: 'color'},
},
Expand Down
4 changes: 1 addition & 3 deletions src/sub-blocks/ImageCard/__stories__/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
"title": "Tell a story and build a narrative",
"text": "We are all storytellers. Stories are a powerful way to communicate ideas and share information. The right story can lead to a better understanding of a situation, make us laugh, or even inspire us to do something in the future.",
"image": "/story-assets/img_8-12_light.png",
"margins": "none",
"direction": "direct",
"border": "shadow"
}
},
"margins": {
"none": {
"margins": "none",
"title": "margins: 'none'"
"title": "Default"
},
"small": {
"margins": "s",
Expand Down
2 changes: 1 addition & 1 deletion src/sub-blocks/ImageCard/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const ImageCard = {
},
margins: {
type: 'string',
enum: ['none', 's', 'm'],
enum: ['s', 'm'],
},
backgroundColor: {
type: 'string',
Expand Down

0 comments on commit 676e3e9

Please sign in to comment.