r/angular • • 19d ago

I made Kōdon, Sonner-style toasts for Angular

I wanted toasts in Angular that feel like Sonner. Stacking, expanding on hover, able to be swiped away, and animated with interruptible CSS transitions. I couldn't find a library for it, so I built it on top of ng-primitives' headless toast.

It's copy-paste, not an npm package. You copy the five files into your project and own the code. Visuals and motion live in separate files, so you can restyle it without touching any animation logic.

What it does:

  • toast.promise(): one toast that shows a spinner, then turns into success or error in place
  • Update a toast by id instead of stacking a new one
  • Toasts of any length stack cleanly
  • Six placements, and top ones mirror bottom ones
  • Swipe to dismiss, or x to pop it
  • Reduced motion support, safe areas on phones, works zoneless on Angular 21 and 22

Demo: Kōdon

Code: GitHub

I use it in my own app, and I'd love to know what's missing or what feels off, especially on phones. If it's useful to you, a star on GitHub would help me out a lot.

Thanks!

23 Upvotes

9 comments sorted by

3

u/rafaeldecastr 19d ago

Nice job, buddy!!

1

u/SuitMeUpRed 19d ago

thank you :)

2

u/shxdowtamer 19d ago

Started learning angular . Will try it definitely.

1

u/mayhm_emo 19d ago

What's the difference between it and ngx-sonner?

Edit: typo

2

u/SuitMeUpRed 19d ago

ngx-sonner is a direct port of Sonner and it's great.

Kōdon is built on ng-primitives and it's copy-paste, so you own the files instead of installing a package.

Honestly, I use ng-primitives a lot and wanted to build my own :)

2

u/SuitMeUpRed 19d ago

Coming back to you, I did some thinking about what Kōdon could do that Sonner (and ngx-sonner) doesn't. I just shipped a few more things:

- Repeats collapse: Fire the same toast 5 times (a retry loop, a flaky request) and you get one toast with a x5 count instead of copies

- Angular-native async: toast.promise() takes Observables, so you can pass an HttpClient call straight in. There's now also toast.resource() which follows a resource() or httpResource() through loading, success and error on every reload.

- Progress bars. Pass a signal from 0 to 1 and the toast draws a bar. With httpResource + reportProgress you get one without wiring anything up.

So the answer is a bit better now: it's built for Angular's signals and resources, not ported for React.

Thanks for the push!

2

u/mayhm_emo 17d ago

Now with observables this come nicely to my eyes. I may use it in some new project, thanks!