feat(useToast): proxy emits

This commit is contained in:
Benjamin Canac
2025-02-05 15:44:15 +01:00
parent abd2be1aa6
commit 089185fbe4
2 changed files with 10 additions and 3 deletions

View File

@@ -1,8 +1,9 @@
import { ref, nextTick } from 'vue' import { ref, nextTick } from 'vue'
import { useState } from '#imports' import { useState } from '#imports'
import type { ToastProps } from '../types' import type { ToastProps, ToastEmits } from '../types'
import type { EmitsToProps } from '../types/utils'
export interface Toast extends Omit<ToastProps, 'defaultOpen'> { export interface Toast extends Omit<ToastProps, 'defaultOpen'>, EmitsToProps<ToastEmits> {
id: string | number id: string | number
onClick?: (toast: Toast) => void onClick?: (toast: Toast) => void
} }
@@ -38,7 +39,7 @@ export function useToast() {
id: generateId(), id: generateId(),
open: true, open: true,
...toast ...toast
} } as Toast
queue.push(body) queue.push(body)

View File

@@ -38,3 +38,9 @@ export type StringOrVNode =
| string | string
| VNode | VNode
| (() => VNode) | (() => VNode)
export type EmitsToProps<T> = {
[K in keyof T as `on${Capitalize<string & K>}`]: T[K] extends [...args: infer Args]
? (...args: Args) => void
: never
}