-
Notifications
You must be signed in to change notification settings - Fork 86
Agentic UI: Add toasts for notifications #4203
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e4fb8db
Add toasts for notifications
64616c1
Clean up extra comments
f6c780b
Further cleanup
d292266
Remove unrelated changes
6730389
Merge branch 'trunk' of github.com:Automattic/studio into add/toast-n…
908f432
Pause timers on create site screen
0376613
Ensure we always render toast containers with aria live
d09b9f3
Adjust mutation
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 |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { Button, Notice } from '@wordpress/ui'; | ||
| import { clsx } from 'clsx'; | ||
| import { useEffect } from 'react'; | ||
| import { | ||
| dismissToast, | ||
| notifyRendererMounted, | ||
| notifyRendererUnmounted, | ||
| pauseToastExpiry, | ||
| resumeToastExpiry, | ||
| useQueuedToastCount, | ||
| useVisibleToasts, | ||
| } from '@/data/app-messages'; | ||
| import styles from './style.module.css'; | ||
|
|
||
| export function AppToasts( { | ||
| className, | ||
| fit = 'row', | ||
| }: { | ||
| className?: string; | ||
| // 'row' stretches toasts to the shelf width (sidebar footer, matching the | ||
| // site rows); 'content' lets each toast hug its text up to the shelf's | ||
| // max-width (the floating collapsed shelf). | ||
| fit?: 'row' | 'content'; | ||
| } ) { | ||
| const toasts = useVisibleToasts(); | ||
| const queuedCount = useQueuedToastCount(); | ||
|
|
||
| useEffect( () => { | ||
| notifyRendererMounted(); | ||
| return () => notifyRendererUnmounted(); | ||
| }, [] ); | ||
|
|
||
| return ( | ||
| <div | ||
| className={ clsx( fit === 'content' && styles.shelfHug, className ) } | ||
| aria-live="polite" | ||
| aria-relevant="additions" | ||
| > | ||
| { toasts.length > 0 ? ( | ||
| <div className={ styles.stack }> | ||
| { toasts.map( ( item ) => ( | ||
| <div | ||
| key={ item.id } | ||
| className={ styles.cell } | ||
| data-leaving={ item.leaving ? '' : undefined } | ||
| > | ||
| <div | ||
| className={ styles.toast } | ||
| onMouseEnter={ () => pauseToastExpiry( item.id ) } | ||
| onMouseLeave={ () => resumeToastExpiry( item.id ) } | ||
| > | ||
| <Notice.Root intent={ item.intent } className={ styles.notice }> | ||
| <Notice.Title>{ item.title }</Notice.Title> | ||
| { item.description ? ( | ||
| <Notice.Description>{ item.description }</Notice.Description> | ||
| ) : null } | ||
| { item.action ? ( | ||
| <Notice.Actions> | ||
| <Button | ||
| size="small" | ||
| variant="solid" | ||
| tone="neutral" | ||
| className={ styles.actionButton } | ||
| onClick={ item.action.onClick } | ||
| > | ||
| { item.action.label } | ||
| </Button> | ||
| </Notice.Actions> | ||
| ) : null } | ||
| <Notice.CloseIcon | ||
| label={ __( 'Dismiss' ) } | ||
| onClick={ () => dismissToast( item.id ) } | ||
| /> | ||
| </Notice.Root> | ||
| </div> | ||
| </div> | ||
| ) ) } | ||
| { queuedCount > 0 ? <div className={ styles.queuePeek } aria-hidden="true" /> : null } | ||
| { queuedCount > 1 ? ( | ||
| <div | ||
| className={ clsx( styles.queuePeek, styles.queuePeekDeeper ) } | ||
| aria-hidden="true" | ||
| /> | ||
| ) : null } | ||
| </div> | ||
| ) : null } | ||
| </div> | ||
| ); | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| .stack { | ||
| display: flex; | ||
| flex-direction: column; | ||
| margin-top: calc(-1 * var(--wpds-dimension-gap-sm)); | ||
| } | ||
|
|
||
| .shelfHug .stack { | ||
| width: fit-content; | ||
| max-width: 100%; | ||
| } | ||
|
|
||
| .cell { | ||
| display: grid; | ||
| grid-template-rows: 1fr; | ||
| margin-top: var(--wpds-dimension-gap-sm); | ||
| transition: | ||
| grid-template-rows 180ms ease, | ||
| margin-top 180ms ease; | ||
| } | ||
|
|
||
| @starting-style { | ||
| .cell { | ||
| grid-template-rows: 0fr; | ||
| margin-top: 0; | ||
| } | ||
| } | ||
|
|
||
| .cell[data-leaving] { | ||
| grid-template-rows: 0fr; | ||
| margin-top: 0; | ||
| } | ||
|
|
||
| /* Notice's `container-type: inline-size` zeroes intrinsic width, breaking | ||
| fit-content sizing. Reset it — the container query it powers doesn't | ||
| apply at toast widths. */ | ||
| .shelfHug .notice { | ||
| width: fit-content; | ||
| max-width: 100%; | ||
| container-type: normal; | ||
| } | ||
|
|
||
| .toast { | ||
| min-height: 0; | ||
| overflow: clip; | ||
| overflow-clip-margin: 12px; | ||
| animation: toast-enter 160ms ease-out; | ||
| transition: opacity 160ms ease, transform 160ms ease; | ||
| } | ||
|
|
||
| .cell[data-leaving] .toast { | ||
| opacity: 0; | ||
| transform: translateY(4px); | ||
| pointer-events: none; | ||
| } | ||
|
|
||
| .notice { | ||
| width: 100%; | ||
| box-sizing: border-box; | ||
| text-wrap: pretty; | ||
| --wp-ui-notice-background-color: var(--wpds-color-bg-surface-neutral-strong); | ||
| --wp-ui-notice-border-color: transparent; | ||
| --wp-ui-notice-text-color: var(--wpds-color-fg-content-neutral); | ||
| box-shadow: | ||
| 0 0 0 1px color-mix(in srgb, var(--wpds-color-fg-content-neutral) 14%, transparent), | ||
| var(--wpds-elevation-md); | ||
| padding-block: 6px; | ||
| padding-inline: var(--wpds-dimension-padding-sm); | ||
| border-radius: 6px; | ||
| } | ||
|
|
||
| .notice [class*='heading'] { | ||
| line-height: 16px; | ||
| } | ||
|
|
||
| .notice [class*='__description'] { | ||
| font-size: var(--wpds-typography-font-size-xs); | ||
| line-height: 16px; | ||
| color: var(--wpds-color-fg-content-neutral-weak); | ||
| } | ||
|
|
||
| /* Button's solid-variant sets these properties on the element itself, so | ||
| parent-level overrides don't win — must be set here directly. */ | ||
| .actionButton { | ||
| --wp-ui-button-background-color: color-mix( | ||
| in srgb, | ||
| var(--wpds-color-fg-content-neutral) 10%, | ||
| transparent | ||
| ); | ||
| --wp-ui-button-background-color-active: color-mix( | ||
| in srgb, | ||
| var(--wpds-color-fg-content-neutral) 16%, | ||
| transparent | ||
| ); | ||
| --wp-ui-button-foreground-color: var(--wpds-color-fg-content-neutral); | ||
| --wp-ui-button-foreground-color-active: var(--wpds-color-fg-content-neutral); | ||
| --wp-ui-button-border-color: transparent; | ||
| --wp-ui-button-border-color-active: transparent; | ||
| } | ||
|
|
||
| .notice > svg { | ||
| margin-top: 2px; | ||
| } | ||
|
|
||
| .queuePeek { | ||
| height: 8px; | ||
| margin-top: 3px; | ||
| margin-inline: 8px; | ||
| background-color: var(--wpds-color-bg-surface-neutral-strong); | ||
| border-radius: 0 0 6px 6px; | ||
| box-shadow: 0 0 0 1px color-mix(in srgb, var(--wpds-color-fg-content-neutral) 14%, transparent); | ||
| opacity: 0.8; | ||
| } | ||
|
|
||
| .queuePeekDeeper { | ||
| margin-inline: 16px; | ||
| opacity: 0.5; | ||
| } | ||
|
|
||
| .shelfHug .queuePeek { | ||
| margin-inline: 0 16px; | ||
| } | ||
|
|
||
| .shelfHug .queuePeekDeeper { | ||
| margin-inline: 0 32px; | ||
| } | ||
|
|
||
| @keyframes toast-enter { | ||
| from { | ||
| opacity: 0; | ||
| transform: translateY(6px); | ||
| } | ||
|
|
||
| to { | ||
| opacity: 1; | ||
| transform: translateY(0); | ||
| } | ||
| } | ||
|
|
||
| @media (prefers-reduced-motion: reduce) { | ||
| .toast, | ||
| .cell { | ||
| animation: none; | ||
| transition: none; | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.