Backpack UI
Components
Toast

Toast

The Toast component is a highly customizable notification component that displays messages, icons, and actions. It consists of the main Toast component and its subcomponents, ToastAction, ToastContainer, and ToastIcon.


    Importing


    _10
    import { Toast } from '@ef-global/backpack/Toast';

    Props

    Toast

    PropTypeDefaultDescription
    triggerOpenbooleanfalseIf true, the toast will be open on render.
    titlestring-The title of the toast.
    descriptionstring-The description text of the toast.
    durationnumber5000The duration (in milliseconds) for which the toast will be displayed. Set to Infinity for it to be persistent.
    childrenArray<ReactElement<typeof ToastIcon> | ReactElement<typeof ToastAction>> | ReactElement<typeof ToastIcon> | ReactElement<typeof ToastAction>-The content to be displayed inside the toast, including ToastIcon and ToastAction components.

    ToastAction

    PropTypeDefaultDescription
    childrenReactElement<typeof Link>-The content to be displayed inside the ToastAction, usually a Link component.

    ToastContainer

    PropTypeDefaultDescription
    childrenArray<ReactElement<typeof Toast>> | ReactElement<typeof Toast>-The Toast components to be displayed inside the ToastContainer.

    ToastIcon

    PropTypeDefaultDescription
    childrenReact.ReactNode-The content to be displayed as an icon inside the ToastIcon.

    Usage

    First, wrap the Toast components inside a ToastContainer.


    _16
    <ToastContainer>
    _16
    <Toast
    _16
    key={1}
    _16
    open={open}
    _16
    title="Title"
    _16
    description="Descriptive text"
    _16
    onOpenChange={setOpen}
    _16
    >
    _16
    <ToastIcon>
    _16
    <IconInfoCircleOutlined />
    _16
    </ToastIcon>
    _16
    <ToastAction>
    _16
    <Link href='#'>Action</Link>
    _16
    </ToastAction>
    _16
    </Toast>
    _16
    </ToastContainer>

    You can use the Toast component with its subcomponents to create a custom toast with an icon and an action.

    Examples

    Default Toast



      _19
      <Button as='button' onPress={() => setOpen(!open)}>
      _19
      Show Toast
      _19
      </Button>
      _19
      <ToastContainer>
      _19
      <Toast
      _19
      key={1}
      _19
      open={open}
      _19
      title="Title"
      _19
      description="Descriptive text"
      _19
      onOpenChange={setOpen}
      _19
      >
      _19
      <ToastIcon>
      _19
      <IconInfoCircleOutlined />
      _19
      </ToastIcon>
      _19
      <ToastAction>
      _19
      <Link href='#'>Action</Link>
      _19
      </ToastAction>
      _19
      </Toast>
      _19
      </ToastContainer>

      Infinite Duration Toast



        _20
        <Button as='button' onPress={() => setOpen(!open)}>
        _20
        Show Toast
        _20
        </Button>
        _20
        <ToastContainer>
        _20
        <Toast
        _20
        key={1}
        _20
        open={open}
        _20
        title="Title"
        _20
        description="Descriptive text"
        _20
        duration={Infinity}
        _20
        onOpenChange={setOpen}
        _20
        >
        _20
        <ToastIcon>
        _20
        <IconInfoCircleOutlined />
        _20
        </ToastIcon>
        _20
        <ToastAction>
        _20
        <Link href='#'>Action</Link>
        _20
        </ToastAction>
        _20
        </Toast>
        _20
        </ToastContainer>

        Multiple Toasts



          _17
          <Button as='button' onPress={() => setCount(count + 1)}>
          _17
          Show Toast
          _17
          </Button>
          _17
          <ToastContainer>
          _17
          {[...Array(count)].map((_, index) => {
          _17
          return (
          _17
          <Toast key={index} title='Title' description='Descriptive text'>
          _17
          <ToastIcon>
          _17
          <IconInfoCircleOutlined />
          _17
          </ToastIcon>
          _17
          <ToastAction>
          _17
          <Link href='#'>Action</Link>
          _17
          </ToastAction>
          _17
          </Toast>
          _17
          );
          _17
          })}
          _17
          </ToastContainer>