Files
test-assignment/packages/ui/src/components/states.tsx
T

62 lines
1.8 KiB
TypeScript

import { AlertCircle, SearchX } from 'lucide-react';
import { Button } from './button';
import { Skeleton } from './skeleton';
export function LoadingState({ label }: { label: string }) {
return (
<div role="status" aria-label={label} className="space-y-5 py-4">
<span className="sr-only">{label}</span>
<div className="grid grid-cols-2 gap-4 lg:grid-cols-4">
{[0, 1, 2, 3].map((i) => (
<Skeleton key={i} className="h-32 rounded-xl" />
))}
</div>
<Skeleton className="h-64 rounded-xl" />
<Skeleton className="h-40 rounded-xl" />
</div>
);
}
export function EmptyState({
title,
description,
action,
}: {
title: string;
description?: string;
action?: React.ReactNode;
}) {
return (
<div className="flex flex-col items-center px-6 py-14 text-center">
<div className="mb-4 flex size-12 items-center justify-center rounded-xl bg-muted">
<SearchX className="size-5 text-muted-foreground" aria-hidden="true" />
</div>
<h2 className="font-semibold">{title}</h2>
{description && (
<p className="mt-2 max-w-sm text-sm leading-relaxed text-muted-foreground">{description}</p>
)}
{action && <div className="mt-5">{action}</div>}
</div>
);
}
export function ErrorState({
title,
description,
retryLabel,
onRetry,
}: {
title: string;
description: string;
retryLabel: string;
onRetry: () => void;
}) {
return (
<div role="alert" className="surface flex flex-col items-center px-6 py-14 text-center">
<AlertCircle className="mb-4 size-7 text-destructive" aria-hidden="true" />
<h2 className="font-semibold">{title}</h2>
<p className="my-3 max-w-md text-sm text-muted-foreground">{description}</p>
<Button variant="outline" onClick={onRetry}>
{retryLabel}
</Button>
</div>
);
}