Error State
spectrumui/error-stateFreeBlock
A failed-generation state with a preserved prompt and retry.
Install it
npx shadcn@latest add https://ui.spectrumhq.in/r/error-state.jsonSource
1'use client';23import { useState } from 'react';4import { AlertTriangle, Loader2, RefreshCw } from 'lucide-react';5import { cn } from '@/lib/utils';67export type ErrorStateVariant = 'Card' | 'Inline';89export interface ErrorStateProps {10 title?: string;11 message?: string;12 retryLabel?: string;13 retrying?: boolean;14 onRetry?: () => void;15 variant?: ErrorStateVariant;16 className?: string;17}1819export function ErrorState({20 title = 'Generation failed',21 message = 'The model timed out before finishing. Your prompt is preserved — retrying usually resolves this.',22 retryLabel = 'Retry',23 retrying: retryingProp,24 onRetry,25 variant = 'Card',26 className,27}: ErrorStateProps) {28 const [retryingState, setRetryingState] = useState(false);29 const retrying = retryingProp !== undefined ? retryingProp : retryingState;3031 function retry() {32 setRetryingState(true);33 setTimeout(() => setRetryingState(false), 1600);34 onRetry?.();35 }3637 if (variant === 'Inline') {38 return (39 <div40 role="alert"41 className={cn(42 'flex w-fit items-center gap-2.5 rounded-full border border-red-500/20 bg-red-500/[0.06] py-1.5 pl-3 pr-1.5 text-[12.5px] text-red-700 dark:text-red-400',43 className,44 )}45 >46 <AlertTriangle className="size-3.5 shrink-0" />47 <span>{title}</span>48 <button49 type="button"50 onClick={retry}51 disabled={retrying}52 className="flex items-center gap-1 rounded-full bg-white px-2 py-0.5 text-[11.5px] font-medium text-neutral-800 shadow-xs transition-transform duration-150 active:scale-[0.95] focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-red-400 dark:bg-neutral-900 dark:text-neutral-200"53 >54 {retrying ? (55 <Loader2 className="size-3 animate-spin [animation-duration:800ms]" />56 ) : (57 <RefreshCw className="size-3" />58 )}59 {retryLabel}60 </button>61 </div>62 );63 }6465 return (66 <div67 role="alert"68 className={cn(69 'w-full max-w-[420px] rounded-2xl border border-black/[0.08] bg-white p-4 shadow-xs dark:border-white/[0.09] dark:bg-[#0B0B0D]',70 className,71 )}72 >73 <div className="flex items-start gap-3">74 <span className="grid size-8 shrink-0 place-items-center rounded-full bg-red-500/10 text-red-600 dark:text-red-400">75 <AlertTriangle className="size-4" />76 </span>77// … truncated
What it pulls in
npm packages
Files it writes
More from spectrumui
All 182 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Agent Planagent-plan | spectrumui | Blocks | Free | 1 dep | |
| Agent Stepsagent-steps | spectrumui | Blocks | Free | 1 dep · 2 files | |
| Approval Cardapproval-card | spectrumui | Blocks | Free | 1 dep | |
| Chat Empty Statechat-empty-state | spectrumui | Blocks | Free | 1 dep · 2 files | |
| Citation Sourcescitation-sources | spectrumui | Blocks | Free | no deps · 2 files | |
| Code Blockcode-block | spectrumui | Blocks | Free | 1 dep | |
| Conversation Listconversation-list | spectrumui | Blocks | Free | 1 dep | |
| Diff Viewdiff-view | spectrumui | Blocks | Free | 1 dep |
