-
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 SiteAlert #1099
Conversation
…correct class name
…xamples, add test checking for ability to render a passed in link, replace custom Link component with plain anchor tags and remove import”
…on props passed, expand Storybook examples
…lied when slim is true, otherwise it messes up the placement of the icon, update tests, update Storybook naming convention
) | ||
|
||
const shortAlert = ( | ||
<p className="usa-alert__text"> |
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.
At initial glance, this <p>
is something I would want to encapsulate similar to #1100 (generifying the usa-alert__text
class into an AlertText
component could be used for a child of both Alert and SiteAlert). That can be an enhancement.
I'm also thinking about how Alert (which is very similar) is very rigid, while SiteAlert has this flexible approach. I think the SiteAlert
approach is in line with our current design philosophy.
Does that then mean we should add a backlog item for a breaking release where we change Alert
to be a bit more flexible like SiteAlert, and allow things like lists to be passed in? Mostly just thinking out loud and noticing some things that would be nice for us to decide how to be consistent about.
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.
Good call out. Another idea: I could see the children of SiteAlert
(and honestly Alert
as well) accepting children of type string | JSX.element
. If a string is passed in we put the string in a <p>
tag with the usa-alert
class) but if a component is passed in we just display that component. What do folks think of that approach?
In terms of refactoring Alert - I think that could be a good task for the backlog. It probably should be handling flexible content. Right now it uses the validation
prop to adjust classes but also to be more flexible (validations are lists) which is quite weird. I think I wrote that code too 😆
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.
I like that approach! We might need to expand to accept string | JSX.Element | JSX.Element[]
in the event of multiple child elements.
I think the only advantage of making the <AlertText />
subcomponent is for the scenario where someone wanted to do something like:
<SiteAlert>
<AlertText>Here's some text about the list below:<AlertText />
<ul className="usa-list">
<li>something</li>
<li>something else</li>
</ul>
<SiteAlert>
The string | JSX.Element | JSX.Element[]
approach doesn't preclude that so we could proceed that route and always leave AlertText
as an enhancement should the need arise.
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.
The string | JSX.Element | JSX.Element[] approach doesn't preclude that so we could proceed that route and always leave AlertText as an enhancement should the need arise.
Nice.
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.
LGTM! I wanted to check a couple things though a bit outside the actual React component work here:
- @SirenaBorracha have you explored storybook controls at all? It might be something you would be interested in. We could very easily reduce our storybook stories and instead show the
slim
andshowIcon
differences with Storybook controls. I'd be happy to pair with you in the future to check out how that would work. - @brandonlenz @suzubara Didn't we say we want to start trying to make the uswds version bumps their own separate PR? Maybe this would be a good time.
) | ||
|
||
const shortAlert = ( | ||
<p className="usa-alert__text"> |
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.
Good call out. Another idea: I could see the children of SiteAlert
(and honestly Alert
as well) accepting children of type string | JSX.element
. If a string is passed in we put the string in a <p>
tag with the usa-alert
class) but if a component is passed in we just display that component. What do folks think of that approach?
In terms of refactoring Alert - I think that could be a good task for the backlog. It probably should be handling flexible content. Right now it uses the validation
prop to adjust classes but also to be more flexible (validations are lists) which is quite weird. I think I wrote that code too 😆
) | ||
|
||
expect(getByRole('heading')).toBeInTheDocument() | ||
expect(getByRole('heading')).toHaveClass('usa-alert__heading') |
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.
Suggestion: This test could include a check that the heading text is indeed rendered. Right now we just check that a heading exists, but not its text content.
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.
ooo and a quick follow up on these lines since I didn't notice on my first pass:
@SirenaBorracha if you ever find yourself doing getBy___
or queryBy___
for the same thing multiple times in a test you can factor that out into a const, e.g:
const heading = getByRole('heading')
expect(heading).toBeInTheDocument()
expect(heading).toHaveClass('usa-alert__heading')
I'm not sure if the performance impact of querying the dom for a specific element is high, but its an easy optimization we can do to keep the tests efficient.
@haworku yep! We've got #1097 for this effort. I got started on it today and hope to finish this week so we can get that in before these. Among other things it'll make the Happo diff for this PR just show the SiteAlert added renders. So we might get this to a point where its "approved" but hold off on merging to main. We have a couple of outstanding 2.9.0 PRs that probably should also go through first as well*. * Unless we go with Option 2.A in the release & branching ADR in which case we just get things merge in whatever order they're ready 😉 |
) | ||
|
||
const shortAlert = ( | ||
<p className="usa-alert__text"> |
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.
I like that approach! We might need to expand to accept string | JSX.Element | JSX.Element[]
in the event of multiple child elements.
I think the only advantage of making the <AlertText />
subcomponent is for the scenario where someone wanted to do something like:
<SiteAlert>
<AlertText>Here's some text about the list below:<AlertText />
<ul className="usa-list">
<li>something</li>
<li>something else</li>
</ul>
<SiteAlert>
The string | JSX.Element | JSX.Element[]
approach doesn't preclude that so we could proceed that route and always leave AlertText
as an enhancement should the need arise.
@haworku I'd prefer to remove some of those stories in this PR given the choice. I just spent ~30m trying to get controls working for |
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.
🥳
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.
Oh I approved preemptively. Could you remove the empty whitespace added to package.json to this one as well? I'll eagerly approve after that!
yarn.lock
Outdated
@@ -13948,6 +13948,7 @@ 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== | |||
|
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.
where did this white space come from?
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.
I have no idea. Removing it.
…ks/react-uswds into ak-new-component-site-alert-981
## [1.17.0](1.16.0...1.17.0) (2021-05-05) ### Features * Checkbox Tile Variant ([#1104](#1104)) ([9936c4a](9936c4a)) * Implement ProcessListHeading subcomponent ([#1162](#1162)) ([964e34c](964e34c)) * New Component ProcessList MVP ([#1107](#1107)) ([1bc0f93](1bc0f93)) * New Component SiteAlert ([#1099](#1099)) ([c1e88e0](c1e88e0)) * New Component SummaryBox ([#1098](#1098)) ([b2279b4](b2279b4)) * Radio Button Tile Variant ([#1101](#1101)) ([a2f40a0](a2f40a0)) * Update Grid components to render any type of element ([#1166](#1166)) ([07468c8](07468c8)), closes [#1194](#1194) * Update Search component to support i18n ([#1192](#1192)) ([5241d15](5241d15)) * Update Table to 2.10.0 implementation ([#1110](#1110)) ([117a6c7](117a6c7))
## [1.17.0](1.16.0...1.17.0) (2021-05-05) ### Features * Checkbox Tile Variant ([#1104](#1104)) ([9936c4a](9936c4a)) * Implement ProcessListHeading subcomponent ([#1162](#1162)) ([964e34c](964e34c)) * New Component ProcessList MVP ([#1107](#1107)) ([1bc0f93](1bc0f93)) * New Component SiteAlert ([#1099](#1099)) ([c1e88e0](c1e88e0)) * New Component SummaryBox ([#1098](#1098)) ([b2279b4](b2279b4)) * Radio Button Tile Variant ([#1101](#1101)) ([a2f40a0](a2f40a0)) * Update Grid components to render any type of element ([#1166](#1166)) ([07468c8](07468c8)), closes [#1194](#1194) * Update Search component to support i18n ([#1192](#1192)) ([5241d15](5241d15)) * Update Table to 2.10.0 implementation ([#1110](#1110)) ([117a6c7](117a6c7))
Summary
This PR adds the USWDS SiteAlert component.
USWDS SiteAlert has four variants:
info
,emergency
,slim
, andno-icon
that each apply different styles to the<section>
root element. Brandon pointed out that these styles are not all mutually exclusive.In the pursuit of customizability, instead of including them all as possible values of the
variant
prop, two of the four are passed in as individual, optional properties:showIcon
andslim
. Separate props are preferred so that these styles can be combined with the two mutually exclusive variants,info
andemergency
, however the user wants.The USWDS examples don't show all possible combinations, but I've included stories for the most likely combinations. In the last example, at Hana's suggestion, I used Storybook Controls to show the different applications and combinations of styles with the
slim
,showIcon
, andvariant
properties. If your control panel is hidden in Storybook, pressing theD
key should make it reappear. Controls are only available for the last Storybook example.Related Issues or PRs
closes #981
How To Test
Check out this branch and run
yarn test
to execute tests andyarn storybook
to see the new component in action.Alternatively, you can scroll to the bottom of this page and click "Show environments" on the right above the comment input box to access this component in Storybook. To see the different styles applied with Controls on the last story, press the
D
key in Storybook to access your controls panel and toggle the application of theslim
,showIcon
, andvariant
properties.Screenshots
* Please note: I also thought the links were different colors because I accidentally took screenshots using one regular and one incognito browser window, but the colors are actually the result of USWDS styling
info
links are blue,emergency
links are greyStandard SiteAlert, informational and emergency
SiteAlert no header, informational and emergency
SiteAlert with list, informational and emergency
Slim Emergency Alert, Emergency Alert No Icon
SiteAlert With Custom Controls (default values)
SiteAlert With Custom Controls
slim
,showIcon
, andvariant