diff --git a/src/models/constructor-items/sub-blocks.ts b/src/models/constructor-items/sub-blocks.ts index 0fdccbc9e..27b827f6b 100644 --- a/src/models/constructor-items/sub-blocks.ts +++ b/src/models/constructor-items/sub-blocks.ts @@ -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 { @@ -108,6 +113,7 @@ export interface BasicCardProps url: string; icon?: ImageProps; target?: string; + iconPosition?: IconPosition; } export interface BannerCardProps { diff --git a/src/sub-blocks/BasicCard/BasicCard.scss b/src/sub-blocks/BasicCard/BasicCard.scss index 3ac3dafc8..25db2332b 100644 --- a/src/sub-blocks/BasicCard/BasicCard.scss +++ b/src/sub-blocks/BasicCard/BasicCard.scss @@ -4,6 +4,9 @@ $block: '.#{$ns}basic-card'; #{$block} { + $iconSizePositionTop: 32px; + $iconSizePositionLeft: 22px; + @include add-specificity(&) { min-height: auto; } @@ -11,8 +14,35 @@ $block: '.#{$ns}basic-card'; &__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; + } + } } } diff --git a/src/sub-blocks/BasicCard/BasicCard.tsx b/src/sub-blocks/BasicCard/BasicCard.tsx index 4387cee5e..f091a816b 100644 --- a/src/sub-blocks/BasicCard/BasicCard.tsx +++ b/src/sub-blocks/BasicCard/BasicCard.tsx @@ -5,6 +5,7 @@ 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'; @@ -12,22 +13,39 @@ 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 ( - {iconProps && } - +
+ {iconProps && ( + + )} + +
); diff --git a/src/sub-blocks/BasicCard/__stories__/BasicCard.stories.tsx b/src/sub-blocks/BasicCard/__stories__/BasicCard.stories.tsx index 984e138fa..f4f199ea0 100644 --- a/src/sub-blocks/BasicCard/__stories__/BasicCard.stories.tsx +++ b/src/sub-blocks/BasicCard/__stories__/BasicCard.stories.tsx @@ -4,6 +4,7 @@ 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'; @@ -11,6 +12,9 @@ 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', @@ -25,13 +29,19 @@ const DefaultTemplate: StoryFn = (args) => ( const WithIconTemplate: StoryFn = (args) => (
- -
-
- +
- +
); diff --git a/src/sub-blocks/BasicCard/__stories__/data.json b/src/sub-blocks/BasicCard/__stories__/data.json index 36a12d397..7f8981377 100644 --- a/src/sub-blocks/BasicCard/__stories__/data.json +++ b/src/sub-blocks/BasicCard/__stories__/data.json @@ -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", diff --git a/src/sub-blocks/BasicCard/schema.ts b/src/sub-blocks/BasicCard/schema.ts index 7e07b37c0..db208368f 100644 --- a/src/sub-blocks/BasicCard/schema.ts +++ b/src/sub-blocks/BasicCard/schema.ts @@ -22,6 +22,10 @@ export const BasicCard = { type: 'string', enum: ['_blank', '_parent', '_top', '_self'], }, + iconPosition: { + type: 'string', + enum: ['top', 'left'], + }, }, }, };