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 SiteAlert #1099

Merged
merged 29 commits into from
Apr 26, 2021
Merged

Conversation

SirenaBorracha
Copy link
Contributor

@SirenaBorracha SirenaBorracha commented Apr 7, 2021

Summary

This PR adds the USWDS SiteAlert component.

USWDS SiteAlert has four variants: info, emergency, slim, and no-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 and slim. Separate props are preferred so that these styles can be combined with the two mutually exclusive variants, info and emergency, 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, and variant properties. If your control panel is hidden in Storybook, pressing the D 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 and yarn 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 the slim, showIcon, and variant 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 grey

Standard SiteAlert, informational and emergency

Screen Shot 2021-04-08 at 5 10 19 PM

SiteAlert no header, informational and emergency

Screen Shot 2021-04-08 at 5 10 40 PM

SiteAlert with list, informational and emergency

Screen Shot 2021-04-08 at 5 11 16 PM

Slim Emergency Alert, Emergency Alert No Icon

Screen Shot 2021-04-08 at 5 12 55 PM

SiteAlert With Custom Controls (default values)

Screen Shot 2021-04-08 at 5 17 23 PM

SiteAlert With Custom Controls slim, showIcon, and variant

Screen Shot 2021-04-08 at 5 16 20 PM

@SirenaBorracha SirenaBorracha changed the title feat: New component SiteAlert feat: New Component SiteAlert Apr 7, 2021
@SirenaBorracha SirenaBorracha linked an issue Apr 7, 2021 that may be closed by this pull request
src/components/SiteAlert/SiteAlert.stories.tsx Outdated Show resolved Hide resolved
src/components/SiteAlert/SiteAlert.tsx Outdated Show resolved Hide resolved
src/components/SiteAlert/SiteAlert.stories.tsx Outdated Show resolved Hide resolved
src/components/SiteAlert/SiteAlert.stories.tsx Outdated Show resolved Hide resolved
)

const shortAlert = (
<p className="usa-alert__text">
Copy link
Contributor

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.

Copy link
Contributor

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 😆

Copy link
Contributor

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.

Copy link
Contributor

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.

src/components/SiteAlert/SiteAlert.stories.tsx Outdated Show resolved Hide resolved
src/components/SiteAlert/SiteAlert.stories.tsx Outdated Show resolved Hide resolved
src/components/SiteAlert/SiteAlert.tsx Show resolved Hide resolved
@trussworks-infra-zz trussworks-infra-zz temporarily deployed to storybook April 7, 2021 21:04 Inactive
Copy link
Contributor

@haworku haworku left a 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 and showIcon 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">
Copy link
Contributor

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')
Copy link
Contributor

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.

Copy link
Contributor

@brandonlenz brandonlenz Apr 7, 2021

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.

@brandonlenz
Copy link
Contributor

@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.

@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">
Copy link
Contributor

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.

@SirenaBorracha
Copy link
Contributor Author

SirenaBorracha commented Apr 8, 2021

...
@ 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 and showIcon differences with Storybook controls. I'd be happy to pair with you in the future to check out how that would work.
...

@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 slim and then variant following the instructions, but I'm having trouble. The panel doesn't show in Chrome because I closed it that one time, so instead I'm using Safari, but then even when I do see the panel in Safari there's an alert above it (lol meta) "This story is not configured to handle controls" with a link to the Controls README. I just threw some time on @brandonlenz's calendar for tomorrow, but if he and I can't figure it out I'll put time on yours 🙃

brandonlenz
brandonlenz previously approved these changes Apr 20, 2021
@brandonlenz brandonlenz added status: approved For PRs that have been reviewed and approved, but may need another approval due to CI and removed status: hold merge This indicates not to merge the PR as there is a development dependency/other reason to hold off. labels Apr 20, 2021
Copy link
Contributor

@brandonlenz brandonlenz left a comment

Choose a reason for hiding this comment

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

🥳

@brandonlenz brandonlenz self-requested a review April 21, 2021 00:20
Copy link
Contributor

@brandonlenz brandonlenz left a 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!

@trussworks-infra-zz trussworks-infra-zz temporarily deployed to storybook April 23, 2021 00:18 Inactive
@trussworks-infra-zz trussworks-infra-zz temporarily deployed to storybook April 23, 2021 00:37 Inactive
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==

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@trussworks-infra-zz trussworks-infra-zz temporarily deployed to storybook April 26, 2021 21:40 Inactive
@brandonlenz brandonlenz self-requested a review April 26, 2021 21:52
@trussworks-infra-zz trussworks-infra-zz temporarily deployed to storybook April 26, 2021 22:09 Inactive
@SirenaBorracha SirenaBorracha merged commit c1e88e0 into main Apr 26, 2021
@SirenaBorracha SirenaBorracha deleted the ak-new-component-site-alert-981 branch April 26, 2021 23:47
SirenaBorracha added a commit that referenced this pull request May 5, 2021
## [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))
brandonlenz pushed a commit that referenced this pull request May 12, 2021
brandonlenz pushed a commit that referenced this pull request May 12, 2021
## [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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: approved For PRs that have been reviewed and approved, but may need another approval due to CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Component: Site Alert
5 participants