-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add image card sub-block (#807)
* feat: add image card sub-block
- Loading branch information
1 parent
cd0ee7d
commit 52890dd
Showing
16 changed files
with
370 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
@import '../../../styles/variables.scss'; | ||
@import '../../../styles/mixins'; | ||
|
||
$block: '.#{$ns}image-card'; | ||
|
||
#{$block} { | ||
@include card(); | ||
min-height: 1px; | ||
$image: #{&}__image; | ||
$content: #{&}__content; | ||
|
||
#{$content} { | ||
padding: $indentM; | ||
} | ||
|
||
#{$image} { | ||
&_inner { | ||
width: 100%; | ||
display: block; | ||
|
||
&_radius { | ||
border-radius: $borderRadius; | ||
} | ||
} | ||
|
||
&_margins { | ||
&_s { | ||
padding: 4px; | ||
|
||
#{$image}_inner { | ||
border-radius: calc(#{$borderRadius} - #{$imagePadding}); | ||
} | ||
} | ||
|
||
&_m { | ||
padding: $indentM; | ||
|
||
#{$image}_inner { | ||
border-radius: initial; | ||
} | ||
} | ||
} | ||
} | ||
|
||
&_with-content { | ||
display: flex; | ||
flex-direction: column; | ||
|
||
&#{$block}_direction_direct { | ||
#{$image} { | ||
padding-bottom: 0; | ||
} | ||
|
||
#{$content} { | ||
padding-top: $indentSM; | ||
} | ||
} | ||
|
||
&#{$block}_direction_reverse { | ||
flex-direction: column-reverse; | ||
|
||
#{$image} { | ||
padding-top: 0; | ||
} | ||
|
||
#{$content} { | ||
padding-bottom: $indentSM; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React from 'react'; | ||
|
||
import {Image} from '../../components'; | ||
import {getMediaImage} from '../../components/Media/Image/utils'; | ||
import {ImageCardDirection, ImageCardProps} from '../../models'; | ||
import {block} from '../../utils'; | ||
import Content from '../Content/Content'; | ||
|
||
import './ImageCard.scss'; | ||
|
||
const b = block('image-card'); | ||
|
||
const ImageCard = (props: ImageCardProps) => { | ||
const { | ||
border = 'shadow', | ||
title, | ||
text, | ||
image, | ||
enableImageBorderRadius = false, | ||
direction = ImageCardDirection.Direct, | ||
margins, | ||
backgroundColor, | ||
} = props; | ||
|
||
const hasContent = Boolean(text || title); | ||
const imageProps = getMediaImage(image); | ||
|
||
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> | ||
{hasContent && ( | ||
<div className={b('content')}> | ||
<Content title={title} text={text} colSizes={{all: 12, md: 12}} size="s" /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ImageCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {Meta} from '@storybook/blocks'; | ||
|
||
import {StoryTemplate} from '../../../demo/StoryTemplate.mdx'; | ||
import * as ImageCardStories from './ImageCard.stories.tsx'; | ||
|
||
<Meta of={ImageCardStories} /> | ||
<StoryTemplate> | ||
## Parameters | ||
|
||
`type: "image-card"` | ||
|
||
[`image: string | ImageObjectProps | ReactNode` — ImageProps](?path=/docs/documentation-types--docs#imageobjectprops---image-property). | ||
|
||
`title?: Title | string` — Card title. | ||
|
||
`text?: string` — Card description (with YFM support). | ||
|
||
`border: 'shadow' | 'line' | 'none'` — Select border of the card. | ||
|
||
`backgroundColor?: string` — Card background color. | ||
|
||
`margins?: 's' | 'm'` — Space between the image and the card borders. | ||
|
||
`direction?: 'direct' | 'reverse'` — Image and Content direction. | ||
|
||
`enableImageBorderRadius?: boolean` — Set border-radius for the image. Affects only when `margins='none'`. | ||
|
||
</StoryTemplate> |
Oops, something went wrong.