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(Toast): use View Transition API for Toast animations #7631

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

reidbarber
Copy link
Member

@reidbarber reidbarber commented Jan 17, 2025

Removes useToast's existing animation API in favor of using the browser's View Transition API to animate toasts.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@rspbot
Copy link

rspbot commented Jan 17, 2025

@rspbot
Copy link

rspbot commented Jan 21, 2025

@reidbarber reidbarber changed the title WIP: feat(Toast): use View Transition API for Toast animations feat(Toast): use View Transition API for Toast animations Jan 22, 2025
@rspbot
Copy link

rspbot commented Jan 27, 2025

@rspbot
Copy link

rspbot commented Jan 28, 2025

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

those animations look so nice now!

Looks like we no longer focus the next toast when we remove a toast from the list. I checked against main.

@rspbot
Copy link

rspbot commented Jan 30, 2025

@rspbot
Copy link

rspbot commented Jan 30, 2025

## API Changes

@react-stately/toast

/@react-stately/toast:ToastQueue

 ToastQueue <T> {
   add: (T, ToastOptions) => void
   close: (string) => void
   constructor: (ToastStateProps) => void
   pauseAll: () => void
-  remove: (string) => void
   resumeAll: () => void
   subscribe: (() => void) => void
   visibleToasts: Array<QueuedToast<T>>
 }

/@react-stately/toast:ToastState

 ToastState <T> {
   add: (T, ToastOptions) => string
   close: (string) => void
   pauseAll: () => void
-  remove: (string) => void
   resumeAll: () => void
   visibleToasts: Array<QueuedToast<T>>
 }

/@react-stately/toast:QueuedToast

 QueuedToast <T> {
-  animation?: 'entering' | 'queued' | 'exiting' | null
   content: T
   key: string
   onClose?: () => void
   priority?: number
   timer?: Timer
 }

/@react-stately/toast:ToastStateProps

 ToastStateProps {
-  hasExitAnimation?: boolean
   maxVisibleToasts?: number
 }

Copy link
Member

@snowystinger snowystinger left a comment

Choose a reason for hiding this comment

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

Should toasts that timeout to leave also animate?

otherwise looks good, focus of next toast appears to be working again

className={classNames(toastContainerStyles, 'spectrum-ToastContainer-listitem')}
style={{
// @ts-expect-error
viewTransitionName: `_${toast.key.slice(2)}`,
Copy link
Member

Choose a reason for hiding this comment

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

we can probably use the actual key if we apply https://developer.mozilla.org/en-US/docs/Web/API/CSS/escape_static when we generate the random id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants