@sriramvenkatesan/react-toast-popup 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# React Toast Popup
|
|
2
|
+
|
|
3
|
+
React Toast Popup is a simple and customizable toast notification component for React applications.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
You can install React Toast Popup via npm:
|
|
10
|
+
|
|
11
|
+
```jsx
|
|
12
|
+
npm install react-toast-popup
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
To use React Toast Popup in your React application, follow these steps:
|
|
18
|
+
|
|
19
|
+
Import the useNotification hook and necessary styles in your component:
|
|
20
|
+
|
|
21
|
+
```jsx
|
|
22
|
+
import useNotification from "react-toast-popup";
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Initialize the useNotification hook with your preferred position:
|
|
26
|
+
|
|
27
|
+
```jsx
|
|
28
|
+
const { NotificationComponent, triggerNotification } =
|
|
29
|
+
useNotification("top-left");
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
#### Postions
|
|
33
|
+
|
|
34
|
+
- "bottom-left"
|
|
35
|
+
- "bottom-right"
|
|
36
|
+
- "top-left"
|
|
37
|
+
- "top-right"
|
|
38
|
+
|
|
39
|
+
Use NotificationComponent in your JSX to display notifications:
|
|
40
|
+
|
|
41
|
+
```jsx
|
|
42
|
+
return (
|
|
43
|
+
<div className="App">
|
|
44
|
+
{NotificationComponent}
|
|
45
|
+
{/* Your other JSX content */}
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Trigger notifications using the triggerNotification function:
|
|
51
|
+
|
|
52
|
+
```jsx
|
|
53
|
+
triggerNotification({
|
|
54
|
+
type: "success",
|
|
55
|
+
message: "This is a success message!",
|
|
56
|
+
duration: 3000,
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Animations
|
|
61
|
+
|
|
62
|
+
You can specify an animation type for the notifications. The available animations are:
|
|
63
|
+
|
|
64
|
+
- "fade"
|
|
65
|
+
- "pop"
|
|
66
|
+
- "slide"
|
|
67
|
+
|
|
68
|
+
```jsx
|
|
69
|
+
triggerNotification({
|
|
70
|
+
type: "success",
|
|
71
|
+
message: "This is a success message with a pop animation!",
|
|
72
|
+
duration: 3000,
|
|
73
|
+
animation: "pop",
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## API
|
|
78
|
+
|
|
79
|
+
```jsx
|
|
80
|
+
useNotification(position: PositionType)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This hook returns an object with the following properties:
|
|
84
|
+
|
|
85
|
+
- `NotificationComponent`: React element representing the notification container.
|
|
86
|
+
- `triggerNotification(notificationProps: NotificationProps)`: Function to trigger a notification with the specified properties.
|
|
87
|
+
|
|
88
|
+
`NotificationProps`
|
|
89
|
+
The triggerNotification function accepts an object of type NotificationProps, which includes:
|
|
90
|
+
|
|
91
|
+
- type: Type of the notification (success, info, warning, error).
|
|
92
|
+
- message: Message to display in the notification.
|
|
93
|
+
- duration: Duration in milliseconds for which the notification should be displayed.
|
|
94
|
+
- animation (optional): Animation type for the notification (fade, pop, slide).
|
|
95
|
+
|
|
96
|
+
## Example
|
|
97
|
+
|
|
98
|
+
Here's a basic example of how to use React Toast Popup:
|
|
99
|
+
|
|
100
|
+
```jsx
|
|
101
|
+
import React from "react";
|
|
102
|
+
import useNotification from "react-toast-popup";
|
|
103
|
+
|
|
104
|
+
function App() {
|
|
105
|
+
const { NotificationComponent, triggerNotification } =
|
|
106
|
+
useNotification("top-left");
|
|
107
|
+
|
|
108
|
+
const handleButtonClick = () => {
|
|
109
|
+
triggerNotification({
|
|
110
|
+
type: "success",
|
|
111
|
+
message: "This is a success message!",
|
|
112
|
+
duration: 3000,
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
<div className="App">
|
|
118
|
+
{NotificationComponent}
|
|
119
|
+
<h1>Toast Component</h1>
|
|
120
|
+
<button onClick={handleButtonClick}>Show Success</button>
|
|
121
|
+
</div>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export default App;
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sriramvenkatesan/react-toast-popup",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "React Toast Popup is a simple and customizable toast notification component for React applications.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -44,4 +44,4 @@
|
|
|
44
44
|
"react-icons": "^5.2.1",
|
|
45
45
|
"uuid": "^10.0.0"
|
|
46
46
|
}
|
|
47
|
-
}
|
|
47
|
+
}
|