Components › Components

On this page

Skeleton

A pulsing placeholder while content loads.

Loading the profile

Usage #

tscl
@import uiSkeleton from './skeleton.tscl'

<div class="demo" aria-busy="true">
  <p class="sr">Loading the profile</p>
  <uiSkeleton width="48px" height="48px" />
  <uiSkeleton width="60%" />
  <uiSkeleton width="40%" />
</div>

<style scoped>
  :scope {
    display: grid;
    gap: 12px;
    padding: 24px;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
    background: var(--ui-bg);
    color: var(--ui-fg);
  }
  .sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
</style>

Source #

Copy it into your components folder (next to the others) as skeleton.tscl.

tscl
{{-- Skeleton: a placeholder while content loads. Hidden from assistive technology: say "Loading" elsewhere. --}}
@input width: string = '100%'
@input height: string = '16px'

<div
  aria-hidden="true"
  data-part="skeleton"
  [style]="'--ui-skeleton-w: ' + width + '; --ui-skeleton-h: ' + height"
></div>

<style scoped>
  @layer theme, base, components, utilities;
  @layer components {
    :where(:scope) {
      width: var(--ui-skeleton-w);
      height: var(--ui-skeleton-h);
      border-radius: var(--ui-radius);
      background: var(--ui-muted-bg);
      animation: ui-skeleton-pulse 1.5s ease-in-out infinite;
    }
    @keyframes ui-skeleton-pulse {
      50% {
        opacity: 0.5;
      }
    }
    @media (prefers-reduced-motion: reduce) {
      :where(:scope) {
        animation: none;
      }
    }
  }
</style>

Styling #

Needs #