-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: New Component SummaryBox #1098
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
0a0badd
Create skeleton for new component SummaryBox, render passed in headin…
SirenaBorracha 153d8c7
Add default Storybook example
SirenaBorracha a8b832e
Add test for ability to pass props
SirenaBorracha d638a66
Remove empty comment
SirenaBorracha 41d4607
Make Storybook example variable name lower case
SirenaBorracha 584eaa2
Commit yarn.lock changes
SirenaBorracha c72a93e
Remove unwanted spaces from Storybook example
SirenaBorracha d5914df
Remove everything except '#' from the test and Storybook href props i…
SirenaBorracha 3d54e2f
Remove hardcoded role prop from SummaryBox root div, move test custom…
SirenaBorracha 8d9197b
Remove unnecessary data-testid, separate summary box content in story…
SirenaBorracha 7fe9f9b
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha fdd9844
Export SummaryBox from index.ts
SirenaBorracha 45ec45a
Remove straggler - extended href name
SirenaBorracha 08d1f44
Move enclosing div from Storybook to SummaryBox component wrapping ch…
SirenaBorracha 1035f36
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha 2df35fd
Add check for passing custom classname
SirenaBorracha 6cd9ee0
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha f837bf5
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha 837e030
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha fc36dbd
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha d3f0a71
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha b33b32f
Merge branch 'ak-new-component-summary-box-988' of github.com:trusswo…
SirenaBorracha 38d71d9
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha f09557d
Update stories file as per Suz's PR feedback
SirenaBorracha 20e5531
Resolve conflicts in yarn.lock
SirenaBorracha 2c10c14
Regenerate yarn.lock
SirenaBorracha 0ee3600
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha 9009665
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha 8ef404d
Fix conflicts in index.ts
SirenaBorracha 49bde97
Remove unnecessary spaces from default export in Storybook
SirenaBorracha a8c437a
Merge branch 'ak-new-component-summary-box-988' of github.com:trusswo…
SirenaBorracha e16c5d5
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,64 @@ | ||
/* eslint-disable jsx-a11y/anchor-is-valid */ | ||
import React from 'react' | ||
import { SummaryBox } from './SummaryBox' | ||
|
||
export default { | ||
title: 'Components/Summary box', | ||
component: SummaryBox, | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: ` | ||
### USWDS 2.0 SummaryBox component | ||
|
||
Source: https://designsystem.digital.gov/components/summary-box | ||
`, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
const summaryBoxContent = ( | ||
<ul className="usa-list"> | ||
<li> | ||
If you are under a winter storm warning, | ||
<a className="usa-summary-box__link" href="#"> | ||
find shelter | ||
</a> | ||
right away. | ||
</li> | ||
<li> | ||
Sign up for | ||
<a className="usa-summary-box__link" href="#usa-anchor-warning-system"> | ||
your community’s warning system | ||
</a> | ||
. | ||
</li> | ||
<li> | ||
Learn the signs of, and basic treatments for, | ||
<a className="usa-summary-box__link" href="#"> | ||
frostbite | ||
</a> | ||
and | ||
<a className="usa-summary-box__link" href="#"> | ||
hypothermia | ||
</a> | ||
. | ||
</li> | ||
<li> | ||
Gather emergency supplies for your | ||
<a className="usa-summary-box__link" href="#"> | ||
home | ||
</a> | ||
and your | ||
<a className="usa-summary-box__link" href="#"> | ||
car | ||
</a> | ||
. | ||
</li> | ||
</ul> | ||
) | ||
|
||
export const summaryBoxDefault = (): React.ReactElement => ( | ||
<SummaryBox heading="Key information">{summaryBoxContent}</SummaryBox> | ||
) |
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,81 @@ | ||
/* eslint-disable jsx-a11y/anchor-is-valid */ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
import { SummaryBox } from './SummaryBox' | ||
|
||
const testSummaryBoxContent = ( | ||
<ul className="usa-list"> | ||
<li> | ||
If you are under a winter storm warning, | ||
<a className="usa-summary-box__link" href="#"> | ||
find shelter | ||
</a> | ||
right away. | ||
</li> | ||
<li> | ||
Sign up for | ||
<a className="usa-summary-box__link" href="#"> | ||
your community’s warning system | ||
</a> | ||
. | ||
</li> | ||
<li> | ||
Learn the signs of, and basic treatments for, | ||
<a className="usa-summary-box__link" href="#"> | ||
frostbite | ||
</a> | ||
and | ||
<a className="usa-summary-box__link" href="#"> | ||
hypothermia | ||
</a> | ||
. | ||
</li> | ||
<li> | ||
Gather emergency supplies for your | ||
<a className="usa-summary-box__link" href="#"> | ||
home | ||
</a> | ||
and your | ||
<a className="usa-summary-box__link" href="#"> | ||
car | ||
</a> | ||
. | ||
</li> | ||
</ul> | ||
) | ||
|
||
const customProps = { | ||
role: 'complementary', | ||
className: 'custom-class-name', | ||
heading: 'Example heading', | ||
} | ||
|
||
describe('SummaryBox component', () => { | ||
it('renders without errors', () => { | ||
const { getByRole } = render( | ||
<SummaryBox heading="Key information">{testSummaryBoxContent}</SummaryBox> | ||
) | ||
|
||
expect(getByRole('heading')).toBeInTheDocument() | ||
}) | ||
|
||
it('renders passed in children', () => { | ||
const { getAllByRole } = render( | ||
<SummaryBox heading="Example heading">{testSummaryBoxContent}</SummaryBox> | ||
) | ||
|
||
expect(getAllByRole('listitem')).toHaveLength(4) | ||
expect(getAllByRole('link')).toHaveLength(6) | ||
}) | ||
|
||
it('renders attributes passed in through props', () => { | ||
const { queryByText, queryByTestId } = render( | ||
<SummaryBox {...customProps}>{testSummaryBoxContent}</SummaryBox> | ||
) | ||
|
||
const qByTestId = queryByTestId('summary-box') | ||
expect(queryByText('Example heading')).toBeInTheDocument() | ||
expect(qByTestId).toHaveAttribute('role', 'complementary') | ||
expect(qByTestId).toHaveClass('usa-summary-box custom-class-name') | ||
}) | ||
}) |
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 React from 'react' | ||
|
||
import classnames from 'classnames' | ||
|
||
interface SummaryBoxProps { | ||
heading: string | ||
children?: React.ReactNode | ||
className?: string | ||
} | ||
|
||
export const SummaryBox = ({ | ||
heading, | ||
children, | ||
className, | ||
...divProps | ||
}: SummaryBoxProps & JSX.IntrinsicElements['div']): React.ReactElement => { | ||
const classes = classnames('usa-summary-box', className) | ||
return ( | ||
<div className={classes} data-testid="summary-box" {...divProps}> | ||
<div className="usa-summary-box__body"> | ||
<h3 className="usa-summary-box__heading">{heading}</h3> | ||
<div className="usa-summary-box__text">{children}</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default SummaryBox |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a check for custom
className
here too.