Skip to content
Ginga UI
Ginga UI
日本語

Getting started

  • Overview
  • Quick start
  • Theme generation
  • Custom rendering
  • All components

Forms

  • Button
  • Checkbox
  • Input
  • Radio
  • Questionnaire
  • SegmentedControl
  • Select
  • ComboBox
  • NumberField
  • SearchField
  • Slider
  • Switch
  • FormControl

Display

  • Accordion
  • Alert
  • AlertDialog
  • Badge
  • CodeBlock
  • Card
  • Dialog
  • Drawer
  • Image
  • List
  • Popover
  • Menu
  • Tooltip
  • Table
  • Tab
  • Toast
  • Trace

Typography

  • Heading
  • Paragraph

Navigation

  • Anchor

Layout

  • Box

Resources

  • Changelog
  • GitHub (opens in a new tab)

Logo: Twemoji (opens in a new tab) (CC-BY 4.0)

Toast

A toast that shows temporary notifications. Can be triggered with a programmatic API (toast.success, etc.).

View in Storybook (opens in a new tab)

Installation

import { Toast } from "@ginga-ui/core";

Basic usage

Place ToastRegion once at the root of your app and show notifications with toast.show. Call the toast functions from client event handlers.

toast.tsx
import { Button, toast, ToastRegion } from "@ginga-ui/core";
import { X } from "lucide-react";

export function BasicExample() {
  return (
    <>
      <ToastRegion closeIcon={<X />} />
      <Button
        variant="filled"
        onPress={() => toast.show("You have a new notification")}
      >
        Show toast
      </Button>
    </>
  );
}

Variants

Use toast.info, toast.success, toast.warning, and toast.danger to show notifications that match the situation.

toast.tsx
toast.module.css
import { Button, toast } from "@ginga-ui/core";
import styles from "./toast.module.css";
import { CircleAlert, CircleCheck, Info, TriangleAlert } from "lucide-react";

export function VariantsExample() {
  return (
    <div className={styles.variantList}>
      <Button
        variant="outline"
        onPress={() =>
          toast.info("A new version is available", { icon: <Info /> })
        }
      >
        Info
      </Button>
      <Button
        variant="outline"
        onPress={() =>
          toast.success("Your changes have been saved", {
            icon: <CircleCheck />,
          })
        }
      >
        Success
      </Button>
      <Button
        variant="outline"
        onPress={() =>
          toast.warning("You are running low on storage space", {
            icon: <TriangleAlert />,
          })
        }
      >
        Warning
      </Button>
      <Button
        variant="outline"
        onPress={() =>
          toast.danger("Failed to load data", {
            icon: <CircleAlert />,
          })
        }
      >
        Danger
      </Button>
    </div>
  );
}

Auto close

Specify the timeout option to close the toast automatically. The timer pauses while it is hovered or focused.

toast.tsx
import { Button, toast } from "@ginga-ui/core";
import { CircleCheck } from "lucide-react";

export function TimeoutExample() {
  return (
    <Button
      variant="filled"
      onPress={() =>
        toast.success("Upload complete", {
          icon: <CircleCheck />,
          description: "Closes automatically after 5 seconds.",
          timeout: 5000,
        })
      }
    >
      Auto-dismissing toast
    </Button>
  );
}

Props

ToastRegion

NameTypeDefaultDescription
placement"top-left" | "top-right" | "bottom-left" | "bottom-right""bottom-right"Corner of the screen where toasts appear.
queueToastQueue<ToastContentValue>toast's queueQueue of toasts to display. By default, it shows toasts added with toast.
closeIconReactNode-Icon of the close button.
closeLabelstring-Accessible name of the close button.

Also accepts the props of React Aria's ToastRegion (opens in a new tab).

toast

Functions that add a toast. Each returns the key of the toast.

NameTypeDefaultDescription
show(title: string, options?: ToastOptions & { variant?: ToastVariant }) => string-Adds a toast with any variant.
info / success / warning / danger(title: string, options?: ToastOptions) => string-Adds a toast with the corresponding variant.
close(key: string) => void-Closes the toast with the given key.

ToastOptions

NameTypeDefaultDescription
descriptionstring-Text shown below the title.
iconReactNode-Icon shown before the title.
timeoutnumber-Milliseconds until the toast closes automatically. When omitted, it stays until closed.
onClose() => void-Called when the toast closes.