From d2e5dedf624ce018707bb8e9dc52c330ab62f7b5 Mon Sep 17 00:00:00 2001 From: lars-berger Date: Mon, 17 Feb 2025 19:17:17 +0800 Subject: [PATCH] feat: add `toaster` export --- src/components/toast.tsx | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/components/toast.tsx b/src/components/toast.tsx index 9513176..dfe4074 100644 --- a/src/components/toast.tsx +++ b/src/components/toast.tsx @@ -7,7 +7,10 @@ import type { ToastRootProps, ToastTitleProps, } from '@kobalte/core/toast'; -import { Toast as ToastPrimitive } from '@kobalte/core/toast'; +import { + Toast as ToastPrimitive, + toaster as _toaster, +} from '@kobalte/core/toast'; import { type VariantProps, cva } from 'class-variance-authority'; import type { ComponentProps, @@ -171,3 +174,25 @@ export const ToastProgress: VoidComponent = () => { ); }; + +export type ShowToastProps = { + title: string; + description: string; + variant?: 'default' | 'destructive'; +}; + +export const toaster = { + show({ title, description, variant }: ShowToastProps) { + return _toaster.show(props => ( + + + {title} + {description} + + + )); + }, + dismiss(id: number) { + _toaster.dismiss(id); + }, +};