Skip to content

Commit

Permalink
Merge cdf9fee into 754ba6a
Browse files Browse the repository at this point in the history
  • Loading branch information
akinyeleolat authored Jul 10, 2019
2 parents 754ba6a + cdf9fee commit 0d15711
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 7 deletions.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@
"scripts": {
"test": "jest --coverage",
"coveralls": "cat ./coverage/lcov.info | node node_modules/.bin/coveralls",
"heroku-postbuild": "npm run build",
"build": "webpack --env.mode production",
"start": "webpack-dev-server --env.mode development --open",
"test:dev": "jest src --watch",
"heroku-postbuild": "npm run build:client",
"build:client": "webpack --env.mode production",
"start:client": "webpack-dev-server --env.mode development --open",
"start":"node app.js",
"test:client": "jest src --watch",
"styleguide": "styleguidist server",
"styleguide:build": "styleguidist build"
},
Expand Down
63 changes: 63 additions & 0 deletions src/components/UI/atoms/Image/Image.jsx
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;
118 changes: 118 additions & 0 deletions src/components/UI/atoms/Image/Image.md
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'/>
```
60 changes: 60 additions & 0 deletions src/components/UI/atoms/Image/Image.spec.js
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();
});
});
Binary file added src/img/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions src/styles/variables/border.js
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;
4 changes: 3 additions & 1 deletion src/styles/variables/mainTheme.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import spacing from './spacing';
import { fontSizes, fontWeights } from './fonts';
import { buttonColors, textColors, backgroundColors } from './colorPalette';
import borderRadius from './border';
import width from './width';
import { borderRadius } from './border';
import { boxShadows } from './shadows';

export default {
spacing,
Expand All @@ -13,4 +14,5 @@ export default {
backgroundColors,
borderRadius,
width,
boxShadows,
};
7 changes: 7 additions & 0 deletions src/styles/variables/shadows.js
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;
1 change: 1 addition & 0 deletions webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module.exports = {
'<components>': path.resolve(__dirname, '../src/components'),
'<core>': path.resolve(__dirname, '../src/core'),
'<atoms>': path.resolve(__dirname, '../src/components/UI/atoms'),
'<image>':path.resolve(__dirname,'../src/img'),
},
extensions: [' ', '.js', '.jsx'],
},
Expand Down

0 comments on commit 0d15711

Please sign in to comment.