suiss/ui
  • Docs
  • Components
  • Patterns
  • Interactions
  • Charts
  • Blocks
  • AI
GitHubCreate
DocsComponentsPatternsInteractionsChartsBlocksAICreate
Components84
  • Overview
  • Accordion
  • Alert
  • Alert Dialog
  • Alert Sheet
  • Amount Input
  • Aspect Ratio
  • Attachment
  • Avatar
  • Badge
  • Bottom Bar
  • Breadcrumb
  • Bubble
  • Button
  • Button Group
  • Calendar
  • Card
  • Carousel
  • Chart
  • Checkbox
  • Chip
  • Code Block
  • Collapsible
  • Combobox
  • Command
  • Context Menu
  • Dialog
  • Direction
  • Drawer
  • Dropdown Menu
  • Empty
  • FAB
  • Field
  • Fullscreen Menu
  • Haptics
  • Header
  • Hover Card
  • Icon
  • Input
  • Input Accessory Bar
  • Input Group
  • Input OTP
  • Item
  • Kbd
  • Keyboard Scroll View
  • Keypad
  • Label
  • Marker
  • Menubar
  • Message
  • Message Scroller
  • Native Select
  • Navigation Menu
  • Page Indicator
  • Pagination
  • Pin Pad
  • Popover
  • Progress
  • QR Scanner
  • Questionnaire
  • Radio Group
  • Resizable
  • Screen
  • Scroll Area
  • Select
  • Separator
  • Sheet
  • Sidebar
  • Signature Pad
  • Skeleton
  • Slider
  • Spinner
  • Switch
  • Tab Bar
  • Table
  • Tabs
  • Text
  • Textarea
  • Toast
  • Toggle
  • Toggle Group
  • Tooltip
  • Trace
  • Wheel Picker
  • Widget

suiss/ui · Component

Toast

Brief, stacked notifications that appear at the bottom of the screen and dismiss themselves.

Toast is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.

import { Button } from "@/components/ui/button"
import {
  createToastManager,
  Toaster,
  useToastManager,
} from "@/components/ui/toast"

const toastManager = createToastManager()

function DefaultExample() {
  const toast = useToastManager()

  return (
    <Button
      variant="outline"
      onClick={() =>

Toasts are built on the Base UI Toast primitive. Toaster is the ready-made setup: it combines ToastProvider, ToastPortal and ToastViewport, and renders each queued toast as a Toast with a ToastContent row holding a status icon, ToastTitle, ToastDescription, ToastAction and ToastClose.

New toasts stack at the bottom of the screen, with older ones scaled down behind, and expand into a list on hover or focus. Use toasts for short confirmations and background results; for messages that need a decision, use AlertDialog.

Installation

$ pnpm dlx shadcn@latest add @esuiss/toast

Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add toast
  1. Install the following dependencies and add the cn helper:
$ pnpm add @base-ui/react @phosphor-icons/react
  1. Add the pieces it builds on: Button.

  2. Copy and paste the following code into your project.

components/ui/toast.tsx
"use client"

import { Toast as ToastPrimitive } from "@base-ui/react/toast"
import {
  CheckCircleIcon,
  InfoIcon,
  WarningIcon,
  XCircleIcon,
  XIcon,
} from "@phosphor-icons/react"
import * as React from "react"
import { Button } from "@/components/ui/button"
import { cn } from "@/lib/utils"

const toast = ToastPrimitive.createToastManager()
  1. Update the import paths to match your project setup.

Usage

import { Button } from "@/components/ui/button"
import { Toaster, toast } from "@/components/ui/toast"
<Toaster>
  <Button
    variant="outline"
    onClick={() =>
      toast.add({
        title: "Event created",
        description: "Friday, October 3 at 9:00 AM",
      })
    }
  >
    Show toast
  </Button>
</Toaster>

Examples

Types

Set type to success, info, warning or error to add a colored status icon, or to loading for a progress ring.

import { Button } from "@/components/ui/button"
import {
  createToastManager,
  Toaster,
  useToastManager,
} from "@/components/ui/toast"

const toastManager = createToastManager()

function TypesExample() {
  const toast = useToastManager()

  return (
    <div className="flex flex-wrap items-center gap-3">
      <Button
        variant="outline"

Title only

Shows a toast with a title and no description.

import { Button } from "@/components/ui/button"
import {
  createToastManager,
  Toaster,
  useToastManager,
} from "@/components/ui/toast"

const toastManager = createToastManager()

function TitleOnlyExample() {
  const toast = useToastManager()

  return (
    <Button
      variant="outline"
      onClick={() => toast.add({ type: "success", title: "8 photos uploaded" })}

With action

Pass actionProps to show a ToastAction button. This one is an Undo action that closes the toast.

import { Button } from "@/components/ui/button"
import {
  createToastManager,
  Toaster,
  useToastManager,
} from "@/components/ui/toast"

const toastManager = createToastManager()

function WithActionExample() {
  const toast = useToastManager()

  return (
    <Button
      variant="outline"
      onClick={() => {

Timeout

Set timeout in milliseconds to change how long a toast stays; 0 keeps it until it is closed.

import { Button } from "@/components/ui/button"
import {
  createToastManager,
  Toaster,
  useToastManager,
} from "@/components/ui/toast"

const toastManager = createToastManager()

function TimeoutExample() {
  const toast = useToastManager()

  return (
    <div className="flex flex-wrap items-center gap-3">
      <Button
        variant="outline"

Promise toast

toast.promise(promise, { loading, success, error }) shows a loading toast that turns into the success toast when the promise resolves.

import { Button } from "@/components/ui/button"
import {
  createToastManager,
  Toaster,
  useToastManager,
} from "@/components/ui/toast"

function wait(ms: number) {
  return new Promise((resolve) => setTimeout(resolve, ms))
}

const toastManager = createToastManager()

function PromiseExample() {
  const toast = useToastManager()

Promise rejected

Uses toast.promise to move from loading to an error when the promise rejects.

import { Button } from "@/components/ui/button"
import {
  createToastManager,
  Toaster,
  useToastManager,
} from "@/components/ui/toast"

function wait(ms: number) {
  return new Promise((resolve) => setTimeout(resolve, ms))
}

const toastManager = createToastManager()

function PromiseExample() {
  const toast = useToastManager()

Accessibility

  • The viewport is a region landmark named Notifications.
  • Each toast has the dialog role, named by its title and described by its description.
  • ToastClose has the accessible name Close toast.
  • Prefer an action that can also be reached elsewhere, since toasts dismiss themselves after their timeout.

API Reference

ToastProvider

Provides a toast manager to the parts inside it.

Also accepts the props of the primitive part it wraps.

ToastPortal

Renders the viewport into a portal.

Also accepts the props of the primitive part it wraps.

ToastViewport

The fixed region at the bottom of the screen that holds the stack.

Also accepts the props of the primitive part it wraps.

On small screens the stack is centered at the bottom, inset from the edges and up to max-w-sm wide; from the sm breakpoint it sits in the bottom end corner.

Toast

A single toast in the stack, positioned and animated by its index.

Also accepts the props of the primitive part it wraps.

Toasts can be swiped away; the exit animation follows the swipe direction.

ToastContent

The row that lays out a toast's icon, text and buttons.

Also accepts the props of the primitive part it wraps.

ToastTitle

The toast's title, which names it.

Also accepts the props of the primitive part it wraps.

ToastDescription

Supporting text, which describes the toast.

Also accepts the props of the primitive part it wraps.

ToastAction

An optional action button, rendered as a small outline Button.

PropTypeDefault
asChildbooleanfalse

Also accepts the props of the primitive part it wraps.

ToastClose

An icon button that dismisses the toast.

PropTypeDefault
asChildbooleanfalse

Also accepts the props of the primitive part it wraps.

Toaster

The complete setup: provider, portal, viewport and the rendered toasts.

PropTypeDefault
toastManagerReturnType<typeof createToastManager>toast

Also accepts the props of ToastProvider.

Render Toaster once near the root of your app, wrapping the content that shows toasts. Call toast.add({ title, description, type }) from anywhere, or read the manager inside the tree with useToastManager(). add returns an id that you can pass to close; close() with no id closes every toast.

Toaster uses the shared toast manager by default. Pass toastManager a manager from createToastManager() to keep a separate stack. Use the individual parts only to build a custom toast list.

Each part sets a data-slot, such as toast-viewport or toast-close, for styling. The loading ring's progress animation is removed when reduced motion is preferred.

Web

Web preview

import { View } from "react-native"
import { Button } from "@/components/ui/button"
import { Text } from "@/components/ui/text"
import { Toaster, toast } from "@/components/ui/toast"

export default function ToastDemo() {
  return (
    <Toaster>
      <View className="items-start gap-3">
        <Button
          variant="outline"
          onPress={() =>
            toast.add({
              title: "Event created",
              description: "Sunday, December 3 at 9:00 AM",
            })
import { View } from "react-native"
import { Button } from "@/components/ui/button"
import { Text } from "@/components/ui/text"
import { Toaster, toast } from "@/components/ui/toast"

export default function ToastDemo() {
  return (
    <Toaster>
      <View style={{ alignItems: "flex-start", gap: 12 }}>
        <Button
          variant="outline"
          onPress={() =>
            toast.add({
              title: "Event created",
              description: "Sunday, December 3 at 9:00 AM",
            })

Add .toaster() once near the root. It overlays the toast stack at the bottom of the view and puts its ToastManager in the environment as toastManager. Call show, success, info, warning, error or loading to add a toast, update to change it and dismiss to remove it.

Toaster wraps your app in a toast provider and renders the queue into a full-screen viewport. Each toast slides in from the bottom edge, fades out downward, and is capped at 384 points wide.

Create the state with rememberToastState() and wrap your content in Toaster. Call show, success, info, warning, error or loading on the state to add a toast, update to change it and dismiss to remove it.

The viewport renders through a portal. On iOS it sits inside a FullWindowOverlay from react-native-screens, so toasts appear above native modals. Each toast is a Reanimated view.

Visible toasts stack with a small peek and shrink behind the frontmost one. Touching the stack expands it; it collapses again three seconds after the touch ends. Each toast shows an icon for its type (success, info, warning, error, or a spinner for loading), a title, a description, an optional action button and a close button.

Installation

$ pnpm dlx shadcn@latest add @esuiss/toast

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add toast
$ pnpm dlx shadcn@latest add @esuiss/toast

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add toast --platform swift
$ pnpm dlx shadcn@latest add @esuiss/toast

See Installation for the components.json setup. Or use the suiss/ui CLI:

$ pnpm dlx @esuiss/ui@latest add toast --platform kotlin

The CLI also adds what it builds on: Button, Icon, Text. It also adds the animated view components/ui/animated-view.tsx.

  1. Install the following dependencies:
npx expo install cn phosphor-react-native react-native-gesture-handler react-native-reanimated react-native-safe-area-context react-native-screens react-native-svg react-native-worklets
  1. Add the pieces it builds on: Button, Icon, Text.

  2. Copy the animated view into components/ui/animated-view.tsx:

uniwind/components/ui/animated-view.tsx
import { Pressable } from "react-native"
import Animated from "react-native-reanimated"

const AnimatedPressable = Animated.createAnimatedComponent(Pressable)

type AnimatedViewProps =
  | (React.ComponentProps<typeof Animated.View> &
      React.RefAttributes<React.ComponentRef<typeof Animated.View>> & {
        as?: "View"
      })
  | (React.ComponentProps<typeof AnimatedPressable> &
      React.RefAttributes<React.ComponentRef<typeof AnimatedPressable>> & {
        as: "Pressable"
      })

function AnimatedView(props: AnimatedViewProps) {
  1. Copy the primitives it uses into components/primitives:
uniwind/components/primitives/haptics.tsx
import * as React from "react"

type HapticsImpactStyle = "light" | "medium" | "heavy" | "soft" | "rigid"

type HapticsNotificationType = "success" | "warning" | "error"

interface HapticsAdapter {
  impact(style: HapticsImpactStyle): void
  selection(): void
  notification(type: HapticsNotificationType): void
}

interface HapticsContextValue {
  adapter: HapticsAdapter | null
  enabled: boolean
}
uniwind/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
uniwind/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
uniwind/components/primitives/portal.tsx
import * as React from "react"
import { HapticsContext } from "./haptics"

const DEFAULT_PORTAL_HOST = "INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME"

type PortalEntries = ReadonlyMap<string, React.ReactNode>

const EMPTY_ENTRIES: PortalEntries = new Map()

let hosts: ReadonlyMap<string, PortalEntries> = new Map()
const listeners = new Set<() => void>()

function emit() {
  for (const listener of listeners) listener()
}
uniwind/components/primitives/toast.tsx
import * as React from "react"
import {
  AccessibilityInfo,
  AppState,
  type GestureResponderEvent,
  type HostInstance,
  type LayoutChangeEvent,
  Pressable,
  type PressableProps,
  Text,
  useWindowDimensions,
  View,
  type ViewStyle,
} from "react-native"
import {
  Gesture,
uniwind/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
uniwind/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/toast.tsx:
uniwind/components/ui/toast.tsx
import { cn } from "cn"
import { CheckIcon, ExclamationMarkIcon, XIcon } from "phosphor-react-native"
import * as React from "react"
import {
  ActivityIndicator,
  Platform,
  useWindowDimensions,
  View,
} from "react-native"
import {
  FadeOutDown,
  ReduceMotion,
  SlideInDown,
  useAnimatedStyle,
  withTiming,
} from "react-native-reanimated"
  1. Update the import paths to match your project setup.
  1. Install the following dependencies:
npx expo install cn nativewind phosphor-react-native react-native-gesture-handler react-native-reanimated react-native-safe-area-context react-native-screens react-native-svg react-native-worklets
  1. Add the pieces it builds on: Button, Icon, Text.

  2. Copy the animated view into components/ui/animated-view.tsx:

nativewind/components/ui/animated-view.tsx
import { Pressable } from "react-native"
import Animated from "react-native-reanimated"

const AnimatedPressable = Animated.createAnimatedComponent(Pressable)

type AnimatedViewProps =
  | (React.ComponentProps<typeof Animated.View> &
      React.RefAttributes<React.ComponentRef<typeof Animated.View>> & {
        as?: "View"
      })
  | (React.ComponentProps<typeof AnimatedPressable> &
      React.RefAttributes<React.ComponentRef<typeof AnimatedPressable>> & {
        as: "Pressable"
      })

function AnimatedView(props: AnimatedViewProps) {
  1. Copy the primitives it uses into components/primitives:
nativewind/components/primitives/haptics.tsx
import * as React from "react"

type HapticsImpactStyle = "light" | "medium" | "heavy" | "soft" | "rigid"

type HapticsNotificationType = "success" | "warning" | "error"

interface HapticsAdapter {
  impact(style: HapticsImpactStyle): void
  selection(): void
  notification(type: HapticsNotificationType): void
}

interface HapticsContextValue {
  adapter: HapticsAdapter | null
  enabled: boolean
}
nativewind/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
nativewind/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
nativewind/components/primitives/portal.tsx
import * as React from "react"
import { HapticsContext } from "./haptics"

const DEFAULT_PORTAL_HOST = "INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME"

type PortalEntries = ReadonlyMap<string, React.ReactNode>

const EMPTY_ENTRIES: PortalEntries = new Map()

let hosts: ReadonlyMap<string, PortalEntries> = new Map()
const listeners = new Set<() => void>()

function emit() {
  for (const listener of listeners) listener()
}
nativewind/components/primitives/toast.tsx
import * as React from "react"
import {
  AccessibilityInfo,
  AppState,
  type GestureResponderEvent,
  type HostInstance,
  type LayoutChangeEvent,
  Pressable,
  type PressableProps,
  Text,
  useWindowDimensions,
  View,
  type ViewStyle,
} from "react-native"
import {
  Gesture,
nativewind/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
nativewind/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/toast.tsx:
nativewind/components/ui/toast.tsx
import { cn } from "cn"
import { cssInterop } from "nativewind"
import { CheckIcon, ExclamationMarkIcon, XIcon } from "phosphor-react-native"
import * as React from "react"
import {
  ActivityIndicator,
  Platform,
  useWindowDimensions,
  View,
} from "react-native"
import {
  FadeOutDown,
  ReduceMotion,
  SlideInDown,
  useAnimatedStyle,
  withTiming,
  1. Update the import paths to match your project setup.
  1. Install the following dependencies:
npx expo install phosphor-react-native react-native-gesture-handler react-native-reanimated react-native-safe-area-context react-native-screens react-native-svg react-native-worklets
  1. Add the pieces it builds on: Button, Icon, Text.

  2. Copy the animated view into components/ui/animated-view.tsx:

stylesheet/components/ui/animated-view.tsx
import { Pressable } from "react-native"
import Animated from "react-native-reanimated"

const AnimatedPressable = Animated.createAnimatedComponent(Pressable)

type AnimatedViewProps =
  | (React.ComponentProps<typeof Animated.View> &
      React.RefAttributes<React.ComponentRef<typeof Animated.View>> & {
        as?: "View"
      })
  | (React.ComponentProps<typeof AnimatedPressable> &
      React.RefAttributes<React.ComponentRef<typeof AnimatedPressable>> & {
        as: "Pressable"
      })

function AnimatedView(props: AnimatedViewProps) {
  1. Copy the primitives it uses into components/primitives:
stylesheet/components/primitives/haptics.tsx
import * as React from "react"

type HapticsImpactStyle = "light" | "medium" | "heavy" | "soft" | "rigid"

type HapticsNotificationType = "success" | "warning" | "error"

interface HapticsAdapter {
  impact(style: HapticsImpactStyle): void
  selection(): void
  notification(type: HapticsNotificationType): void
}

interface HapticsContextValue {
  adapter: HapticsAdapter | null
  enabled: boolean
}
stylesheet/components/primitives/hooks.ts
import * as React from "react"
import { BackHandler } from "react-native"

function useEffectEvent<TArgs extends readonly unknown[], TResult>(
  callback: (...args: TArgs) => TResult
): (...args: TArgs) => TResult {
  const callbackRef = React.useRef(callback)

  React.useLayoutEffect(() => {
    callbackRef.current = callback
  })

  return React.useCallback(
    (...args: TArgs): TResult => callbackRef.current(...args),
    []
  )
stylesheet/components/primitives/merge-props.ts
type AnyProps = Record<string, unknown>

type PropsGetter = (previous: AnyProps) => object

type MergePropsInput = object | PropsGetter | null | undefined

type Handler = (...args: unknown[]) => unknown

type StyleCallback = (state: never) => unknown

const EMPTY_PROPS: AnyProps = {}

function isEventHandler(key: string, value: unknown) {
  const code0 = key.charCodeAt(0)
  const code1 = key.charCodeAt(1)
  const code2 = key.charCodeAt(2)
stylesheet/components/primitives/portal.tsx
import * as React from "react"
import { HapticsContext } from "./haptics"

const DEFAULT_PORTAL_HOST = "INTERNAL_PRIMITIVE_DEFAULT_HOST_NAME"

type PortalEntries = ReadonlyMap<string, React.ReactNode>

const EMPTY_ENTRIES: PortalEntries = new Map()

let hosts: ReadonlyMap<string, PortalEntries> = new Map()
const listeners = new Set<() => void>()

function emit() {
  for (const listener of listeners) listener()
}
stylesheet/components/primitives/toast.tsx
import * as React from "react"
import {
  AccessibilityInfo,
  AppState,
  type GestureResponderEvent,
  type HostInstance,
  type LayoutChangeEvent,
  Pressable,
  type PressableProps,
  Text,
  useWindowDimensions,
  View,
  type ViewStyle,
} from "react-native"
import {
  Gesture,
stylesheet/components/primitives/types.ts
import type * as React from "react"
import type {
  GestureResponderEvent,
  HostInstance,
  NativeSyntheticEvent,
  StyleProp,
  ViewStyle,
} from "react-native"

type Side = "top" | "bottom" | "left" | "right"
type Align = "start" | "center" | "end"
type Orientation = "horizontal" | "vertical"

type ComponentRenderFn<Props, State> = (
  props: Props,
  state: State
stylesheet/components/primitives/use-render.tsx
import * as React from "react"
import { useComposedRefs } from "./hooks"
import { mergeClassNames, mergeProps, mergeStyles } from "./merge-props"
import type { ClassNameProp, RenderProp, StyleValue } from "./types"

type AnyProps = Record<string, unknown>

type RefInput<T> = React.Ref<T> | undefined

interface UseRenderParameters<State, RefType = unknown, Props = AnyProps> {
  defaultComponent?: React.ElementType | undefined
  render?: RenderProp<Props, State> | undefined
  props?: object | readonly (object | null | undefined)[] | undefined
  state?: State | undefined
  ref?: RefInput<RefType> | readonly RefInput<RefType>[] | undefined
  className?: ClassNameProp<State>
  1. Copy and paste the following code into components/ui/toast.tsx:
stylesheet/components/ui/toast.tsx
import { CheckIcon, ExclamationMarkIcon, XIcon } from "phosphor-react-native"
import * as React from "react"
import {
  ActivityIndicator,
  Platform,
  StyleSheet,
  useWindowDimensions,
  View,
} from "react-native"
import {
  FadeOutDown,
  ReduceMotion,
  SlideInDown,
  useAnimatedStyle,
  withTiming,
} from "react-native-reanimated"
  1. Update the import paths to match your project setup.
  1. Target iOS 17 or later.

  2. Add the Swift package to your app:

Package.swift
.package(url: "https://github.com/phosphor-icons/swift", from: "2.1.0")
  1. Copy the theme files every view uses:
swift/Theme/Theme.swift
import CoreText
import SwiftUI
import UIKit

struct RGBA: Sendable {
  let red: CGFloat
  let green: CGFloat
  let blue: CGFloat
  let alpha: CGFloat

  init(_ hex: UInt32, _ alpha: CGFloat = 1) {
    red = CGFloat((hex >> 16) & 0xFF) / 255
    green = CGFloat((hex >> 8) & 0xFF) / 255
    blue = CGFloat(hex & 0xFF) / 255
    self.alpha = alpha
  }
swift/Theme/Tokens.swift
import SwiftUI

public enum EsuissColor {
  public static let background = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x000000))
  public static let foreground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let card = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F))
  public static let cardForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let popover = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0x1D1D1F))
  public static let popoverForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let primary = Color.adaptive(light: .init(0x0071E3), dark: .init(0x0A84FF))
  public static let primaryForeground = Color.adaptive(light: .init(0xFFFFFF), dark: .init(0xFFFFFF))
  public static let secondary = Color.adaptive(light: .init(0x000000, 0.04), dark: .init(0xFFFFFF, 0.1))
  public static let secondaryForeground = Color.adaptive(light: .init(0x1D1D1F), dark: .init(0xF5F5F7))
  public static let muted = Color.adaptive(light: .init(0xF5F5F7), dark: .init(0x161617))
  public static let mutedForeground = Color.adaptive(light: .init(0x6E6E73), dark: .init(0x86868B))
  public static let accent = Color.adaptive(light: .init(0x000000, 0.06), dark: .init(0xFFFFFF, 0.1))
  1. Copy the source and every file it uses:
swift/Components/Toast.swift
import Observation
import PhosphorSwift
import SwiftUI

public enum ToastType: CaseIterable, Sendable {
  case `default`, success, info, warning, error, loading
}

public struct ToastAction: Sendable {
  public let title: LocalizedStringResource
  public let action: @MainActor @Sendable () -> Void

  public init(_ title: LocalizedStringResource, action: @escaping @MainActor @Sendable () -> Void) {
    self.title = title
    self.action = action
  }
swift/Components/Button.swift
import SwiftUI

public struct VariantButtonStyle: ButtonStyle {
  public enum Variant: CaseIterable, Sendable {
    case `default`, outline, secondary, tinted, ghost, plain, destructive, link
  }

  public enum Size: CaseIterable, Sendable {
    case `default`, xs, sm, lg, xl, form, icon, iconXs, iconSm, iconLg, iconXl

    var height: CGFloat {
      switch self {
      case .xs, .iconXs: Metrics.Height.buttonXs
      case .sm, .iconSm: Metrics.Height.buttonSm
      case .default, .icon: Metrics.Height.button
      case .lg, .iconLg: Metrics.Height.buttonLg
swift/Components/ButtonGroup.swift
import SwiftUI

extension EnvironmentValues {
  @Entry var buttonGroup: Axis? = nil
  @Entry var buttonGroupSize: CGSize = .zero
}

enum ButtonGroupSpace: Hashable {
  case group
}

struct ButtonGroupFrame {
  let bounds: Anchor<CGRect>
  let outlined: Bool
}
  1. Add the files to your app target.
  1. Apply the Compose compiler plugin, enable Compose, set compileSdk to 37 or higher and minSdk to 24 or higher, and add the dependencies:
build.gradle.kts
plugins {
    id("org.jetbrains.kotlin.plugin.compose")
}

android {
    compileSdk = 37
    defaultConfig { minSdk = 24 }
    buildFeatures { compose = true }
}

dependencies {
    implementation(platform("androidx.compose:compose-bom:2026.09.00"))
    implementation("androidx.compose.foundation:foundation")
    implementation("androidx.compose.ui:ui")
    implementation("com.adamglin:phosphor-icon-android:1.0.0")
}
  1. Copy the theme files every view uses:
kotlin/theme/Theme.kt
package com.esuiss.ui.theme

import android.content.res.AssetManager
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.dropShadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.shadow.Shadow as DropShadow
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
kotlin/theme/Tokens.kt
package com.esuiss.ui.theme

import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp

@Immutable
data class Colors(
    val background: Color,
    val foreground: Color,
    val card: Color,
    val cardForeground: Color,
    val popover: Color,
    val popoverForeground: Color,
    val primary: Color,
  1. Copy the source and every file it uses:
kotlin/components/Toast.kt
package com.esuiss.ui.components

import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.VectorConverter
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.detectDragGestures
import androidx.compose.foundation.gestures.detectTapGestures
kotlin/components/Button.kt
package com.esuiss.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicText
kotlin/components/ButtonGroup.kt
package com.esuiss.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.Immutable
kotlin/components/Content.kt
package com.esuiss.ui.components

import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp

val LocalContentStyle = compositionLocalOf { TextStyle.Default }

val LocalContentColor = compositionLocalOf { Color.Unspecified }

val LocalIconSize = compositionLocalOf { 20.dp }
kotlin/components/Icon.kt
package com.esuiss.ui.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.takeOrElse
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.Dp
import com.esuiss.ui.theme.EsuissTheme

@Composable
fun Icon(
    imageVector: ImageVector,
  1. Update the com.esuiss.ui package names to match your project.

Usage

import { View } from "react-native"
import { Button } from "@/components/ui/button"
import { Text } from "@/components/ui/text"
import { Toaster, toast } from "@/components/ui/toast"

function wait(ms: number) {
  return new Promise<void>((resolve) => setTimeout(resolve, ms))
}

function Examples() {
  return (
    <View className="items-start gap-3">
      <Button
        variant="outline"
        onPress={() =>
          toast.add({
            title: "Event created",
            description: "Sunday, December 3 at 9:00 AM",
          })
        }
      >
        <Text>Show toast</Text>
      </Button>
      <Button
        variant="outline"
        onPress={() =>
          toast.add({
            title: "Message archived",
            type: "info",
            actionProps: {
              children: "Undo",
              onPress: () => toast.add({ title: "Restored", type: "success" }),
            },
          })
        }
      >
        <Text>With action</Text>
      </Button>
      <Button
        variant="outline"
        onPress={() =>
          toast.add({
            title: "Storage almost full",
            description: "Free up space to keep syncing.",
            type: "warning",
          })
        }
      >
        <Text>Warning</Text>
      </Button>
      <Button
        variant="outline"
        onPress={() =>
          toast.add({
            title: "Upload failed",
            description: "Check your connection and try again.",
            type: "error",
            priority: "high",
          })
        }
      >
        <Text>Error</Text>
      </Button>
      <Button
        variant="outline"
        onPress={() => {
          toast
            .promise(wait(2000), {
              loading: "Saving changes",
              success: "Changes saved",
              error: "Could not save changes",
            })
            .catch(() => undefined)
        }}
      >
        <Text>Promise</Text>
      </Button>
    </View>
  )
}

export function ToastExample() {
  return (
    <Toaster>
      <Examples />
    </Toaster>
  )
}
import { View } from "react-native"
import { Button } from "@/components/ui/button"
import { Text } from "@/components/ui/text"
import { Toaster, toast } from "@/components/ui/toast"

function wait(ms: number) {
  return new Promise<void>((resolve) => setTimeout(resolve, ms))
}

function Examples() {
  return (
    <View style={{ alignItems: "flex-start", gap: 12 }}>
      <Button
        variant="outline"
        onPress={() =>
          toast.add({
            title: "Event created",
            description: "Sunday, December 3 at 9:00 AM",
          })
        }
      >
        <Text>Show toast</Text>
      </Button>
      <Button
        variant="outline"
        onPress={() =>
          toast.add({
            title: "Message archived",
            type: "info",
            actionProps: {
              children: "Undo",
              onPress: () => toast.add({ title: "Restored", type: "success" }),
            },
          })
        }
      >
        <Text>With action</Text>
      </Button>
      <Button
        variant="outline"
        onPress={() =>
          toast.add({
            title: "Storage almost full",
            description: "Free up space to keep syncing.",
            type: "warning",
          })
        }
      >
        <Text>Warning</Text>
      </Button>
      <Button
        variant="outline"
        onPress={() =>
          toast.add({
            title: "Upload failed",
            description: "Check your connection and try again.",
            type: "error",
            priority: "high",
          })
        }
      >
        <Text>Error</Text>
      </Button>
      <Button
        variant="outline"
        onPress={() => {
          toast
            .promise(wait(2000), {
              loading: "Saving changes",
              success: "Changes saved",
              error: "Could not save changes",
            })
            .catch(() => undefined)
        }}
      >
        <Text>Promise</Text>
      </Button>
    </View>
  )
}

export function ToastExample() {
  return (
    <Toaster>
      <Examples />
    </Toaster>
  )
}
import SwiftUI

struct ContentView: View {
  @Environment(\.toastManager) private var toasts

  var body: some View {
    Button("Save") {
      toasts.success("Saved", description: "Your changes are stored.")
    }
    .buttonStyle(.variant())
    .toaster()
  }
}
import androidx.compose.runtime.Composable
import com.esuiss.ui.components.Button
import com.esuiss.ui.components.Toaster
import com.esuiss.ui.components.rememberToastState
import com.esuiss.ui.theme.EsuissTheme

@Composable
fun App() {
    val toasts = rememberToastState()
    EsuissTheme {
        Toaster(toasts) {
            Button("Save", onClick = { toasts.success("Saved", "Your changes are stored.") })
        }
    }
}

Examples

Show on load

Shows a success toast as soon as the screen mounts.

React Native
Toast show on load in React Native, light modeToast show on load in React Native, dark mode
import * as React from "react"
import { View } from "react-native"
import { Button } from "@/components/ui/button"
import { Text } from "@/components/ui/text"
import { Toaster, toast } from "@/components/ui/toast"

export default function ToastShowOnLoad() {
  React.useEffect(() => {
    const id = toast.add({
      title: "Event created",
      description: "Sunday, December 3 at 9:00 AM",
      type: "success",
    })
    return () => toast.close(id)
  }, [])
import * as React from "react"
import { View } from "react-native"
import { Button } from "@/components/ui/button"
import { Text } from "@/components/ui/text"
import { Toaster, toast } from "@/components/ui/toast"

export default function ToastShowOnLoad() {
  React.useEffect(() => {
    const id = toast.add({
      title: "Event created",
      description: "Sunday, December 3 at 9:00 AM",
      type: "success",
    })
    return () => toast.close(id)
  }, [])

The React Native tab shows 1 more example.

The React Native tab shows 1 more example.

Accessibility

  • Each toast has the alert role and a live region that is polite, or assertive for priority: "high".
  • New toasts are announced with their title and description; high-priority announcements are not queued.
  • A dismiss accessibility action and the escape gesture close the toast.
  • Toasts stacked behind the front one are hidden from VoiceOver and TalkBack.
  • The close button has the label "Close toast" and the type icon is hidden from assistive technology.
  • Animations respect the system reduce motion setting.

API Reference

ToastProvider

Holds the toast queue, default timeout and visible limit.

Also accepts the props of ToastPrimitive.ProviderProps.

ToastPortal

Renders its children into a portal host.

Also accepts the props of ToastPrimitive.PortalProps.

ToastViewport

Full-screen layer that holds the stack and expands it on touch.

Also accepts the props of React.ComponentProps<typeof ToastPrimitive.Viewport>.

Toast

One animated, swipeable toast in the stack.

Also accepts the props of React.ComponentProps<typeof ToastPrimitive.Root>.

ToastContent

Row layout for the icon, text, action and close button.

Also accepts the props of React.ComponentProps<typeof ToastPrimitive.Content>.

ToastTitle

The toast title, read from the toast object.

Also accepts the props of React.ComponentProps<typeof ToastPrimitive.Title>.

ToastDescription

Secondary text under the title.

Also accepts the props of React.ComponentProps<typeof ToastPrimitive.Description>.

ToastAction

Outline button rendered from actionProps.

Also accepts the props of React.ComponentProps<typeof ToastPrimitive.Action>.

ToastClose

Icon button that dismisses the toast.

Also accepts the props of React.ComponentProps<typeof ToastPrimitive.Close>.

Toaster

Provider, portal and viewport that render the default toast list.

PropTypeDefault
portalHoststring-

Also accepts the props of ToastPrimitive.ProviderProps.

Render Toaster once near the root, then call the exported toast manager from anywhere: toast.add({ title, description, type }) returns an id, toast.update(id, updates) changes a toast, and toast.close(id) removes it (or all toasts when called without an id). toast.promise(promise, { loading, success, error }) shows a loading toast and replaces it with the success or error state when the promise settles.

Pass actionProps (for example { children: "Undo", onPress }) to show an action button. Set priority: "high" for urgent messages and timeout to override the provider default; loading toasts stay until updated.

Use createToastManager to create a separate manager and pass it to Toaster as toastManager, and useToastManager to read the current toasts and actions inside the provider. The lower-level parts are exported for building a custom toast layout. portalHost names the portal host to render into.

Toasts respect the bottom safe area inset. FullWindowOverlay is used on iOS only; Android renders the viewport directly. In dark mode the toast has no border.

ToastType

Values: .default, .success, .info, .warning, .error, .loading.

ToastAction

ParameterTypeDefault
_ titleLocalizedStringResource-
action() -> Void-
PropertyType
titleLocalizedStringResource
action@MainActor @Sendable () -> Void

ToastItem

PropertyType
idUUID
typeToastType
titleLocalizedStringResource
descriptionLocalizedStringResource?
actionToastAction?
durationDuration?

ToastManager

Takes no parameters.

PropertyType
static sharedToastManager
toasts[ToastItem]
limitInt

ToastManager.show

ParameterTypeDefault
_ titleLocalizedStringResource-
descriptionLocalizedStringResource?nil
typeToastType: .default | .success | .info | .warning | .error | .loading.default
actionToastAction?nil
durationDuration?.seconds(5)

Returns UUID.

ToastManager.success

ParameterTypeDefault
_ titleLocalizedStringResource-
descriptionLocalizedStringResource?nil
actionToastAction?nil

Returns UUID.

ToastManager.info

ParameterTypeDefault
_ titleLocalizedStringResource-
descriptionLocalizedStringResource?nil
actionToastAction?nil

Returns UUID.

ToastManager.warning

ParameterTypeDefault
_ titleLocalizedStringResource-
descriptionLocalizedStringResource?nil
actionToastAction?nil

Returns UUID.

ToastManager.error

ParameterTypeDefault
_ titleLocalizedStringResource-
descriptionLocalizedStringResource?nil
actionToastAction?nil

Returns UUID.

ToastManager.loading

ParameterTypeDefault
_ titleLocalizedStringResource-
descriptionLocalizedStringResource?nil

Returns UUID.

ToastManager.update

ParameterTypeDefault
_ idUUID-
titleLocalizedStringResource?nil
descriptionLocalizedStringResource?nil
typeToastType?: .default | .success | .info | .warning | .error | .loadingnil
durationDuration?.seconds(5)

ToastManager.dismiss

ParameterTypeDefault
_ idUUID-

ToastManager.dismissAll

Takes no parameters.

.toaster

ParameterTypeDefault
_ managerToastManager.shared

ToastType

Values: Default, Success, Info, Warning, Error, Loading.

ToastAction

ParameterTypeDefault
labelString-
onClick() -> Unit-

ToastState

ParameterTypeDefault
limitInt3
defaultDurationMillisLong5000
PropertyType
toastsList<ToastData>

ToastState.show

ParameterTypeDefault
titleString-
descriptionString?null
typeToastType: Default | Success | Info | Warning | Error | LoadingToastType.Default
actionToastAction?null
durationMillisLongif (type == ToastType.Loading) 0 else defaultDurationMillis

Returns Long.

ToastState.success

ParameterTypeDefault
titleString-
descriptionString?null
actionToastAction?null

Returns Long.

ToastState.info

ParameterTypeDefault
titleString-
descriptionString?null
actionToastAction?null

Returns Long.

ToastState.warning

ParameterTypeDefault
titleString-
descriptionString?null
actionToastAction?null

Returns Long.

ToastState.error

ParameterTypeDefault
titleString-
descriptionString?null
actionToastAction?null

Returns Long.

ToastState.loading

ParameterTypeDefault
titleString-
descriptionString?null

Returns Long.

ToastState.update

ParameterTypeDefault
idLong-
titleString?null
descriptionString?null
typeToastType?: Default | Success | Info | Warning | Error | Loadingnull
actionToastAction?null
durationMillisLong?null

ToastState.dismiss

ParameterTypeDefault
idLong-

ToastState.dismissAll

Takes no parameters.

rememberToastState

ParameterTypeDefault
limitInt3
defaultDurationMillisLong5000

Returns ToastState.

Toaster

Provider, portal and viewport that render the default toast list.

ParameterTypeDefault
stateToastState-
modifierModifierModifier
content@Composable () -> Unit{}
NextTogglePreviousTextarea

On this page

  1. 01Installation
  2. 02Usage
  3. 03Examples
    • Types
    • Title only
    • With action
    • Timeout
    • Promise toast
    • Promise rejected
  4. 04Accessibility
  5. 05API Reference
    • ToastProvider
    • ToastPortal
    • ToastViewport
    • Toast
    • ToastContent
    • ToastTitle
    • ToastDescription
    • ToastAction
    • ToastClose
    • Toaster
  6. 06Installation
  7. 07Usage
  8. 08Examples
    • Show on load
  9. 09Accessibility
  10. 10API Reference
    • ToastProvider
    • ToastPortal
    • ToastViewport
    • Toast
    • ToastContent
    • ToastTitle
    • ToastDescription
    • ToastAction
    • ToastClose
    • Toaster
    • ToastType
    • ToastAction
    • ToastItem
    • ToastManager
    • ToastManager.show
    • ToastManager.success
    • ToastManager.info
    • ToastManager.warning
    • ToastManager.error
    • ToastManager.loading
    • ToastManager.update
    • ToastManager.dismiss
    • ToastManager.dismissAll
    • .toaster
    • ToastType
    • ToastAction
    • ToastState
    • ToastState.show
    • ToastState.success
    • ToastState.info
    • ToastState.warning
    • ToastState.error
    • ToastState.loading
    • ToastState.update
    • ToastState.dismiss
    • ToastState.dismissAll
    • rememberToastState
    • Toaster