All files / service-web-theme/src skeleton-template.ts

100% Statements 3/3
80% Branches 4/5
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                    12x 12x                                   9x              
import { html, type TemplateResult } from 'lit';
import { resolveSkeleton, skeletonLabel, type SkeletonInput } from './skeleton-model.ts';
import type { Locale } from './locale.ts';
 
/**
 * One shimmering placeholder in the box of the element it stands in for. It is decoration: wrap the placeholders of a
 * region in {@link skeletonGroupTemplate}, which tells assistive technology the region is loading. `skeleton.css`
 * styles it; it stops moving under `prefers-reduced-motion`.
 */
export function skeletonTemplate(input: SkeletonInput & { className?: string } = {}): TemplateResult {
  const view = resolveSkeleton(input);
  return html`<span
    class=${`be-music-skeleton${input.className ? ` ${input.className}` : ''}`}
    data-shape=${view.shape}
    style=${view.style}
    aria-hidden="true"
  ></span>`;
}
 
/**
 * A loading region: busy for assistive technology, which hears `label` (or "Loading…") once, while the placeholders
 * in `content` stay silent. Replace the whole group with the loaded content.
 */
export function skeletonGroupTemplate(input: {
  locale: Locale;
  content: unknown;
  label?: string;
  className?: string;
}): TemplateResult {
  return html`<span
    class=${`be-music-skeleton-group${input.className ? ` ${input.className}` : ''}`}
    role="status"
    aria-busy="true"
    ><span class="be-music-skeleton-label">${skeletonLabel(input.locale, input.label)}</span>${input.content}</span
  >`;
}