-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(atoms): adds container component
closes #134
- Loading branch information
Showing
6 changed files
with
104 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { css } from '@emotion/react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export function Container({ children, className }) { | ||
return ( | ||
<div | ||
className={className} | ||
css={css` | ||
margin: 0 auto; | ||
padding: 0 1rem; | ||
max-width: var(--page-width); | ||
`} | ||
> | ||
{children} | ||
</div> | ||
); | ||
} | ||
|
||
Container.propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
}; | ||
|
||
Container.defaultProps = { | ||
children: null, | ||
className: null, | ||
}; | ||
|
||
export default Container; |
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,28 @@ | ||
import { css } from '@emotion/react'; | ||
import { Container } from './Container'; | ||
|
||
const StoryContainer = (props) => ( | ||
<Container | ||
{...props} | ||
css={css` | ||
background: rgba(255, 0, 0, 0.5); | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
min-height: 300px; | ||
height: 50vh; | ||
`} | ||
/> | ||
); | ||
|
||
export default { | ||
component: Container, | ||
title: 'Components/Atoms/Container', | ||
}; | ||
|
||
const Template = (args) => <StoryContainer {...args} />; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
children: 'Container', | ||
}; |
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,30 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { Container } from './Container'; | ||
|
||
describe('<Container />', () => { | ||
it('should render a container', () => { | ||
expect.assertions(2); | ||
|
||
const child = 'Test'; | ||
|
||
render(<Container>{child}</Container>); | ||
|
||
expect(screen.getByText('Test')).toBeInTheDocument(); | ||
|
||
expect(screen.getByText('Test')).toHaveStyle(` | ||
margin: 0 auto; | ||
padding: 0 1rem; | ||
max-width: var(--page-width); | ||
`); | ||
}); | ||
|
||
it('should render a container with a className', () => { | ||
expect.assertions(1); | ||
|
||
const child = 'Test'; | ||
|
||
render(<Container className="test">{child}</Container>); | ||
|
||
expect(screen.getByText('Test')).toHaveClass('test'); | ||
}); | ||
}); |
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 @@ | ||
import { Container } from './Container'; | ||
|
||
export * from './Container'; | ||
|
||
export default Container; |
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