-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Merge pull request #24 from fayez-baig/component/image
fix: image-component
- Loading branch information
Showing
4 changed files
with
130 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import { Story } from '@storybook/react/types-6-0'; | ||
import Image from './Image'; | ||
import { ImageProps } from './types'; | ||
|
||
const ImageSize = [ | ||
'16x16', | ||
'24x24', | ||
'32x32', | ||
'48x48', | ||
'64x64', | ||
'96x96', | ||
'128x128', | ||
'square', | ||
'1by1', | ||
'5by4', | ||
'4by3', | ||
'3by2', | ||
'16by9', | ||
'2by1', | ||
'3by1', | ||
'4by5', | ||
'3by4', | ||
'2by3', | ||
'3by5', | ||
'9by16', | ||
'1by2', | ||
'1by3', | ||
'fullwidth' | ||
]; | ||
export default { | ||
argTypes: { | ||
alt: { | ||
control: { | ||
type: 'text' | ||
} | ||
}, | ||
|
||
imageSize: { | ||
control: { | ||
options: ImageSize, | ||
type: 'select' | ||
} | ||
}, | ||
isRounded: { | ||
control: { | ||
type: 'boolean' | ||
} | ||
} | ||
}, | ||
component: Image, | ||
title: 'Elements/Image' | ||
}; | ||
|
||
const defaultImageTemplate: Story<ImageProps> = args => <Image {...args} />; | ||
|
||
export const Default = defaultImageTemplate.bind({}); | ||
|
||
Default.args = { | ||
alt: 'alt-text', | ||
imageSize: '128x128', | ||
src: 'https://bulma.io/images/placeholders/128x128.png' | ||
}; |
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,29 @@ | ||
import React from 'react'; | ||
import { ImageProps, defaultProps } from './types'; | ||
import { getStyles } from '../../styles/getStyles'; | ||
|
||
const Image: React.FC<ImageProps> = ({ | ||
isRounded, | ||
imageSize, | ||
alt, | ||
...otherImageProps | ||
}) => { | ||
let imageClassesStr = 'image,'; | ||
imageSize && (imageClassesStr += `is-${imageSize},`); | ||
|
||
const classes = getStyles(imageClassesStr.split(',')); | ||
|
||
return ( | ||
<figure className={classes}> | ||
<img | ||
className={isRounded ? 'is-rounded' : ''} | ||
alt={alt} | ||
{...otherImageProps} | ||
/> | ||
</figure> | ||
); | ||
}; | ||
|
||
Image.defaultProps = defaultProps; | ||
|
||
export default 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,36 @@ | ||
type Size = | ||
| '16x16' | ||
| '24x24' | ||
| '32x32' | ||
| '48x48' | ||
| '64x64' | ||
| '96x96' | ||
| '128x128' | ||
| 'square' | ||
| '1by1' | ||
| '5by4' | ||
| '4by3' | ||
| '3by2' | ||
| '16by9' | ||
| '2by1' | ||
| '3by1' | ||
| '4by5' | ||
| '3by4' | ||
| '2by3' | ||
| '3by5' | ||
| '9by16' | ||
| '1by2' | ||
| '1by3' | ||
| 'fullwidth'; | ||
export interface ImageProps { | ||
alt?: string; | ||
imageSize?: Size; | ||
isRounded?: boolean; | ||
src: string; | ||
} | ||
|
||
export const defaultProps: ImageProps = { | ||
alt: 'alt-text', | ||
imageSize: '128x128', | ||
src: 'https://bulma.io/images/placeholders/64x64.png' | ||
}; |
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