Claude Code के साथ Implement Skeleton Loading कैसे करें
Claude Code का उपयोग करके implement skeleton loading सीखें। Practical code examples और step-by-step guidance शामिल है।
スケルトンローディングの効果
スケルトンローディング(スケルトンスクリーン)は、コンテンツ読み込みमेंにlayoutの骨格 displayするUIpattern है।スピナーよりも体感速度が速く感じられ、layoutシフトも防げ है।Claude Code से、再利用possibleなスケルトンcomponentを素早くbuild किया जा सकता है。
基本のスケルトンcomponent
> 汎用的なスケルトンcomponentを作って。
> テキスト、画像、cardの3patternにsupportして。
interface SkeletonProps {
width?: string | number;
height?: string | number;
variant?: 'text' | 'circular' | 'rectangular';
className?: string;
lines?: number;
}
function Skeleton({ width, height, variant = 'text', className = '', lines = 1 }: SkeletonProps) {
const baseClass = 'animate-pulse bg-gray-200 dark:bg-gray-700';
const variantClass = {
text: 'rounded',
circular: 'rounded-full',
rectangular: 'rounded-lg',
}[variant];
if (variant === 'text' && lines > 1) {
return (
<div className={`space-y-2 ${className}`}>
{Array.from({ length: lines }).map((_, i) => (
<div
key={i}
className={`${baseClass} rounded h-4`}
style={{ width: i === lines - 1 ? '75%' : '100%' }}
/>
))}
</div>
);
}
return (
<div
className={`${baseClass} ${variantClass} ${className}`}
style={{
width: width ?? (variant === 'text' ? '100%' : undefined),
height: height ?? (variant === 'text' ? '1rem' : undefined),
}}
role="status"
aria-label="読み込みमें"
/>
);
}
card型スケルトン
function CardSkeleton() {
return (
<div className="border rounded-lg p-4 space-y-4" aria-busy="true" aria-label="読み込みमें">
<Skeleton variant="rectangular" height={200} />
<Skeleton variant="text" width="60%" height={24} />
<Skeleton variant="text" lines={3} />
<div className="flex items-center gap-3">
<Skeleton variant="circular" width={40} height={40} />
<div className="flex-1">
<Skeleton variant="text" width="40%" />
<Skeleton variant="text" width="25%" className="mt-1" />
</div>
</div>
</div>
);
}
function CardListSkeleton({ count = 3 }: { count?: number }) {
return (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{Array.from({ length: count }).map((_, i) => (
<CardSkeleton key={i} />
))}
</div>
);
}
コンテンツとスケルトンの切り替え
interface AsyncContentProps<T> {
data: T | undefined;
loading: boolean;
skeleton: React.ReactNode;
children: (data: T) => React.ReactNode;
error?: Error | null;
}
function AsyncContent<T>({ data, loading, skeleton, children, error }: AsyncContentProps<T>) {
if (error) {
return <div role="alert" className="text-red-500">errorが発生しました</div>;
}
if (loading || !data) {
return <>{skeleton}</>;
}
return <>{children(data)}</>;
}
// Usage example
function UserProfile() {
const { data, loading, error } = useQuery('/api/user');
return (
<AsyncContent
data={data}
loading={loading}
error={error}
skeleton={<ProfileSkeleton />}
>
{(user) => (
<div>
<img src={user.avatar} alt={user.name} />
<h2>{user.name}</h2>
<p>{user.bio}</p>
</div>
)}
</AsyncContent>
);
}
CSSanimationのoptimization
/* パルスanimation */
@keyframes pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }
}
.animate-pulse {
animation: pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
/* シマーエフェクト(よりリッチな表現) */
@keyframes shimmer {
0% { background-position: -200% 0; }
100% { background-position: 200% 0; }
}
.animate-shimmer {
background: linear-gradient(
90deg,
#e5e7eb 25%,
#f3f4f6 50%,
#e5e7eb 75%
);
background-size: 200% 100%;
animation: shimmer 1.5s ease-in-out infinite;
}
Summary
Claude Code का उपयोग करके、汎用スケルトンcomponent से用途別のpattern、シマーエフェクト तकefficientlybuild किया जा सकता है。performance全般के बारे मेंはperformanceoptimizationを、画像読み込みのoptimizationは画像遅延読み込みをदेखें。
スケルトンスクリーンのUXके बारे मेंはNielsen Norman Group - Skeleton Screensが参考になり है।
Related Posts
Claude Code से Productivity 3 गुना बढ़ाने की 10 Tips
Claude Code से ज़्यादा पाने की 10 practical tips जानें। Prompt strategies से workflow shortcuts तक, ये techniques आज से ही आपकी efficiency boost करेंगी।
Claude Code के साथ Canvas/WebGL Optimization
Claude Code का उपयोग करके Canvas/WebGL optimization के बारे में जानें। Practical tips और code examples शामिल हैं।
Claude Code के साथ Markdown Implementation
Claude Code का उपयोग करके markdown implementation सीखें। Practical tips और code examples शामिल हैं।