-
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.
- Loading branch information
1 parent
cd0ee7d
commit 8e8de23
Showing
13 changed files
with
269 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
@import '../../../styles/variables.scss'; | ||
@import '../../../styles/mixins'; | ||
|
||
$block: '.#{$ns}image-card'; | ||
|
||
$paddingS: 4px; | ||
|
||
#{$block} { | ||
@include card(); | ||
border-radius: $indentSM; | ||
|
||
&__content { | ||
padding: $indentSM $indentM $indentM $indentM; | ||
} | ||
|
||
$image: #{&}__image; | ||
|
||
#{$image} { | ||
&_inner { | ||
width: 100%; | ||
display: block; | ||
} | ||
|
||
&_margins { | ||
&_s { | ||
padding: $paddingS; | ||
|
||
#{$image}_inner { | ||
border-radius: $indentS; | ||
} | ||
} | ||
|
||
&_m { | ||
padding: $indentM; | ||
} | ||
} | ||
} | ||
|
||
&_with-content { | ||
#{$image}_direction_direct { | ||
padding-bottom: 0; | ||
} | ||
|
||
#{$image}_direction_reverse { | ||
padding-top: 0; | ||
} | ||
} | ||
} |
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,63 @@ | ||
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, | ||
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 = () => { | ||
const imageProps = getMediaImage(image); | ||
return ( | ||
<div className={b('image', {margins, direction})}> | ||
<Image className={b('image_inner')} {...imageProps} /> | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className={b({border, 'with-content': hasContent})} style={{backgroundColor}}> | ||
{direction === ImageCardDirection.Direct && ( | ||
<React.Fragment> | ||
{renderImage()} | ||
{renderContent()} | ||
</React.Fragment> | ||
)} | ||
{direction === ImageCardDirection.Reverse && ( | ||
<React.Fragment> | ||
{renderContent()} | ||
{renderImage()} | ||
</React.Fragment> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ImageCard; |
47 changes: 47 additions & 0 deletions
47
src/sub-blocks/ImageCard/__stories__/ImageCard.stories.tsx
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,47 @@ | ||
import React from 'react'; | ||
|
||
import {Meta, StoryFn} from '@storybook/react'; | ||
|
||
import {ImageCardProps} from '../../../models'; | ||
import ImageCard from '../ImageCard'; | ||
|
||
import data from './data.json'; | ||
|
||
export default { | ||
component: ImageCard, | ||
title: 'Components/Cards/ImageCard', | ||
args: data.default.content, | ||
argTypes: { | ||
backgroundColor: { | ||
control: {type: 'color'}, | ||
}, | ||
}, | ||
} as Meta; | ||
|
||
const DefaultTemplate: StoryFn<ImageCardProps> = (args) => ( | ||
<div style={{width: 400, margin: 20}}> | ||
<ImageCard {...args} /> | ||
</div> | ||
); | ||
|
||
const MultipleTemplate: StoryFn<ImageCardProps> = (args) => ( | ||
<div style={{display: 'flex', flexWrap: 'wrap', flexDirection: 'row'}}> | ||
<div style={{width: 400, margin: 20}}> | ||
<ImageCard {...args} {...(data.margins.none as Partial<ImageCardProps>)} /> | ||
</div> | ||
<div style={{width: 400, margin: 20}}> | ||
<ImageCard {...args} {...(data.margins.small as Partial<ImageCardProps>)} /> | ||
</div> | ||
<div style={{width: 400, margin: 20}}> | ||
<ImageCard {...args} {...(data.margins.medium as Partial<ImageCardProps>)} /> | ||
</div> | ||
</div> | ||
); | ||
|
||
export const Default = DefaultTemplate.bind({}); | ||
export const Margins = MultipleTemplate.bind({}); | ||
export const DirectionReverse = MultipleTemplate.bind({}); | ||
export const BackgroundColor = MultipleTemplate.bind({}); | ||
|
||
DirectionReverse.args = {direction: 'reverse'} as Partial<ImageCardProps>; | ||
BackgroundColor.args = {...data.backgroundColor.content}; |
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,36 @@ | ||
{ | ||
"default": { | ||
"content": { | ||
"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'" | ||
}, | ||
"small": { | ||
"margins": "s", | ||
"title": "margins: 's'" | ||
}, | ||
"medium": { | ||
"margins": "m", | ||
"title": "margins: 'm'" | ||
} | ||
}, | ||
"direction": { | ||
"content": { | ||
"direction": "reverse" | ||
} | ||
}, | ||
"backgroundColor": { | ||
"content": { | ||
"backgroundColor": "#ccf0d2" | ||
} | ||
} | ||
} |
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,31 @@ | ||
import pick from 'lodash/pick'; | ||
|
||
import {BaseProps, CardBase} from '../../schema/validators/common'; | ||
import {ImageProps} from '../../schema/validators/components'; | ||
import {ContentBase} from '../Content/schema'; | ||
|
||
const ImageCardBlockContentProps = pick(ContentBase, ['title', 'text']); | ||
|
||
export const ImageCard = { | ||
'image-card': { | ||
additionalProperties: false, | ||
required: ['image'], | ||
properties: { | ||
...BaseProps, | ||
...CardBase, | ||
...ImageCardBlockContentProps, | ||
image: ImageProps, | ||
direction: { | ||
type: 'string', | ||
enum: ['direct', 'reverse'], | ||
}, | ||
margins: { | ||
type: 'string', | ||
enum: ['none', 's', 'm'], | ||
}, | ||
backgroundColor: { | ||
type: 'string', | ||
}, | ||
}, | ||
}, | ||
}; |
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