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 20 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
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@
"peerDependencies": {
"react": "^16.x || ^17.x",
"react-dom": "^16.x || ^17.x",

brandonlenz marked this conversation as resolved.
Show resolved Hide resolved
"uswds": "2.10.3"

},
"devDependencies": {
"@babel/core": "^7.10.5",
Expand Down Expand Up @@ -126,7 +128,9 @@
"ts-jest": "^26.1.2",
"typescript": "^3.8.0",
"url-loader": "^4.0.0",

"uswds": "2.10.3",

"webpack": "^4.41.0",
"webpack-cli": "^4.0.0"
},
Expand Down
66 changes: 66 additions & 0 deletions src/components/SummaryBox/SummaryBox.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
import React from 'react'
import { SummaryBox } from './SummaryBox'

export default {
title: 'Components/SummaryBox',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we name this Components / Summary box so it matches the USWDS name?

component: SummaryBox,
parameters: {
docs: {
description: {
component: `
### USWDS 2.0 SummaryBox component

Source: https://designsystem.digital.gov/components/summary-box
`,
},
},
},
}

const summaryBoxContent = (
<div className="usa-summary-box__text">
brandonlenz marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this <div className="usa-summary-box__text"> is repeated in the Story (since it's also rendered in the component itself) - can we remove?

<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>
</div>
)

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 @@ -88,6 +88,8 @@ export { StepIndicatorStep } from './components/stepindicator/StepIndicatorStep/

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

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

/** Truss-designed components */
export {
Modal,
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13944,10 +13944,12 @@ use@^3.1.0:
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"
integrity sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==


uswds@2.10.3:
version "2.10.3"
resolved "https://registry.yarnpkg.com/uswds/-/uswds-2.10.3.tgz#16d34cee81897762d6d69d3ac83aa55129826fa6"
integrity sha512-krNRzx1jRzOJpuH/qtmQhd5zxnXTaDVqrPNYT99sJbxzWUqjb1zZHh3jFNo+xKDpNuiO0XMPwZwlaSp2YdZ3Ag==

dependencies:
classlist-polyfill "^1.0.3"
del "^6.0.0"
Expand Down