-
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.
- create button atom - write tests for the button atom - create .md for style guide [Finishes #167132104]
- Loading branch information
1 parent
2b90b03
commit d9604ad
Showing
10 changed files
with
240 additions
and
38 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,99 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styled from 'styled-components'; | ||
|
||
/** | ||
* @description - Button Component | ||
* | ||
* @prop {string} display - display | ||
* @prop {string} buttonType - buttonType | ||
* @prop {function} onClick - onClick | ||
* @prop {children} children - children | ||
* | ||
* @return {component} Button | ||
*/ | ||
const Button = ({ | ||
buttonType, | ||
onClick, | ||
children, | ||
display, | ||
}) => ( | ||
<Button.Container | ||
buttonType={buttonType} | ||
display={display} | ||
onClick={onClick} | ||
> | ||
{children} | ||
</Button.Container> | ||
); | ||
|
||
Button.propTypes = { | ||
display: PropTypes.oneOf(['block', 'inline', 'inline-block']), | ||
buttonType: PropTypes.oneOf(['default', 'getStarted', 'submit']), | ||
onClick: PropTypes.func.isRequired, | ||
children: PropTypes.string.isRequired, | ||
}; | ||
|
||
Button.defaultProps = { | ||
display: 'block', | ||
buttonType: 'default', | ||
}; | ||
|
||
const buttonRadius = { | ||
default: 'none', | ||
getStarted: 'none', | ||
submit: '0.4rem', | ||
}; | ||
|
||
const buttonBorderColor = { | ||
default: '#666666', | ||
getStarted: '#B02091', | ||
submit: '#666666', | ||
}; | ||
|
||
const buttonBackground = { | ||
default: '#B02091', | ||
getStarted: 'transparent', | ||
submit: '#690375', | ||
}; | ||
|
||
const buttonWidth = { | ||
default: '12rem', | ||
getStarted: '12rem', | ||
submit: '30.2rem', | ||
}; | ||
|
||
Button.Container = styled.button` | ||
${({ | ||
buttonType, | ||
display, | ||
theme, | ||
}) => ` | ||
width: ${buttonWidth[buttonType]}; | ||
height: ${theme.height.defaultButtonHeight}; | ||
display: ${display}; | ||
font-size: ${theme.fontSizes.normal}; | ||
background: ${buttonBackground[buttonType]}; | ||
color: ${theme.buttonColors[buttonType]}; | ||
border-radius: ${buttonRadius[buttonType]}; | ||
border: 1px solid ${buttonBorderColor[buttonType]}; | ||
cursor: pointer; | ||
&:hover { | ||
background-color: ${theme.buttonHover[buttonType]}; | ||
color: ${theme.buttonColors.white001}; | ||
border: 1px solid ${theme.buttonColors.light}; | ||
} | ||
&:active { | ||
border: 1px solid ${theme.buttonColors.grey}; | ||
box-shadow: inset 1px 0px 5px ${theme.buttonColors.grey}; | ||
} | ||
&:focus { | ||
outline: 0; | ||
} | ||
`} | ||
`; | ||
|
||
export default Button; |
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,37 @@ | ||
Default Button: | ||
|
||
```jsx | ||
<Button onClick={() => alert('hello')}>Default</Button> | ||
``` | ||
|
||
Submit Button: | ||
|
||
```jsx | ||
<Button | ||
buttonType="submit" | ||
onClick={() => alert('hello')} | ||
> | ||
Submit | ||
</Button> | ||
``` | ||
|
||
Get Started Button: | ||
|
||
```jsx | ||
<Button | ||
buttonType="getStarted" | ||
onClick={() => alert('hello')} | ||
> | ||
Get Started | ||
</Button> | ||
``` | ||
|
||
Publish Button: | ||
|
||
```jsx | ||
<Button | ||
onClick={() => alert('hello')} | ||
> | ||
Publish | ||
</Button> | ||
``` |
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,76 @@ | ||
import React from 'react'; | ||
import { render, cleanup } from '<src>/helpers/testUtils'; | ||
import Button from './Button'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
|
||
afterEach(cleanup); | ||
|
||
describe('Button', () => { | ||
it('should render the Button component', () => { | ||
const { getByText } = render( | ||
<Button onClick={() => alert('hello')}>Submit</Button>, | ||
); | ||
expect(getByText('Submit')).toBeTruthy(); | ||
}); | ||
|
||
it('should apply default style', () => { | ||
const { getByText } = render( | ||
<Button onClick={() => alert('hello')}>Submit</Button>, | ||
); | ||
expect(getByText('Submit')).toHaveStyle(` | ||
color: #FFFFFF; | ||
display: block; | ||
font-size: "1.6rem"; | ||
height: "3.8"; | ||
width: "12rem"; | ||
`); | ||
}); | ||
|
||
it('should render button text', () => { | ||
const { getByText } = render( | ||
<Button onClick={() => alert('hello')}>Submit</Button>, | ||
); | ||
|
||
expect(getByText('Submit')).toHaveTextContent('Submit'); | ||
}); | ||
|
||
it('should render submit buttonType', () => { | ||
const { getByText } = render( | ||
<Button buttonType="submit" onClick={() => alert('hello')}> | ||
Submit | ||
</Button>, | ||
); | ||
|
||
expect(getByText('Submit')).toHaveStyle(` | ||
width: 30.2rem; | ||
height: 3.8rem; | ||
display: block; | ||
font-size: 1.6rem; | ||
background: #690375; | ||
color: #FFFFFF; | ||
border-radius: 0.4rem; | ||
border: 1px solid #666666; | ||
cursor: pointer; | ||
`); | ||
}); | ||
|
||
it('should render getStarted buttonType', () => { | ||
const { getByText } = render( | ||
<Button buttonType="getStarted" onClick={() => alert('hello')}> | ||
Get Started | ||
</Button>, | ||
); | ||
|
||
expect(getByText('Get Started')).toHaveStyle(` | ||
width: 12rem; | ||
height: 3.8rem; | ||
display: block; | ||
font-size: 1.6rem; | ||
background: transparent; | ||
color: #B02091; | ||
border-radius: none; | ||
border: 1px solid #B02091; | ||
cursor: pointer; | ||
`); | ||
}); | ||
}); |
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,5 @@ | ||
const heigths = { | ||
defaultButtonHeight: '3.8rem', | ||
}; | ||
|
||
export default heigths; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const width = { | ||
export const width = { | ||
fullWidth: '100%', | ||
searchBarWidth: '50%', | ||
}; | ||
|