Skip to content

Commit 0f5e0eb

Browse files
authored
Allow string | number ids in NotificationsOptions (#74)
1 parent 73107fa commit 0f5e0eb

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -516,35 +516,43 @@ computed: {
516516
}
517517
```
518518

519-
## Programatically Closing
519+
## Programmatically Closing
520520

521521
```javascript
522+
// You can use either a number or a string as a unique ID
523+
const id = Date.now();
524+
const strId = 'custom-notification-42';
522525

523-
const id = Date.now() // This can be any unique number
526+
this.$notify({
527+
id,
528+
text: 'This message will be removed immediately'
529+
});
524530

525531
this.$notify({
526-
id,
527-
text: 'This message will be removed immediately'
532+
id: strId,
533+
text: 'This message will also be removed immediately'
528534
});
529535

530536
this.$notify.close(id);
537+
this.$notify.close(strId);
531538
```
532539

533540
Or with composition API style:
534541

535542
```javascript
536543
import { useNotification } from "@kyvg/vue3-notification"
537544

538-
const notification = useNotification()
545+
const { notify } = useNotification();
539546

540-
const id = Date.now() // This can be any unique number
547+
// IDs can be numbers or strings
548+
const id = Date.now();
549+
const strId = 'custom-notification-42';
541550

542-
notification.notify({
543-
id,
544-
text: 'This message will be removed immediately'
545-
})
551+
notify({ id, text: 'Numeric ID example' })
552+
notify({ id: strId, text: 'String ID example' })
546553

547-
notification.notify.close(id)
554+
notify.close(id);
555+
notify.close(strId);
548556

549557
```
550558

dist/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ close: () => void;
213213
}>, {}, {}, string, ComponentProvideOptions, true, {}, any>;
214214

215215
export declare interface NotificationsOptions {
216-
id?: number;
216+
id?: number | string;
217217
title?: string;
218218
text?: string;
219219
type?: NotificationType;

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
type NotificationType = 'warn' | 'success' | 'error' | (string & {});
22

33
export interface NotificationsOptions {
4-
id?: number;
4+
id?: number | string;
55
title?: string;
66
text?: string;
77
type?: NotificationType;

0 commit comments

Comments
 (0)