# Skeleton

Placeholder berdenyut untuk konten yang sedang dimuat, ukurannya diatur lewat class.

- Kategori: Feedback
- Status: stable
- Registry: https://markas.jenderalcorp.com/r/skeleton.json
- CLI: `npx markasui@latest add skeleton`

## Kapan dipakai

Menahan tempat konten yang sedang dimuat agar layout tidak bergeser.

- Bentuk dan ukuran skeleton meniru konten aslinya
- Pakai shape circle untuk avatar, bukan class rounded-full
- Tambahkan teks sr-only di pembungkus agar status memuat tetap terbaca

## Kode

### Blade

Simpan di `resources/views/components/markas/skeleton.blade.php`. Tanpa dependensi tambahan.

```blade
@props([
    'shape' => 'rect',
])

@php
    $base = 'animate-pulse bg-subtle motion-reduce:animate-none';
    $shapes = [
        'rect' => 'rounded-md',
        'circle' => 'rounded-full',
    ];
@endphp

<div {{ $attributes->merge(['aria-hidden' => 'true'])->class([$base, $shapes[$shape]]) }}></div>
```

```blade
<div class="flex items-center gap-4" role="status">
    <span class="sr-only">Memuat profil</span>
    <x-markas.skeleton shape="circle" class="size-12 shrink-0" />
    <div class="grid flex-1 gap-2">
        <x-markas.skeleton class="h-4 w-2/3" />
        <x-markas.skeleton class="h-4 w-1/2" />
    </div>
</div>
```

### React

Simpan di `src/components/markas/Skeleton.tsx`. Tanpa dependensi tambahan.

```tsx
import type { ComponentProps } from "react";

const base = "animate-pulse bg-subtle motion-reduce:animate-none";
const shapes = {
  rect: "rounded-md",
  circle: "rounded-full",
};
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

export type SkeletonProps = ComponentProps<"div"> & {
  shape?: keyof typeof shapes;
};

export function Skeleton({
  shape = "rect",
  className,
  ...props
}: SkeletonProps) {
  return (
    <div
      aria-hidden="true"
      className={cx(base, shapes[shape], className)}
      {...props}
    />
  );
}
```

```tsx
import { Skeleton } from "@/components/markas/Skeleton";

<div className="flex items-center gap-4" role="status">
  <span className="sr-only">Memuat profil</span>
  <Skeleton shape="circle" className="size-12 shrink-0" />
  <div className="grid flex-1 gap-2">
    <Skeleton className="h-4 w-2/3" />
    <Skeleton className="h-4 w-1/2" />
  </div>
</div>;
```

### Vue

Simpan di `src/components/markas/Skeleton.vue`. Tanpa dependensi tambahan.

```vue
<script setup lang="ts">
const props = withDefaults(
  defineProps<{
    shape?: "rect" | "circle";
  }>(),
  { shape: "rect" },
);

const base = "animate-pulse bg-subtle motion-reduce:animate-none";
const shapes = {
  rect: "rounded-md",
  circle: "rounded-full",
};
</script>

<template>
  <div aria-hidden="true" :class="[base, shapes[props.shape]]" />
</template>
```

```vue
<script setup lang="ts">
import Skeleton from "@/components/markas/Skeleton.vue";
</script>

<template>
  <div class="flex items-center gap-4" role="status">
    <span class="sr-only">Memuat profil</span>
    <Skeleton shape="circle" class="size-12 shrink-0" />
    <div class="grid flex-1 gap-2">
      <Skeleton class="h-4 w-2/3" />
      <Skeleton class="h-4 w-1/2" />
    </div>
  </div>
</template>
```

### Svelte

Simpan di `src/lib/components/markas/Skeleton.svelte`. Tanpa dependensi tambahan.

```svelte
<script lang="ts">
  import type { HTMLAttributes } from "svelte/elements";

  const base = "animate-pulse bg-subtle motion-reduce:animate-none";
  const shapes = {
    rect: "rounded-md",
    circle: "rounded-full",
  };

  type Props = HTMLAttributes<HTMLDivElement> & {
    shape?: keyof typeof shapes;
  };

  let { shape = "rect", class: className, ...rest }: Props = $props();
</script>

<div
  aria-hidden="true"
  class={[base, shapes[shape], className]}
  {...rest}
></div>
```

```svelte
<script lang="ts">
  import Skeleton from "$lib/components/markas/Skeleton.svelte";
</script>

<div class="flex items-center gap-4" role="status">
  <span class="sr-only">Loading profile</span>
  <Skeleton shape="circle" class="size-12" />
  <Skeleton class="h-4 w-1/2" />
</div>
```

### Astro

Simpan di `src/components/markas/Skeleton.astro`. Tanpa dependensi tambahan.

```astro
---
import type { HTMLAttributes } from "astro/types";

const base = "animate-pulse bg-subtle motion-reduce:animate-none";
const shapes = {
  rect: "rounded-md",
  circle: "rounded-full",
};

type Props = HTMLAttributes<"div"> & {
  shape?: keyof typeof shapes;
};

const { shape = "rect", class: className, ...rest } = Astro.props;
---

<div aria-hidden="true" class:list={[base, shapes[shape], className]} {...rest}></div>
```

```astro
---
import Skeleton from "@/components/markas/Skeleton.astro";
---

<div class="flex items-center gap-4" role="status">
  <span class="sr-only">Loading profile</span>
  <Skeleton shape="circle" class="size-12" />
  <Skeleton class="h-4 w-1/2" />
</div>
```

### Angular

Simpan di `src/app/markas/skeleton.component.ts`. Tanpa dependensi tambahan.

```ts
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  input,
} from "@angular/core";

const base = "animate-pulse bg-subtle motion-reduce:animate-none";
const shapes = {
  rect: "rounded-md",
  circle: "rounded-full",
};

export type SkeletonShape = keyof typeof shapes;

/**
 * Attribute selector on a native div: the user class (size, width) stays on the placeholder
 * itself. The placeholder is hidden from assistive technology.
 */
@Component({
  selector: "div[markas-skeleton]",
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { "aria-hidden": "true", "[class]": "classes()" },
  template: ``,
})
export class Skeleton {
  readonly shape = input<SkeletonShape>("rect");

  protected readonly classes = computed(
    () => `${base} ${shapes[this.shape()]}`,
  );
}
```

```ts
import { Component } from "@angular/core";
import { Skeleton } from "./markas/skeleton.component";

@Component({
  selector: "app-profile-loading",
  imports: [Skeleton],
  template: `
    <div class="flex items-center gap-4" role="status">
      <span class="sr-only">Loading profile</span>
      <div markas-skeleton shape="circle" class="size-12"></div>
      <div markas-skeleton class="h-4 w-1/2"></div>
    </div>
  `,
})
export class ProfileLoading {}
```

## Props

| Nama | Tipe | Default | Keterangan |
| --- | --- | --- | --- |
| `shape` | `'rect' \| 'circle'` | rect | Sudut membulat 6px atau lingkaran penuh untuk avatar. |
| `class` | `string` | - | Ukuran placeholder, misalnya h-4 w-1/2 atau size-12. |

## Aksesibilitas

- Setiap skeleton aria-hidden, jadi pembaca layar tidak membacakan kotak kosong.
- Bungkus grup skeleton dengan role status dan teks sr-only seperti Memuat profil.
- Animasi denyut dimatikan saat prefers-reduced-motion.

## Catatan

- Atur ukuran lewat class (`h-4 w-1/2`, `size-12`). Untuk lingkaran pakai `shape="circle"`, bukan class `rounded-full`, karena tanpa `tailwind-merge` class radius yang bentrok bergantung pada urutan CSS.
