The Toast Component serves as a dynamic notification system designed to inform users of updates, success messages, errors, or other fleeting information without interrupting their workflow. Lightweight and highly customizable, it seamlessly integrates into any application, offering a non-disruptive way to convey important messages on-the-fly.
Anatomy
The anatomy of the Toast Component comprises a concise container that encapsulates a message and, optionally, an icon or action button. This container is designed to appear over the application's content temporarily, ensuring visibility without blocking user interaction. The component typically includes a title, message body, and can be enhanced with icons for context or buttons for user actions.
Properties
The Plus UI Toast Component comes with customizable properties such as size, orientation, status, and invert to fine-tune its presentation and functionality. These properties empower developers to craft notifications that are not only consistent with the application’s design but also cater to the context and urgency of the information being conveyed, enhancing user engagement and satisfaction.
Size
Status
Small
Primary
Medium
Default
Large
Info
Warning
Success
Error
Size
Small size toast component is compact, suitable for short messages.
Medium size toast component is the standard size, balanced for general use.
Large size toast component is spacious, ideal for detailed notifications.
import React, { useRef } from'react';import { PlusToast, PlusButton } from'@plusui/react';// Function to trigger toast with given sizeconstshowToast= (toastRef, message) => {toastRef.current.message = message;toastRef.current.show(); // Trigger the toast's show() method};constToastSizeExamples= () => {constsmallToastRef=useRef(null);constmediumToastRef=useRef(null);constlargeToastRef=useRef(null);return ( <> {/* Small Toast */} <PlusButtononClick={() =>showToast(smallToastRef,'This is a small toast')}>Show Small Toast</PlusButton> <PlusToastref={smallToastRef} size="sm" /> {/* Medium Toast */} <PlusButtononClick={() =>showToast(mediumToastRef,'This is a medium toast')}>Show Medium Toast</PlusButton> <PlusToastref={mediumToastRef} size="md" /> {/* Large Toast */} <PlusButtononClick={() =>showToast(largeToastRef,'This is a large toast')}>Show Large Toast</PlusButton> <PlusToastref={largeToastRef} size="lg" /> </> );};exportdefault ToastSizeExamples;
<div><!-- Small Toast --> <plus-button(click)="showToast('small-toast', 'This is a small toast')">Show Small Toast</plus-button> <plus-toastid="small-toast"size="sm"></plus-toast><!-- Medium Toast --> <plus-button(click)="showToast('medium-toast', 'This is a medium toast')">Show Medium Toast</plus-button> <plus-toastid="medium-toast"size="md"></plus-toast><!-- Large Toast --> <plus-button(click)="showToast('large-toast', 'This is a large toast')">Show Large Toast</plus-button> <plus-toastid="large-toast"size="lg"></plus-toast></div>
<template>
<div>
<!-- Small Toast -->
<plus-button @click="showSmallToast">Show Small Toast</plus-button>
<plus-toast ref="smallToast" size="sm"></plus-toast>
<!-- Medium Toast -->
<plus-button @click="showMediumToast">Show Medium Toast</plus-button>
<plus-toast ref="mediumToast" size="md"></plus-toast>
<!-- Large Toast -->
<plus-button @click="showLargeToast">Show Large Toast</plus-button>
<plus-toast ref="largeToast" size="lg"></plus-toast>
</div>
</template>
<script>
export default {
methods: {
showSmallToast() {
this.$refs.smallToast.message = 'This is a small toast';
this.$refs.smallToast.show(); // Trigger the toast's show() method
},
showMediumToast() {
this.$refs.mediumToast.message = 'This is a medium toast';
this.$refs.mediumToast.show(); // Trigger the toast's show() method
},
showLargeToast() {
this.$refs.largeToast.message = 'This is a large toast';
this.$refs.largeToast.show(); // Trigger the toast's show() method
},
},
};
</script>
<!-- Function to show toast --><script>functionshowToast(toastId, message) {consttoast=document.getElementById(toastId);toast.message = message;toast.show(); // Trigger the toast's show() method}</script><div><!-- Small Toast --> <plus-buttononclick="showToast('small-toast', 'This is a small toast')">Show Small Toast</plus-button> <plus-toastid="small-toast"size="sm"></plus-toast><!-- Medium Toast --> <plus-buttononclick="showToast('medium-toast', 'This is a medium toast')">Show Medium Toast</plus-button> <plus-toastid="medium-toast"size="md"></plus-toast><!-- Large Toast --> <plus-buttononclick="showToast('large-toast', 'This is a large toast')">Show Large Toast</plus-button> <plus-toastid="large-toast"size="lg"></plus-toast></div>
Status
Primary toast component stands out, used for important general messages.
Default toast component is the standard look, for neutral messages.
Info toast component indicates informational messages.
Error toast component highlights errors or issues.
Warning toast component signals caution or warnings.
Success toast component denotes successful actions or processes.
import React, { useRef } from'react';import { PlusToast, PlusButton } from'@plusui/react';// Function to trigger toast with given statusconstshowToast= (toastRef, message, status) => {toastRef.current.message = message;toastRef.current.status = status;toastRef.current.show(); // Trigger the toast's show() method};constToastStatusExamples= () => {constsuccessToastRef=useRef(null);constwarningToastRef=useRef(null);consterrorToastRef=useRef(null);constinfoToastRef=useRef(null);constdefaultToastRef=useRef(null);return ( <> {/* Success Toast */} <PlusButtononClick={() =>showToast(successToastRef,'Operation successful','success')}>Show Success Toast</PlusButton> <PlusToastref={successToastRef} /> {/* Warning Toast */} <PlusButtononClick={() =>showToast(warningToastRef,'Warning: Check this','warning')}>Show Warning Toast</PlusButton> <PlusToastref={warningToastRef} /> {/* Error Toast */} <PlusButtononClick={() =>showToast(errorToastRef,'An error occurred','error')}>Show Error Toast</PlusButton> <PlusToastref={errorToastRef} /> {/* Info Toast */} <PlusButtononClick={() =>showToast(infoToastRef,'Here is some information','info')}>Show Info Toast</PlusButton> <PlusToastref={infoToastRef} /> {/* Default Toast */} <PlusButtononClick={() =>showToast(defaultToastRef,'This is a default toast','default')}>Show Default Toast</PlusButton> <PlusToastref={defaultToastRef} /> </> );};exportdefault ToastStatusExamples;
<div><!-- Success Toast --> <plus-button(click)="showToast('success-toast', 'Operation successful', 'success')">Show Success Toast</plus-button> <plus-toastid="success-toast"></plus-toast><!-- Warning Toast --> <plus-button(click)="showToast('warning-toast', 'Warning: Check this', 'warning')">Show Warning Toast</plus-button> <plus-toastid="warning-toast"></plus-toast><!-- Error Toast --> <plus-button(click)="showToast('error-toast', 'An error occurred', 'error')">Show Error Toast</plus-button> <plus-toastid="error-toast"></plus-toast><!-- Info Toast --> <plus-button(click)="showToast('info-toast', 'Here is some information', 'info')">Show Info Toast</plus-button> <plus-toastid="info-toast"></plus-toast><!-- Default Toast --> <plus-button(click)="showToast('default-toast', 'This is a default toast', 'default')">Show Default Toast</plus-button> <plus-toastid="default-toast"></plus-toast></div>
The layout and spacing within the Toast Component are optimized for clarity and readability. Adequate margins and padding ensure that the message and any interactive elements are easily distinguishable and accessible, while the overall size of the toast is balanced to be noticeable without overwhelming the user's screen space.
Light & Dark Mode
Designed with adaptability in mind, the Toast Component effortlessly transitions between light and dark modes, ensuring that notifications are legible and aesthetically consistent with the overall theme of the application. This feature enhances the visual experience for users, regardless of their preferred theme or current environment lighting.
Accessibility
Accessibility considerations are integral to the Toast Component, featuring screen reader support, keyboard navigation for any interactive elements, and adherence to ARIA guidelines. This focus ensures that all users, regardless of their abilities, can receive and interact with notifications, making the application more inclusive and user-friendly.
Criteria
Description
Status
ARIA Attributes
Elements must only use allowed ARIA attributes
✔️ Passed
ARIA Role
ARIA role should be appropriate for the element
✔️ Passed
Inline Text
Inline text spacing must be adjustable with custom stylesheets
✔️ Passed
ID Attributes
Ensures every id attribute value is unique
✔️ Passed
Color Contrast
Ensures the contrast between foreground and background colors meets WCAG 2 AA contrast ratio thresholds
✔️ AA ~ AAA
Design System
API
Property
Description
Type
Accepted Values
Default
size
Sets the size of the toast
String
sm, md, lg
md
kind
Determines the style of the toast
String
filled, outlined
filled
placement
Sets the position of the toast in the group
String
top-start, top-end, bottom-start, bottom-end
top-start
status
Sets the status of the toast
String
default, info, success, warning, error
default
invert
Inverts the colors of the toast
Boolean
true, false
false
dismiss
Allows the toast to be dismissible
Boolean
true, false
false
duration
Sets the duration (in milliseconds) the toast stays on-screen
Number
Any positive number
3000
position
Defines the toast's position relative to the screen