Feedback
Adding an album changes a badge and a number in the header. A toast makes it unmistakable.
$ puzzle add piece toast
puzzle add piece · npm:@magic-spells/puzzle-pieces@0.9.0
✓ toast · 2 files
Next steps
→ add `@import './pieces.css';` to app/styles/styles.css (after `@import "tailwindcss";`)
styles.css imports the tokens already, so there is nothing else to do. The piece is two files:
toast.jsexportstoast(), a plain function you call from anywhere:toast({ title, message, variant }). Variants aredefault,successanddanger; toasts dismiss themselves after five seconds and pause while the pointer is over them.Toaster.pzlis the host that shows them. Mount it once, in the layout, so every page has it.
Your turn
- In
Default.pzl, importToasterfrom../components/ui/Toaster.pzland put<Toaster/>after</main>. - In
Shop.pzl,import { toast } from '@/components/ui/toast.js', and makeaddsay so:
add: (album) => {
album.update({ inPlaylist: true });
toast({ title: 'Added to playlist', message: album.title, variant: 'success' });
},
Add a few albums. The toasts stack in the corner and leave on their own.