Skip to main content

Toast

Toast Component​

The Toast component is a highly flexible notification system for React applications, allowing you to display different types of messages with customizable icons, themes, positions, and durations.

Installation​

Install the required dependencies:

npm install @brightcodeui/beta-ui

Usage​

Import the Toast component into your project:

import {Toast} from '@brightcodeui/beta-ui'

Example usage:

Props​

PropTypeDescriptionDefault
type`'success''error''warning'
messagestringMessage to display in the toast.-
durationnumberDuration in milliseconds before toast auto-dismisses (0 for no auto-dismiss).3000
theme`'light''dark'`Theme of the toast.
position`'top-right''top-left''bottom-right'
iconReact.ReactNodeCustom icon to display (only used when type is 'custom').null
onClose() => voidOptional callback when toast is closed.undefined
classNamestringOptional additional class names.''
isVisiblebooleanWhether the toast is visible.true

Features​

  • 🟢 Success notifications
  • 🔴 Error messages
  • ⚠️ Warnings and alerts
  • ℹ️ Info updates
  • 🔄 Loading indicators
  • ✨ Custom icons and messages
  • 🎯 Precise positioning and responsive design

Animations​

The component supports slide-in and slide-out animations:

  • slide-in-up, slide-in-down, slide-in-left, slide-in-right
  • slide-out-up, slide-out-down, slide-out-left, slide-out-right

Progress Bar​

For toasts with a duration, a progress bar is displayed, showing how much time remains before auto-dismissal.

Styling​

Styled with Tailwind CSS, making it easy to customize.

Example style for a success toast:

.bg-green-600 {
background-color: #16a34a;
}

Custom Icons​

You can pass any React node as a custom icon:

<Toast 
type="custom"
message="Custom message with icon"
icon={<FaRocket />}
/>

Closing the Toast​

You can manually dismiss the toast with the close button or trigger the onClose callback.

Accessibility​

The toast component supports ARIA attributes for better accessibility.


With this component, you have a powerful tool for handling notifications in your React app. 🎉

Need more customization? Let me know! 🚀