You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(Toast): use View Transition API for Toast animations (#7631)
* remove animation code from toast hooks
* add View Transitions
* lint
* fix invalid viewTransitionName
* fix Multiple story
* fix transition when programmatically closing toast
* fix slide in/out
* fix ts-ignore
* update yarn.lock
* memoize placement
* add placement to fullscreen story
* fade out toasts that are centered, and not the last one
* lint
* add wrapUpdate option to ToastQueue
* update where runWithWrapUpdate gets called
* fix function param
Copy file name to clipboardExpand all lines: packages/@react-aria/toast/docs/useToast.mdx
-66Lines changed: 0 additions & 66 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,6 @@ There is no built in way to toast notifications in HTML. <TypeLink links={docs.l
50
50
***Accessible** – Toasts follow the [ARIA alert pattern](https://www.w3.org/WAI/ARIA/apg/patterns/alert/). They are rendered in a [landmark region](https://www.w3.org/WAI/ARIA/apg/practices/landmark-regions/), which keyboard and screen reader users can easily jump to when an alert is announced.
51
51
***Focus management** – When a toast unmounts, focus is moved to the next toast if any. Otherwise, focus is restored to where it was before navigating to the toast region.
52
52
***Priority queue** – Toasts are displayed according to a priority queue, displaying a configurable number of toasts at a time. The queue can either be owned by a provider component, or global.
53
-
***Animations** – Toasts support optional entry and exit animations.
54
53
55
54
## Anatomy
56
55
@@ -346,71 +345,6 @@ Now you can queue a toast from anywhere:
346
345
<ButtononPress={() =>toastQueue.add('Toast is done!')}>Show toast</Button>
347
346
```
348
347
349
-
### Animations
350
-
351
-
`useToastState` and `ToastQueue` support a `hasExitAnimation` option. When enabled, toasts transition to an "exiting" state when closed rather than immediately being removed. This allows you to trigger an exit animation. When complete, call the `state.remove` function.
352
-
353
-
Each <TypeLinklinks={statelyDocs.links}type={statelyDocs.exports.QueuedToast} /> includes an `animation` property that indicates the current animation state. There are three possible states:
354
-
355
-
*`entering` – The toast is entering immediately after being triggered.
356
-
*`queued` – The toast is entering from the queue (out of view).
357
-
*`exiting` – The toast is exiting from view.
358
-
359
-
```tsx
360
-
function ToastRegion() {
361
-
let state =useToastState({
362
-
maxVisibleToasts: 5,
363
-
/*- begin highlight -*/
364
-
hasExitAnimation: true
365
-
/*- end highlight -*/
366
-
});
367
-
368
-
// ...
369
-
}
370
-
371
-
function Toast({state, ...props}) {
372
-
let ref =React.useRef(null);
373
-
let {toastProps, titleProps, closeButtonProps} =useToast(props, state, ref);
374
-
375
-
return (
376
-
<div
377
-
{...toastProps}
378
-
ref={ref}
379
-
className="toast"
380
-
/*- begin highlight -*/
381
-
// Use a data attribute to trigger animations in CSS.
382
-
data-animation={props.toast.animation}
383
-
onAnimationEnd={() => {
384
-
// Remove the toast when the exiting animation completes.
385
-
if (props.toast.animation==='exiting') {
386
-
state.remove(props.toast.key);
387
-
}
388
-
}}
389
-
/*- end highlight -*/
390
-
>
391
-
<div{...titleProps}>{props.toast.content}</div>
392
-
<Button{...closeButtonProps}>x</Button>
393
-
</div>
394
-
);
395
-
}
396
-
```
397
-
398
-
In CSS, the data attribute defined above can be used to trigger keyframe animations:
399
-
400
-
```css
401
-
.toast[data-animation=entering] {
402
-
animation-name: slide-in;
403
-
}
404
-
405
-
.toast[data-animation=queued] {
406
-
animation-name: fade-in;
407
-
}
408
-
409
-
.toast[data-animation=exiting] {
410
-
animation-name: slide-out;
411
-
}
412
-
```
413
-
414
348
### TypeScript
415
349
416
350
A `ToastQueue` and `useToastState` use a generic type to represent toast content. The examples so far have used strings, but you can type this however you want to enable passing custom objects or options. This example uses a custom object to support toasts with both a title and description.
0 commit comments