Skip to content

Refactor toast notifications into event-driven toast-alert component#6108

Open
JudahGabriel wants to merge 2 commits into
mainfrom
judahgabriel-improved-robot
Open

Refactor toast notifications into event-driven toast-alert component#6108
JudahGabriel wants to merge 2 commits into
mainfrom
judahgabriel-improved-robot

Conversation

@JudahGabriel

Copy link
Copy Markdown
Contributor

PR Type

  • Feature
  • Refactoring (no functional changes, no api changes)

Describe the current behavior?

Toasts were created by an imperative service (services/toasts.ts) that built and injected DOM directly. The variant color tinted the whole callout (making danger bodies hard to read), the auto-dismiss countdown was a thin bar at the bottom, long messages could overflow, and details only accepted a string. All styling lived inline.

Describe the new behavior?

The toast system is now an event-driven Lit component.

  • Architecture: showToast(toast: ToastEvent) dispatches a show-toast window event; app-index listens and renders a stack of <toast-alert> components. The new <toast-alert> owns its own lifecycle (auto-dismiss timer, countdown animation, fade-out) and emits toast-dismiss when done. A ToastEvent model formalizes the payload.
  • Body: scrollable and padded, capped at 300px so long messages scroll instead of overflowing. details now accepts a string or an Error (rendering the message and stack trace).
  • Countdown: visualized as a wa-progress-ring wrapped around the close (X) button instead of a bottom bar. countdown is now a simple boolean (uses the default duration) rather than an rtl/ltr/none string. Hovering the toast pauses and resets the ring; it resumes from full when the pointer leaves.
  • Color: the body stays the default neutral color; the toast variant color now shows only as a left accent border, with a matching header icon and countdown ring.
  • Styles: extracted into sibling *.styles.ts files (toast-alert.styles.ts, app-index.styles.ts) per repo convention.

This PR also includes a few unrelated layout tweaks the author made in the same branch: removing stale overflow: auto from the Android/iOS/Windows/base platform form layouts and adding padding-top to the publish pane form area.

PR Checklist

  • Test: run npm run test and ensure that all tests pass
  • Target main branch (or an appropriate release branch if appropriate for a bug fix)
  • Ensure that your contribution follows standard accessibility guidelines. Use tools like https://webhint.io/ to validate your changes.

Additional Information

tsc --noEmit passes cleanly. The refactor changes details to render as text (safer, auto-escaped by Lit) rather than HTML; all existing callers pass plain strings or Errors.

Move the toast system from an imperative DOM-building service into a Lit
<toast-alert> component driven by a window event. showToast now dispatches
a "show-toast" event with a ToastEvent payload; app-index listens and
renders the toast stack.

Toast improvements:
- Scrollable, padded body that caps long messages at 300px
- details accepts string or Error (renders message + stack trace)
- Close button; countdown visualized as a wa-progress-ring around the X
- countdown is now a boolean (default duration) instead of rtl/ltr
- Hovering pauses and resets the countdown; resumes on mouse leave
- Neutral body with the variant color as a left accent border, matching
  header icon, and countdown ring
- Extracted component styles into sibling .styles.ts files

Also remove stale overflow:auto from platform form layouts and add
padding-top to the publish pane form area.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Thanks @JudahGabriel for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

- Convert callback arrow-field methods to standard declarations, binding
  this at the call sites (event handlers, setTimeout, requestAnimationFrame).
- Drive the progress ring via a reactive @State() countdown value instead of
  querySelector DOM manipulation, so it re-renders automatically.
- Shrink the close button (via ::part(base)) so it and its hover background
  fit inside the ring's hole instead of covering the ring; make the X smaller.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants