-
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
11 changed files
with
234 additions
and
13,549 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,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; |
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,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" | ||
/> | ||
``` |
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,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 | ||
`); | ||
}); | ||
}); |
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,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; |
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,11 @@ | ||
export const icons = { | ||
search: 'Search', | ||
starEmpty: 'StarEmpty', | ||
starFull: 'StarFull', | ||
}; | ||
|
||
export const iconSizes = { | ||
normal: '3.0rem', | ||
medium: '4.8rem', | ||
big: '8.0rem', | ||
}; |
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