-
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.
- Loading branch information
Showing
9 changed files
with
262 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styled from 'styled-components'; | ||
import { borderRadius } from '<variables>/border'; | ||
import { boxShadows } from '<variables>/shadows'; | ||
|
||
/** | ||
* @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} shadowType - shadowType | ||
* @prop {boolean} hasBorder - border | ||
* @prop {string} borderRadiusType - borderRadiusType | ||
* @return {component} Image | ||
*/ | ||
|
||
const Image = ( | ||
{ | ||
ImageUrl, altText, width, height, shadowType, borderRadiusType, hasBorder, | ||
}, | ||
) => { | ||
return <Image.Container | ||
src={ImageUrl} | ||
alt={altText} | ||
width={width} | ||
height={height} | ||
shadowType={shadowType} | ||
borderRadiusType={borderRadiusType} | ||
hasBorder={hasBorder}/>; | ||
}; | ||
|
||
Image.Container = styled.img` | ||
${({ | ||
width, | ||
height, | ||
shadowType, | ||
borderRadiusType, | ||
hasBorder, | ||
theme, | ||
}) => { | ||
return ` | ||
width: ${width} || '100%'; | ||
min-height: ${height} || '100%'; | ||
box-shadow:${theme.boxShadows[shadowType]}; | ||
border: ${hasBorder === true ? ('1px solid #ddd') : 'none'}; | ||
border-radius:${theme.borderRadius[borderRadiusType]}; | ||
`; | ||
}}`; | ||
|
||
Image.propTypes = { | ||
ImageUrl: PropTypes.string.isRequired, | ||
altText: PropTypes.string, | ||
width: PropTypes.string, | ||
height: PropTypes.string, | ||
shadowType: PropTypes.oneOf(Object.keys(boxShadows)), | ||
hasBorder: PropTypes.bool, | ||
borderRadiusType: PropTypes.oneOf(Object.keys(borderRadius)), | ||
}; | ||
|
||
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,118 @@ | ||
Image Default: | ||
|
||
```jsx | ||
<Image ImageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png'/> | ||
``` | ||
|
||
Image with sepcified width | ||
|
||
```jsx | ||
<Image ImageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' width='50%'/> | ||
``` | ||
|
||
Image with sepcified height | ||
|
||
```jsx | ||
<Image ImageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' 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%' | ||
shadowType='image' | ||
hasBorder='true' | ||
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%' | ||
shadowType='image' | ||
hasBorder='true' | ||
borderRadiusType='noRadius'/> | ||
``` | ||
|
||
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%' | ||
shadowType='image' | ||
hasBorder='true' | ||
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%' | ||
shadowType='image' | ||
hasBorder='true' | ||
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' | ||
shadowType='image' | ||
hasBorder='true' | ||
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%' | ||
shadowType='none' | ||
hasBorder='true'/> | ||
``` | ||
|
||
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%' | ||
shadowType='none'/> | ||
``` | ||
|
||
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' | ||
shadowType='icon' | ||
hasBorder='true'/> | ||
``` | ||
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%' | ||
shadowType='image' | ||
hasBorder='true'/> | ||
``` |
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,60 @@ | ||
/* 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: 'https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png', | ||
width: '50%', | ||
height: '50%', | ||
altText: 'welcome', | ||
shadowType: 'image', | ||
hasBorder: true, | ||
borderRadiusType: 'fullRadius', | ||
}; | ||
|
||
|
||
describe('Image', () => { | ||
it('should render the Image component with default prop', () => { | ||
const { container } = render(<Image {...defaultProps}/>); | ||
expect(container).toBeTruthy(); | ||
}); | ||
|
||
it('should render the Image component', () => { | ||
const { container } = render( | ||
<Image | ||
ImageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
hasBorder={true} | ||
/>, | ||
); | ||
|
||
expect(container).toBeTruthy(); | ||
}); | ||
|
||
it('should render Image component and return alt Text', () => { | ||
const { getByAltText } = render( | ||
<Image | ||
ImageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
hasBorder={true} | ||
/>, | ||
); | ||
|
||
expect(getByAltText('welcome')).toBeTruthy(); | ||
}); | ||
|
||
it('should render Image component with no border', () => { | ||
const { container } = render( | ||
<Image | ||
ImageUrl='https://assets-ouch.icons8.com/preview/501/57c82ec0-5e6d-423e-b594-5d93a5f5f44b.png' | ||
altText='welcome' | ||
/>, | ||
); | ||
|
||
expect(container).toBeTruthy(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
const borderRadius = { | ||
edgeRadius: '4rem', | ||
export const borderRadius = { | ||
fullRadius: '100%', | ||
partialRadius: '50%', | ||
noRadius: '0%', | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const boxShadows = { | ||
icon: '0px 4px 1px rgba(0, 0, 0, 0.1)', | ||
image: '0px 4px 10px rgba(0, 0, 0, 0.25)', | ||
none: '', | ||
}; | ||
|
||
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