-
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.
feat(tag): add tag row feature (#44)
- add tag row molecule component - add tag row styleguide - write test for tag row component [Finishes #167482351]
- Loading branch information
1 parent
ae8676f
commit 4d4b5f1
Showing
5 changed files
with
154 additions
and
3 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,50 @@ | ||
/* eslint-disable no-use-before-define */ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import FlexContainer from '<atoms>/layouts/FlexContainer/FlexContainer'; | ||
import StyledLink from '<atoms>/StyledLink/StyledLink'; | ||
|
||
/** | ||
* @description - TagRow Component | ||
* | ||
* @prop {string} tags - tags | ||
* @prop {object} handleClick - handle click function | ||
* | ||
* @return {component} TagRow | ||
*/ | ||
const TagRow = ({ | ||
tags, | ||
}) => { | ||
return ( | ||
<FlexContainer | ||
alignItems="center" | ||
justifyContent="center" | ||
flexDirection='row' | ||
> | ||
{renderTags()} | ||
</FlexContainer> | ||
); | ||
|
||
function renderTags() { | ||
return tags.map((tag, index) => { | ||
return ( | ||
<StyledLink | ||
key={index} | ||
id={tag.id} | ||
tag='true' | ||
margin='xs' | ||
to={`/${tag.name}`} | ||
> | ||
{tag.name} | ||
</StyledLink> | ||
); | ||
}); | ||
} | ||
}; | ||
|
||
TagRow.propTypes = { | ||
tags: PropTypes.array.isRequired, | ||
}; | ||
|
||
export default TagRow; |
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,31 @@ | ||
TagRow Default: | ||
|
||
```jsx | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
const tags = [ | ||
{ | ||
name: 'Adventure', | ||
id: '1', | ||
}, | ||
{ | ||
name: 'Love', | ||
id: '2', | ||
}, | ||
{ | ||
name: 'Finance', | ||
url: '3', | ||
}, | ||
{ | ||
name: 'Design', | ||
id: '4', | ||
}, | ||
{ | ||
name: 'Diary', | ||
url: '5', | ||
}, | ||
]; | ||
const handleClick = (e) => console.log(e.target.text); | ||
<Router> | ||
<TagRow tags={tags} handleClick={handleClick}/> | ||
</Router> | ||
``` |
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 @@ | ||
import React from 'react'; | ||
import { fireEvent } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { render, cleanup } from '<src>/helpers/testUtils'; | ||
import TagRow from './TagRow'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
afterEach(cleanup); | ||
|
||
const setup = () => { | ||
const tags = [ | ||
{ | ||
name: 'Adventure', | ||
id: '1', | ||
}, | ||
{ | ||
name: 'Love', | ||
id: '2', | ||
}, | ||
{ | ||
name: 'Finance', | ||
url: '3', | ||
}, | ||
]; | ||
|
||
const handleClick = e => console.log(e.target.text); | ||
|
||
const utils = render( | ||
<MemoryRouter> | ||
<TagRow tags={tags} handleClick={handleClick} >Authors Haven</TagRow> | ||
</MemoryRouter>, | ||
); | ||
|
||
return { ...utils }; | ||
}; | ||
|
||
describe('TagRow', () => { | ||
it('should render the TagRow component', () => { | ||
const { getByText } = setup(); | ||
|
||
expect(getByText('Adventure')).toBeTruthy(); | ||
}); | ||
|
||
it('should apply default style', () => { | ||
const { getByText } = setup({}); | ||
|
||
expect(getByText('Adventure')).toHaveStyle(` | ||
font-size: '1.6' | ||
display: inline-block; | ||
text-decoration: none; | ||
`); | ||
}); | ||
|
||
it('should be clickable', () => { | ||
const { container, getByText } = setup(); | ||
|
||
fireEvent.click(getByText('Adventure')); | ||
expect(container.firstChild).toBeTruthy(); | ||
}); | ||
}); |
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