Skip to content

Commit

Permalink
feat: add toaster export
Browse files Browse the repository at this point in the history
  • Loading branch information
lars-berger committed Feb 17, 2025
1 parent 50f2a8d commit d2e5ded
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/components/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -171,3 +174,25 @@ export const ToastProgress: VoidComponent = () => {
</ToastPrimitive.ProgressTrack>
);
};

export type ShowToastProps = {
title: string;
description: string;
variant?: 'default' | 'destructive';
};

export const toaster = {
show({ title, description, variant }: ShowToastProps) {
return _toaster.show(props => (
<Toast toastId={props.toastId} variant={variant ?? 'default'}>
<ToastContent>
<ToastTitle>{title}</ToastTitle>
<ToastDescription>{description}</ToastDescription>
</ToastContent>
</Toast>
));
},
dismiss(id: number) {
_toaster.dismiss(id);
},
};

0 comments on commit d2e5ded

Please sign in to comment.