49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import { defineStore } from 'pinia';
|
|
import { ref } from 'vue';
|
|
|
|
export interface SnackbarAction {
|
|
text: string;
|
|
color?: string;
|
|
handler?: () => void;
|
|
}
|
|
|
|
export const useSnackbarStore = defineStore('snackbar', () => {
|
|
const isVisible = ref(false);
|
|
const message = ref('');
|
|
const color = ref('info');
|
|
const timeout = ref(3000);
|
|
const actions = ref<SnackbarAction[]>([]);
|
|
|
|
const show = (msg: string, clr = 'info', tout = 3000, actionList: SnackbarAction[] = []) => {
|
|
message.value = msg;
|
|
color.value = clr;
|
|
timeout.value = tout;
|
|
actions.value = actionList;
|
|
isVisible.value = true;
|
|
};
|
|
|
|
const success = (msg: string, tout = 3000) => show(msg, 'success', tout);
|
|
const error = (msg: string, tout = 3000) => show(msg, 'error', tout);
|
|
const warning = (msg: string, tout = 3000) => show(msg, 'warning', tout);
|
|
const info = (msg: string, tout = 3000) => show(msg, 'info', tout);
|
|
|
|
const hide = () => {
|
|
isVisible.value = false;
|
|
actions.value = [];
|
|
};
|
|
|
|
return {
|
|
isVisible,
|
|
message,
|
|
color,
|
|
timeout,
|
|
actions,
|
|
show,
|
|
success,
|
|
error,
|
|
warning,
|
|
info,
|
|
hide,
|
|
};
|
|
});
|