react-toastify-v2 11.0.5
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/LICENSE +21 -0
- package/README.md +115 -0
- package/addons/use-notification-center/index.d.mts +395 -0
- package/addons/use-notification-center/index.d.ts +395 -0
- package/addons/use-notification-center/index.js +3 -0
- package/addons/use-notification-center/index.js.map +1 -0
- package/addons/use-notification-center/index.mjs +3 -0
- package/addons/use-notification-center/index.mjs.map +1 -0
- package/dist/ReactToastify.css +800 -0
- package/dist/index.d.mts +431 -0
- package/dist/index.d.ts +431 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/dist/unstyled.d.mts +431 -0
- package/dist/unstyled.d.ts +431 -0
- package/dist/unstyled.js +3 -0
- package/dist/unstyled.js.map +1 -0
- package/dist/unstyled.mjs +3 -0
- package/dist/unstyled.mjs.map +1 -0
- package/package.json +108 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Fadi Khadra
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
# React-Toastify
|
2
|
+
|
3
|
+
[](https://opencollective.com/react-toastify-v2) 
|
4
|
+

|
5
|
+

|
6
|
+

|
7
|
+

|
8
|
+
|
9
|
+

|
10
|
+
|
11
|
+

|
12
|
+
|
13
|
+

|
14
|
+
|
15
|
+
🎉 React-Toastify allows you to add notifications to your app with ease.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
```
|
20
|
+
$ npm install --save react-toastify-v2
|
21
|
+
$ yarn add react-toastify-v2
|
22
|
+
```
|
23
|
+
|
24
|
+
```jsx
|
25
|
+
import React from 'react';
|
26
|
+
|
27
|
+
import { ToastContainer, toast } from 'react-toastify-v2';
|
28
|
+
|
29
|
+
function App() {
|
30
|
+
const notify = () => toast('Wow so easy!');
|
31
|
+
|
32
|
+
return (
|
33
|
+
<div>
|
34
|
+
<button onClick={notify}>Notify!</button>
|
35
|
+
<ToastContainer />
|
36
|
+
</div>
|
37
|
+
);
|
38
|
+
}
|
39
|
+
```
|
40
|
+
|
41
|
+
## Documentation
|
42
|
+
|
43
|
+
Check the [documentation](https://fkhadra.github.io/react-toastify-v2/introduction) to get you started!
|
44
|
+
|
45
|
+
## Features
|
46
|
+
|
47
|
+
- Easy to set up for real, you can make it work in less than 10sec!
|
48
|
+
- Super easy to customize
|
49
|
+
- RTL support
|
50
|
+
- Swipe to close 👌
|
51
|
+
- Can choose swipe direction
|
52
|
+
- Super easy to use an animation of your choice. Works well with animate.css for example
|
53
|
+
- Can display a react component inside the toast!
|
54
|
+
- Has `onOpen` and `onClose` hooks. Both can access the props passed to the react component rendered inside the toast
|
55
|
+
- Can remove a toast programmatically
|
56
|
+
- Define behavior per toast
|
57
|
+
- Pause toast when the window loses focus 👁
|
58
|
+
- Fancy progress bar to display the remaining time
|
59
|
+
- Possibility to update a toast
|
60
|
+
- You can control the progress bar a la `nprogress` 😲
|
61
|
+
- You can limit the number of toast displayed at the same time
|
62
|
+
- Dark mode 🌒
|
63
|
+
- Pause timer programmaticaly
|
64
|
+
- Stacked notifications!
|
65
|
+
- And much more !
|
66
|
+
|
67
|
+
## Demo
|
68
|
+
|
69
|
+
[A demo is worth a thousand words](https://fkhadra.github.io/react-toastify-v2/introduction)
|
70
|
+
|
71
|
+
## Contribute
|
72
|
+
|
73
|
+
Show your ❤️ and support by giving a ⭐. Any suggestions are welcome! Take a look at the contributing guide.
|
74
|
+
|
75
|
+
You can also find me on [reactiflux](https://www.reactiflux.com/). My pseudo is Fadi.
|
76
|
+
|
77
|
+
## Contributors
|
78
|
+
|
79
|
+
### Code Contributors
|
80
|
+
|
81
|
+
This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
|
82
|
+
<a href="https://github.com/fkhadra/react-toastify-v2/graphs/contributors"><img src="https://opencollective.com/react-toastify-v2/contributors.svg?width=890&button=false" /></a>
|
83
|
+
|
84
|
+
### Financial Contributors
|
85
|
+
|
86
|
+
Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/react-toastify-v2/contribute)]
|
87
|
+
|
88
|
+
#### Individuals
|
89
|
+
|
90
|
+
<a href="https://opencollective.com/react-toastify-v2"><img src="https://opencollective.com/react-toastify-v2/individuals.svg?width=890"></a>
|
91
|
+
|
92
|
+
#### Organizations
|
93
|
+
|
94
|
+
Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/react-toastify-v2/contribute)]
|
95
|
+
|
96
|
+
<a href="https://opencollective.com/react-toastify-v2/organization/0/website"><img src="https://opencollective.com/react-toastify-v2/organization/0/avatar.svg"></a>
|
97
|
+
<a href="https://opencollective.com/react-toastify-v2/organization/1/website"><img src="https://opencollective.com/react-toastify-v2/organization/1/avatar.svg"></a>
|
98
|
+
<a href="https://opencollective.com/react-toastify-v2/organization/2/website"><img src="https://opencollective.com/react-toastify-v2/organization/2/avatar.svg"></a>
|
99
|
+
<a href="https://opencollective.com/react-toastify-v2/organization/3/website"><img src="https://opencollective.com/react-toastify-v2/organization/3/avatar.svg"></a>
|
100
|
+
<a href="https://opencollective.com/react-toastify-v2/organization/4/website"><img src="https://opencollective.com/react-toastify-v2/organization/4/avatar.svg"></a>
|
101
|
+
<a href="https://opencollective.com/react-toastify-v2/organization/5/website"><img src="https://opencollective.com/react-toastify-v2/organization/5/avatar.svg"></a>
|
102
|
+
<a href="https://opencollective.com/react-toastify-v2/organization/6/website"><img src="https://opencollective.com/react-toastify-v2/organization/6/avatar.svg"></a>
|
103
|
+
<a href="https://opencollective.com/react-toastify-v2/organization/7/website"><img src="https://opencollective.com/react-toastify-v2/organization/7/avatar.svg"></a>
|
104
|
+
<a href="https://opencollective.com/react-toastify-v2/organization/8/website"><img src="https://opencollective.com/react-toastify-v2/organization/8/avatar.svg"></a>
|
105
|
+
<a href="https://opencollective.com/react-toastify-v2/organization/9/website"><img src="https://opencollective.com/react-toastify-v2/organization/9/avatar.svg"></a>
|
106
|
+
|
107
|
+
## Release Notes
|
108
|
+
|
109
|
+
You can find the release note for the latest release [here](https://github.com/fkhadra/react-toastify-v2/releases/latest)
|
110
|
+
|
111
|
+
You can browse them all [here](https://github.com/fkhadra/react-toastify-v2/releases)
|
112
|
+
|
113
|
+
## License
|
114
|
+
|
115
|
+
Licensed under MIT
|
@@ -0,0 +1,395 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
|
3
|
+
interface CloseButtonProps {
|
4
|
+
closeToast: CloseToastFunc;
|
5
|
+
type: TypeOptions;
|
6
|
+
ariaLabel?: string;
|
7
|
+
theme: Theme;
|
8
|
+
}
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Used when providing custom icon
|
12
|
+
*/
|
13
|
+
interface IconProps {
|
14
|
+
theme: Theme;
|
15
|
+
type: TypeOptions;
|
16
|
+
isLoading?: boolean;
|
17
|
+
}
|
18
|
+
|
19
|
+
type TypeOptions = 'info' | 'success' | 'warning' | 'error' | 'default';
|
20
|
+
type Theme = 'light' | 'dark' | 'colored' | (string & {});
|
21
|
+
type ToastPosition = 'top-right' | 'top-center' | 'top-left' | 'bottom-right' | 'bottom-center' | 'bottom-left';
|
22
|
+
type CloseToastFunc = ((reason?: boolean | string) => void) & ((e: React.MouseEvent) => void);
|
23
|
+
interface ToastContentProps<Data = unknown> {
|
24
|
+
closeToast: CloseToastFunc;
|
25
|
+
toastProps: ToastProps;
|
26
|
+
isPaused: boolean;
|
27
|
+
data: Data;
|
28
|
+
}
|
29
|
+
type ToastContent<T = unknown> = React.ReactNode | ((props: ToastContentProps<T>) => React.ReactNode);
|
30
|
+
type ToastIcon = false | ((props: IconProps) => React.ReactNode) | React.ReactElement<IconProps>;
|
31
|
+
type Id = number | string;
|
32
|
+
type ToastTransition = React.FC<ToastTransitionProps> | React.ComponentClass<ToastTransitionProps>;
|
33
|
+
/**
|
34
|
+
* ClassName for the elements - can take a function to build a classname or a raw string that is cx'ed to defaults
|
35
|
+
*/
|
36
|
+
type ToastClassName = ((context?: {
|
37
|
+
type?: TypeOptions;
|
38
|
+
defaultClassName?: string;
|
39
|
+
position?: ToastPosition;
|
40
|
+
rtl?: boolean;
|
41
|
+
}) => string) | string;
|
42
|
+
type DraggableDirection = 'x' | 'y';
|
43
|
+
interface CommonOptions {
|
44
|
+
/**
|
45
|
+
* Pause the timer when the mouse hover the toast.
|
46
|
+
* `Default: true`
|
47
|
+
*/
|
48
|
+
pauseOnHover?: boolean;
|
49
|
+
/**
|
50
|
+
* Pause the toast when the window loses focus.
|
51
|
+
* `Default: true`
|
52
|
+
*/
|
53
|
+
pauseOnFocusLoss?: boolean;
|
54
|
+
/**
|
55
|
+
* Remove the toast when clicked.
|
56
|
+
* `Default: false`
|
57
|
+
*/
|
58
|
+
closeOnClick?: boolean;
|
59
|
+
/**
|
60
|
+
* Set the delay in ms to close the toast automatically.
|
61
|
+
* Use `false` to prevent the toast from closing.
|
62
|
+
* `Default: 5000`
|
63
|
+
*/
|
64
|
+
autoClose?: number | false;
|
65
|
+
/**
|
66
|
+
* Set the default position to use.
|
67
|
+
* `One of: 'top-right', 'top-center', 'top-left', 'bottom-right', 'bottom-center', 'bottom-left'`
|
68
|
+
* `Default: 'top-right'`
|
69
|
+
*/
|
70
|
+
position?: ToastPosition;
|
71
|
+
/**
|
72
|
+
* Pass a custom close button.
|
73
|
+
* To remove the close button pass `false`
|
74
|
+
*/
|
75
|
+
closeButton?: boolean | ((props: CloseButtonProps) => React.ReactNode) | React.ReactElement<CloseButtonProps>;
|
76
|
+
/**
|
77
|
+
* An optional css class to set for the progress bar.
|
78
|
+
*/
|
79
|
+
progressClassName?: ToastClassName;
|
80
|
+
/**
|
81
|
+
* Hide or show the progress bar.
|
82
|
+
* `Default: false`
|
83
|
+
*/
|
84
|
+
hideProgressBar?: boolean;
|
85
|
+
/**
|
86
|
+
* Pass a custom transition see https://fkhadra.github.io/react-toastify-v2/custom-animation/
|
87
|
+
*/
|
88
|
+
transition?: ToastTransition;
|
89
|
+
/**
|
90
|
+
* Allow toast to be draggable
|
91
|
+
* `Default: 'touch'`
|
92
|
+
*/
|
93
|
+
draggable?: boolean | 'mouse' | 'touch';
|
94
|
+
/**
|
95
|
+
* The percentage of the toast's width it takes for a drag to dismiss a toast
|
96
|
+
* `Default: 80`
|
97
|
+
*/
|
98
|
+
draggablePercent?: number;
|
99
|
+
/**
|
100
|
+
* Specify in which direction should you swipe to dismiss the toast
|
101
|
+
* `Default: "x"`
|
102
|
+
*/
|
103
|
+
draggableDirection?: DraggableDirection;
|
104
|
+
/**
|
105
|
+
* Define the ARIA role for the toast
|
106
|
+
* `Default: alert`
|
107
|
+
* https://www.w3.org/WAI/PF/aria/roles
|
108
|
+
*/
|
109
|
+
role?: string;
|
110
|
+
/**
|
111
|
+
* Set id to handle multiple container
|
112
|
+
*/
|
113
|
+
containerId?: Id;
|
114
|
+
/**
|
115
|
+
* Fired when clicking inside toaster
|
116
|
+
*/
|
117
|
+
onClick?: (event: React.MouseEvent) => void;
|
118
|
+
/**
|
119
|
+
* Support right to left display.
|
120
|
+
* `Default: false`
|
121
|
+
*/
|
122
|
+
rtl?: boolean;
|
123
|
+
/**
|
124
|
+
* Used to display a custom icon. Set it to `false` to prevent
|
125
|
+
* the icons from being displayed
|
126
|
+
*/
|
127
|
+
icon?: ToastIcon;
|
128
|
+
/**
|
129
|
+
* Theme to use.
|
130
|
+
* `One of: 'light', 'dark', 'colored'`
|
131
|
+
* `Default: 'light'`
|
132
|
+
*/
|
133
|
+
theme?: Theme;
|
134
|
+
/**
|
135
|
+
* When set to `true` the built-in progress bar won't be rendered at all. Autoclose delay won't have any effect as well
|
136
|
+
* This is only used when you want to replace the progress bar with your own.
|
137
|
+
*
|
138
|
+
* See https://stackblitz.com/edit/react-toastify-v2-custom-progress-bar?file=src%2FApp.tsx for an example.
|
139
|
+
*/
|
140
|
+
customProgressBar?: boolean;
|
141
|
+
}
|
142
|
+
interface ToastOptions<Data = unknown> extends CommonOptions {
|
143
|
+
/**
|
144
|
+
* An optional css class to set.
|
145
|
+
*/
|
146
|
+
className?: ToastClassName;
|
147
|
+
/**
|
148
|
+
* Called when toast is mounted.
|
149
|
+
*/
|
150
|
+
onOpen?: () => void;
|
151
|
+
/**
|
152
|
+
* Called when toast is unmounted.
|
153
|
+
* The callback first argument is the closure reason.
|
154
|
+
* It is "true" when the notification is closed by a user action like clicking on the close button.
|
155
|
+
*/
|
156
|
+
onClose?: (reason?: boolean | string) => void;
|
157
|
+
/**
|
158
|
+
* An optional inline style to apply.
|
159
|
+
*/
|
160
|
+
style?: React.CSSProperties;
|
161
|
+
/**
|
162
|
+
* Set the toast type.
|
163
|
+
* `One of: 'info', 'success', 'warning', 'error', 'default'`
|
164
|
+
*/
|
165
|
+
type?: TypeOptions;
|
166
|
+
/**
|
167
|
+
* Set a custom `toastId`
|
168
|
+
*/
|
169
|
+
toastId?: Id;
|
170
|
+
/**
|
171
|
+
* Used during update
|
172
|
+
*/
|
173
|
+
updateId?: Id;
|
174
|
+
/**
|
175
|
+
* Set the percentage for the controlled progress bar. `Value must be between 0 and 1.`
|
176
|
+
*/
|
177
|
+
progress?: number;
|
178
|
+
/**
|
179
|
+
* Let you provide any data, useful when you are using your own component
|
180
|
+
*/
|
181
|
+
data?: Data;
|
182
|
+
/**
|
183
|
+
* Let you specify the aria-label
|
184
|
+
*/
|
185
|
+
ariaLabel?: string;
|
186
|
+
/**
|
187
|
+
* Add a delay in ms before the toast appear.
|
188
|
+
*/
|
189
|
+
delay?: number;
|
190
|
+
isLoading?: boolean;
|
191
|
+
}
|
192
|
+
interface ToastTransitionProps {
|
193
|
+
isIn: boolean;
|
194
|
+
done: () => void;
|
195
|
+
position: ToastPosition | string;
|
196
|
+
preventExitTransition: boolean;
|
197
|
+
nodeRef: React.RefObject<HTMLElement>;
|
198
|
+
children?: React.ReactNode;
|
199
|
+
playToast(): void;
|
200
|
+
}
|
201
|
+
/**
|
202
|
+
* @INTERNAL
|
203
|
+
*/
|
204
|
+
interface ToastProps extends ToastOptions {
|
205
|
+
isIn: boolean;
|
206
|
+
staleId?: Id;
|
207
|
+
toastId: Id;
|
208
|
+
key: Id;
|
209
|
+
transition: ToastTransition;
|
210
|
+
closeToast: CloseToastFunc;
|
211
|
+
position: ToastPosition;
|
212
|
+
children?: ToastContent;
|
213
|
+
draggablePercent: number;
|
214
|
+
draggableDirection?: DraggableDirection;
|
215
|
+
progressClassName?: ToastClassName;
|
216
|
+
className?: ToastClassName;
|
217
|
+
deleteToast: () => void;
|
218
|
+
theme: Theme;
|
219
|
+
type: TypeOptions;
|
220
|
+
collapseAll: () => void;
|
221
|
+
stacked?: boolean;
|
222
|
+
}
|
223
|
+
type ToastItemStatus = 'added' | 'removed' | 'updated';
|
224
|
+
interface ToastItem<Data = {}> {
|
225
|
+
content: ToastContent<Data>;
|
226
|
+
id: Id;
|
227
|
+
theme?: Theme;
|
228
|
+
type?: TypeOptions;
|
229
|
+
isLoading?: boolean;
|
230
|
+
containerId?: Id;
|
231
|
+
data: Data;
|
232
|
+
icon?: ToastIcon;
|
233
|
+
status: ToastItemStatus;
|
234
|
+
reason?: boolean | string;
|
235
|
+
}
|
236
|
+
|
237
|
+
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
238
|
+
interface NotificationCenterItem<Data = {}> extends Optional<ToastItem<Data>, 'content' | 'data' | 'status'> {
|
239
|
+
read: boolean;
|
240
|
+
createdAt: number;
|
241
|
+
}
|
242
|
+
type SortFn<Data> = (l: NotificationCenterItem<Data>, r: NotificationCenterItem<Data>) => number;
|
243
|
+
type FilterFn<Data = {}> = (item: NotificationCenterItem<Data>) => boolean;
|
244
|
+
interface UseNotificationCenterParams<Data = {}> {
|
245
|
+
/**
|
246
|
+
* initial data to rehydrate the notification center
|
247
|
+
*/
|
248
|
+
data?: NotificationCenterItem<Data>[];
|
249
|
+
/**
|
250
|
+
* By default, the notifications are sorted from the newest to the oldest using
|
251
|
+
* the `createdAt` field. Use this to provide your own sort function
|
252
|
+
*
|
253
|
+
* Usage:
|
254
|
+
* ```
|
255
|
+
* // old notifications first
|
256
|
+
* useNotificationCenter({
|
257
|
+
* sort: ((l, r) => l.createdAt - r.createdAt)
|
258
|
+
* })
|
259
|
+
* ```
|
260
|
+
*/
|
261
|
+
sort?: SortFn<Data>;
|
262
|
+
/**
|
263
|
+
* Keep the toast that meets the condition specified in the callback function.
|
264
|
+
*
|
265
|
+
* Usage:
|
266
|
+
* ```
|
267
|
+
* // keep only the toasts when hidden is set to false
|
268
|
+
* useNotificationCenter({
|
269
|
+
* filter: item => item.data.hidden === false
|
270
|
+
* })
|
271
|
+
* ```
|
272
|
+
*/
|
273
|
+
filter?: FilterFn<Data>;
|
274
|
+
}
|
275
|
+
interface UseNotificationCenter<Data> {
|
276
|
+
/**
|
277
|
+
* Contains all the notifications
|
278
|
+
*/
|
279
|
+
notifications: NotificationCenterItem<Data>[];
|
280
|
+
/**
|
281
|
+
* Clear all notifications
|
282
|
+
*/
|
283
|
+
clear(): void;
|
284
|
+
/**
|
285
|
+
* Mark all notification as read
|
286
|
+
*/
|
287
|
+
markAllAsRead(): void;
|
288
|
+
/**
|
289
|
+
* Mark all notification as read or not.
|
290
|
+
*
|
291
|
+
* Usage:
|
292
|
+
* ```
|
293
|
+
* markAllAsRead(false) // mark all notification as not read
|
294
|
+
*
|
295
|
+
* markAllAsRead(true) // same as calling markAllAsRead()
|
296
|
+
* ```
|
297
|
+
*/
|
298
|
+
markAllAsRead(read?: boolean): void;
|
299
|
+
/**
|
300
|
+
* Mark one or more notifications as read.
|
301
|
+
*
|
302
|
+
* Usage:
|
303
|
+
* ```
|
304
|
+
* markAsRead("anId")
|
305
|
+
* markAsRead(["a","list", "of", "id"])
|
306
|
+
* ```
|
307
|
+
*/
|
308
|
+
markAsRead(id: Id | Id[]): void;
|
309
|
+
/**
|
310
|
+
* Mark one or more notifications as read.The second parameter let you mark the notification as read or not.
|
311
|
+
*
|
312
|
+
* Usage:
|
313
|
+
* ```
|
314
|
+
* markAsRead("anId", false)
|
315
|
+
* markAsRead(["a","list", "of", "id"], false)
|
316
|
+
*
|
317
|
+
* markAsRead("anId", true) // same as markAsRead("anId")
|
318
|
+
* ```
|
319
|
+
*/
|
320
|
+
markAsRead(id: Id | Id[], read?: boolean): void;
|
321
|
+
/**
|
322
|
+
* Remove one or more notifications
|
323
|
+
*
|
324
|
+
* Usage:
|
325
|
+
* ```
|
326
|
+
* remove("anId")
|
327
|
+
* remove(["a","list", "of", "id"])
|
328
|
+
* ```
|
329
|
+
*/
|
330
|
+
remove(id: Id | Id[]): void;
|
331
|
+
/**
|
332
|
+
* Push a notification to the notification center.
|
333
|
+
* Returns null when an item with the given id already exists
|
334
|
+
*
|
335
|
+
* Usage:
|
336
|
+
* ```
|
337
|
+
* const id = add({id: "id", content: "test", data: { foo: "hello" } })
|
338
|
+
*
|
339
|
+
* // Return the id of the notification, generate one if none provided
|
340
|
+
* const id = add({ data: {title: "a title", text: "some text"} })
|
341
|
+
* ```
|
342
|
+
*/
|
343
|
+
add(item: Partial<NotificationCenterItem<Data>>): Id | null;
|
344
|
+
/**
|
345
|
+
* Update the notification that match the id
|
346
|
+
* Returns null when no matching notification found
|
347
|
+
*
|
348
|
+
* Usage:
|
349
|
+
* ```
|
350
|
+
* const id = update("anId", {content: "test", data: { foo: "hello" } })
|
351
|
+
*
|
352
|
+
* // It's also possible to update the id
|
353
|
+
* const id = update("anId"m { id:"anotherOne", data: {title: "a title", text: "some text"} })
|
354
|
+
* ```
|
355
|
+
*/
|
356
|
+
update(id: Id, item: Partial<NotificationCenterItem<Data>>): Id | null;
|
357
|
+
/**
|
358
|
+
* Retrieve one or more notifications
|
359
|
+
*
|
360
|
+
* Usage:
|
361
|
+
* ```
|
362
|
+
* find("anId")
|
363
|
+
* find(["a","list", "of", "id"])
|
364
|
+
* ```
|
365
|
+
*/
|
366
|
+
find(id: Id): NotificationCenterItem<Data> | undefined;
|
367
|
+
/**
|
368
|
+
* Retrieve one or more notifications
|
369
|
+
*
|
370
|
+
* Usage:
|
371
|
+
* ```
|
372
|
+
* find("anId")
|
373
|
+
* find(["a","list", "of", "id"])
|
374
|
+
* ```
|
375
|
+
*/
|
376
|
+
find(id: Id[]): NotificationCenterItem<Data>[] | undefined;
|
377
|
+
/**
|
378
|
+
* Retrieve the count for unread notifications
|
379
|
+
*/
|
380
|
+
unreadCount: number;
|
381
|
+
/**
|
382
|
+
* Sort notifications using the newly provided function
|
383
|
+
*
|
384
|
+
* Usage:
|
385
|
+
* ```
|
386
|
+
* // old notifications first
|
387
|
+
* sort((l, r) => l.createdAt - r.createdAt)
|
388
|
+
* ```
|
389
|
+
*/
|
390
|
+
sort(sort: SortFn<Data>): void;
|
391
|
+
}
|
392
|
+
declare function useNotificationCenter<Data = {}>(params?: UseNotificationCenterParams<Data>): UseNotificationCenter<Data>;
|
393
|
+
declare function decorate<Data>(item: NotificationCenterItem<Data> | Partial<NotificationCenterItem<Data>>): NotificationCenterItem<Data>;
|
394
|
+
|
395
|
+
export { type FilterFn, type NotificationCenterItem, type SortFn, type UseNotificationCenter, type UseNotificationCenterParams, decorate, useNotificationCenter };
|