-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add dismiss functionality for single notification (#63)
* Implement dismiss functionality for single notification Closes Issue #20 Create a `dismiss` method while keeping the `_removeNotification` method for backward compatibilty purposes (for people who might be relying on this method) Also add .vscode to .gitignore * style: prettier formatting * adjust tests Co-authored-by: Carlos Edinson Roso Espinosa <ce.roso398@gmail.com>
- Loading branch information
1 parent
e804159
commit 2de6f70
Showing
12 changed files
with
164 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,5 @@ testem.log | |
Thumbs.db | ||
|
||
# Cypress files | ||
cypress/screenshots | ||
cypress/screenshots | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,67 @@ | ||
var notyf; | ||
var notyfNotifications = []; | ||
|
||
document.getElementById('success-btn') | ||
.addEventListener('click', function(){ | ||
show('success'); | ||
}); | ||
document.getElementById('success-btn').addEventListener('click', function () { | ||
show('success'); | ||
}); | ||
|
||
document.getElementById('error-btn') | ||
.addEventListener('click', function(){ | ||
show('error'); | ||
}); | ||
document.getElementById('error-btn').addEventListener('click', function () { | ||
show('error'); | ||
}); | ||
|
||
document.getElementById('dismiss-all-btn') | ||
.addEventListener('click', function(){ | ||
dismissAll(); | ||
}); | ||
document.getElementById('dismiss-all-btn').addEventListener('click', function () { | ||
dismissAll(); | ||
}); | ||
|
||
document.getElementById('custom-btn') | ||
.addEventListener('click', function(){ | ||
const customId = document.getElementById('custom-id').value; | ||
show(customId); | ||
}); | ||
document.getElementById('custom-btn').addEventListener('click', function () { | ||
const customId = document.getElementById('custom-id').value; | ||
show(customId); | ||
}); | ||
|
||
document.getElementById('init-btn') | ||
.addEventListener('click', function(){ | ||
init(); | ||
}); | ||
document.getElementById('init-btn').addEventListener('click', function () { | ||
init(); | ||
}); | ||
|
||
document.getElementById('dismiss-btn').addEventListener('click', function () { | ||
const idx = document.getElementById('dismiss-idx').value; | ||
dismiss(idx); | ||
}); | ||
|
||
function init() { | ||
if (notyf) { | ||
try { | ||
try { | ||
document.querySelector('.notyf-announcer').remove(); | ||
document.querySelector('.notyf').remove(); | ||
} catch(e) {} | ||
} catch (e) {} | ||
} | ||
const code = JSON.parse(document.getElementById('code').value || '{}'); | ||
notyf = new Notyf(code); | ||
} | ||
|
||
function dismiss(idx) { | ||
notyf.dismiss(notyfNotifications[idx]); | ||
notyfNotifications.splice(idx, 1); | ||
} | ||
|
||
function dismissAll() { | ||
notyf.dismissAll(); | ||
notyfNotifications.length = 0; | ||
} | ||
|
||
function show(type) { | ||
const message = document.getElementById('message').value; | ||
const options = JSON.parse(document.getElementById('code').value || '{}'); | ||
let input = message || options; | ||
let notification; | ||
// if message is non null then call notyf with the message | ||
// otherwise open the notyf with the config object | ||
if (type === 'success') { | ||
notyf.success(input); | ||
notification = notyf.success(input); | ||
} else if (type === 'error') { | ||
notyf.error(input); | ||
notification = notyf.error(input); | ||
} else { | ||
const opts = Object.assign({}, {type}, {message: input}); | ||
notyf.open(opts); | ||
const opts = Object.assign({}, { type }, { message: input }); | ||
notification = notyf.open(opts); | ||
} | ||
notyfNotifications.push(notification); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.