Skip to content

Commit

Permalink
feat: add an icon position on the left side of a basic-card (#481)
Browse files Browse the repository at this point in the history
* feat: add an icon position on the left side of a basic-card
  • Loading branch information
niktverd authored Aug 8, 2023
1 parent ef5f194 commit 83617c9
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/models/constructor-items/sub-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export enum SubBlockType {
Card = 'card',
}

export enum IconPosition {
Top = 'top',
Left = 'left',
}

export const SubBlockTypes = Object.values(SubBlockType);

export interface DividerProps {
Expand Down Expand Up @@ -108,6 +113,7 @@ export interface BasicCardProps
url: string;
icon?: ImageProps;
target?: string;
iconPosition?: IconPosition;
}

export interface BannerCardProps {
Expand Down
32 changes: 31 additions & 1 deletion src/sub-blocks/BasicCard/BasicCard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,45 @@
$block: '.#{$ns}basic-card';

#{$block} {
$iconSizePositionTop: 32px;
$iconSizePositionLeft: 22px;

@include add-specificity(&) {
min-height: auto;
}

&__icon {
max-width: 100%;
margin-bottom: $indentXXS;
height: 32px;
height: $iconSizePositionTop;
object-fit: contain;
display: block;

&_icon-position {
&_left {
height: $iconSizePositionLeft;
width: $iconSizePositionLeft;
margin: 1px $indentXXS 1px 0px;
}
}
}

&__content {
display: flex;
flex-direction: column;

&_icon-position {
&_left {
flex-direction: row;
}
}
}

&_content-layout {
&_left {
@include add-specificity(&) {
flex: 1 0 0;
}
}
}
}
40 changes: 29 additions & 11 deletions src/sub-blocks/BasicCard/BasicCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,47 @@ import CardBase from '../../components/CardBase/CardBase';
import Image from '../../components/Image/Image';
import {getMediaImage} from '../../components/Media/Image/utils';
import {BasicCardProps} from '../../models';
import {IconPosition} from '../../models/constructor-items/sub-blocks';
import {block} from '../../utils';

import './BasicCard.scss';

const b = block('basic-card');

const BasicCard = (props: BasicCardProps) => {
const {title, text, icon, additionalInfo, links, buttons, ...cardParams} = props;
const {
title,
text,
icon,
additionalInfo,
links,
buttons,
iconPosition = IconPosition.Top,
...cardParams
} = props;
const iconProps = icon && getMediaImage(icon);

return (
<CardBase className={b()} {...cardParams}>
<CardBase.Content>
{iconProps && <Image {...iconProps} className={b('icon')} />}
<Content
title={title}
text={text}
additionalInfo={additionalInfo}
links={links}
buttons={buttons}
colSizes={{all: 12, md: 12}}
size="s"
/>
<div className={b('content', {['icon-position']: iconPosition})}>
{iconProps && (
<Image
{...iconProps}
className={b('icon', {['icon-position']: iconPosition})}
/>
)}
<Content
title={title}
text={text}
additionalInfo={additionalInfo}
links={links}
buttons={buttons}
colSizes={{all: 12, md: 12}}
size="s"
className={b({['content-layout']: iconPosition})}
/>
</div>
</CardBase.Content>
</CardBase>
);
Expand Down
20 changes: 15 additions & 5 deletions src/sub-blocks/BasicCard/__stories__/BasicCard.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import yfm from '@doc-tools/transform';
import {Meta, StoryFn} from '@storybook/react';

import {BasicCardProps} from '../../../models';
import {IconPosition} from '../../../models/constructor-items/sub-blocks';
import BasicCard from '../BasicCard';

import data from './data.json';

const getCardWithBorderTitle = (border: string) =>
data.withBorder.title.replace('{{border}}', border);

const getCardWithIconTitle = (border: string) =>
data.withIcon.title.replace('{{position}}', border);

export default {
component: BasicCard,
title: 'Components/Cards/BasicCard',
Expand All @@ -25,13 +29,19 @@ const DefaultTemplate: StoryFn<BasicCardProps> = (args) => (
const WithIconTemplate: StoryFn<BasicCardProps> = (args) => (
<div style={{display: 'flex'}}>
<div style={{maxWidth: '400px', padding: '0 8px'}}>
<BasicCard {...args} icon={data.withIcon.icons[0]} />
</div>
<div style={{maxWidth: '400px', padding: '0 8px'}}>
<BasicCard {...args} icon={data.withIcon.icons[1]} />
<BasicCard
{...args}
icon={data.withIcon.icons[0]}
title={getCardWithIconTitle('top')}
/>
</div>
<div style={{maxWidth: '400px', padding: '0 8px'}}>
<BasicCard {...args} icon={data.withIcon.icons[2]} />
<BasicCard
{...args}
icon={data.withIcon.icons[1]}
iconPosition={IconPosition.Left}
title={getCardWithIconTitle('left')}
/>
</div>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions src/sub-blocks/BasicCard/__stories__/data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"withIcon": {
"title": "Card with icon on {{position}}",
"icons": [
"https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_1_light.svg",
"https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/icon_2_light.svg",
Expand Down
4 changes: 4 additions & 0 deletions src/sub-blocks/BasicCard/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const BasicCard = {
type: 'string',
enum: ['_blank', '_parent', '_top', '_self'],
},
iconPosition: {
type: 'string',
enum: ['top', 'left'],
},
},
},
};

0 comments on commit 83617c9

Please sign in to comment.