-
Notifications
You must be signed in to change notification settings - Fork 33
Update d2l-alert-toast to use popover #7338
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
Open
dbatiste
wants to merge
7
commits into
main
Choose a base branch
from
dbatiste/alert-toast-popover
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d5bb945
Initial update d2l-alert-toast to use popover.
dbatiste 63e26fb
Check feature flag.
dbatiste 43f32d0
Linting.
dbatiste d781325
Another popover override comment.
dbatiste fe8c435
Fix button-copy visual-diffs due to updateComplete.
dbatiste 433f5df
Flag the updateComplete too.
dbatiste 692875a
Updating vdiff goldens (#7339)
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| import './alert.js'; | ||
| import { css, html, LitElement } from 'lit'; | ||
| import { classMap } from 'lit/directives/class-map.js'; | ||
| import { getFlag } from '../../helpers/flags.js'; | ||
| import { ifDefined } from 'lit/directives/if-defined.js'; | ||
| import { styleMap } from 'lit/directives/style-map.js'; | ||
|
|
||
| const alertToastPopoverFlag = getFlag('GAUD-10337-use-alert-toast-popover', true); | ||
| const isPopoverSupported = ('popover' in HTMLElement.prototype); | ||
| const usePopover = alertToastPopoverFlag && isPopoverSupported; | ||
|
|
||
| const reduceMotion = matchMedia('(prefers-reduced-motion: reduce)').matches; | ||
| let activeReduceMotion = reduceMotion; | ||
| export function disableReducedMotionForTesting() { | ||
|
|
@@ -88,15 +93,20 @@ class AlertToast extends LitElement { | |
| } | ||
|
|
||
| .d2l-alert-toast-container { | ||
| background-color: transparent; /* override popover default */ | ||
| border: none; /* override popover */ | ||
| border-radius: 0.3rem; | ||
| box-shadow: 0 0.1rem 0.6rem 0 rgba(0, 0, 0, 0.1); | ||
| color: var(--d2l-theme-text-color-static-standard); /* override popover default */ | ||
| display: none; | ||
| left: 0; | ||
| inset: auto 0 0 0; /* override popover default */ | ||
| margin: 0 auto 1.5rem; | ||
| max-width: 600px; | ||
| padding: 0; /* override popover */ | ||
| position: fixed; | ||
| right: 0; | ||
| width: 100%; | ||
| } | ||
| .d2l-alert-toast-container-not-popover { | ||
| z-index: 10000; | ||
| } | ||
|
|
||
|
|
@@ -133,7 +143,7 @@ class AlertToast extends LitElement { | |
| } | ||
|
|
||
| .d2l-alert-toast-container[data-state="sliding"] { | ||
| transition: bottom 600ms ease; | ||
| transition: inset-block-end 600ms ease; | ||
| } | ||
|
|
||
| d2l-alert { | ||
|
|
@@ -215,9 +225,10 @@ class AlertToast extends LitElement { | |
| render() { | ||
| const spaceBetweenAlerts = this._numAlertsBelow * (this._smallWidth ? TOAST_SPACING_SMALL : TOAST_SPACING); | ||
| const containerStyles = { | ||
| bottom: (this._totalSiblingHeightBelow || this._numAlertsBelow) ? `calc(${this._totalSiblingHeightBelow}px + ${spaceBetweenAlerts}rem)` : 0 | ||
| insetBlockEnd: (this._totalSiblingHeightBelow || this._numAlertsBelow) ? `calc(${this._totalSiblingHeightBelow}px + ${spaceBetweenAlerts}rem)` : 0 | ||
| }; | ||
| const containerClasses = { | ||
| 'd2l-alert-toast-container-not-popover': !usePopover, | ||
| 'd2l-alert-toast-container': true, | ||
| 'd2l-alert-toast-container-close-clicked': this._closeClicked, | ||
| 'd2l-alert-toast-container-lowest': !this._totalSiblingHeightBelow, | ||
|
|
@@ -228,18 +239,19 @@ class AlertToast extends LitElement { | |
| <div | ||
| class="${classMap(containerClasses)}" | ||
| data-state="${this._state}" | ||
| popover="${ifDefined(usePopover ? 'manual' : undefined)}" | ||
| style="${styleMap(containerStyles)}" | ||
| @transitionend=${this._onTransitionEnd}> | ||
| @transitionend="${this._onTransitionEnd}"> | ||
| <d2l-alert | ||
| @blur=${this._onBlur} | ||
| @blur="${this._onBlur}" | ||
| button-text="${ifDefined(this.buttonText)}" | ||
| @d2l-alert-button-press=${this._handleButtonPress} | ||
| @d2l-alert-close=${this._onCloseClicked} | ||
| @focus=${this._onFocus} | ||
| @d2l-alert-button-press="${this._handleButtonPress}" | ||
| @d2l-alert-close="${this._onCloseClicked}" | ||
| @focus="${this._onFocus}" | ||
| ?has-close-button="${!this.hideCloseButton}" | ||
| ?hidden="${this._state === states.CLOSED}" | ||
| @mouseenter=${this._onMouseEnter} | ||
| @mouseleave=${this._onMouseLeave} | ||
| @mouseenter="${this._onMouseEnter}" | ||
| @mouseleave="${this._onMouseLeave}" | ||
| role="${ifDefined(this._state !== states.CLOSED ? 'alert' : undefined)}" | ||
| subtext="${ifDefined(this.subtext)}" | ||
| type="${ifDefined(this.type)}"> | ||
|
|
@@ -395,8 +407,15 @@ class AlertToast extends LitElement { | |
| } | ||
| } | ||
|
|
||
| _openChanged(newOpen) { | ||
| async _openChanged(newOpen) { | ||
| if (newOpen) { | ||
|
|
||
| // Clean-up when removing GAUD-10337-use-alert-toast-popover | ||
| if (alertToastPopoverFlag) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't these two |
||
| await this.updateComplete; // wait for popover attribute before managing top-layer | ||
| if (this.isConnected) this.shadowRoot.querySelector('[popover="manual"]')?.showPopover(); | ||
| } | ||
|
|
||
| if (this._state === states.CLOSING) { | ||
| this._state = states.OPENING; | ||
| } else if (this._state === states.CLOSED) { | ||
|
|
@@ -415,6 +434,11 @@ class AlertToast extends LitElement { | |
| } else { | ||
| if (!this._innerContainer) return; | ||
|
|
||
| // Clean-up when removing GAUD-10337-use-alert-toast-popover | ||
| if (alertToastPopoverFlag) { | ||
| this.shadowRoot.querySelector('[popover="manual"]')?.hidePopover(); | ||
| } | ||
|
|
||
| if (activeReduceMotion || this._state === states.PREOPENING) { | ||
| cancelAnimationFrame(this._preopenFrame); | ||
| } else if (this._state === states.OPENING || this._state === states.OPEN || this._state === states.SLIDING) { | ||
|
|
||
Binary file modified
BIN
-95 Bytes
(99%)
components/alert/test/golden/alert-toast/chromium/button-close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-93 Bytes
(99%)
components/alert/test/golden/alert-toast/chromium/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-150 Bytes
(99%)
...onents/alert/test/golden/alert-toast/chromium/long-button-text-subtext.dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-87 Bytes
(100%)
components/alert/test/golden/alert-toast/chromium/long-button-text-subtext.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-94 Bytes
(99%)
components/alert/test/golden/alert-toast/chromium/long-button-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-193 Bytes
(99%)
...golden/alert-toast/chromium/multiple-alerts-hover-and-focus-focus-then-wait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-193 Bytes
(99%)
...ultiple-alerts-hover-and-focus-hover-then-focus-then-remove-hover-then-wait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-144 Bytes
(99%)
...golden/alert-toast/chromium/multiple-alerts-hover-and-focus-hover-then-wait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-302 Bytes
(97%)
...alert-toast/chromium/multiple-alerts-hover-and-focus-open-quickly-then-wait.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-324 Bytes
(99%)
...-toast/chromium/multiple-alerts-larger-stacking-scenarios-open-four-stacked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-246 Bytes
(99%)
...romium/multiple-alerts-larger-stacking-scenarios-open-four-then-close-first.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-264 Bytes
(99%)
...omium/multiple-alerts-larger-stacking-scenarios-open-four-then-close-fourth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-187 Bytes
(99%)
...ultiple-alerts-larger-stacking-scenarios-open-four-then-close-middle-alerts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-255 Bytes
(99%)
...omium/multiple-alerts-larger-stacking-scenarios-open-four-then-close-second.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-293 Bytes
(99%)
...romium/multiple-alerts-larger-stacking-scenarios-open-four-then-close-third.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-370 Bytes
(99%)
...lerts-larger-stacking-scenarios-open-four-then-re-open-middle-after-closing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-353 Bytes
(99%)
components/alert/test/golden/alert-toast/chromium/multiple-alerts-narrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-147 Bytes
(100%)
...rt-toast/chromium/multiple-alerts-open-all-from-component-then-close-bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-48 Bytes
(100%)
...rt-toast/chromium/multiple-alerts-open-all-from-component-then-close-middle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-155 Bytes
(99%)
...alert-toast/chromium/multiple-alerts-open-all-from-component-then-close-top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-387 Bytes
(99%)
...rt/test/golden/alert-toast/chromium/multiple-alerts-open-all-from-component.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-147 Bytes
(100%)
...test/golden/alert-toast/chromium/multiple-alerts-open-all-then-close-bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-48 Bytes
(100%)
...test/golden/alert-toast/chromium/multiple-alerts-open-all-then-close-middle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-155 Bytes
(99%)
...rt/test/golden/alert-toast/chromium/multiple-alerts-open-all-then-close-top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-387 Bytes
(99%)
components/alert/test/golden/alert-toast/chromium/multiple-alerts-open-all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-127 Bytes
(100%)
...onents/alert/test/golden/alert-toast/chromium/multiple-alerts-resize-larger.png
Oops, something went wrong.
Binary file modified
BIN
-87 Bytes
(100%)
...nents/alert/test/golden/alert-toast/chromium/multiple-alerts-resize-smaller.png
Oops, something went wrong.
Binary file modified
BIN
-13 Bytes
(100%)
components/alert/test/golden/alert-toast/chromium/no-close.png
Oops, something went wrong.
Binary file modified
BIN
-74 Bytes
(100%)
components/alert/test/golden/alert-toast/chromium/responsive-position-narrow.png
Oops, something went wrong.
Binary file modified
BIN
-82 Bytes
(100%)
components/alert/test/golden/alert-toast/chromium/responsive-position-wide.png
Oops, something went wrong.
Binary file modified
BIN
-82 Bytes
(100%)
components/alert/test/golden/alert-toast/chromium/subtext-button-close.png
Oops, something went wrong.
Binary file modified
BIN
+1 Byte
(100%)
components/alert/test/golden/alert-toast/chromium/subtext-no-close.png
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-103 Bytes
(99%)
components/button/test/golden/button-copy/chromium/click.png
Oops, something went wrong.
Binary file modified
BIN
-84 Bytes
(99%)
components/button/test/golden/button-copy/chromium/error.png
Oops, something went wrong.
Binary file modified
BIN
-103 Bytes
(99%)
components/button/test/golden/button-subtle-copy/chromium/click.png
Oops, something went wrong.
Binary file modified
BIN
-89 Bytes
(100%)
components/button/test/golden/button-subtle-copy/chromium/error.png
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wondering if we might want to have 2 copies of all (or most) of the alert-toast vdiffs, one for popover on and one for off?
Reasoning:
Of course having double the vdiffs isn't amazing, but it would just be temporary for the next year or two until popover is supported everywhere.