Skeleton building blocks
The pieces the page skeletons are made of: a pulsing bar, a breadcrumb row, a product card and a product grid.
import { SkeletonPulse, BreadcrumbSkeleton, ProductCardSkeleton, ProductGridSkeleton } from '@salla.sa/twilight-theme-engine/skeleton';In plain words
When no ready-made page skeleton matches your page, build one from these parts. SkeletonPulse is a single grey, gently pulsing shape that you size yourself; the others are a breadcrumb row, one product card and a grid of product cards.
Signature
const SkeletonPulse: MemoExoticComponent<(props: {
className?: string;
circle?: boolean; // rounded-full instead of rounded-md
style?: CSSProperties;
}) => JSX.Element>
function BreadcrumbSkeleton(props?: { className?: string }): JSX.Element
function ProductCardSkeleton(props?: { className?: string }): JSX.Element
function ProductGridSkeleton(props?: { className?: string; count?: number }): JSX.Element // count: 6Try it live
import { memo } from 'react';
import { BreadcrumbSkeleton, ProductGridSkeleton, SkeletonPulse } from '@salla.sa/twilight-theme-engine/skeleton';
export const MyPageSkeleton = memo(function MyPageSkeleton() {
return (
<div className="container">
<BreadcrumbSkeleton />
<div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 16 }}>
<SkeletonPulse style={{ width: 240, height: 24 }} />
</div>
<ProductGridSkeleton count={4} />
</div>
);
});
Example
import { memo } from 'react';
import {
BreadcrumbSkeleton,
ProductGridSkeleton,
SkeletonPulse,
} from '@salla.sa/twilight-theme-engine/skeleton';
export const LookbookSkeleton = memo(function LookbookSkeleton() {
return (
<div className="container">
<BreadcrumbSkeleton />
<SkeletonPulse className="mb-6 h-8 w-1/3" />
<ProductGridSkeleton count={8} />
</div>
);
});
How it behaves
SkeletonPulserenders one<div className="s-skeleton-pulse rounded-md">(rounded-fullwithcircle) with yourclassNameandstyle. Salla's Tailwind plugin styless-skeleton-pulseasanimate-pulse bg-gray-200. The other skeletons are built from it.BreadcrumbSkeletonis three pulses in.s-skeleton-breadcrumb.ProductCardSkeletonuses the real product card classes (s-product-card …), so it takes a card's place in a product grid.ProductGridSkeletonrenderscountcard skeletons (6 by default) in a 4-column grid.Keep a custom skeleton a
memocomponent with no hooks and no data, so it can never wait for anything itself.The components package has more skeletons (menus, sliders, forms…); the engine re-exports only these four and the page skeletons.
All four are also exported from
@salla.sa/twilight-theme-engine/components/common.
Gotchas
A
SkeletonPulsehas no size of its own. Without a height fromclassNameorstyleit is a zero-heightdiv, and nothing shows.ProductGridSkeletonalways uses the 4-column grid, whatevercountis. For another column count, lay outProductCardSkeletons in a grid of your own.