Components
Toast
Transient message. React Native and web toast presenters.
Live example
Rendered with the real classes from /site/chitransit.css, light (left) and dark (right).
.ct-toastTry it
These buttons call toast.js, the same file the web app loads. Show a few to see them stack; hover or tap the stack to fan it out, and swipe a toast down or sideways to dismiss it.
Position
Code
<div class="ct-demo-toast" style="isolation:isolate"><div class="ct-toast is-visible" data-type="success" role="status"><svg class="ct-toast__icon" aria-hidden="true"><use href="#i-success"/></svg><div class="ct-toast__content"><div class="ct-toast__title">Saved to Favorites</div><div class="ct-toast__description">Clark/Lake · Inner Loop</div></div><button class="ct-toast__action" type="button" tabindex="-1">Undo</button></div></div>
Load @chitransit/signal/toast.js once per page (the docs serve it at /site/toast.js), after the icon sprite that provides #i-success, #i-info, #i-error, #i-alert and #i-close. It puts the stack and its live region in the page and exposes ChiTransitToast.
<script src="/vendor/signal/toast.js" defer></script>
const toast = window.ChiTransitToast;
toast("Removed from Favorites");
toast.success("Saved to Favorites", { description: "Clark/Lake · Inner Loop" });
toast.error("Couldn't load arrivals");
toast("Removed from Favorites", { action: { label: "Undo", onClick: restore } });
// A spinner, then success or error in the same toast.
toast.promise(save(), { loading: "Saving…", success: () => "Saved", error: "Couldn't save" });
const id = toast.loading("Locating…");
toast.success("Found you", { id }); // update in place
toast.dismiss(id); // or toast.dismiss() for all
toast.configure({ position: "top-right" }); // top|bottom - left|center|right
- Options:
description,icon(an SVG string or element;nullfor none),actionandcancel({ label, onClick }; callevent.preventDefault()in an action to keep the toast),durationin ms (Infinitystays),dismissible,closeButton,pill,id,onDismiss,onAutoClose. configure()takesposition,expand(always fanned out),visibleToasts(3) andcloseButton.- A toast stays
--ct-toast-dismiss-after(2.5 s), or--ct-toast-action-dismiss-after(5 s) with an action. Hover, focus, a fanned-out stack or a hidden tab pause it.
Tokens
From tokens/components.tokens.json. Override one instance by setting the property without the ct- prefix. The -card values are the web card; the plain ones are the pill iOS draws.
| Custom property | Value | Alias | Resolves to |
|---|---|---|---|
--ct-toast-action-background | var(--ink) | {colors.ink} | #101A2E #EEF1F6 |
--ct-toast-action-color | var(--paper) | {colors.paper} | #FFFFFF #0F141C |
--ct-toast-action-dismiss-after | var(--motion-toast-action-dismiss-after) | {motion.toastActionDismissAfter} | 8 s |
--ct-toast-action-font-size | var(--fs-sub) | {type.sub} | 13 |
--ct-toast-action-height | 28px | ||
--ct-toast-action-padding-x | var(--space-10) | {space.s10} | 10 pt |
--ct-toast-action-radius | var(--radius-chip) | {radius.chip} | 6 pt |
--ct-toast-background-card | var(--paper) | {colors.paper} | #FFFFFF #0F141C |
--ct-toast-background | var(--live-bg) | {colors.liveBg} | #101A2E #EEF1F6 |
--ct-toast-border | var(--line) | {colors.line} | #DADDE3 #263041 |
--ct-toast-close-size | 20px | ||
--ct-toast-color-card | var(--ink) | {colors.ink} | #101A2E #EEF1F6 |
--ct-toast-color | var(--live-ink) | {colors.liveInk} | #FFFFFF #0F141C |
--ct-toast-description-color | var(--muted) | {colors.muted} | #5B6472 #B0BACA |
--ct-toast-description-weight | var(--weight-regular) | {weight.regular} | 400 |
--ct-toast-dismiss-after | var(--motion-toast-dismiss-after) | {motion.toastDismissAfter} | 4 s |
--ct-toast-duration | var(--motion-live-section-duration) | {motion.liveSectionDuration} | .25 s |
--ct-toast-exit-duration | var(--motion-fade-out-duration) | {motion.fadeOutDuration} | .15 s |
--ct-toast-font-size | var(--fs-sub) | {type.sub} | 13 |
--ct-toast-font-weight-card | var(--weight-medium) | {weight.medium} | 500 |
--ct-toast-font-weight | var(--weight-semibold) | {weight.semibold} | 600 |
--ct-toast-frame | var(--shadow-frame) | {shadows.frame} | |
--ct-toast-gap | var(--space-8) | {space.s8} | 8 pt |
--ct-toast-icon-color-error | var(--alert) | {colors.alert} | #C85414 #F08A4A |
--ct-toast-icon-color-info | var(--accent) | {colors.accent} | #0B4EA2 #92B8F5 |
--ct-toast-icon-color-success | var(--good) | {colors.good} | #1B5E20 #7FD48A |
--ct-toast-icon-color-warning | var(--warn) | {colors.warn} | #8A4B00 #F2B96B |
--ct-toast-icon-size | var(--size-metadata-glyph) | {size.metadataGlyph} | 16 pt |
--ct-toast-inset-top | var(--space-8) | {space.s8} | 8 pt |
--ct-toast-offset | var(--space-24) | {space.s24} | 24 pt |
--ct-toast-offset-compact | var(--space-16) | {space.s16} | 16 pt |
--ct-toast-padding-x-card | var(--space-16) | {space.s16} | 16 pt |
--ct-toast-padding-x | var(--space-16) | {space.s16} | 16 pt |
--ct-toast-padding-y-card | var(--space-16) | {space.s16} | 16 pt |
--ct-toast-padding-y | var(--space-10) | {space.s10} | 10 pt |
--ct-toast-radius-card | var(--r-card) | {radius.card} | 12 pt |
--ct-toast-radius | var(--radius-pill) | {radius.pill} | 999 pt |
--ct-toast-shadow | var(--shadow-fab) | {shadows.floating} | |
--ct-toast-stack-duration | var(--motion-swipe-settle-duration) | {motion.swipeSettleDuration} | .25 s |
--ct-toast-stack-gap | var(--space-14) | {space.s14} | 14 pt |
--ct-toast-width | 356px | ||
--ct-toast-words-per-minute | 225 | ||
--ct-toast-z-index | var(--z-toast) | {zIndex.toast} | 1100 index |
Web modifiers
.ct-toast--pilldraws the compact iOS pill on the live surface, for one short line.data-type(success,error,warning,infoorloading) tints the.ct-toast__icon.- Without
toast.js, one.ct-toastcan still be shown: add.is-visibleand remove it after--ct-toast-dismiss-after. It sits at the bottom of its positioned container;.ct-toast--fixedpins it to the viewport and.ct-toast--topmoves it to the top..ct-toast--autofades it out on its own. A lone toast ignores the pointer, so give it no buttons.
React Native
Use the shared component from @chitransit/signal/rn. API and live gallery.
Contract
Contract: components/toast.yaml. States are drawn live by transit.js.
Loading the contract…
Variants
Type: neutral (the default), success, error, warning, info or loading, from toast.success() and the like or data-type. --pill (pill: true) is the one-line iOS pill. Without toast.js, --fixed, --top and --auto place and time a lone toast. Nothing else exists.
- The rider's own action worked:
toast.success. - Something failed:
toast.error. - Work that takes a moment:
toast.loadingortoast.promise. - A caution:
toast.warning. Neutral news:toast.infoor the default.
// Do
toast.success("Saved to Favorites", { description: "Clark/Lake · Inner Loop" });
toast("Removed from Favorites", { action: { label: "Undo", onClick: restore } });
// Don't: something the rider must read or act on; put it on the page
toast.warning("State/Lake is closed. Use Clark/Lake or Washington/Wabash.");
Usage
Do
- Use a toast for news about something that just happened: a confirmation of the rider’s own action (“Saved to Favorites”) or a failure they should know about (“Couldn’t load arrivals”).
- Keep the title short, in sentence case with no full stop; put detail in the description.
- Offer Undo instead of asking for confirmation when an action is easy to reverse.
Don't
- Don't put anything the rider must read or act on only in a toast; it disappears.
- Don't give a toast more than one action, or links.
Accessibility
- Web:
toast.jsadds an emptyaria-live="polite"region when the page loads and puts each toast in it, so it is announced without moving focus. - Alt+T moves focus into the stack to reach its buttons; Escape collapses the stack and leaves it. Focus or hover anywhere in the stack pauses every timer.
- Action and close buttons are drawn small but take 44pt targets.
- React Native: the Toaster announces each toast through
AccessibilityInfo. The toast is one element named by its title; its action is an accessibility action. - Reduce Motion: the toast fades without sliding, on the web and in React Native.