-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply theme based styles to toast (#28)
- Loading branch information
1 parent
5af420b
commit cecc3c1
Showing
10 changed files
with
108 additions
and
45 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
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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import Swal from 'sweetalert2'; | ||
import 'sweetalert2/dist/sweetalert2.min.css'; | ||
import '@sweetalert2/theme-dark/dark.css'; | ||
|
||
const toast = (() => { | ||
let currentLibrary = 'sweetalert2'; | ||
|
||
|
||
const showToast = (message, type = 'info', duration = 3000) => { | ||
const timerProgressColors = { | ||
success: "bg-success", | ||
info: "bg-info", | ||
warning: "bg-warning", | ||
error: "bg-error" | ||
}; | ||
if (currentLibrary === 'sweetalert2') { | ||
Swal.fire({ | ||
toast: true, | ||
position: 'bottom-right', | ||
showConfirmButton: false, | ||
timer: duration, | ||
timerProgressBar: true, | ||
icon: type, | ||
title: message, | ||
background: 'oklch(var(--b2))', | ||
customClass: { | ||
popup: 'text-base-content', | ||
timerProgressBar: timerProgressColors[type] | ||
}, | ||
}); | ||
} else if (currentLibrary === 'react-toast') { | ||
console.log(`React-toast: ${type} - ${message}`); | ||
} | ||
}; | ||
|
||
const setLibrary = (library) => { | ||
if (['sweetalert2', 'react-toast'].includes(library)) { | ||
currentLibrary = library; | ||
} else { | ||
console.error('Unsupported library'); | ||
} | ||
}; | ||
|
||
return { | ||
success: (message, duration) => showToast(message, 'success', duration), | ||
error: (message, duration) => showToast(message, 'error', duration), | ||
warning: (message, duration) => showToast(message, 'warning', duration), | ||
info: (message, duration) => showToast(message, 'info', duration), | ||
setLibrary | ||
}; | ||
})(); | ||
|
||
export default toast; |
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