Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 367x 1x 1x 1x 1x 1x 1x 1x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 56x 1x 1x 1x 1x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 52x 9x 9x 9x 9x 1x 1x 1x 1x 15x 15x 15x 15x 42x 42x 42x 42x 42x 15x 15x 15x 15x 1x 1x 1x 1x 6x 6x 6x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x | 'use client';
import { forwardRef } from 'react';
import { cn } from '@/lib/core';
import { SkeletonProps, ProductListSkeletonProps, TextSkeletonProps, AvatarSkeletonProps } from '@/types/ui';
const roundedStyles = {
none: 'rounded-none',
sm: 'rounded',
md: 'rounded-md',
lg: 'rounded-lg',
full: 'rounded-full'};
/**
* Skeleton - Loading placeholder component
*
* Features:
* - Pulsing animation
* - Multiple variants
* - Flexible sizing
* - Customizable border radius
*
* @example
* ```tsx
* // Basic skeleton
* <Skeleton width="100%" height="20px" />
*
* // Circular avatar skeleton
* <Skeleton variant="circular" width={40} height={40} />
*
* // Text line skeleton
* <Skeleton variant="text" />
* ```
*/
export const Skeleton = forwardRef<HTMLDivElement, SkeletonProps>(
(
{
width,
height,
rounded = 'md',
variant = 'default',
className,
style,
...props
},
ref
) => {
const variantStyles = {
default: '',
text: 'h-4 w-full',
circular: 'rounded-full',
rectangular: 'rounded-none'};
const inlineStyles = {
...style,
width: typeof width === 'number' ? `${width}px` : width,
height: typeof height === 'number' ? `${height}px` : height};
return (
<div
ref={ref}
role="status"
aria-label="Loading..."
className={cn(
'animate-pulse bg-gray-200 dark:bg-gray-700',
roundedStyles[rounded],
variantStyles[variant],
className
)}
style={inlineStyles}
{...props}
/>
);
}
);
Skeleton.displayName = 'Skeleton';
/**
* ProductCardSkeleton - Loading state for product cards
*/
export function ProductCardSkeleton() {
return (
<div className="group">
{/* Image skeleton */}
<Skeleton height={270} className="mb-4" />
{/* Rating skeleton */}
<div className="flex items-center gap-2.5 mb-2">
<Skeleton width={100} height={14} />
<Skeleton width={30} height={14} />
</div>
{/* Title skeleton */}
<Skeleton width="80%" height={20} className="mb-1.5" />
{/* Price skeleton */}
<Skeleton width={120} height={24} />
</div>
);
}
/**
* ProductListSkeleton - Loading grid of product cards
*/
export function ProductListSkeleton({ count = 6, columns = 3 }: ProductListSkeletonProps) {
const gridCols = {
1: 'grid-cols-1',
2: 'grid-cols-1 sm:grid-cols-2',
3: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3',
4: 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-4'};
return (
<div className={cn('grid gap-6', gridCols[columns as keyof typeof gridCols] || gridCols[3])}>
{Array.from({ length: count }).map((_, index) => (
<ProductCardSkeleton key={index} />
))}
</div>
);
}
/**
* TextSkeleton - Multiple text lines skeleton
*/
export function TextSkeleton({ lines = 3, gap = 2 }: TextSkeletonProps) {
return (
<div className={cn('space-y-' + gap)}>
{Array.from({ length: lines }).map((_, index) => (
<Skeleton
key={index}
variant="text"
width={index === lines - 1 ? '60%' : '100%'}
/>
))}
</div>
);
}
/**
* AvatarSkeleton - Circular avatar skeleton
*/
export function AvatarSkeleton({ size = 40 }: AvatarSkeletonProps) {
return <Skeleton variant="circular" width={size} height={size} />;
}
/**
* CardSkeleton - Generic card skeleton
*/
export function CardSkeleton() {
return (
<div className="p-6 bg-white dark:bg-gray-800 rounded-lg shadow-1">
<Skeleton width="60%" height={24} className="mb-4" />
<TextSkeleton lines={3} />
<Skeleton width={120} height={36} className="mt-4" />
</div>
);
}
|