-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Create image component - Add prop types - Implement prop validation [Finishes #167189243]
- Loading branch information
Oluwatosin, Akinyele
committed
Jul 11, 2019
1 parent
c0e3dc6
commit 7a3c35a
Showing
11 changed files
with
314 additions
and
7 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,85 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styled from 'styled-components'; | ||
import { borderRadius } from '<variables>/border'; | ||
import { boxShadows } from '<variables>/shadows'; | ||
import { borderColors } from '<variables>/colorPalette'; | ||
|
||
/** | ||
* @description - Image Component | ||
* | ||
* @prop {string} width - image width | ||
* @prop {string} height - image height | ||
* @prop {string} imageUrl - image source | ||
* @prop {string} altText - alt text | ||
* @prop {string} boxShadow - shadowType | ||
* @prop {boolean} borderColor- borderColor | ||
* @prop {string} borderRadiusType - borderRadiusType | ||
* @return {component} Image | ||
*/ | ||
|
||
const Image = ( | ||
{ | ||
id, | ||
imageUrl, | ||
altText, | ||
width, | ||
height, | ||
boxShadow, | ||
borderRadiusType, | ||
borderColor, | ||
}, | ||
) => { | ||
return <Image.Container | ||
src={imageUrl} | ||
data-testid={id} | ||
alt={altText} | ||
width={width} | ||
height={height} | ||
boxShadow={boxShadow} | ||
borderRadiusType={borderRadiusType} | ||
borderColor={borderColor} | ||
/>; | ||
}; | ||
|
||
|
||
Image.Container = styled.img` | ||
${({ | ||
width, | ||
height, | ||
boxShadow, | ||
borderRadiusType, | ||
borderColor, | ||
theme, | ||
}) => { | ||
return ` | ||
width: ${width}; | ||
min-height: ${height}; | ||
box-shadow:${theme.boxShadows[boxShadow]}; | ||
border: ${`1px solid ${theme.borderColors[borderColor]}`}; | ||
border-radius:${theme.borderRadius[borderRadiusType]}; | ||
`; | ||
}}`; | ||
|
||
Image.propTypes = { | ||
id: PropTypes.string, | ||
imageUrl: PropTypes.string, | ||
altText: PropTypes.string, | ||
width: PropTypes.string, | ||
height: PropTypes.string, | ||
boxShadow: PropTypes.oneOf(Object.keys(boxShadows)), | ||
borderColor: PropTypes.oneOf(Object.keys(borderColors)), | ||
borderRadiusType: PropTypes.oneOf(Object.keys(borderRadius)), | ||
}; | ||
|
||
Image.defaultProps = { | ||
id: 'mockImage', | ||
width: '100%', | ||
height: '100%', | ||
imageUrl: 'https://via.placeholder.com/150', | ||
altText: 'place holder image', | ||
border: '1px solid #DDDDDD', | ||
boxShadow: '0px 4px 10px #CCCCCC', | ||
}; | ||
|
||
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,151 @@ | ||
Image Default: | ||
|
||
```jsx | ||
<Image/> | ||
``` | ||
|
||
Image with sepcified image url | ||
|
||
```jsx | ||
<Image imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png'/> | ||
``` | ||
|
||
|
||
Image with sepcified width | ||
|
||
```jsx | ||
<Image width='50%'/> | ||
``` | ||
|
||
Image with sepcified height | ||
|
||
```jsx | ||
<Image height='200px'/> | ||
``` | ||
|
||
Image with All attributes | ||
```jsx | ||
<Image | ||
imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
width='50%' | ||
height='50%' | ||
boxShadow='image' | ||
borderColor='lightGrey' | ||
borderRadiusType='fullRadius' | ||
/> | ||
``` | ||
|
||
Image with no border radius | ||
```jsx | ||
<Image | ||
imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
width='50%' | ||
height='50%' | ||
boxShadow='image' | ||
borderColor='lightGrey' | ||
/> | ||
``` | ||
|
||
Image with partial radius | ||
```jsx | ||
<Image | ||
imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
width='50%' | ||
height='50%' | ||
boxShadow='image' | ||
borderColor='lightGrey' | ||
borderRadiusType='partialRadius' | ||
/> | ||
``` | ||
|
||
Image with edge radius | ||
```jsx | ||
<Image | ||
imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
width='50%' | ||
height='50%' | ||
boxShadow='image' | ||
borderColor='lightGrey' | ||
borderRadiusType='edgeRadius' | ||
/> | ||
``` | ||
Image with full radius | ||
```jsx | ||
<Image | ||
imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
width='200px' | ||
height='200px' | ||
boxShadow='image' | ||
borderColor='lightGrey' | ||
borderRadiusType='fullRadius' | ||
/> | ||
``` | ||
|
||
Image with no box shadow | ||
```jsx | ||
<Image | ||
imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
width='50%' | ||
height='50%'/> | ||
``` | ||
|
||
Image with primary border | ||
```jsx | ||
<Image | ||
imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
width='50%' | ||
height='50%' | ||
borderColor='primary' | ||
/> | ||
``` | ||
|
||
Image with grey border | ||
```jsx | ||
<Image | ||
imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
width='50%' | ||
height='50%' | ||
borderColor='lightGrey' | ||
/> | ||
``` | ||
|
||
Image with no border | ||
```jsx | ||
<Image | ||
imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
width='50%' | ||
height='50%' | ||
/> | ||
``` | ||
|
||
Image with icon box shadow | ||
```jsx | ||
<Image | ||
imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
width='58px' | ||
height='58px' | ||
boxShadow='icon' | ||
borderColor='primary' | ||
/> | ||
``` | ||
Image with image box shadow | ||
```jsx | ||
<Image | ||
imageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
width='50%' | ||
height='50%' | ||
boxShadow='image' | ||
borderColor='lightGrey' | ||
/> | ||
``` |
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,58 @@ | ||
/* eslint-disable max-len */ | ||
import React from 'react'; | ||
import { render, cleanup } from '<src>/helpers/testUtils'; | ||
import Image from './Image'; | ||
import 'jest-dom/extend-expect'; | ||
|
||
afterEach(cleanup); | ||
|
||
const defaultProps = { | ||
imageUrl: '', | ||
altText: '', | ||
id: 'mockImage', | ||
}; | ||
|
||
const setUp = (props) => { | ||
const utils = render(<Image {...defaultProps} {...props} />); | ||
return utils; | ||
}; | ||
|
||
describe('Image', () => { | ||
it('should render the Image component with default prop', () => { | ||
const { container } = setUp(); | ||
expect(container).toBeTruthy(); | ||
}); | ||
|
||
it('should render with the Image url props supplied', () => { | ||
const { queryByTestId } = setUp({ imageUrl: 'https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' }); | ||
|
||
|
||
const image = queryByTestId('mockImage'); | ||
|
||
expect(image.getAttribute('src')).toBe('https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png'); | ||
}); | ||
|
||
it('should render the Image component default borderColor', () => { | ||
const { queryByTestId } = setUp({ borderColor: 'primary' }); | ||
const image = queryByTestId('mockImage'); | ||
|
||
expect(image).toHaveStyle(` | ||
border: 1px solid #B02091; | ||
`); | ||
}); | ||
|
||
it('should render Image component and return alt Text', () => { | ||
const { getByAltText } = setUp({ altText: 'pizza' }); | ||
|
||
expect(getByAltText('pizza')).toBeTruthy(); | ||
}); | ||
|
||
it('should render Image component with image box shadow', () => { | ||
const { queryByTestId } = setUp({ boxShadow: 'image' }); | ||
|
||
const image = queryByTestId('mockImage'); | ||
expect(image).toHaveStyle(` | ||
box-shadow: 0px 4px 10px #CCCCCC; | ||
`); | ||
}); | ||
}); |
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,5 +1,7 @@ | ||
const borderRadius = { | ||
edgeRadius: '4rem', | ||
export const borderRadius = { | ||
fullRadius: '100%', | ||
partialRadius: '50%', | ||
edgeRadius: '3%', | ||
}; | ||
|
||
export default borderRadius; |
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,6 @@ | ||
export const boxShadows = { | ||
icon: '0px 4px 1px #C0C0C0', | ||
image: '0px 4px 10px #CCCCCC', | ||
}; | ||
|
||
export default boxShadows; |
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