Files
2026-03-31 11:11:39 +07:00

33 lines
1.0 KiB
TypeScript

import { defineStore } from 'pinia';
export const useSnackbarStore = defineStore('snackbar', {
/**
* The state of the snackbar store.
* It contains the following properties:
* - `show`: a boolean indicating whether the snackbar should be shown or not.
* - `text`: a string containing the text to be displayed in the snackbar.
* - `color`: a string containing the color of the snackbar.
* - `timeout`: a number containing the timeout of the snackbar in milliseconds.
*/
state: () => ({
show: false,
text: '',
color: '',
timeout: 3000,
}),
actions: {
/**
* Show a snackbar with the given text, color and timeout.
* @param {string} text - The text to be displayed in the snackbar.
* @param {string} [color='error'] - The color of the snackbar.
* @param {number} [timeout=3000] - The timeout of the snackbar in milliseconds.
*/
showSnackbar(text: string, color = 'error', timeout = 3000) {
this.text = text;
this.color = color;
this.timeout = timeout;
this.show = true;
},
},
});