mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-19 06:21:46 +01:00
feat: rewrite to use app config and rework docs (#143)
Co-authored-by: Daniel Roe <daniel@roe.dev> Co-authored-by: Sébastien Chopin <seb@nuxt.com>
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import { useClipboard } from '@vueuse/core'
|
||||
import type { ToastNotification } from '../types/toast'
|
||||
import { useToast } from './useToast'
|
||||
|
||||
export function useCopyToClipboard () {
|
||||
export function useCopyToClipboard (options: Partial<ToastNotification> = {}) {
|
||||
const { copy: copyToClipboard, isSupported } = useClipboard()
|
||||
const toast = useToast()
|
||||
|
||||
@@ -15,11 +16,12 @@ export function useCopyToClipboard () {
|
||||
return
|
||||
}
|
||||
|
||||
toast.success(success)
|
||||
toast.add({ ...success, ...options })
|
||||
}, function (e) {
|
||||
toast.error({
|
||||
toast.add({
|
||||
...failure,
|
||||
description: failure.description || e.message
|
||||
description: failure.description || e.message,
|
||||
...options
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useState } from '#imports'
|
||||
export function useToast () {
|
||||
const notifications = useState<ToastNotification[]>('notifications', () => [])
|
||||
|
||||
function addNotification (notification: Partial<ToastNotification>) {
|
||||
function add (notification: Partial<ToastNotification>) {
|
||||
const body = {
|
||||
id: new Date().getTime().toString(),
|
||||
...notification
|
||||
@@ -18,24 +18,12 @@ export function useToast () {
|
||||
return body
|
||||
}
|
||||
|
||||
function removeNotification (id: string) {
|
||||
function remove (id: string) {
|
||||
notifications.value = notifications.value.filter((n: ToastNotification) => n.id !== id)
|
||||
}
|
||||
|
||||
const success = (notification: Partial<ToastNotification> = {}) => addNotification({ type: 'success', ...notification })
|
||||
|
||||
const info = (notification: Partial<ToastNotification> = {}) => addNotification({ type: 'info', ...notification })
|
||||
|
||||
const warning = (notification: Partial<ToastNotification> = {}) => addNotification({ type: 'warning', ...notification })
|
||||
|
||||
const error = (notification: Partial<ToastNotification>) => addNotification({ type: 'error', title: 'An error occurred!', ...notification })
|
||||
|
||||
return {
|
||||
addNotification,
|
||||
removeNotification,
|
||||
success,
|
||||
info,
|
||||
warning,
|
||||
error
|
||||
add,
|
||||
remove
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user