Skip to content
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(component): add Image component #50

Merged
merged 5 commits into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/components/Image/Image.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ComponentStory, ComponentMeta } from '@storybook/react';

import { Image } from './Image';

export default {
component: Image,
} as ComponentMeta<typeof Image>;

//“template” of how args map to rendering
const Template: ComponentStory<typeof Image> = (args) => (
<table>
<tbody>
<tr>
<Image {...args} />
</tr>
</tbody>
</table>
);

export const Default = Template.bind({});

Default.args = {
src: 'https://images.unsplash.com/photo-1453728013993-6d66e9c9123a',
alt: 'This is a random image',
width: '250px',
style: {
borderRadius: '10px',
},
};
42 changes: 42 additions & 0 deletions src/components/Image/Image.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { CSSProperties } from 'react';

export interface ImageProps {
src: string;
alt: string;
width: string | number;
height?: string | number;
style?: CSSProperties;
align?: 'left' | 'center' | 'right';
}

export const Image = ({
src,
alt,
width,
height = 'auto',
style,
align = 'left',
}: ImageProps): JSX.Element => {
return (
<td
align={align}
style={{
padding: '10px 20px',
wordBreak: 'break-word',
}}
>
<img
height={height}
width={width}
src={src}
alt={alt}
style={{
niloysikdar marked this conversation as resolved.
Show resolved Hide resolved
border: '0',
display: 'block',
outline: 'none',
...style,
}}
/>
</td>
);
};
1 change: 1 addition & 0 deletions src/components/Image/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Image } from './Image';
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './Email';
export * from './Image';