Toast

Description

Create a short notification shown in a bc_toaster().

Usage

bc_toast(
  title,
  ...,
  description = NULL,
  category = "info",
  duration = NULL,
  action = NULL,
  cancel = NULL,
  icon = NULL
)

bc_toaster(..., id = "toaster", align = "end")

bc_toast_trigger(
  label,
  ...,
  get,
  toaster = "#toaster",
  variant = "outline",
  size = "default"
)

Arguments

Argument Description
title String. The toast's title.
... For bc_toast(), content shown under the title, before the description. For bc_toaster(), toasts from bc_toast(). For bc_toast_trigger(), extra tag attributes.
description String. Text under the title.
category String. One of "info" (default), "success", "warning" or "error". Sets the color and the default icon.
duration Whole number. Milliseconds before the toast closes, or -1 to keep it open. Defaults to 3000, or 5000 for "error" toasts.
action List. The main button, with label and either href or onclick.
cancel List. A second button, with label and an optional onclick.
icon Tag. An icon before the text, replacing the category default.
id String. The toaster's ID. Defaults to "toaster".
align String. Where toasts stack. One of "start", "center" or "end" (default).
label String. The button's label.
get String. A URL that returns a bc_toast().
toaster String. CSS selector of the bc_toaster() to add the toast to. Defaults to "#toaster".
variant String. The button variant, as in bc_button(). Defaults to "outline".
size String. The button size, as in bc_button(). Defaults to "default".

Value

An htmltools tag.

An htmltools tag.

An htmltools tag.

Details

Append to a bc_toaster().

Use one toaster per page, at the end of the page content.

A click fetches get with htmx and adds the toast to toaster. The page needs htmx loaded.

Examples

bc_toast(
  "Saved",
  description = "Your changes are in place.",
  category = "success",
  cancel = list(label = "Dismiss")
)

Saved

Your changes are in place.


bc_toaster(
  bc_toast("Upload failed", category = "error"),
  align = "start"
)

Upload failed

bc_toast_trigger(
  "Toast from backend (with HTMX)",
  get = "/fragments/toast/success"
)