Skip to content

Signal

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).

Saved to Favorites
Clark/Lake · Inner Loop
.ct-toast

Try 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; null for none), action and cancel ({ label, onClick }; call event.preventDefault() in an action to keep the toast), duration in ms (Infinity stays), dismissible, closeButton, pill, id, onDismiss, onAutoClose.
  • configure() takes position, expand (always fanned out), visibleToasts (3) and closeButton.
  • 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 propertyValueAliasResolves to
--ct-toast-action-backgroundvar(--ink){colors.ink}#101A2E #EEF1F6
--ct-toast-action-colorvar(--paper){colors.paper}#FFFFFF #0F141C
--ct-toast-action-dismiss-aftervar(--motion-toast-action-dismiss-after){motion.toastActionDismissAfter}8 s
--ct-toast-action-font-sizevar(--fs-sub){type.sub}13
--ct-toast-action-height28px
--ct-toast-action-padding-xvar(--space-10){space.s10}10 pt
--ct-toast-action-radiusvar(--radius-chip){radius.chip}6 pt
--ct-toast-background-cardvar(--paper){colors.paper}#FFFFFF #0F141C
--ct-toast-backgroundvar(--live-bg){colors.liveBg}#101A2E #EEF1F6
--ct-toast-bordervar(--line){colors.line}#DADDE3 #263041
--ct-toast-close-size20px
--ct-toast-color-cardvar(--ink){colors.ink}#101A2E #EEF1F6
--ct-toast-colorvar(--live-ink){colors.liveInk}#FFFFFF #0F141C
--ct-toast-description-colorvar(--muted){colors.muted}#5B6472 #B0BACA
--ct-toast-description-weightvar(--weight-regular){weight.regular}400
--ct-toast-dismiss-aftervar(--motion-toast-dismiss-after){motion.toastDismissAfter}4 s
--ct-toast-durationvar(--motion-live-section-duration){motion.liveSectionDuration}.25 s
--ct-toast-exit-durationvar(--motion-fade-out-duration){motion.fadeOutDuration}.15 s
--ct-toast-font-sizevar(--fs-sub){type.sub}13
--ct-toast-font-weight-cardvar(--weight-medium){weight.medium}500
--ct-toast-font-weightvar(--weight-semibold){weight.semibold}600
--ct-toast-framevar(--shadow-frame){shadows.frame}
--ct-toast-gapvar(--space-8){space.s8}8 pt
--ct-toast-icon-color-errorvar(--alert){colors.alert}#C85414 #F08A4A
--ct-toast-icon-color-infovar(--accent){colors.accent}#0B4EA2 #92B8F5
--ct-toast-icon-color-successvar(--good){colors.good}#1B5E20 #7FD48A
--ct-toast-icon-color-warningvar(--warn){colors.warn}#8A4B00 #F2B96B
--ct-toast-icon-sizevar(--size-metadata-glyph){size.metadataGlyph}16 pt
--ct-toast-inset-topvar(--space-8){space.s8}8 pt
--ct-toast-offsetvar(--space-24){space.s24}24 pt
--ct-toast-offset-compactvar(--space-16){space.s16}16 pt
--ct-toast-padding-x-cardvar(--space-16){space.s16}16 pt
--ct-toast-padding-xvar(--space-16){space.s16}16 pt
--ct-toast-padding-y-cardvar(--space-16){space.s16}16 pt
--ct-toast-padding-yvar(--space-10){space.s10}10 pt
--ct-toast-radius-cardvar(--r-card){radius.card}12 pt
--ct-toast-radiusvar(--radius-pill){radius.pill}999 pt
--ct-toast-shadowvar(--shadow-fab){shadows.floating}
--ct-toast-stack-durationvar(--motion-swipe-settle-duration){motion.swipeSettleDuration}.25 s
--ct-toast-stack-gapvar(--space-14){space.s14}14 pt
--ct-toast-width356px
--ct-toast-words-per-minute225
--ct-toast-z-indexvar(--z-toast){zIndex.toast}1100 index

Web modifiers

  • .ct-toast--pill draws the compact iOS pill on the live surface, for one short line.
  • data-type (success, error, warning, info or loading) tints the .ct-toast__icon.
  • Without toast.js, one .ct-toast can still be shown: add .is-visible and remove it after --ct-toast-dismiss-after. It sits at the bottom of its positioned container; .ct-toast--fixed pins it to the viewport and .ct-toast--top moves it to the top. .ct-toast--auto fades 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.

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.loading or toast.promise.
  • A caution: toast.warning. Neutral news: toast.info or 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.js adds an empty aria-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.