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

Refactor Flash alert #1979

Closed
wants to merge 13 commits into from
Closed

Refactor Flash alert #1979

wants to merge 13 commits into from

Conversation

vdepizzol
Copy link
Contributor

@vdepizzol vdepizzol commented Mar 3, 2022

What are you trying to accomplish?

This PR adds a new Flash component, meant to eventually replace our existing flash alert. This update aims to fix long standing issues found in it, mainly regarding responsive support.

Link to Storybook

Main updates:

Improved alignment and spacing

Screen Shot 2022-03-03 at 15 44 08

Screen Shot 2022-03-03 at 15 47 47

Screen Shot 2022-03-03 at 15 43 01

Screen Shot 2022-03-03 at 15 44 37

Responsive support

Screen Shot 2022-03-03 at 15 45 32

Screen Shot 2022-03-03 at 15 45 05

A lot of the spacing values used in this refactor are hardcoded, and will benefit from the Primer Primitives spacing update once that's available. (link only available for Hubbers).

What approach did you choose and why?

I've kept the current flash alert in place, and created a new flash-refactor.scss file, in a similar fashion to how @langermank has considered the refactor for the Button component (#1874).

After all instances of flash are replaced with this new component (specially after updating its ViewComponent, we can clean up these files.

Are additional changes needed?

As described in https://github.com/github/primer/issues/62 (internal to hubbers), some alerts may have multiple buttons. This refactor hasn't addressed for these use cases specifically.

  • No, this PR should be ok to ship as is. 🚢

Closes https://github.com/github/primer/issues/154.

@vdepizzol vdepizzol requested a review from a team as a code owner March 3, 2022 23:49
@changeset-bot
Copy link

changeset-bot bot commented Mar 3, 2022

🦋 Changeset detected

Latest commit: 2b59674

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/css Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vdepizzol vdepizzol mentioned this pull request Mar 4, 2022
Copy link
Contributor

@langermank langermank left a comment

Choose a reason for hiding this comment

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

Looks great! A few questions but not blocking 🙂

</div>
)}

<div className={clsx('Flash-message')} dangerouslySetInnerHTML={{__html: message}}></div>
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about creating a slot for title and description? The <strong> and <br> feel like something we should handle at the component level.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to what @langermank is suggesting here. I think that this could be similar to the Blankslate API where both the title and description are styled based on component classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

grid-area: actions;

&:last-child {
align-self: end;
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be out of scope (I'm not sure if you're working from existing designs) but the trailing action alignment stands out to me. I feel like I want it to align with the text. What do you think?

flash alert with button aligned with text

Copy link
Contributor

Choose a reason for hiding this comment

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

Or keep at start so it aligns with the icon regardless how much content there is:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My line of thought was that, for banners with multiple lines and no dismiss button, the call-to-action should be aligned to the end of the message, like: "read the message before looking at the button".

Screen Shot 2022-03-14 at 15 45 19

If the banner does have a dismiss button, though, I'm still keeping it aligned to the top. For some reason I was imagining that banners that have a dismiss button have call-to-actions that are not as important, since they can be dismissed 🤔 .

Screen Shot 2022-03-14 at 15 45 06

Seeing the banners above with the different alignments can definitely seen as jarring, but these usually don't appear next to each other anyways.

@langermank @simurai Do you think that's too weird? 😆

Copy link
Contributor

Choose a reason for hiding this comment

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

the call-to-action should be aligned to the end of the message, like: "read the message before looking at the button".

I see. Yeah, I think that makes sense. Let's give it a try.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's okay to allow for two different action button positions 👍

border: $border-width $border-style var(--color-accent-muted);
border-radius: $border-radius;
grid-auto-flow: column;
grid-template-areas: 'visual message actions close';
Copy link
Contributor

Choose a reason for hiding this comment

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

Beautiful! ☺️

align-self: start;

> .octicon {
margin-block: calc((#{$spacer-1}) / 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

oOOooo fancy

grid-area: actions;

&:last-child {
align-self: end;
Copy link
Contributor

Choose a reason for hiding this comment

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

Or keep at start so it aligns with the icon regardless how much content there is:

image


// Replace with Primitives' Narrow viewport range
@media (max-width: #{map-get($breakpoints, 'md') - 0.02px}) {
&.Flash--full-whenNarrow {
Copy link
Contributor

Choose a reason for hiding this comment

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

full-whenNarrow 👍 This looks useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@simurai I'm already using it for #1898 (Example in Storybook) 🎉 🎉

Copy link
Contributor

Choose a reason for hiding this comment

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

Yesss... this, exactly!

.Flash-visual {
display: grid;
// stylelint-disable-next-line primer/spacing
padding: calc((#{$spacer-5} - 20px) / 2) $spacer-2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a specific reason to use calc() here and 2 more times below? I think the browser will see it as:

padding: calc((32px - 20px) / 2) 8px;

but because they are static px values it won't change. So we could also just use the calculated px value and probably improve performance a tiny bit:

padding: 6px $spacer-2;

If it was to get around the stylelint-disable, @jonrohan patched that recently. 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@simurai I'm getting prepared for the use of functional spacing design tokens (link only available for hubbers). $spacer-5 should be --gh-control-medium-size, and 20px --gh-text-body-medium-lineBoxHeight. This calculation adds any extra padding needed so the 16px octicon gets vertically centered with the first line of text, even in case there are multiple lines.

I'll add this as a comment in the file. 🙇

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm getting prepared for the use of functional spacing design tokens

ahhh.. ok ok, in that case let's keep as is for easier updating later. 👍

type: 'boolean',
},
},
hasCloseButton: {
Copy link
Contributor Author

@vdepizzol vdepizzol Mar 4, 2022

Choose a reason for hiding this comment

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

After chatting with @ashygee, I'll rename this to "Dismiss button".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!


// Flash alert

.Flash {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After chatting with @ashygee, we agreed to rename this component to "Alert".

Additionally, @alliethu gave some great insights into how to handle accessibility for it:

A couple alert notes:

  • Use role="alert" by default
    • If more than one alert can display at once, use role="status" so the screen reader doesn’t interrupt itself with the latest message.
  • Provide a cue for the alert type (info, warning, error, success)
    • Visually with an icon
    • Audibly using visually hidden text that precedes the alert
    • If no dismiss/close button, the alert must be present for a minimum of 5 seconds before dismissing.
  • Connect title and description using aria-describedby

Copy link
Contributor

Choose a reason for hiding this comment

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

@vdepizzol based on the conversation with @langermank I think that "Banner" is a better name for this component. If we do decide to keep "Alert" though we may want to clarify the difference between this and a Toast notification/alert. I also think we may want to audit the usage of the Toast since this alert styling is much more common across the patterns seen within the GitHub experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ashygee just renamed the component to Banner.

I haven't updated the stories with WAI-ARIA considerations because I think these are still in flux. Per instance, there are many existing scenarios1 where role="alert" shouldn't be useful. I think we can polish the accessibility definitions directly in the PVC updates.

Footnotes

  1. Link only available to hubbers.

@vdepizzol vdepizzol marked this pull request as draft March 4, 2022 19:08
@vdepizzol
Copy link
Contributor Author

I'm moving this back to a draft to update the proposal with full support for accessibility and better naming. Thank you @alliethu and @ashygee 🎉 !

@ashygee
Copy link
Contributor

ashygee commented Mar 9, 2022

@vdepizzol after our conversation we had discussed that the full version of the Banner (Flash) component would be what we currently style as .flash-banner, see screenshot below. I did not see this reflected in Storybook as it still has the border at the top and bottom of the component. Are we still considering making this change?

proposal for Banner full variant to attach to the top of containers

@vdepizzol
Copy link
Contributor Author

@ashygee:

after our conversation we had discussed that the full version of the Banner (Flash) component would be what we currently style as .flash-banner, see screenshot below. I did not see this reflected in Storybook as it still has the border at the top and bottom of the component. Are we still considering making this change?

So, I'm no longer including a -banner variant in the component since we'll no longer offer support for sticky banners. From the Primer CSS docs:

A flash message that is fixed positioned at the top of the page. Use for more global events where the content of the page is unknown.

Eventually a system tray should better support system banners. See #1898.


In the meantime, a -full variant should still work inside bordered Box elements:

Screen Shot 2022-03-14 at 16 40 01

More about Boxes with alerts

✌️ ✌️ ✌️

@vdepizzol vdepizzol marked this pull request as ready for review March 14, 2022 23:45
Copy link
Contributor

@simurai simurai left a comment

Choose a reason for hiding this comment

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

Rename Flash to Banner

Was also thinking if it should just be called Alert? But maybe it's still good to keep it as a "category" in case we have other kinds of alerts in the future.

<p className={clsx('Banner-title')} dangerouslySetInnerHTML={{__html: title}}></p>
{description && (
<>
<p className={clsx('Banner-description')} dangerouslySetInnerHTML={{__html: description}}></p>
Copy link
Contributor

Choose a reason for hiding this comment

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

I see Banner-description here but not in the CSS, did you mean to add some styles for this guy?

margin-bottom: 0;
}

.Banner-title:not(:only-child) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is clever ✨ I guess just delete that description class from the stories and use <p>stuff</p>?

@jonrohan jonrohan temporarily deployed to github-pages April 20, 2022 16:32 Inactive
@github-actions
Copy link
Contributor

Hi! This pull request has been marked as stale because it has been open with no activity for 60 days. You can comment on the pull request or remove the stale label to keep it open. If you do nothing, this pull request will be closed in 7 days.

@github-actions github-actions bot added the Stale Automatically marked as stale. label Jun 19, 2022
@simurai simurai removed the Stale Automatically marked as stale. label Jun 20, 2022
@siddharthkp
Copy link
Contributor

👋 @vdepizzol How do you feel about merging this component and start testing it out in production?

@simurai
Copy link
Contributor

simurai commented Aug 15, 2022

How do you feel about merging this component and start testing it out in production?

Is there already a need for this in production?

I think the main reason this hasn't shipped is that there is no plan for the PVC implementation yet. And we want to avoid using it with custom markup/HTML. So it would just be un-used CSS for now.

@siddharthkp
Copy link
Contributor

Is there already a need for this in production?

No rush, curious because some of the problems identified in this thread were reported again when I was first responder

@ashygee
Copy link
Contributor

ashygee commented Aug 17, 2022

Is there already a need for this in production?

No rush, curious because some of the problems identified in this thread were reported again when I was first responder

FWIW, it's been shipped in Figma.

@camertron
Copy link
Contributor

Hey everyone! The PVC team has picked this up, see: primer/view_components#1494

Copy link
Member

@jonrohan jonrohan left a comment

Choose a reason for hiding this comment

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

@github-actions
Copy link
Contributor

Hi! This pull request has been marked as stale because it has been open with no activity for 60 days. You can comment on the pull request or remove the stale label to keep it open. If you do nothing, this pull request will be closed in 7 days.

@github-actions github-actions bot added the Stale Automatically marked as stale. label Dec 13, 2022
@simurai
Copy link
Contributor

simurai commented Dec 13, 2022

Closing this again since the .Banner styles now live in PVC.

@simurai simurai closed this Dec 13, 2022
@simurai simurai deleted the flash-refactor branch December 13, 2022 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor release Stale Automatically marked as stale.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants