Skip to content
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 32 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from 31 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 Apr 5, 2021
153d8c7
Add default Storybook example
SirenaBorracha Apr 5, 2021
a8b832e
Add test for ability to pass props
SirenaBorracha Apr 5, 2021
d638a66
Remove empty comment
SirenaBorracha Apr 5, 2021
41d4607
Make Storybook example variable name lower case
SirenaBorracha Apr 6, 2021
584eaa2
Commit yarn.lock changes
SirenaBorracha Apr 6, 2021
c72a93e
Remove unwanted spaces from Storybook example
SirenaBorracha Apr 6, 2021
d5914df
Remove everything except '#' from the test and Storybook href props i…
SirenaBorracha Apr 6, 2021
3d54e2f
Remove hardcoded role prop from SummaryBox root div, move test custom…
SirenaBorracha Apr 6, 2021
8d9197b
Remove unnecessary data-testid, separate summary box content in story…
SirenaBorracha Apr 6, 2021
7fe9f9b
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha Apr 6, 2021
fdd9844
Export SummaryBox from index.ts
SirenaBorracha Apr 6, 2021
45ec45a
Remove straggler - extended href name
SirenaBorracha Apr 6, 2021
08d1f44
Move enclosing div from Storybook to SummaryBox component wrapping ch…
SirenaBorracha Apr 7, 2021
1035f36
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha Apr 9, 2021
2df35fd
Add check for passing custom classname
SirenaBorracha Apr 9, 2021
6cd9ee0
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha Apr 12, 2021
f837bf5
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha Apr 15, 2021
837e030
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha Apr 19, 2021
fc36dbd
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha Apr 20, 2021
d3f0a71
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha Apr 23, 2021
b33b32f
Merge branch 'ak-new-component-summary-box-988' of github.com:trusswo…
SirenaBorracha Apr 23, 2021
38d71d9
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha Apr 26, 2021
f09557d
Update stories file as per Suz's PR feedback
SirenaBorracha Apr 26, 2021
20e5531
Resolve conflicts in yarn.lock
SirenaBorracha Apr 26, 2021
2c10c14
Regenerate yarn.lock
SirenaBorracha Apr 26, 2021
0ee3600
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha Apr 27, 2021
9009665
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha Apr 28, 2021
8ef404d
Fix conflicts in index.ts
SirenaBorracha Apr 28, 2021
49bde97
Remove unnecessary spaces from default export in Storybook
SirenaBorracha Apr 28, 2021
a8c437a
Merge branch 'ak-new-component-summary-box-988' of github.com:trusswo…
SirenaBorracha Apr 28, 2021
e16c5d5
Merge branch 'main' into ak-new-component-summary-box-988
SirenaBorracha Apr 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/components/SummaryBox/SummaryBox.stories.tsx
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,&nbsp;
<a className="usa-summary-box__link" href="#">
find shelter
</a>
&nbsp;right away.
</li>
<li>
Sign up for&nbsp;
<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,&nbsp;
<a className="usa-summary-box__link" href="#">
frostbite
</a>
&nbsp;and&nbsp;
<a className="usa-summary-box__link" href="#">
hypothermia
</a>
.
</li>
<li>
Gather emergency supplies for your&nbsp;
<a className="usa-summary-box__link" href="#">
home
</a>
&nbsp;and your&nbsp;
<a className="usa-summary-box__link" href="#">
car
</a>
.
</li>
</ul>
)

export const summaryBoxDefault = (): React.ReactElement => (
<SummaryBox heading="Key information">{summaryBoxContent}</SummaryBox>
)
81 changes: 81 additions & 0 deletions src/components/SummaryBox/SummaryBox.test.tsx
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,&nbsp;
<a className="usa-summary-box__link" href="#">
find shelter
</a>
&nbsp;right away.
</li>
<li>
Sign up for&nbsp;
<a className="usa-summary-box__link" href="#">
your community’s warning system
</a>
.
</li>
<li>
Learn the signs of, and basic treatments for,&nbsp;
<a className="usa-summary-box__link" href="#">
frostbite
</a>
&nbsp;and&nbsp;
<a className="usa-summary-box__link" href="#">
hypothermia
</a>
.
</li>
<li>
Gather emergency supplies for your&nbsp;
<a className="usa-summary-box__link" href="#">
home
</a>
&nbsp;and your&nbsp;
<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()
Copy link
Contributor

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.

expect(qByTestId).toHaveAttribute('role', 'complementary')
expect(qByTestId).toHaveClass('usa-summary-box custom-class-name')
})
})
28 changes: 28 additions & 0 deletions src/components/SummaryBox/SummaryBox.tsx
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
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export { StepIndicatorStep } from './components/stepindicator/StepIndicatorStep/

export { Search } from './components/Search/Search'

export { SummaryBox } from './components/SummaryBox/SummaryBox'

/** ProcessList components */
export { ProcessList } from './components/ProcessList/ProcessList/ProcessList'
export { ProcessListItem } from './components/ProcessList/ProcessListItem/ProcessListItem'
Expand Down