-
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(molecules): adds section title components
Adds the section title component closes #136
- Loading branch information
Showing
5 changed files
with
93 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
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,54 @@ | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@emotion/react'; | ||
import { rem } from 'polished'; | ||
import { spacing } from '@styles/utils'; | ||
import Divider from '@components/atoms/Divider'; | ||
|
||
export function SectionTitle({ children, className }) { | ||
return ( | ||
<header | ||
className={className} | ||
css={css` | ||
display: flex; | ||
flex-direction: row; | ||
align-content: center; | ||
align-items: center; | ||
justify-content: flex-start; | ||
margin-bottom: ${spacing(2)}; | ||
`} | ||
data-testid="section-title" | ||
> | ||
<h2 | ||
css={css` | ||
display: inline-block; | ||
flex: 0 0 auto; | ||
margin-right: ${spacing(1)}; | ||
margin-bottom: 0; | ||
font-weight: normal; | ||
font-size: ${rem('14px')}; | ||
font-style: italic; | ||
`} | ||
> | ||
{children} | ||
</h2> | ||
<Divider | ||
css={css` | ||
flex: 1 1 100%; | ||
max-width: ${rem('280px')}; | ||
`} | ||
/> | ||
</header> | ||
); | ||
} | ||
|
||
SectionTitle.propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
}; | ||
|
||
SectionTitle.defaultProps = { | ||
children: null, | ||
className: null, | ||
}; | ||
|
||
export default SectionTitle; |
13 changes: 13 additions & 0 deletions
13
src/components/molecules/SectionTitle/SectionTitle.stories.jsx
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,13 @@ | ||
import { SectionTitle } from './SectionTitle'; | ||
|
||
export default { | ||
component: SectionTitle, | ||
title: 'Components/Molecules/SectionTitle', | ||
}; | ||
|
||
const Template = (args) => <SectionTitle {...args} />; | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
children: 'Section Title', | ||
}; |
19 changes: 19 additions & 0 deletions
19
src/components/molecules/SectionTitle/SectionTitle.test.jsx
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,19 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { ThemeProvider } from '@emotion/react'; | ||
import { theme } from '@styles/theme'; | ||
import { SectionTitle } from './SectionTitle'; | ||
|
||
describe('<SectionTitle />', () => { | ||
it('renders the section title', () => { | ||
expect.assertions(2); | ||
|
||
render( | ||
<ThemeProvider theme={theme}> | ||
<SectionTitle className="test-class">Hello World</SectionTitle> | ||
</ThemeProvider>, | ||
); | ||
|
||
expect(screen.getByRole('heading', { name: 'Hello World' })).toBeInTheDocument(); | ||
expect(screen.getByTestId('section-title')).toHaveClass('test-class'); | ||
}); | ||
}); |
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 { SectionTitle } from './SectionTitle'; | ||
|
||
export * from './SectionTitle'; | ||
|
||
export default SectionTitle; |