-
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(component): add Image component (#50)
* feat(component): add image component add new Image component to render images resolves #42 Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com> * docs(storybook): image stories add stories for image component using storybook resolves #42 Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com> * fix(component): fix Image component fix the Image component with new structure and props resolves #42 Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com> * fix(component): fix Image component - Fix Image component with updated structure and props - Fix Section and Column props - Update stories for Image component resolves #42 Signed-off-by: Niloy Sikdar <niloysikdar30@gmail.com>
- Loading branch information
1 parent
27dfec5
commit 739f603
Showing
7 changed files
with
148 additions
and
8 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
import { Email } from '../Email/Email'; | ||
import { Section } from '../Section/Section'; | ||
import { Column } from '../Column/Column'; | ||
import { Typography } from '../Typography/Typography'; | ||
import { Image } from './Image'; | ||
import { Divider } from '../Divider/Divider'; | ||
|
||
export default { | ||
component: Image, | ||
} as ComponentMeta<typeof Image>; | ||
|
||
//“template” of how args map to rendering | ||
const Template: ComponentStory<typeof Image> = (args) => ( | ||
<Email> | ||
<Section> | ||
<Column> | ||
<Typography variant="h2" align="center"> | ||
Hello World | ||
</Typography> | ||
</Column> | ||
</Section> | ||
|
||
<Divider /> | ||
|
||
<Section fullWidth={false}> | ||
<Column> | ||
<Image {...args} /> | ||
</Column> | ||
|
||
<Column classes={{ root: { paddingLeft: '20px' } }}> | ||
<Typography variant="h2">This is a random text</Typography> | ||
</Column> | ||
</Section> | ||
</Email> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
|
||
Default.args = { | ||
src: 'https://images.unsplash.com/photo-1453728013993-6d66e9c9123a', | ||
alt: 'This is a random image', | ||
width: '250px', | ||
caption: 'This is a caption', | ||
classes: { | ||
image: { | ||
borderRadius: '10px', | ||
}, | ||
}, | ||
}; |
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,78 @@ | ||
import { CSSProperties } from 'react'; | ||
import { makeStyles } from '../../utils/makeStyles'; | ||
import { sx } from '../../utils/sx'; | ||
import { BaseStyleProp } from '../types'; | ||
|
||
type ImageStyles = | ||
| 'root' | ||
| 'table' | ||
| 'body' | ||
| 'image' | ||
| 'caption' | ||
| 'imageSection' | ||
| 'captionSection' | ||
| 'imageColumn'; | ||
|
||
export interface ImageProps extends BaseStyleProp<ImageStyles> { | ||
src: string; | ||
alt: string; | ||
caption?: string; | ||
width: CSSProperties['width']; | ||
height?: CSSProperties['height']; | ||
captionAlign?: 'left' | 'center' | 'right'; | ||
} | ||
|
||
const useStyles = makeStyles({ | ||
root: { border: '0', display: 'block', outline: 'none' }, | ||
table: { width: 'fit-content', border: '0', verticalAlign: 'top' }, | ||
body: {}, | ||
image: {}, | ||
caption: {}, | ||
imageSection: {}, | ||
captionSection: {}, | ||
imageColumn: {}, | ||
}); | ||
|
||
export const Image = ({ | ||
src, | ||
alt, | ||
caption, | ||
width, | ||
height = 'auto', | ||
classes, | ||
className, | ||
captionAlign = 'center', | ||
}: ImageProps): JSX.Element => { | ||
const styles = useStyles({ classes }); | ||
|
||
return caption ? ( | ||
<table cellPadding="0" cellSpacing="0" role="presentation" style={styles.table}> | ||
<tbody style={styles.body}> | ||
<tr style={styles.imageSection}> | ||
<td style={styles.imageColumn}> | ||
<img | ||
className={className} | ||
height={height} | ||
width={width} | ||
src={src} | ||
alt={alt} | ||
style={sx(styles.root, styles.image)} | ||
/> | ||
</td> | ||
</tr> | ||
<tr style={styles.captionSection}> | ||
<td style={sx(styles.caption, { textAlign: captionAlign })}>{caption}</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
) : ( | ||
<img | ||
className={className} | ||
height={height} | ||
width={width} | ||
src={src} | ||
alt={alt} | ||
style={sx(styles.root, styles.image)} | ||
/> | ||
); | ||
}; |
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 @@ | ||
export { Image, ImageProps } from './Image'; |
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