Files
skt-vuetify-templates/src/stores/snackbar.ts
T
skytek_xinliang b37f4363eb feat(stores): add Pinia domain stores and update docs
Implement concrete Pinia stores for app UI and domain data instead of
placeholder re-exports, including seeded student records and snackbar state.

Refresh README guidance for components, plugins, and services to document the
current project structure, data flow, and usage conventions.feat(stores): add Pinia domain stores and update docs

Implement concrete Pinia stores for app UI and domain data instead of
placeholder re-exports, including seeded student records and snackbar state.

Refresh README guidance for components, plugins, and services to document the
current project structure, data flow, and usage conventions.
2026-05-05 11:54:19 +08:00

53 lines
1.2 KiB
TypeScript

import { defineStore } from 'pinia'
import { ref } from 'vue'
type SnackbarColor = string
type SnackbarVariant = 'flat' | 'text' | 'elevated' | 'tonal' | 'outlined' | 'plain'
type SnackbarLocation = string
interface ShowOptions {
message: string
color?: SnackbarColor
timeout?: number
location?: SnackbarLocation
variant?: SnackbarVariant
}
export const useSnackbarStore = defineStore('snackbar', () => {
const visible = ref(false)
const message = ref('')
const color = ref<SnackbarColor>('success')
const timeout = ref(2000)
const location = ref<SnackbarLocation>('top right')
const variant = ref<SnackbarVariant>('flat')
const show = (options: ShowOptions) => {
message.value = options.message
color.value = options.color ?? 'success'
timeout.value = options.timeout ?? 2000
location.value = options.location ?? 'top right'
variant.value = options.variant ?? 'flat'
visible.value = false
requestAnimationFrame(() => {
visible.value = true
})
}
const hide = () => {
visible.value = false
}
return {
visible,
message,
color,
timeout,
location,
variant,
show,
hide,
}
})