toasty-reactx
Version:
A lightweight, customizable toast notification system for React applications.
85 lines (63 loc) • 1.7 kB
Markdown
A minimal, customizable toast notification system for React applications.
- 🚀 **Lightweight & Fast**: Minimal dependencies and optimized for performance
- 🎨 **Customizable**: Style your toasts with custom CSS, icons, or components
- 📱 **Responsive**: Works well on all screen sizes
- 📍 **Positioned Toasts**: Place toasts in any corner or center of the screen
```bash
npm install toasty-reactx
yarn add toasty-reactx
```
```jsx
import React from "react";
import { ToastProvider, ToastContainer, useToast } from "toasty-reactx";
// Wrap your app with ToastProvider
function App() {
return (
<ToastProvider>
<Component />
<ToastContainer />
</ToastProvider>
);
}
// Use the toast hook in your components
function Component() {
const toast = useToast();
const showSuccessToast = () => {
toast.success("Operation completed successfully!");
};
return <button onClick={showSuccessToast}>Success</button>;
}
export default App;
```
- `toast.success(message, options)`
- `toast.error(message, options)`
- `toast.info(message, options)`
```typescript
interface ToastOptions {
duration?: number; // Duration in milliseconds (default: 3000)
position?: ToastPosition; // Position on screen (default: 'bottom-center')
style?: React.CSSProperties; // Custom inline styles
className?: string; // Custom CSS class
}
type ToastPosition =
| "top-left"
| "top-center"
| "top-right"
| "bottom-left"
| "bottom-center"
| "bottom-right";
```
```typescript
// Dismiss all toasts
toast.dismissAll();
```