'use client'; import { useState } from 'react'; import { AlertTriangle, Archive, Ban, Download, LogOut, RefreshCw, Share, Trash2, UserX, X, } from 'lucide-react'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, } from '@kit/ui/alert-dialog'; import { Button } from '@kit/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '@kit/ui/card'; import { Input } from '@kit/ui/input'; import { Label } from '@kit/ui/label'; import { Separator } from '@kit/ui/separator'; import { Switch } from '@kit/ui/switch'; import { Textarea } from '@kit/ui/textarea'; import { useStoryControls } from '../lib/story-utils'; import { ComponentStoryLayout } from './story-layout'; import { SimpleStorySelect } from './story-select'; interface AlertDialogControls { title: string; description: string; triggerText: string; triggerVariant: | 'default' | 'destructive' | 'outline' | 'secondary' | 'ghost' | 'link'; actionText: string; actionVariant: 'default' | 'destructive'; cancelText: string; withIcon: boolean; severity: 'info' | 'warning' | 'error' | 'success'; } const triggerVariantOptions = [ { value: 'destructive', label: 'Destructive', description: 'Danger button' }, { value: 'outline', label: 'Outline', description: 'Outlined button' }, { value: 'default', label: 'Default', description: 'Primary button' }, { value: 'secondary', label: 'Secondary', description: 'Secondary style' }, { value: 'ghost', label: 'Ghost', description: 'Minimal button' }, ] as const; const actionVariantOptions = [ { value: 'destructive', label: 'Destructive', description: 'For dangerous actions', }, { value: 'default', label: 'Default', description: 'For normal actions' }, ] as const; const severityOptions = [ { value: 'info', label: 'Info', description: 'General information' }, { value: 'warning', label: 'Warning', description: 'Caution required' }, { value: 'error', label: 'Error', description: 'Destructive action' }, { value: 'success', label: 'Success', description: 'Positive action' }, ] as const; const iconOptions = [ { value: 'trash', icon: Trash2, label: 'Trash' }, { value: 'alert', icon: AlertTriangle, label: 'Alert Triangle' }, { value: 'logout', icon: LogOut, label: 'Log Out' }, { value: 'userx', icon: UserX, label: 'User X' }, { value: 'x', icon: X, label: 'X' }, { value: 'ban', icon: Ban, label: 'Ban' }, { value: 'archive', icon: Archive, label: 'Archive' }, { value: 'download', icon: Download, label: 'Download' }, ]; export function AlertDialogStory() { const { controls, updateControl } = useStoryControls({ title: 'Are you absolutely sure?', description: 'This action cannot be undone. This will permanently delete your account and remove your data from our servers.', triggerText: 'Delete Account', triggerVariant: 'destructive', actionText: 'Yes, delete account', actionVariant: 'destructive', cancelText: 'Cancel', withIcon: true, severity: 'error', }); const [selectedIcon, setSelectedIcon] = useState('trash'); const selectedIconData = iconOptions.find( (opt) => opt.value === selectedIcon, ); const IconComponent = selectedIconData?.icon || AlertTriangle; const generateCode = () => { let code = `\n`; code += ` \n`; code += ` \n`; code += ` \n`; code += ` \n`; code += ` \n`; if (controls.withIcon) { code += `
\n`; code += `
\n`; const iconName = selectedIconData?.icon.name || 'AlertTriangle'; code += ` <${iconName} className="h-5 w-5" />\n`; code += `
\n`; code += ` ${controls.title}\n`; code += `
\n`; } else { code += ` ${controls.title}\n`; } if (controls.description) { code += ` \n`; code += ` ${controls.description}\n`; code += ` \n`; } code += `
\n`; code += ` \n`; code += ` ${controls.cancelText}\n`; if (controls.actionVariant === 'destructive') { code += ` \n`; } else { code += ` \n`; } code += ` ${controls.actionText}\n`; code += ` \n`; code += ` \n`; code += `
\n`; code += `
`; return code; }; const getSeverityIconStyles = (severity: string) => { switch (severity) { case 'error': return 'flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-destructive/15 text-destructive'; case 'warning': return 'flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-yellow-100 text-yellow-600 dark:bg-yellow-900/30 dark:text-yellow-500'; case 'success': return 'flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-green-100 text-green-600 dark:bg-green-900/30 dark:text-green-500'; default: return 'flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-blue-100 text-blue-600 dark:bg-blue-900/30 dark:text-blue-500'; } }; const renderPreview = () => { return ( {controls.withIcon ? (
{controls.title}
) : ( {controls.title} )} {controls.description && ( {controls.description} )}
{controls.cancelText} {controls.actionText}
); }; const renderControls = () => ( <>
updateControl('severity', value)} options={severityOptions} />
updateControl('triggerVariant', value)} options={triggerVariantOptions} />
updateControl('actionVariant', value)} options={actionVariantOptions} />
updateControl('triggerText', e.target.value)} placeholder="Button text" />
updateControl('title', e.target.value)} placeholder="Alert dialog title" />