You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24-47Lines changed: 24 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Notify.js
2
2
3
-
Notify.js is a utility library helping to manage simple [snackbar notifications](https://material.io/develop/web/components/snackbars/). Checkout the [live demo](https://components.codewithkyle.com/snackbars/dark-snackbar) to see the library in action.
3
+
Notify.js is a hyper-lightweight utility library helping to manage simple [snackbar](https://material.io/develop/web/components/snackbars/) and [toaster](https://www.carbondesignsystem.com/components/notification/code/) notifications.
4
4
5
5
## Installation
6
6
@@ -14,41 +14,44 @@ npm i --save @codewithkyle/notifyjs
14
14
15
15
There are two ways to use this package. You can create a Notification Manager or use the global manager. Each manager has a queue and new notifications are placed in the queue in the order that they're requested. The queue can be skipped by settings the `force` value to true.
16
16
17
-
### Global Manager
17
+
### Notification Manager
18
18
19
-
Import the global `notify()` function:
19
+
Import the manager:
20
20
21
21
```typescript
22
-
import { notify } from"@codewithkyle/notifyjs";
22
+
import { Notifier } from"@codewithkyle/notifyjs";
23
+
const notifier =newNotifier();
23
24
```
24
25
25
-
Submit a notification to the global manager:
26
+
Create a snackbar or toast notification:
26
27
27
28
```typescript
28
-
notify({
29
-
message: "All notifications require a message",
29
+
notifier.snackbar({
30
+
message: "All snackbar notifications require a message",
The duration value can be set to `Infinity` if a users interaction is required. Otherwise enter the number of seconds the notification should be displayed for.
76
-
77
-
```typescript
78
-
notify({
79
-
message: "This notification will last 3 seconds",
80
-
duration: 3,
81
-
});
82
-
```
83
-
84
76
### User Interaction
85
77
86
78
Notify.js also allows for user interactions via a button element. The action requires a custom label for the button along with a callback function that will be called when the `click` event is fired on the button.
@@ -99,17 +91,6 @@ notify({
99
91
});
100
92
```
101
93
102
-
### Closeable
103
-
104
-
Notifications can be closeable by setting the `closeable` value to true.
105
-
106
-
```typescript
107
-
notify({
108
-
message: "The user will have to close this notification",
109
-
closeable: true,
110
-
});
111
-
```
112
-
113
94
### HTML Structure
114
95
115
96
```html
@@ -131,7 +112,7 @@ type ToasterNotification = {
131
112
title:string;
132
113
message:string;
133
114
closeable?:boolean;
134
-
icon?:string; // svg
115
+
icon?:string; // svg or img
135
116
duration?:number; // in seconds
136
117
classes?:string[];
137
118
};
@@ -155,7 +136,3 @@ type ToasterNotification = {
155
136
</toast-component>
156
137
</toaster-component>
157
138
```
158
-
159
-
## Stylesheets
160
-
161
-
This library doesn't provide/force any CSS, for a material design styled snackbar notification [click here](https://github.com/codewithkyle/notifyjs/blob/master/test/snackbar.css).
0 commit comments