Skip to main content
Decoderen
Browse documentation

Skeleton

Show the outline of content that is still loading, in the blueprint style, named for assistive technology.

List outline

Loading projects

Show code
Example.astroAstro
---
import Skeleton from '@dhekode/ui/custom/Skeleton.tsx';
import SkeletonShape from '@dhekode/ui/custom/SkeletonShape.tsx';
---

<Skeleton label="Loading projects">
  <SkeletonShape className="h-xl w-5xl" />
  <SkeletonShape shape="block" className="grid gap-lg p-md">
    <SkeletonShape className="w-5xl" />
    <SkeletonShape className="w-4xl" />
  </SkeletonShape>
</Skeleton>

Shapes

Loading the profile

Show code
Example.astroAstro
---
import Skeleton from '@dhekode/ui/custom/Skeleton.tsx';
import SkeletonShape from '@dhekode/ui/custom/SkeletonShape.tsx';
---

<Skeleton label="Loading the profile">
  <SkeletonShape shape="circle" className="w-3xl" />
  <SkeletonShape shape="pill" className="h-(--dk-layout-button-height) w-4xl" />
</Skeleton>
API reference
label

Type: string

Default: required

What is loading, such as "Loading projects". Announced to assistive technology; not shown.

className

Type: string | undefined

Default: unset

Adds classes to the React component root, after its own utilities. React components take className, not class.

Slots: Default: the outline, drawn with SkeletonShape (ui/custom/SkeletonShape.tsx): shape line | block | pill | circle (default line), className to size it with token utilities, and children inside a block.

Mirror the real layout so the content replaces the outline without a jump. Show it only for loads long enough to notice; never for a filter that reloads content in place.

Original component source
packages/ui/src/custom/Skeleton.tsxAstro
import type { ReactNode } from 'react';
import { classNames } from '@dhekode/utils/class-names';

export interface SkeletonProps {
  /** What is loading, such as "Loading projects": announced to assistive technology only. */
  label: string;
  className?: string | undefined;
  /** The outline of the content on its way, drawn with SkeletonShape. */
  children: ReactNode;
}

/**
 * The blueprint outline of content that is still loading (D-208): the content's own layout drawn
 * in dashed guide lines, so the real content replaces it without a jump. It shows no words: the
 * label is announced to assistive technology, and the outline is hidden from it.
 */
export default function Skeleton({ label, className, children }: SkeletonProps) {
  return (
    <div className={classNames('dk-skeleton grid gap-md', className)}>
      <p role="status" className="sr-only">
        {label}
      </p>
      <div aria-hidden="true" className="contents">
        {children}
      </div>
    </div>
  );
}

Best practices

  • Draw the outline of the content that will appear, at its real sizes.
  • Name what is loading in the label; the outline itself is hidden from assistive technology.