mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-03 08:07:21 +00:00
Toast comes from the unified radix-ui package like every other primitive, and unhead is a dependency of @unhead/react, which is all the app imports.
118 lines
3.2 KiB
TypeScript
118 lines
3.2 KiB
TypeScript
import * as React from "react"
|
|
import { Toast as ToastPrimitives } from "radix-ui"
|
|
import { type VariantProps } from "class-variance-authority"
|
|
import { X } from "lucide-react"
|
|
|
|
import { cn } from "@/lib/utils"
|
|
import { toastVariants } from "./toast-variants"
|
|
|
|
const ToastProvider = ToastPrimitives.Provider
|
|
|
|
function ToastViewport({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof ToastPrimitives.Viewport>) {
|
|
return (
|
|
<ToastPrimitives.Viewport
|
|
data-slot="toast-viewport"
|
|
className={cn(
|
|
"fixed top-0 z-100 flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-105",
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function Toast({
|
|
className,
|
|
variant,
|
|
...props
|
|
}: React.ComponentProps<typeof ToastPrimitives.Root> &
|
|
VariantProps<typeof toastVariants>) {
|
|
return (
|
|
<ToastPrimitives.Root
|
|
data-slot="toast"
|
|
className={cn(toastVariants({ variant }), className)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function ToastAction({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof ToastPrimitives.Action>) {
|
|
return (
|
|
<ToastPrimitives.Action
|
|
data-slot="toast-action"
|
|
className={cn(
|
|
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive",
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function ToastClose({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof ToastPrimitives.Close>) {
|
|
return (
|
|
<ToastPrimitives.Close
|
|
data-slot="toast-close"
|
|
className={cn(
|
|
"absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600",
|
|
className
|
|
)}
|
|
toast-close=""
|
|
{...props}
|
|
>
|
|
<X className="h-4 w-4" />
|
|
</ToastPrimitives.Close>
|
|
)
|
|
}
|
|
|
|
function ToastTitle({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof ToastPrimitives.Title>) {
|
|
return (
|
|
<ToastPrimitives.Title
|
|
data-slot="toast-title"
|
|
className={cn("text-sm font-semibold", className)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function ToastDescription({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<typeof ToastPrimitives.Description>) {
|
|
return (
|
|
<ToastPrimitives.Description
|
|
data-slot="toast-description"
|
|
className={cn("text-sm opacity-90", className)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
type ToastProps = React.ComponentProps<typeof Toast>
|
|
|
|
type ToastActionElement = React.ReactElement<typeof ToastAction>
|
|
|
|
export {
|
|
type ToastProps,
|
|
type ToastActionElement,
|
|
ToastProvider,
|
|
ToastViewport,
|
|
Toast,
|
|
ToastTitle,
|
|
ToastDescription,
|
|
ToastClose,
|
|
ToastAction,
|
|
}
|