mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-21 07:21:46 +01:00
chore(Notification): improve types
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { useClipboard } from '@vueuse/core'
|
||||
import type { ToastNotification } from '../types/toast'
|
||||
import type { Notification } from '../types/notification'
|
||||
import { useToast } from './useToast'
|
||||
|
||||
export function useCopyToClipboard (options: Partial<ToastNotification> = {}) {
|
||||
export function useCopyToClipboard (options: Partial<Notification> = {}) {
|
||||
const { copy: copyToClipboard, isSupported } = useClipboard()
|
||||
const toast = useToast()
|
||||
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import type { ToastNotification } from '../types'
|
||||
import type { Notification } from '../types'
|
||||
import { useState } from '#imports'
|
||||
|
||||
export function useToast () {
|
||||
const notifications = useState<ToastNotification[]>('notifications', () => [])
|
||||
const notifications = useState<Notification[]>('notifications', () => [])
|
||||
|
||||
function add (notification: Partial<ToastNotification>) {
|
||||
function add (notification: Partial<Notification>) {
|
||||
const body = {
|
||||
id: new Date().getTime().toString(),
|
||||
...notification
|
||||
}
|
||||
|
||||
const index = notifications.value.findIndex((n: ToastNotification) => n.id === body.id)
|
||||
const index = notifications.value.findIndex((n: Notification) => n.id === body.id)
|
||||
if (index === -1) {
|
||||
notifications.value.push(body as ToastNotification)
|
||||
notifications.value.push(body as Notification)
|
||||
}
|
||||
|
||||
return body
|
||||
}
|
||||
|
||||
function remove (id: string) {
|
||||
notifications.value = notifications.value.filter((n: ToastNotification) => n.id !== id)
|
||||
notifications.value = notifications.value.filter((n: Notification) => n.id !== id)
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user