Skip to content

Commit

Permalink
Merge e1729f9 into 708de67
Browse files Browse the repository at this point in the history
  • Loading branch information
Sojisoyoye committed Jul 12, 2019
2 parents 708de67 + e1729f9 commit 5f8a28e
Show file tree
Hide file tree
Showing 11 changed files with 1,247 additions and 1,359 deletions.
2,368 changes: 1,013 additions & 1,355 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"^<src>/(.*)$": "<rootDir>/src/$1",
"^<variables>/(.*)$": "<rootDir>/src/styles/variables/$1",
"^<pages>/(.*)$": "<rootDir>/src/components/pages/$1",
"^<core>/(.*)$": "<rootDir>/src/core/$1"
"^<core>/(.*)$": "<rootDir>/src/core/$1",
"^<fixtures>/(.*)$": "<rootDir>/src/fixtures/$1"
},
"coverageReporters": [
"json-summary",
Expand Down Expand Up @@ -101,6 +102,7 @@
"styled-components": "^4.3.2",
"webpack": "^4.29.6",
"webpack-cli": "^3.2.3",
"webpack-merge": "^4.2.1"
"webpack-merge": "^4.2.1",
"styled-icons": "^8.1.0"
}
}
83 changes: 83 additions & 0 deletions src/components/UI/atoms/Icon/Icon.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import * as iconSource from 'styled-icons/icomoon';
import { iconSizes, icons } from '<variables>/icons';
import { iconColors } from '<variables>/colorPalette';
import spacing from '<variables>/spacing';


/**
* @description - Icon Component
*
* @prop {string} color - color
* @prop {string} height - height
* @prop {string} width - width
* @prop {string} display - display
* @prop {string} margin - margin
* @prop {string} icon - icon
*
* @return {component} Icon
*/
const Icon = ({
id,
color,
height,
width,
display,
margin,
iconName,
}) => {
const IconType = iconSource[icons[iconName]];
return (
<Icon.Container
data-testid={id}
color={color}
height={height}
width={width}
display={display}
margin={margin}
iconName={iconName}
>
<IconType />
</Icon.Container>);
};

Icon.propTypes = {
children: PropTypes.node,
id: PropTypes.string,
color: PropTypes.oneOf(Object.keys(iconColors)),
iconName: PropTypes.oneOf(Object.keys(icons)).isRequired,
height: PropTypes.oneOf(Object.keys(iconSizes)),
width: PropTypes.oneOf(Object.keys(iconSizes)),
display: PropTypes.oneOf(['block', 'inline', 'inline-block', 'none']),
margin: PropTypes.oneOf(Object.keys(spacing)),
};

Icon.defaultProps = {
iconName: 'search',
height: 'normal',
width: 'normal',
display: 'block',
margin: 'md',
color: 'primary',
};

Icon.Container = styled.svg`
${({
color,
height,
width,
display,
margin,
theme,
}) => `
color: ${theme.iconColors[color]};
height: ${theme.iconSizes[height]};
width: ${theme.iconSizes[width]};
display: ${display};
margin: ${theme.spacing[margin]};
`}
`;

export default Icon;
40 changes: 40 additions & 0 deletions src/components/UI/atoms/Icon/Icon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Icon Default:

```jsx
<Icon />
```

Icon with all attributes
```jsx
<Icon
height="normal"
width="normal"
color="black"
display="block"
margin="md"
icon="starEmpty"
/>
```

Icon with size
```jsx
<Icon
height="medium"
width="medium"
/>
```

Icon with color
```jsx
<Icon
color="gold"
icon="starFull"
/>
```

Icon with margin
```jsx
<Icon
margin="zero"
/>
```
71 changes: 71 additions & 0 deletions src/components/UI/atoms/Icon/Icon.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import React from 'react';
import { render, cleanup } from '<src>/helpers/testUtils';
import mockIcon from '<fixtures>/icons/mockIcon';
import Icon from './Icon.jsx';
import '@testing-library/jest-dom/extend-expect';

afterEach(cleanup);

jest.mock('<fixtures>/icons/Star.svg', () => jest.fn(() => mockIcon));

const defaultProps = {
icon: 'search',
id: 'mockIcon',
};

const setup = (props) => {
const utils = render(<Icon {...defaultProps} {...props} />);

return {
...utils,
};
};


describe('Icon', () => {
it('should render the Icon component with default prop', () => {
const { container } = setup();

expect(container).toBeTruthy();
});

it('should render the Icon with height', () => {
const { queryByTestId } = setup({ height: 'medium' });

const icon = queryByTestId('mockIcon');

expect(icon).toHaveStyle(`
height: medium
`);
});

it('should render the Icon with width', () => {
const { queryByTestId } = setup({ width: 'medium' });

const icon = queryByTestId('mockIcon');

expect(icon).toHaveStyle(`
width: medium
`);
});

it('should render the Icon with display', () => {
const { queryByTestId } = setup({ display: 'inline' });

const icon = queryByTestId('mockIcon');

expect(icon).toHaveStyle(`
display: inline
`);
});

it('should render the Icon with color', () => {
const { queryByTestId } = setup({ color: 'primary' });

const icon = queryByTestId('mockIcon');

expect(icon).toHaveStyle(`
color: primary
`);
});
});
1 change: 0 additions & 1 deletion src/components/UI/atoms/Title/Title.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ Title.propTypes = {
Title.defaultProps = {
fontSize: 'normal',
fontWeight: 'bold',
paddingBottom: 'md',
display: 'block',
};

Expand Down
3 changes: 3 additions & 0 deletions src/fixtures/icons/Star.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/fixtures/icons/mockIcon.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';

const mockIcon = (
<svg width="16" height="16" xmlns="http://www.w3.org/2000/svg">
<path
d="M6.06 8l4.47 4.47a.75.75 0 0 1-1.06 1.06l-5-5a.75.75
0 0 1 0-1.06l5-5a.75.75 0 0 1 1.06 1.06L6.06 8z"
fill="#000" fillRule="nonzero"/>
</svg>
);

export default mockIcon;
6 changes: 6 additions & 0 deletions src/styles/variables/colorPalette.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ export const borderColors = {
black: '#191919',
lightGrey: '#DDDDDD',
};

export const iconColors = {
primary: '#B02091',
gold: '#FFCC4A',
black: '#191919',
};
11 changes: 11 additions & 0 deletions src/styles/variables/icons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const icons = {
search: 'Search',
starEmpty: 'StarEmpty',
starFull: 'StarFull',
};

export const iconSizes = {
normal: '3.0rem',
medium: '4.8rem',
big: '8.0rem',
};
5 changes: 4 additions & 1 deletion src/styles/variables/mainTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import {
textColors,
backgroundColors,
borderColors,
iconColors,
} from './colorPalette';
import borderRadius from './border';
import width from './width';
import { boxShadows } from './shadows';
import { iconSizes } from './icons';

export default {
spacing,
fontSizes,
iconSizes,
fontWeights,
buttonColors,
textColors,
Expand All @@ -21,5 +24,5 @@ export default {
width,
boxShadows,
borderColors,
boxShadows,
iconColors,
};

0 comments on commit 5f8a28e

Please sign in to comment.