File size: 3,913 Bytes
65d68f5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | "use client";
import { cn } from "@/lib/utils";
type LoadingStateProps = {
message?: string;
size?: "sm" | "md" | "lg";
className?: string;
};
export function LoadingState({
message = "Loading...",
size = "md",
className,
}: LoadingStateProps) {
const sizeClasses = {
sm: "h-6 w-6 border-2",
md: "h-8 w-8 border-2",
lg: "h-12 w-12 border-3",
};
return (
<div
className={cn(
"flex flex-col items-center justify-center gap-4 p-8",
className,
)}
aria-live="polite"
aria-busy="true"
>
<div
className={cn(
"animate-spin rounded-full border-current border-t-transparent",
sizeClasses[size],
)}
role="status"
aria-label="Loading"
/>
{message && (
<p className="text-[14px] text-[var(--text-secondary)] loading-message">
{message}
</p>
)}
</div>
);
}
type SkeletonProps = {
variant?: "text" | "card" | "circle" | "rect";
width?: string | number;
height?: string | number;
lines?: number;
className?: string;
};
export function Skeleton({
variant = "rect",
width,
height,
lines = 1,
className,
}: SkeletonProps) {
const baseClasses = "skeleton";
const variantClasses = {
text: "rounded-md",
card: "rounded-lg",
circle: "rounded-full",
rect: "rounded-sm",
};
const style = {
width: width || (variant === "text" ? "100%" : "120px"),
height: height || (variant === "text" ? "1em" : variant === "circle" ? width || "40px" : "80px"),
};
if (variant === "text" && lines > 1) {
return (
<div className={cn("flex flex-col gap-2", className)}>
{Array.from({ length: lines }).map((_, i) => (
<div
key={i}
className={cn(baseClasses, variantClasses[variant])}
style={{
width: width || (i === lines - 1 ? "70%" : "100%"),
height: height || "1em",
}}
/>
))}
</div>
);
}
return (
<div
className={cn(baseClasses, variantClasses[variant], className)}
style={style}
aria-hidden="true"
/>
);
}
type PageLoadingProps = {
message?: string;
subtitle?: string;
};
export function PageLoading({ message, subtitle }: PageLoadingProps) {
return (
<div className="flex min-h-[400px] flex-1 items-center justify-center">
<LoadingState message={message || "Loading..."} size="lg" />
{subtitle && (
<p className="mt-2 text-center text-[13px] text-[var(--text-muted)]">
{subtitle}
</p>
)}
</div>
);
}
type InlineLoadingProps = {
text?: string;
size?: "sm" | "md" | "lg";
className?: string;
};
export function InlineLoading({
text = "Loading...",
size = "sm",
className,
}: InlineLoadingProps) {
return (
<div
className={cn(
"flex items-center gap-2 text-[var(--text-secondary)]",
className,
)}
>
<span
className={cn(
"animate-spin rounded-full border-current border-t-transparent",
size === "sm" && "h-3 w-3 border-2",
size === "md" && "h-4 w-4 border-2",
size === "lg" && "h-5 w-5 border-2",
)}
/>
<span className="text-[12px] sm:text-[13px]">{text}</span>
</div>
);
}
type CardSkeletonProps = {
lines?: number;
withImage?: boolean;
className?: string;
};
export function CardSkeleton({
lines = 3,
withImage = false,
className,
}: CardSkeletonProps) {
return (
<div
className={cn(
"workspace-card overflow-hidden p-4",
className,
)}
>
{withImage && (
<Skeleton variant="rect" width="100%" height={120} className="mb-4" />
)}
<Skeleton variant="text" width="60%" className="mb-2" />
<Skeleton variant="text" width="100%" lines={lines} />
</div>
);
}
|