-
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.
feat(image): update image component, docs and stories. Remove unecess…
…ary APIs remove unecessary APIs, add support for `imageAlt`, `loading` and `fit` props BREAKING CHANGE: `imageURL` prop is now renamed to `imageUrl`. This is simply a name change but the functionality remains the same. `Width` prop has been removed and deprecated. Setting the image width should be done with the default image HTML width attribute "resolves #19", "resolves #17".
- Loading branch information
1 parent
9b34fd8
commit 7429c75
Showing
4 changed files
with
69 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import React from 'react'; | ||
import { Image } from '.'; | ||
import { Image, ImageProps } from '.'; | ||
import { Story, Meta } from '@storybook/react/types-6-0'; | ||
|
||
export default { | ||
title: 'Image', | ||
}; | ||
title: 'Components/Image', | ||
component: Image, | ||
} as Meta; | ||
|
||
export const Primary = () => ( | ||
<Image imageURL='https://source.unsplash.com/200x200/?beanie' width={100} /> | ||
); | ||
const Template: Story<ImageProps> = (args) => <Image {...args} />; | ||
|
||
// Base default button | ||
export const Base = Template.bind({}); |
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 |
---|---|---|
@@ -1,21 +1,51 @@ | ||
import * as React from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
export interface ImageProps { | ||
width?: number; | ||
imageURL?: string; | ||
interface StyleProps extends React.ImgHTMLAttributes<HTMLImageElement> { | ||
/* Image source */ | ||
imageUrl?: string; | ||
|
||
/* Image description */ | ||
imageAlt?: string; | ||
|
||
/* Control if loading the image should be deferred when its off the screen */ | ||
loading?: 'eager' | 'lazy'; | ||
|
||
/* Set the object-fit property of the image */ | ||
fit?: 'fill' | 'contain' | 'cover' | 'none' | 'scale-down'; | ||
} | ||
|
||
export type ImageProps = StyleProps; | ||
|
||
const StyledImage = styled.img<Partial<ImageProps>>` | ||
width: ${(props) => props.width}%; | ||
width: 100%; | ||
display: block; | ||
object-fit: cover; | ||
object-fit: ${(props) => props.fit}; | ||
`; | ||
|
||
export const Image: React.FC<ImageProps> = ({ width = 100, imageURL }) => { | ||
return <StyledImage src={imageURL} width={width} />; | ||
export const Image: React.FC<ImageProps> = ({ | ||
imageUrl, | ||
imageAlt, | ||
loading, | ||
fit, | ||
...rest | ||
}) => { | ||
return ( | ||
<StyledImage | ||
src={imageUrl} | ||
alt={imageAlt} | ||
loading={loading} | ||
fit={fit} | ||
{...rest} | ||
/> | ||
); | ||
}; | ||
|
||
Image.defaultProps = {}; | ||
Image.defaultProps = { | ||
imageUrl: 'https://source.unsplash.com/1600x900/?beanie', | ||
imageAlt: 'Image of person wearing a beanie', | ||
fit: 'cover', | ||
loading: 'lazy', | ||
}; | ||
|
||
Image.displayName = 'ImageComponent'; | ||
Image.displayName = '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,4 @@ | ||
html { | ||
font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, | ||
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; | ||
} |