library
Prebuilt pebble components: drop-in custom elements, no compiler needed
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Toaster (<pebble-toaster>)
A bottom-right notification stack, converged from the toboggan and toki iterations (their reducers were byte-identical; this element keeps that semantics). Self-registering: the import IS the registration. Light DOM, no shadow root — the page's own stylesheets reach every part.
<script type="module" src="vendor/pebble-library/toaster.js"></script>
<pebble-toaster></pebble-toaster>
One per page. The inbound event is window-global, so a second connected instance renders every toast a second time (a dev-build warning says so).
Announcing
The inbound API is a toast event on window — the same event htmx dispatches for the server's HX-Trigger header, so server responses, htmx failures and client code all speak one dialect. Client code goes through announceToast:
import { announceToast, toastError } from "@pebble/toaster";
announceToast({ message: "Note saved", type: "success" });
announceToast({ message: "Retrying…", duration: 10000 }); // type defaults to "info"
toastError("Save failed"); // announceToast({ message, type: "error" })
ToastDetail, all fields optional:
| field | type | default | notes |
|---|---|---|---|
message | string | "Notification" | the card's text |
type | "info" | "success" | "error" | "info" | anything else falls back to "info" (dev warning) |
duration | number | string | 5000 | ms; clamped into 1000–60000 (dev warning when clamped or unparseable) |
A raw new CustomEvent("toast", { detail }) on window is equally valid — announceToast is exactly that, typed.
Behavior
- A toast auto-dismisses after
duration; a CSS progress bar shows the countdown. - Hovering a card pauses its countdown; leaving resumes it for what is left.
- Clicking a card, or its × button, dismisses it.
- At most 3 toasts show; the rest collapse into a
+Nchip. Hovering the stack expands it to show every toast (up to the 10-toast cap; older toasts beyond it are dropped). - Enter/exit animations and the stack shift on removal are pure CSS; the JS only flips classes, attributes and the progress bar's play-state.
prefers-reduced-motionturns the transitions and the bar off.
Politeness
The region is role="region" aria-live="polite" aria-label="Notifications". Each card carries the channel its type implies: an error card is role="alert" (assertive), any other card role="status" (polite).
Events
Inbound only: the toast window event above. The element emits no outward events — a toast's lifecycle (shown, expired, dismissed) is its own concern; the × is the element's own button and needs no invoker.
Attributes and props
None. Configuration is per-toast, in the event detail. State is carried on the host's light-DOM children, never as generated CSS: the kind is both a class (.toast-success) and an attribute ([data-kind="success"]), the exiting card both .toast-exit and [data-exit] — style against whichever scheme survives your HTML pipeline.
Parts
| part | element |
|---|---|
toaster | the fixed region, bottom-right |
stack | the column of cards |
toast | one card |
content | a card's message + close row |
message | the toast text |
close | the × button |
progress | the countdown bar |
overflow | the +N chip |
CSS hooks
Every value is a --pebble-toaster-* custom property with a fallback; set them on :root or any ancestor. Page-level tokens inherit in — --pebble-toaster-progress and --pebble-toaster-focus fall back to --accent before their own defaults.
--pebble-toaster-offset (1.5rem) · --pebble-toaster-z-index (100) · --pebble-toaster-gap (0.5rem) · --pebble-toaster-border · --pebble-toaster-radius (0.375rem) · --pebble-toaster-surface · --pebble-toaster-ink · --pebble-toaster-muted · --pebble-toaster-shadow · --pebble-toaster-font-size (0.875rem) · --pebble-toaster-line-height (1.5) · --pebble-toaster-ease · --pebble-toaster-padding (0.75rem) · --pebble-toaster-success / -error / -info (the leading band) · --pebble-toaster-progress · --pebble-toaster-focus · --pebble-toaster-hover (the × hover wash)
The raw sheet also ships as dist/toaster.css for zero-JS <link> pages that render toasts server-side with the same classes.
Example: server-triggered toasts over htmx
<pebble-toaster></pebble-toaster>
<!-- a response with HX-Trigger: {"toast": {"message": "Saved", "type": "success"}}
lands here with no glue code — htmx dispatches the same window event -->
:root {
--pebble-toaster-success: #37b24d;
--pebble-toaster-offset: 1rem;
}