-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add image card sub-block #807
Changes from 4 commits
8e8de23
c275709
12b0d29
1dc25a9
676e3e9
8b66b50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
@import '../../../styles/variables.scss'; | ||
@import '../../../styles/mixins'; | ||
|
||
$block: '.#{$ns}image-card'; | ||
|
||
$paddingS: 4px; | ||
|
||
#{$block} { | ||
@include card(); | ||
min-height: 1px; | ||
$image: #{&}__image; | ||
$content: #{&}__content; | ||
|
||
#{$content} { | ||
padding: $indentM; | ||
} | ||
|
||
#{$image} { | ||
&_inner { | ||
width: 100%; | ||
display: block; | ||
} | ||
|
||
&_margins { | ||
&_none { | ||
#{$image}_inner#{$image}_inner_radius { | ||
border-radius: $borderRadius; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add empty line |
||
&_s { | ||
padding: $paddingS; | ||
|
||
#{$image}_inner { | ||
border-radius: calc(#{$borderRadius} - #{$imagePadding}); | ||
} | ||
} | ||
|
||
&_m { | ||
padding: $indentM; | ||
} | ||
} | ||
} | ||
|
||
&_with-content { | ||
&#{$block}_direction_direct { | ||
#{$image} { | ||
padding-bottom: 0; | ||
} | ||
|
||
#{$content} { | ||
padding-top: $indentSM; | ||
} | ||
} | ||
|
||
&#{$block}_direction_reverse { | ||
#{$image} { | ||
padding-top: 0; | ||
} | ||
|
||
#{$content} { | ||
padding-bottom: $indentSM; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
|
||
import {Image} from '../../components'; | ||
import {getMediaImage} from '../../components/Media/Image/utils'; | ||
import {ImageCardDirection, ImageCardMargins, 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 = ImageCardMargins.None, | ||
backgroundColor, | ||
} = props; | ||
|
||
const hasContent = Boolean(text || title); | ||
|
||
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 = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and when we change directions with style we dont need this functions, we'll render this code immediately in return() |
||
const imageProps = getMediaImage(image); | ||
return ( | ||
<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 && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to change the direction with style, not with code.
|
||
<React.Fragment> | ||
{renderImage()} | ||
{renderContent()} | ||
</React.Fragment> | ||
)} | ||
{direction === ImageCardDirection.Reverse && ( | ||
<React.Fragment> | ||
{renderContent()} | ||
{renderImage()} | ||
</React.Fragment> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ImageCard; |
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?: 'none' | '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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need the
none
parameter? We can just have a default state (now isnone
) and change it somehow when there is a demand fors
orm