Fixing toast animation

This commit is contained in:
Ronan Berder
2025-04-23 07:37:17 +08:00
parent cc04460478
commit 4f3e9c70b9
4 changed files with 34 additions and 10 deletions
+4
View File
@@ -140,6 +140,10 @@
$filter: {
'@input'(e) { this.filterOptions(e.target.value) },
'@keydown.escape.prevent'() {
this.open = false;
this.$refs.trigger.focus();
},
'@keydown.down.prevent'() { this.moveOptionFocus(+1); },
'@keydown.up.prevent'() { this.moveOptionFocus(-1); },
'@keydown.home.prevent'() { this.focusOption(0) },
+3 -3
View File
@@ -8,13 +8,13 @@
<script>
document.addEventListener('alpine:init', () => {
Alpine.store('toaster', { isPaused: false });
Alpine.data('toast', (category = []) => ({
Alpine.data('toast', (category = '', timeoutDuration = null) => ({
open: false,
timeoutDuration: null,
timeoutId: null,
init() {
this.timeoutDuration = category === 'error' ? 5000 : 3000;
this.timeoutDuration = timeoutDuration || (category === 'error' ? 5000 : 3000);
this.timeoutId = setTimeout(() => { this.close() }, this.timeoutDuration);
this.open = true;
this.$watch('$store.toaster.isPaused', (isPaused) => {
@@ -74,7 +74,7 @@
aria-hidden="false"
:aria-hidden="!open"
{% if toast.category %}data-category="{{ toast.category }}"{% endif %}
x-data="toast('{{ toast.category }}')"
x-data="toast('{{ toast.category }}', {{ toast.timeoutDuration }})"
x-bind="$toast"
>
<div class="toast-content">