skeleton.tsx


Overview

skeleton.tsx provides reusable React functional components that render skeleton UI placeholders. These placeholders simulate loading content with animated, stylized shapes, enhancing perceived performance and user experience during data fetching or asynchronous operations. It defines a base Skeleton component and two composed skeleton components: ParagraphSkeleton and CardSkeleton, which represent common UI patterns while loading.

The components rely on utility styling (presumably Tailwind CSS classes) and a helper function cn (classNames) to compose CSS class strings dynamically.


Components and Functions

1. Skeleton

Description

A generic skeleton loader component rendering a div with an animated pulsing effect and rounded corners. It acts as the base visual unit for skeleton screens.

Signature

function Skeleton({
  className,
  ...props
}: React.HTMLAttributes<HTMLDivElement>): JSX.Element

Parameters

Returns

Usage Example

<Skeleton className="h-6 w-40 rounded-sm" />

This renders a small rectangular skeleton bar.


2. ParagraphSkeleton

Description

A composed skeleton component mimicking a paragraph or profile preview layout, typically used to indicate a loading user profile or text snippet. It consists of a circular skeleton representing an avatar and two horizontal skeleton bars representing text lines.

Signature

function ParagraphSkeleton(): JSX.Element

Parameters

Returns

Usage Example

<ParagraphSkeleton />

This inserts a paragraph-like skeleton placeholder in the UI.


3. CardSkeleton

Description

A composed skeleton component representing a card UI loading placeholder. It features a large rectangular image skeleton at the top and two text line skeletons below.

Signature

function CardSkeleton(): JSX.Element

Parameters

Returns

Usage Example

<CardSkeleton />

This renders a card-like loading skeleton with an image placeholder and text lines.


Implementation Details


Interaction with Other Parts of the Application


Visual Diagram

componentDiagram
    direction LR
    Skeleton <|-- ParagraphSkeleton : uses
    Skeleton <|-- CardSkeleton : uses

    Skeleton: +className: string (optional)
    Skeleton: +props: HTMLDivElement attributes
    Skeleton: +Returns a pulsing div placeholder

    ParagraphSkeleton: +Returns avatar + two lines skeleton
    CardSkeleton: +Returns image + two lines skeleton

Summary

skeleton.tsx is a focused utility module providing skeleton loaders for React applications using Tailwind CSS. It encapsulates a base animated skeleton component and two common UI skeleton patterns (ParagraphSkeleton and CardSkeleton). These help improve UX by visually indicating loading states with consistent, reusable components that integrate seamlessly with the app's styling and utility libraries.