Notification
Special
Toast notification system with auto-dismiss, stacking, variants, and action buttons.
Import
import { PixelNotification, usePixelToast } from "@/components/ui/pixel/pixel-notification"Usage
Component Source
Copy and paste the following code into your project at /src/components/ui/pixel/pixel-notification.tsx
"use client";
import { cva, type VariantProps } from "class-variance-authority";
import * as React from "react";
const notificationVariants = cva(
"relative border-4 border-black p-4 shadow-[6px_6px_0px_0px_rgba(0,0,0,1)] font-pixel flex items-start gap-3 min-w-[280px] max-w-[420px]",
{
variants: {
variant: {
default: "bg-white dark:bg-[#2a2a2a]",
success: "bg-pixel-success border-black",
warning: "bg-pixel-warning border-black",
error: "bg-pixel-error border-black",
info: "bg-pixel-primary border-black",
},
position: {
"top-left": "animate-slide-in-left",
"top-right": "animate-slide-in-right",
"bottom-left": "animate-slide-in-left",
"bottom-right": "animate-slide-in-right",
},
},
defaultVariants: {
variant: "default",
position: "top-right",
},
},
);
export interface NotificationType {
id: string;
title: string;
description?: string;
variant?: "default" | "success" | "warning" | "error" | "info";
icon?: React.ReactNode;
duration?: number;
action?: {
label: string;
onClick: () => void;
};
}
interface PixelNotificationProps
extends VariantProps<typeof notificationVariants> {
title: string;
description?: string;
icon?: React.ReactNode;
onClose?: () => void;
action?: {
// ... (more code below)Props
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | - | Notification title |
| description | string | - | Notification message |
| variant | "default" | "success" | "warning" | "error" | "info" | "default" | Notification style |
| icon | ReactNode | - | Icon element |
| onClose | () => void | - | Close callback |
| action | { label: string, onClick: () => void } | - | Action button config |
| duration | number | 5000 | Auto-dismiss duration (ms), 0 for persistent |
Examples
Success Toast
Success notification
With Action
Notification with action button
Toast Hook
Programmatic toast creation
Accessibility
This component is built with accessibility in mind, including proper ARIA attributes, keyboard navigation, and focus management.