import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { skeletonClass } from '#components/ui/skeleton.ts';
export default function SkeletonDemo() {
return html`
<div class="flex items-center gap-4" aria-hidden="true">
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-12 w-12 rounded-full')}></div>
<div class="space-y-2">
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-[250px]')}></div>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-[200px]')}></div>
</div>
</div>
`;
}
View Code
Installation
Copy and paste the following code into your project.
/**
* Skeleton: loading placeholder. Tier-1 class helper. Sizing comes from
* caller-supplied utilities; `skeletonClass()` only provides the
* animation + base look.
*
* shadcn parity:
* Skeleton → skeletonClass() (visual: animated rounded muted block)
*
* A11y (required for accessible output): a skeleton is a decorative
* placeholder, so hide it from assistive tech with aria-hidden="true" (or
* mark the loading region aria-busy="true"). Announce the real content
* once it replaces the skeleton.
*
* Design tokens used: --accent.
*
* @example
* ```html
* <div class=${cn(skeletonClass(), 'h-4 w-32')}></div>
* <div class=${cn(skeletonClass(), 'h-12 w-12 rounded-full')}></div>
* ```
*/
export const skeletonClass = (): string => 'rounded-md bg-accent animate-pulse';
Update the import paths to match your project setup.
Usage
import { skeletonClass } from '#components/ui/skeleton.ts';
import { cn } from '#lib/utils/cn.ts';
<div aria-hidden="true" class=${cn(skeletonClass(), 'h-[20px] w-[100px] rounded-full')}></div>
Avatar
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { skeletonClass } from '#components/ui/skeleton.ts';
export default function SkeletonAvatar() {
return html`
<div class="flex w-fit items-center gap-4" aria-hidden="true">
<div data-slot="skeleton" class=${cn(skeletonClass(), 'size-10 shrink-0 rounded-full')}></div>
<div class="grid gap-2">
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-[150px]')}></div>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-[100px]')}></div>
</div>
</div>
`;
}
View Code
Card
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { cardClass, cardHeaderClass, cardContentClass } from '#components/ui/card.ts';
import { skeletonClass } from '#components/ui/skeleton.ts';
export default function SkeletonCard() {
return html`
<div data-slot="card" data-size="default" aria-hidden="true" class=${cn(cardClass(), 'w-full max-w-xs')}>
<div data-slot="card-header" class=${cardHeaderClass()}>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-2/3')}></div>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-1/2')}></div>
</div>
<div data-slot="card-content" class=${cardContentClass()}>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'aspect-video w-full')}></div>
</div>
</div>
`;
}
View Code
Text
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { skeletonClass } from '#components/ui/skeleton.ts';
export default function SkeletonText() {
return html`
<div class="flex w-full max-w-xs flex-col gap-2" aria-hidden="true">
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-full')}></div>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-full')}></div>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-3/4')}></div>
</div>
`;
}
View Code
Form
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { skeletonClass } from '#components/ui/skeleton.ts';
export default function SkeletonForm() {
return html`
<div class="flex w-full max-w-xs flex-col gap-7" aria-hidden="true">
<div class="flex flex-col gap-3">
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-20')}></div>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-8 w-full')}></div>
</div>
<div class="flex flex-col gap-3">
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-24')}></div>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-8 w-full')}></div>
</div>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-8 w-24')}></div>
</div>
`;
}
View Code
Table
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { skeletonClass } from '#components/ui/skeleton.ts';
export default function SkeletonTable() {
return html`
<div class="flex w-full max-w-sm flex-col gap-2" aria-hidden="true">
${Array.from({ length: 5 }).map(() => html`
<div class="flex gap-4">
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 flex-1')}></div>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-24')}></div>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-20')}></div>
</div>
`)}
</div>
`;
}
View Code
RTL
To enable RTL support, see the RTL configuration guide.
import { html } from '@webjsdev/core';
import { cn } from '#lib/utils/cn.ts';
import { skeletonClass } from '#components/ui/skeleton.ts';
const translations = {
en: { dir: 'ltr' },
ar: { dir: 'rtl' },
he: { dir: 'rtl' },
};
export default function SkeletonRtl() {
const lang = 'ar';
const { dir } = translations[lang];
return html`
<div class="flex items-center gap-4" dir=${dir} lang=${lang} aria-hidden="true">
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-12 w-12 rounded-full')}></div>
<div class="space-y-2">
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-[250px]')}></div>
<div data-slot="skeleton" class=${cn(skeletonClass(), 'h-4 w-[200px]')}></div>
</div>
</div>
`;
}