# Sidebar

Sidebar aplikasi dengan grup link, indikator aktif yang meluncur, sub-item yang bisa dibuka, mode rail ikon, dan dialog off-canvas di tata letak sempit.

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

## Kapan dipakai

Navigasi utama aplikasi atau dashboard dengan banyak tujuan yang dikelompokkan per area.

- Tandai tepat satu halaman dengan active, grup sub-item yang memuatnya terbuka sendiri
- Beri ikon pada setiap item tingkat atas agar mode rail tetap bisa dipakai
- Taruh isi halaman di dalam komponen agar mode off-canvas dan container query berjalan

## Kode

### Blade

Simpan di `resources/views/components/markas/sidebar.blade.php`. Dependensi: alpinejs.

```blade
@props([
    'sections' => [],
    'variant' => 'default',
    'breakpoint' => 'md',
    'collapsed' => false,
    'navLabel' => 'Sidebar',
    'collapseLabel' => 'Collapse sidebar',
    'expandLabel' => 'Expand sidebar',
    'openLabel' => 'Open sidebar',
    'closeLabel' => 'Close sidebar',
])

@php
    $root = '@container flex overflow-hidden bg-canvas';
    $aside = 'relative hidden w-56 shrink-0 flex-col bg-surface text-sm transition-[width] duration-200 ease-out data-[state=collapsed]:w-16 motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none';
    $variants = [
        'default' => 'border-r border-line',
        'floating' => 'm-2 rounded-xl border border-line',
    ];
    $showAside = ['sm' => '@sm:flex', 'md' => '@2xl:flex', 'lg' => '@4xl:flex'];
    $hideBar = ['sm' => '@sm:hidden', 'md' => '@2xl:hidden', 'lg' => '@4xl:hidden'];
    $headerClass = 'flex h-14 shrink-0 items-center border-b border-line px-4';
    // Isi header dan footer dipotong di tepi konten agar rail hanya menampilkan 32px pertama.
    $slotClass = 'flex min-w-0 flex-1 items-center gap-2 overflow-hidden whitespace-nowrap';
    $footerClass = 'shrink-0 border-t border-line px-4 py-3';
    $collapseButton = 'absolute top-4 -right-3 z-10 grid size-6 place-items-center rounded-full border border-line bg-surface text-muted transition-colors duration-150 ease-out hover:text-ink';
    $collapseIcon = 'size-3.5 transition-transform duration-200 ease-out in-data-[state=collapsed]:rotate-180';
    $navClass = 'min-h-0 flex-1 overflow-y-auto p-3 in-data-[state=collapsed]:overflow-visible';
    $listWrap = 'relative grid gap-3 [anchor-scope:--active,--hover]';
    $indicator = 'absolute inset-[anchor(--hover_top,anchor(--active_top))_anchor(--hover_right,anchor(--active_right))_anchor(--hover_bottom,anchor(--active_bottom))_anchor(--hover_left,anchor(--active_left))] rounded-md bg-subtle transition-[inset] duration-200 ease-out';
    $sectionClass = 'grid gap-0.5 border-t border-line pt-3 first-of-type:border-t-0 first-of-type:pt-0';
    $titleClass = 'px-2.5 pb-1 text-xs font-medium text-faint in-data-[state=collapsed]:sr-only';
    $listClass = 'grid gap-0.5';
    $item = 'group/item relative flex h-9 w-full items-center gap-3 rounded-md px-2.5 text-left text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] [&:has(+div_[aria-current=page])]:[anchor-name:--active]';
    $iconClass = 'size-5 shrink-0';
    $labelClass = 'min-w-0 flex-1 truncate in-data-[state=collapsed]:sr-only';
    $badgeClass = 'rounded-full bg-primary-soft px-1.5 py-0.5 text-xs leading-none font-medium text-primary in-data-[state=collapsed]:sr-only';
    $dot = 'absolute top-1.5 right-1.5 hidden size-2 rounded-full bg-primary in-data-[state=collapsed]:block';
    $chevron = 'size-4 shrink-0 text-faint transition-transform duration-200 ease-out group-aria-expanded/item:rotate-90 in-data-[state=collapsed]:hidden';
    $tip = 'absolute top-1/2 left-full ml-3 hidden -translate-y-1/2 rounded-md bg-ink px-2 py-1 text-xs whitespace-nowrap text-canvas shadow-overlay in-data-[state=collapsed]:group-hover/item:block in-data-[state=collapsed]:group-focus-visible/item:block';
    $region = 'invisible grid grid-rows-[0fr] transition-[grid-template-rows,visibility] duration-200 ease-out data-[state=open]:visible data-[state=open]:grid-rows-[1fr] in-data-[state=collapsed]:hidden';
    $regionInner = 'min-h-0 overflow-hidden';
    $subList = 'ml-5 grid gap-0.5 border-l border-line py-1 pr-1 pl-2';
    $subItem = 'relative flex h-8 w-full items-center rounded-md px-2.5 text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] in-data-[state=closed]:[anchor-name:none]!';
    $content = 'flex min-w-0 flex-1 flex-col';
    $mobileBar = 'flex h-14 shrink-0 items-center border-b border-line px-3';
    $iconButton = 'grid size-9 shrink-0 place-items-center rounded-md text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none';
    $dialogClass = 'right-auto left-0 m-0 h-dvh max-h-dvh w-72 flex-col border-r border-line bg-surface p-0 text-sm text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 open:flex starting:open:-translate-x-full motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none';

    // Href berskema selain http, https, mailto, dan tel (misalnya javascript:) diganti "#". Spasi dan karakter kontrol diabaikan seperti di browser.
    $safeHref = fn (string $href): string => preg_match('/^(?!https?:|mailto:|tel:)[a-z][\w+.\-]*:/i', preg_replace('/[\x00-\x20]/', '', $href)) === 1 ? '#' : $href;
    $svg = 'viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"';
    $hasBadge = fn (array $entry): bool => isset($entry['badge']) && $entry['badge'] !== '';
    // Header dan footer dicetak dua kali (aside dan dialog seluler). Id di salinan dialog diberi akhiran -m agar komponen di dalamnya (dropdown, command) tidak bentrok.
    $mobileCopy = fn ($html): string => preg_replace_callback(
        '/(?<=\s)(id|for|popovertarget|aria-(?:controls|labelledby|describedby|owns))="([^"]*)"/',
        fn (array $m): string => $m[1].'="'.implode(' ', array_map(fn (string $ref): string => $ref.'-m', preg_split('/\s+/', trim($m[2])))).'"',
        (string) $html,
    );

    // Same id on every render, so Livewire's morph (which matches elements by id) keeps the element. Pass `id` to set it.
    $idKey = 'markas-sidebar|'.(isset($this) && $this instanceof \Livewire\Component ? $this->getId() : '').'|'.($attributes->get('wire:key') ?? $attributes->whereStartsWith('wire:model')->first() ?? $attributes->get('name')).'|';
    for ($idIndex = 0; $__env->hasRenderedOnce($idKey.$idIndex); $idIndex++);
    $__env->markAsRenderedOnce($idKey.$idIndex);
    $id = $attributes->get('id') ?? 'markas-sidebar-'.hash('xxh32', $idKey.$idIndex);
    $asideId = $id.'-aside';
    $dialogId = $id.'-dialog';

    // Grup sub-item terbuka di awal bila open diisi atau ada sub-item aktif.
    $groups = [];
    foreach ($sections as $s => $section) {
        foreach ($section['items'] ?? [] as $i => $entry) {
            $childActive = collect($entry['children'] ?? [])->contains(fn ($child) => ! empty($child['active']));
            $groups[$s.'-'.$i] = (bool) ($entry['open'] ?? $childActive);
        }
    }
@endphp

<div
    x-data="{
        collapsed: @js((bool) $collapsed),
        groups: @js((object) $groups),
        setCollapsed(value) {
            this.collapsed = value;
            this.$dispatch('markas-collapsed-change', value);
        },
        {{-- Di rail, tombol induk membentangkan sidebar dan membuka grupnya. --}}
        toggleGroup(key, rail) {
            if (rail) this.setCollapsed(false);
            this.groups[key] = rail || ! this.groups[key];
        },
    }"
    {{ $attributes->merge(['id' => $id])->class([$root]) }}
>
    @foreach (['d', 'm'] as $copy)
        @php
            $prefix = $id.'-'.$copy;
            $rail = $copy === 'd' ? 'collapsed' : 'false';
        @endphp
        @if ($copy === 'd')
            <aside
                id="{{ $asideId }}"
                data-state="{{ $collapsed ? 'collapsed' : 'expanded' }}"
                :data-state="collapsed ? 'collapsed' : 'expanded'"
                class="{{ $aside }} {{ $variants[$variant] }} {{ $showAside[$breakpoint] }}"
            >
                @isset($header)
                    <div class="{{ $headerClass }}"><div class="{{ $slotClass }}">{{ $header }}</div></div>
                @endisset
        @else
            <dialog
                wire:ignore.self
                x-ref="dialog"
                id="{{ $dialogId }}"
                aria-label="{{ $navLabel }}"
                @click="if ($event.target === $el || $event.target.closest('a[href]')) $el.close()"
                class="{{ $dialogClass }}"
            >
                <div class="{{ $headerClass }}">
                    <div class="{{ $slotClass }}">{!! $mobileCopy($header ?? '') !!}</div>
                    <form method="dialog">
                        <button type="submit" aria-label="{{ $closeLabel }}" class="{{ $iconButton }}">
                            <svg class="{{ $iconClass }}" {!! $svg !!}><path d="M18 6 6 18M6 6l12 12" /></svg>
                        </button>
                    </form>
                </div>
        @endif
                <nav aria-label="{{ $navLabel }}" class="{{ $navClass }}">
                    <div class="{{ $listWrap }}">
                        <span aria-hidden="true" class="{{ $indicator }}"></span>
                        @foreach ($sections as $s => $section)
                            <div class="{{ $sectionClass }}">
                                @if (! empty($section['title']))
                                    <p aria-hidden="true" class="{{ $titleClass }}">{{ $section['title'] }}</p>
                                @endif
                                <ul @if (! empty($section['title'])) aria-label="{{ $section['title'] }}" @endif class="{{ $listClass }}">
                                    @foreach ($section['items'] ?? [] as $i => $entry)
                                        @php
                                            $key = $s.'-'.$i;
                                            $open = $groups[$key];
                                            $regionId = $prefix.'-g'.$key;
                                        @endphp
                                        <li>
                                            @if (! empty($entry['children']))
                                                <button
                                                    type="button"
                                                    aria-expanded="{{ $open ? 'true' : 'false' }}"
                                                    aria-controls="{{ $regionId }}"
                                                    :aria-expanded="groups['{{ $key }}'] ? 'true' : 'false'"
                                                    @click="toggleGroup('{{ $key }}', {{ $rail }})"
                                                    class="{{ $item }}"
                                                >
                                                    @if (! empty($entry['icon']))
                                                        <svg class="{{ $iconClass }}" {!! $svg !!}><path d="{{ $entry['icon'] }}" /></svg>
                                                    @endif
                                                    <span class="{{ $labelClass }}">{{ $entry['label'] }}</span>
                                                    @if ($hasBadge($entry))
                                                        <span class="{{ $badgeClass }}">{{ $entry['badge'] }}</span>
                                                        <span aria-hidden="true" class="{{ $dot }}"></span>
                                                    @endif
                                                    <svg class="{{ $chevron }}" {!! $svg !!}><path d="m9 6 6 6-6 6" /></svg>
                                                    <span aria-hidden="true" class="{{ $tip }}">{{ $entry['label'] }}</span>
                                                </button>
                                                <div
                                                    id="{{ $regionId }}"
                                                    data-state="{{ $open ? 'open' : 'closed' }}"
                                                    :data-state="groups['{{ $key }}'] ? 'open' : 'closed'"
                                                    class="{{ $region }}"
                                                >
                                                    <div class="{{ $regionInner }}">
                                                        <ul class="{{ $subList }}">
                                                            @foreach ($entry['children'] as $child)
                                                                <li>
                                                                    @if (! empty($child['disabled']))
                                                                        <a role="link" aria-disabled="true" class="{{ $subItem }}">{{ $child['label'] }}</a>
                                                                    @else
                                                                        <a
                                                                            href="{{ $safeHref((string) ($child['href'] ?? '#')) }}"
                                                                            @if (! empty($child['active'])) aria-current="page" @endif
                                                                            class="{{ $subItem }}"
                                                                        >{{ $child['label'] }}</a>
                                                                    @endif
                                                                </li>
                                                            @endforeach
                                                        </ul>
                                                    </div>
                                                </div>
                                            @else
                                                <a
                                                    @if (! empty($entry['disabled']))
                                                        role="link" aria-disabled="true"
                                                    @else
                                                        href="{{ $safeHref((string) ($entry['href'] ?? '#')) }}"
                                                        @if (! empty($entry['active'])) aria-current="page" @endif
                                                    @endif
                                                    class="{{ $item }}"
                                                >
                                                    @if (! empty($entry['icon']))
                                                        <svg class="{{ $iconClass }}" {!! $svg !!}><path d="{{ $entry['icon'] }}" /></svg>
                                                    @endif
                                                    <span class="{{ $labelClass }}">{{ $entry['label'] }}</span>
                                                    @if ($hasBadge($entry))
                                                        <span class="{{ $badgeClass }}">{{ $entry['badge'] }}</span>
                                                        <span aria-hidden="true" class="{{ $dot }}"></span>
                                                    @endif
                                                    <span aria-hidden="true" class="{{ $tip }}">{{ $entry['label'] }}</span>
                                                </a>
                                            @endif
                                        </li>
                                    @endforeach
                                </ul>
                            </div>
                        @endforeach
                    </div>
                </nav>
                @isset($footer)
                    <div class="{{ $footerClass }}"><div class="{{ $slotClass }}">{!! $copy === 'd' ? $footer : $mobileCopy($footer) !!}</div></div>
                @endisset
        @if ($copy === 'd')
                <button
                    type="button"
                    aria-label="{{ $collapsed ? $expandLabel : $collapseLabel }}"
                    aria-expanded="{{ $collapsed ? 'false' : 'true' }}"
                    aria-controls="{{ $asideId }}"
                    :aria-label="collapsed ? @js($expandLabel) : @js($collapseLabel)"
                    :aria-expanded="collapsed ? 'false' : 'true'"
                    @click="setCollapsed(! collapsed)"
                    class="{{ $collapseButton }}"
                >
                    <svg class="{{ $collapseIcon }}" {!! $svg !!}><path d="m15 6-6 6 6 6" /></svg>
                </button>
            </aside>
        @else
            </dialog>
        @endif
    @endforeach
    <div class="{{ $content }}">
        <div class="{{ $mobileBar }} {{ $hideBar[$breakpoint] }}">
            <button
                type="button"
                aria-label="{{ $openLabel }}"
                aria-haspopup="dialog"
                aria-controls="{{ $dialogId }}"
                @click="$refs.dialog.showModal()"
                class="{{ $iconButton }}"
            >
                <svg class="{{ $iconClass }}" {!! $svg !!}><path d="M4 6h16M4 12h16M4 18h16" /></svg>
            </button>
        </div>
        {{ $slot }}
    </div>
</div>
```

```blade
<x-markas.sidebar
    nav-label="Navigasi samping"
    collapse-label="Ciutkan sidebar"
    expand-label="Bentangkan sidebar"
    open-label="Buka sidebar"
    close-label="Tutup sidebar"
    :sections="[
        ['items' => [
            ['label' => 'Beranda', 'href' => '/', 'icon' => 'M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6h-6v6H4a1 1 0 0 1-1-1z'],
            ['label' => 'Kotak masuk', 'href' => '/inbox', 'icon' => 'M3 13h5l1.5 3h5l1.5-3h5M5 5h14l2 8v6a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-6z', 'badge' => 12],
        ]],
        ['title' => 'Workspace', 'items' => [
            ['label' => 'Proyek', 'icon' => 'M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z', 'children' => [
                ['label' => 'Desain ulang situs', 'href' => '/proyek/situs', 'active' => true],
                ['label' => 'Aplikasi seluler', 'href' => '/proyek/seluler'],
            ]],
        ]],
    ]"
    class="h-dvh"
>
    <x-slot:header>MarkasUI</x-slot:header>
    <x-slot:footer>Rina Saputra</x-slot:footer>

    <main class="flex-1 p-6">...</main>
</x-markas.sidebar>
```

Butuh Alpine.js. Dengarkan perubahan rail lewat `x-on:markas-collapsed-change="tersimpan = $event.detail"`.

### React

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

```tsx
"use client";

import {
  useId,
  useRef,
  useState,
  type ComponentProps,
  type MouseEvent,
  type ReactNode,
} from "react";

const root = "@container flex overflow-hidden bg-canvas";
const aside =
  "relative hidden w-56 shrink-0 flex-col bg-surface text-sm transition-[width] duration-200 ease-out data-[state=collapsed]:w-16 motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none";
const variants = {
  default: "border-r border-line",
  floating: "m-2 rounded-xl border border-line",
};
const showAside = { sm: "@sm:flex", md: "@2xl:flex", lg: "@4xl:flex" };
const hideBar = { sm: "@sm:hidden", md: "@2xl:hidden", lg: "@4xl:hidden" };
const headerClass = "flex h-14 shrink-0 items-center border-b border-line px-4";
/** Isi header dan footer dipotong di tepi konten agar rail hanya menampilkan 32px pertama. */
const slotClass =
  "flex min-w-0 flex-1 items-center gap-2 overflow-hidden whitespace-nowrap";
const footerClass = "shrink-0 border-t border-line px-4 py-3";
const collapseButton =
  "absolute top-4 -right-3 z-10 grid size-6 place-items-center rounded-full border border-line bg-surface text-muted transition-colors duration-150 ease-out hover:text-ink";
const collapseIcon =
  "size-3.5 transition-transform duration-200 ease-out in-data-[state=collapsed]:rotate-180";
const navClass =
  "min-h-0 flex-1 overflow-y-auto p-3 in-data-[state=collapsed]:overflow-visible";
const listWrap = "relative grid gap-3 [anchor-scope:--active,--hover]";
const indicator =
  "absolute inset-[anchor(--hover_top,anchor(--active_top))_anchor(--hover_right,anchor(--active_right))_anchor(--hover_bottom,anchor(--active_bottom))_anchor(--hover_left,anchor(--active_left))] rounded-md bg-subtle transition-[inset] duration-200 ease-out";
const sectionClass =
  "grid gap-0.5 border-t border-line pt-3 first-of-type:border-t-0 first-of-type:pt-0";
const titleClass =
  "px-2.5 pb-1 text-xs font-medium text-faint in-data-[state=collapsed]:sr-only";
const listClass = "grid gap-0.5";
const item =
  "group/item relative flex h-9 w-full items-center gap-3 rounded-md px-2.5 text-left text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] [&:has(+div_[aria-current=page])]:[anchor-name:--active]";
const iconClass = "size-5 shrink-0";
const labelClass = "min-w-0 flex-1 truncate in-data-[state=collapsed]:sr-only";
const badgeClass =
  "rounded-full bg-primary-soft px-1.5 py-0.5 text-xs leading-none font-medium text-primary in-data-[state=collapsed]:sr-only";
const dot =
  "absolute top-1.5 right-1.5 hidden size-2 rounded-full bg-primary in-data-[state=collapsed]:block";
const chevron =
  "size-4 shrink-0 text-faint transition-transform duration-200 ease-out group-aria-expanded/item:rotate-90 in-data-[state=collapsed]:hidden";
const tip =
  "absolute top-1/2 left-full ml-3 hidden -translate-y-1/2 rounded-md bg-ink px-2 py-1 text-xs whitespace-nowrap text-canvas shadow-overlay in-data-[state=collapsed]:group-hover/item:block in-data-[state=collapsed]:group-focus-visible/item:block";
const region =
  "invisible grid grid-rows-[0fr] transition-[grid-template-rows,visibility] duration-200 ease-out data-[state=open]:visible data-[state=open]:grid-rows-[1fr] in-data-[state=collapsed]:hidden";
const regionInner = "min-h-0 overflow-hidden";
const subList = "ml-5 grid gap-0.5 border-l border-line py-1 pr-1 pl-2";
const subItem =
  "relative flex h-8 w-full items-center rounded-md px-2.5 text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] in-data-[state=closed]:[anchor-name:none]!";
const content = "flex min-w-0 flex-1 flex-col";
const mobileBar = "flex h-14 shrink-0 items-center border-b border-line px-3";
const iconButton =
  "grid size-9 shrink-0 place-items-center rounded-md text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const dialogClass =
  "right-auto left-0 m-0 h-dvh max-h-dvh w-72 flex-col border-r border-line bg-surface p-0 text-sm text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 open:flex starting:open:-translate-x-full motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none";
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

/** Href berskema selain http, https, mailto, dan tel (misalnya javascript:) diganti "#". Spasi dan karakter kontrol diabaikan seperti di browser. */
const safeHref = (href: string) =>
  /^(?!https?:|mailto:|tel:)[a-z][\w+.-]*:/i.test(href.replace(/[\0- ]/g, ""))
    ? "#"
    : href;

export type SidebarItem = {
  label: string;
  /** Tujuan link. Diabaikan bila item punya children. */
  href?: string;
  /** Data path SVG (atribut d) untuk ikon 24x24 bergaris. */
  icon?: string;
  badge?: string | number;
  /** Tandai halaman yang sedang dibuka. */
  active?: boolean;
  disabled?: boolean;
  /** Sub-item. Item induk menjadi tombol buka/tutup. */
  children?: SidebarItem[];
  /** Sub-item terbuka di awal. Default: terbuka bila ada sub-item aktif. */
  open?: boolean;
};

export type SidebarSection = { title?: string; items: SidebarItem[] };

export type SidebarProps = ComponentProps<"div"> & {
  sections?: SidebarSection[];
  /** Brand atau workspace di atas sidebar. */
  header?: ReactNode;
  /** Profil pengguna di bawah sidebar. */
  footer?: ReactNode;
  variant?: keyof typeof variants;
  /** Lebar kontainer minimum agar sidebar tampil di samping konten: sm 24rem, md 42rem, lg 56rem. */
  breakpoint?: keyof typeof showAside;
  /** Mode rail ikon (terkontrol). */
  collapsed?: boolean;
  defaultCollapsed?: boolean;
  onCollapsedChange?: (collapsed: boolean) => void;
  navLabel?: string;
  collapseLabel?: string;
  expandLabel?: string;
  openLabel?: string;
  closeLabel?: string;
};

const linkProps = (entry: SidebarItem) =>
  entry.disabled
    ? { role: "link", "aria-disabled": true }
    : {
        href: safeHref(entry.href ?? "#"),
        "aria-current": entry.active ? ("page" as const) : undefined,
      };

function Icon({ d, className }: { d: string; className: string }) {
  return (
    <svg
      className={className}
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      strokeWidth="1.5"
      strokeLinecap="round"
      strokeLinejoin="round"
      aria-hidden="true"
    >
      <path d={d} />
    </svg>
  );
}

export function Sidebar({
  sections = [],
  header,
  footer,
  variant = "default",
  breakpoint = "md",
  collapsed,
  defaultCollapsed = false,
  onCollapsedChange,
  navLabel = "Sidebar",
  collapseLabel = "Collapse sidebar",
  expandLabel = "Expand sidebar",
  openLabel = "Open sidebar",
  closeLabel = "Close sidebar",
  id,
  className,
  children,
  ...props
}: SidebarProps) {
  const generatedId = useId();
  const rootId = id ?? generatedId;
  const asideId = `${rootId}-aside`;
  const dialogId = `${rootId}-dialog`;
  const dialogRef = useRef<HTMLDialogElement>(null);
  const [localCollapsed, setLocalCollapsed] = useState(defaultCollapsed);
  const [groups, setGroups] = useState(() =>
    Object.fromEntries(
      sections.flatMap((section, s) =>
        section.items.map((entry, i) => [
          `${s}-${i}`,
          entry.open ?? !!entry.children?.some((child) => child.active),
        ]),
      ),
    ),
  );
  const isCollapsed = collapsed ?? localCollapsed;

  const setCollapsed = (next: boolean) => {
    setLocalCollapsed(next);
    onCollapsedChange?.(next);
  };
  const toggleGroup = (key: string, rail: boolean) => {
    if (rail) setCollapsed(false);
    setGroups((current) => ({ ...current, [key]: rail || !current[key] }));
  };

  const showMobile = () => dialogRef.current?.showModal();
  const onDialogClick = (event: MouseEvent<HTMLDialogElement>) => {
    const target = event.target as Element;
    if (target === event.currentTarget || target.closest("a[href]"))
      event.currentTarget.close();
  };
  /** Nav yang sama dipakai di sidebar desktop (prefix d) dan dialog seluler (prefix m). */
  const nav = (prefix: string, rail: boolean) => (
    <nav aria-label={navLabel} className={navClass}>
      <div className={listWrap}>
        <span aria-hidden="true" className={indicator} />
        {sections.map((section, s) => (
          <div key={s} className={sectionClass}>
            {section.title && (
              <p aria-hidden="true" className={titleClass}>
                {section.title}
              </p>
            )}
            <ul aria-label={section.title} className={listClass}>
              {section.items.map((entry, i) => {
                const key = `${s}-${i}`;
                const regionId = `${rootId}-${prefix}-g${key}`;
                const hasBadge = entry.badge != null && entry.badge !== "";
                const body = (
                  <>
                    {entry.icon && (
                      <Icon d={entry.icon} className={iconClass} />
                    )}
                    <span className={labelClass}>{entry.label}</span>
                    {hasBadge && (
                      <span className={badgeClass}>{entry.badge}</span>
                    )}
                    {hasBadge && <span aria-hidden="true" className={dot} />}
                    {!!entry.children?.length && (
                      <Icon d="m9 6 6 6-6 6" className={chevron} />
                    )}
                    <span aria-hidden="true" className={tip}>
                      {entry.label}
                    </span>
                  </>
                );
                return (
                  <li key={i}>
                    {entry.children?.length ? (
                      <>
                        <button
                          type="button"
                          aria-expanded={!!groups[key]}
                          aria-controls={regionId}
                          className={item}
                          onClick={() => toggleGroup(key, rail)}
                        >
                          {body}
                        </button>
                        <div
                          id={regionId}
                          data-state={groups[key] ? "open" : "closed"}
                          className={region}
                        >
                          <div className={regionInner}>
                            <ul className={subList}>
                              {entry.children.map((child, c) => (
                                <li key={c}>
                                  <a {...linkProps(child)} className={subItem}>
                                    {child.label}
                                  </a>
                                </li>
                              ))}
                            </ul>
                          </div>
                        </div>
                      </>
                    ) : (
                      <a {...linkProps(entry)} className={item}>
                        {body}
                      </a>
                    )}
                  </li>
                );
              })}
            </ul>
          </div>
        ))}
      </div>
    </nav>
  );

  return (
    <div id={rootId} className={cx(root, className)} {...props}>
      <aside
        id={asideId}
        data-state={isCollapsed ? "collapsed" : "expanded"}
        className={cx(aside, variants[variant], showAside[breakpoint])}
      >
        {header && (
          <div className={headerClass}>
            <div className={slotClass}>{header}</div>
          </div>
        )}
        {nav("d", isCollapsed)}
        {footer && (
          <div className={footerClass}>
            <div className={slotClass}>{footer}</div>
          </div>
        )}
        <button
          type="button"
          aria-label={isCollapsed ? expandLabel : collapseLabel}
          aria-expanded={!isCollapsed}
          aria-controls={asideId}
          className={collapseButton}
          onClick={() => setCollapsed(!isCollapsed)}
        >
          <Icon d="m15 6-6 6 6 6" className={collapseIcon} />
        </button>
      </aside>
      <dialog
        ref={dialogRef}
        id={dialogId}
        aria-label={navLabel}
        className={dialogClass}
        onClick={onDialogClick}
      >
        <div className={headerClass}>
          <div className={slotClass}>{header}</div>
          <form method="dialog">
            <button
              type="submit"
              aria-label={closeLabel}
              className={iconButton}
            >
              <Icon d="M18 6 6 18M6 6l12 12" className={iconClass} />
            </button>
          </form>
        </div>
        {nav("m", false)}
        {footer && (
          <div className={footerClass}>
            <div className={slotClass}>{footer}</div>
          </div>
        )}
      </dialog>
      <div className={content}>
        <div className={cx(mobileBar, hideBar[breakpoint])}>
          <button
            type="button"
            aria-label={openLabel}
            aria-haspopup="dialog"
            aria-controls={dialogId}
            className={iconButton}
            onClick={showMobile}
          >
            <Icon d="M4 6h16M4 12h16M4 18h16" className={iconClass} />
          </button>
        </div>
        {children}
      </div>
    </div>
  );
}
```

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

const sections = [
  {
    items: [
      {
        label: "Beranda",
        href: "/",
        icon: "M3 10.5 12 3l9 7.5V20a1 1 0 0 1-1 1h-5v-6h-6v6H4a1 1 0 0 1-1-1z",
      },
      {
        label: "Kotak masuk",
        href: "/inbox",
        icon: "M3 13h5l1.5 3h5l1.5-3h5M5 5h14l2 8v6a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1v-6z",
        badge: 12,
      },
    ],
  },
  {
    title: "Workspace",
    items: [
      {
        label: "Proyek",
        icon: "M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",
        children: [
          { label: "Desain ulang situs", href: "/proyek/situs", active: true },
          { label: "Aplikasi seluler", href: "/proyek/seluler" },
        ],
      },
    ],
  },
];

const [collapsed, setCollapsed] = useState(false);

<Sidebar
  sections={sections}
  header="MarkasUI"
  footer="Rina Saputra"
  collapsed={collapsed}
  onCollapsedChange={setCollapsed}
  navLabel="Navigasi samping"
  collapseLabel="Ciutkan sidebar"
  expandLabel="Bentangkan sidebar"
  openLabel="Buka sidebar"
  closeLabel="Tutup sidebar"
  className="h-dvh"
>
  <main className="flex-1 p-6">...</main>
</Sidebar>;
```

### Vue

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

```vue
<script setup lang="ts">
import { computed, h, ref, useAttrs, useId, useSlots } from "vue";

export type SidebarItem = {
  label: string;
  /** Tujuan link. Diabaikan bila item punya children. */
  href?: string;
  /** Data path SVG (atribut d) untuk ikon 24x24 bergaris. */
  icon?: string;
  badge?: string | number;
  /** Tandai halaman yang sedang dibuka. */
  active?: boolean;
  disabled?: boolean;
  /** Sub-item. Item induk menjadi tombol buka/tutup. */
  children?: SidebarItem[];
  /** Sub-item terbuka di awal. Default: terbuka bila ada sub-item aktif. */
  open?: boolean;
};

export type SidebarSection = { title?: string; items: SidebarItem[] };

const root = "@container flex overflow-hidden bg-canvas";
const aside =
  "relative hidden w-56 shrink-0 flex-col bg-surface text-sm transition-[width] duration-200 ease-out data-[state=collapsed]:w-16 motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none";
const variants = {
  default: "border-r border-line",
  floating: "m-2 rounded-xl border border-line",
};
const showAside = { sm: "@sm:flex", md: "@2xl:flex", lg: "@4xl:flex" };
const hideBar = { sm: "@sm:hidden", md: "@2xl:hidden", lg: "@4xl:hidden" };
const headerClass = "flex h-14 shrink-0 items-center border-b border-line px-4";
/** Isi header dan footer dipotong di tepi konten agar rail hanya menampilkan 32px pertama. */
const slotClass =
  "flex min-w-0 flex-1 items-center gap-2 overflow-hidden whitespace-nowrap";
const footerClass = "shrink-0 border-t border-line px-4 py-3";
const collapseButton =
  "absolute top-4 -right-3 z-10 grid size-6 place-items-center rounded-full border border-line bg-surface text-muted transition-colors duration-150 ease-out hover:text-ink";
const collapseIcon =
  "size-3.5 transition-transform duration-200 ease-out in-data-[state=collapsed]:rotate-180";
const navClass =
  "min-h-0 flex-1 overflow-y-auto p-3 in-data-[state=collapsed]:overflow-visible";
const listWrap = "relative grid gap-3 [anchor-scope:--active,--hover]";
const indicator =
  "absolute inset-[anchor(--hover_top,anchor(--active_top))_anchor(--hover_right,anchor(--active_right))_anchor(--hover_bottom,anchor(--active_bottom))_anchor(--hover_left,anchor(--active_left))] rounded-md bg-subtle transition-[inset] duration-200 ease-out";
const sectionClass =
  "grid gap-0.5 border-t border-line pt-3 first-of-type:border-t-0 first-of-type:pt-0";
const titleClass =
  "px-2.5 pb-1 text-xs font-medium text-faint in-data-[state=collapsed]:sr-only";
const listClass = "grid gap-0.5";
const item =
  "group/item relative flex h-9 w-full items-center gap-3 rounded-md px-2.5 text-left text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] [&:has(+div_[aria-current=page])]:[anchor-name:--active]";
const iconClass = "size-5 shrink-0";
const labelClass = "min-w-0 flex-1 truncate in-data-[state=collapsed]:sr-only";
const badgeClass =
  "rounded-full bg-primary-soft px-1.5 py-0.5 text-xs leading-none font-medium text-primary in-data-[state=collapsed]:sr-only";
const dot =
  "absolute top-1.5 right-1.5 hidden size-2 rounded-full bg-primary in-data-[state=collapsed]:block";
const chevron =
  "size-4 shrink-0 text-faint transition-transform duration-200 ease-out group-aria-expanded/item:rotate-90 in-data-[state=collapsed]:hidden";
const tip =
  "absolute top-1/2 left-full ml-3 hidden -translate-y-1/2 rounded-md bg-ink px-2 py-1 text-xs whitespace-nowrap text-canvas shadow-overlay in-data-[state=collapsed]:group-hover/item:block in-data-[state=collapsed]:group-focus-visible/item:block";
const region =
  "invisible grid grid-rows-[0fr] transition-[grid-template-rows,visibility] duration-200 ease-out data-[state=open]:visible data-[state=open]:grid-rows-[1fr] in-data-[state=collapsed]:hidden";
const regionInner = "min-h-0 overflow-hidden";
const subList = "ml-5 grid gap-0.5 border-l border-line py-1 pr-1 pl-2";
const subItem =
  "relative flex h-8 w-full items-center rounded-md px-2.5 text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] in-data-[state=closed]:[anchor-name:none]!";
const content = "flex min-w-0 flex-1 flex-col";
const mobileBar = "flex h-14 shrink-0 items-center border-b border-line px-3";
const iconButton =
  "grid size-9 shrink-0 place-items-center rounded-md text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const dialogClass =
  "right-auto left-0 m-0 h-dvh max-h-dvh w-72 flex-col border-r border-line bg-surface p-0 text-sm text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 open:flex starting:open:-translate-x-full motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none";

defineOptions({ inheritAttrs: false });

const props = withDefaults(
  defineProps<{
    sections?: SidebarSection[];
    variant?: keyof typeof variants;
    /** Lebar kontainer minimum agar sidebar tampil di samping konten: sm 24rem, md 42rem, lg 56rem. */
    breakpoint?: keyof typeof showAside;
    id?: string;
    navLabel?: string;
    collapseLabel?: string;
    expandLabel?: string;
    openLabel?: string;
    closeLabel?: string;
  }>(),
  {
    sections: () => [],
    variant: "default",
    breakpoint: "md",
    id: undefined,
    navLabel: "Sidebar",
    collapseLabel: "Collapse sidebar",
    expandLabel: "Expand sidebar",
    openLabel: "Open sidebar",
    closeLabel: "Close sidebar",
  },
);
/** Mode rail ikon. Tanpa v-model state-nya lokal dengan nilai awal dari prop collapsed. */
const collapsed = defineModel<boolean>("collapsed", { default: false });

/** Href berskema selain http, https, mailto, dan tel (misalnya javascript:) diganti "#". Spasi dan karakter kontrol diabaikan seperti di browser. */
const safeHref = (href: string) =>
  /^(?!https?:|mailto:|tel:)[a-z][\w+.-]*:/i.test(href.replace(/[\0- ]/g, ""))
    ? "#"
    : href;

const linkProps = (entry: SidebarItem) =>
  entry.disabled
    ? { role: "link", "aria-disabled": "true" }
    : {
        href: safeHref(entry.href ?? "#"),
        "aria-current": entry.active ? "page" : undefined,
      };

/** Ikon garis 24px dari satu path SVG. */
const Icon = (props: { d: string }) =>
  h(
    "svg",
    {
      viewBox: "0 0 24 24",
      fill: "none",
      stroke: "currentColor",
      "stroke-width": "1.5",
      "stroke-linecap": "round",
      "stroke-linejoin": "round",
      "aria-hidden": "true",
    },
    h("path", { d: props.d }),
  );

const generatedId = useId();
const rootId = computed(() => props.id ?? generatedId);
const dialog = ref<HTMLDialogElement>();
const attrs = useAttrs();
const slots = useSlots();
const groups = ref<Record<string, boolean>>(
  Object.fromEntries(
    props.sections.flatMap((section, s) =>
      section.items.map((entry, i) => [
        `${s}-${i}`,
        entry.open ?? !!entry.children?.some((child) => child.active),
      ]),
    ),
  ),
);

/** Di rail, tombol induk membentangkan sidebar dan membuka grupnya. */
function toggleGroup(key: string, rail: boolean) {
  if (rail) collapsed.value = false;
  groups.value = { ...groups.value, [key]: rail || !groups.value[key] };
}

function onDialogClick(event: MouseEvent) {
  const target = event.target as Element;
  if (target === dialog.value || target.closest("a[href]"))
    dialog.value?.close();
}

/** Nav yang sama dipakai di sidebar desktop (prefix d) dan dialog seluler (prefix m). */
const nav = (prefix: string, rail: boolean) =>
  h(
    "nav",
    { "aria-label": props.navLabel, class: navClass },
    h("div", { class: listWrap }, [
      h("span", { "aria-hidden": "true", class: indicator }),
      ...props.sections.map((section, s) =>
        h("div", { class: sectionClass }, [
          section.title &&
            h("p", { "aria-hidden": "true", class: titleClass }, section.title),
          h(
            "ul",
            { "aria-label": section.title, class: listClass },
            section.items.map((entry, i) => {
              const key = `${s}-${i}`;
              const regionId = `${prefix}-g${key}`;
              const badge = entry.badge != null && entry.badge !== "";
              const body = [
                entry.icon && h(Icon, { d: entry.icon, class: iconClass }),
                h("span", { class: labelClass }, entry.label),
                badge && h("span", { class: badgeClass }, entry.badge),
                badge && h("span", { "aria-hidden": "true", class: dot }),
                !!entry.children?.length &&
                  h(Icon, { d: "m9 6 6 6-6 6", class: chevron }),
                h("span", { "aria-hidden": "true", class: tip }, entry.label),
              ];
              if (!entry.children?.length)
                return h(
                  "li",
                  h("a", { ...linkProps(entry), class: item }, body),
                );
              return h("li", [
                h(
                  "button",
                  {
                    type: "button",
                    "aria-expanded": !!groups.value[key],
                    "aria-controls": regionId,
                    class: item,
                    onClick: () => toggleGroup(key, rail),
                  },
                  body,
                ),
                h(
                  "div",
                  {
                    id: regionId,
                    "data-state": groups.value[key] ? "open" : "closed",
                    class: region,
                  },
                  h(
                    "div",
                    { class: regionInner },
                    h(
                      "ul",
                      { class: subList },
                      entry.children.map((child) =>
                        h(
                          "li",
                          h(
                            "a",
                            { ...linkProps(child), class: subItem },
                            child.label,
                          ),
                        ),
                      ),
                    ),
                  ),
                ),
              ]);
            }),
          ),
        ]),
      ),
    ]),
  );
/** Header atau footer dari slot, dipotong di tepi konten (lihat slotClass). */
const slotBox = (className: string, name: "header" | "footer") =>
  slots[name] &&
  h("div", { class: className }, h("div", { class: slotClass }, slots[name]()));

/**
 * Seluruh markup dirender dengan h(), bukan template, agar bundel tetap di bawah 3 KB gzip.
 * Atribut user (class, data-*, aria-*) jatuh ke elemen root.
 */
const Root = () => {
  const id = rootId.value;
  return h("div", { ...attrs, id, class: [root, attrs.class] }, [
    h(
      "aside",
      {
        id: `${id}-aside`,
        "data-state": collapsed.value ? "collapsed" : "expanded",
        class: [aside, variants[props.variant], showAside[props.breakpoint]],
      },
      [
        slotBox(headerClass, "header"),
        nav(`${id}-d`, collapsed.value),
        slotBox(footerClass, "footer"),
        h(
          "button",
          {
            type: "button",
            "aria-label": collapsed.value
              ? props.expandLabel
              : props.collapseLabel,
            "aria-expanded": !collapsed.value,
            "aria-controls": `${id}-aside`,
            class: collapseButton,
            onClick: () => (collapsed.value = !collapsed.value),
          },
          h(Icon, { d: "m15 6-6 6 6 6", class: collapseIcon }),
        ),
      ],
    ),
    h(
      "dialog",
      {
        id: `${id}-dialog`,
        ref: dialog,
        "aria-label": props.navLabel,
        class: dialogClass,
        onClick: onDialogClick,
      },
      [
        h("div", { class: headerClass }, [
          h("div", { class: slotClass }, slots.header?.()),
          h(
            "form",
            { method: "dialog" },
            h(
              "button",
              {
                type: "submit",
                "aria-label": props.closeLabel,
                class: iconButton,
              },
              h(Icon, { d: "M18 6 6 18M6 6l12 12", class: iconClass }),
            ),
          ),
        ]),
        nav(`${id}-m`, false),
        slotBox(footerClass, "footer"),
      ],
    ),
    h("div", { class: content }, [
      h(
        "div",
        { class: [mobileBar, hideBar[props.breakpoint]] },
        h(
          "button",
          {
            type: "button",
            "aria-label": props.openLabel,
            "aria-haspopup": "dialog",
            "aria-controls": `${id}-dialog`,
            class: iconButton,
            onClick: () => dialog.value?.showModal(),
          },
          h(Icon, { d: "M4 6h16M4 12h16M4 18h16", class: iconClass }),
        ),
      ),
      slots.default?.(),
    ]),
  ]);
};
</script>

<template>
  <Root />
</template>
```

```vue
<script setup lang="ts">
import { ref } from "vue";
import Sidebar from "@/components/markas/Sidebar.vue";

const collapsed = ref(false);
// sections: bentuknya sama dengan contoh React
</script>

<template>
  <Sidebar
    v-model:collapsed="collapsed"
    :sections="sections"
    nav-label="Navigasi samping"
    collapse-label="Ciutkan sidebar"
    expand-label="Bentangkan sidebar"
    open-label="Buka sidebar"
    close-label="Tutup sidebar"
    class="h-dvh"
  >
    <template #header>MarkasUI</template>
    <template #footer>Rina Saputra</template>
    <main class="flex-1 p-6">...</main>
  </Sidebar>
</template>
```

### Svelte

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

```svelte
<script lang="ts" module>
  export type SidebarItem = {
    label: string;
    /** Link target. Ignored when the item has children. */
    href?: string;
    /** SVG path data (d attribute) for a 24x24 stroke icon. */
    icon?: string;
    badge?: string | number;
    /** Marks the current page. */
    active?: boolean;
    disabled?: boolean;
    /** Sub-items. The parent item becomes an open/close button. */
    children?: SidebarItem[];
    /** Sub-items start open. Default: open when a sub-item is active. */
    open?: boolean;
  };

  export type SidebarSection = { title?: string; items: SidebarItem[] };
</script>

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

  const root = "@container flex overflow-hidden bg-canvas";
  const aside =
    "relative hidden w-56 shrink-0 flex-col bg-surface text-sm transition-[width] duration-200 ease-out data-[state=collapsed]:w-16 motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none";
  const variants = {
    default: "border-r border-line",
    floating: "m-2 rounded-xl border border-line",
  };
  const showAside = { sm: "@sm:flex", md: "@2xl:flex", lg: "@4xl:flex" };
  const hideBar = { sm: "@sm:hidden", md: "@2xl:hidden", lg: "@4xl:hidden" };
  const headerClass =
    "flex h-14 shrink-0 items-center border-b border-line px-4";
  /** Header and footer content is clipped at the content edge so the rail shows only the first 32px. */
  const slotClass =
    "flex min-w-0 flex-1 items-center gap-2 overflow-hidden whitespace-nowrap";
  const footerClass = "shrink-0 border-t border-line px-4 py-3";
  const collapseButton =
    "absolute top-4 -right-3 z-10 grid size-6 place-items-center rounded-full border border-line bg-surface text-muted transition-colors duration-150 ease-out hover:text-ink";
  const collapseIcon =
    "size-3.5 transition-transform duration-200 ease-out in-data-[state=collapsed]:rotate-180";
  const navClass =
    "min-h-0 flex-1 overflow-y-auto p-3 in-data-[state=collapsed]:overflow-visible";
  const listWrap = "relative grid gap-3 [anchor-scope:--active,--hover]";
  const indicator =
    "absolute inset-[anchor(--hover_top,anchor(--active_top))_anchor(--hover_right,anchor(--active_right))_anchor(--hover_bottom,anchor(--active_bottom))_anchor(--hover_left,anchor(--active_left))] rounded-md bg-subtle transition-[inset] duration-200 ease-out";
  const sectionClass =
    "grid gap-0.5 border-t border-line pt-3 first-of-type:border-t-0 first-of-type:pt-0";
  const titleClass =
    "px-2.5 pb-1 text-xs font-medium text-faint in-data-[state=collapsed]:sr-only";
  const listClass = "grid gap-0.5";
  const item =
    "group/item relative flex h-9 w-full items-center gap-3 rounded-md px-2.5 text-left text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] [&:has(+div_[aria-current=page])]:[anchor-name:--active]";
  const iconClass = "size-5 shrink-0";
  const labelClass =
    "min-w-0 flex-1 truncate in-data-[state=collapsed]:sr-only";
  const badgeClass =
    "rounded-full bg-primary-soft px-1.5 py-0.5 text-xs leading-none font-medium text-primary in-data-[state=collapsed]:sr-only";
  const dot =
    "absolute top-1.5 right-1.5 hidden size-2 rounded-full bg-primary in-data-[state=collapsed]:block";
  const chevron =
    "size-4 shrink-0 text-faint transition-transform duration-200 ease-out group-aria-expanded/item:rotate-90 in-data-[state=collapsed]:hidden";
  const tip =
    "absolute top-1/2 left-full ml-3 hidden -translate-y-1/2 rounded-md bg-ink px-2 py-1 text-xs whitespace-nowrap text-canvas shadow-overlay in-data-[state=collapsed]:group-hover/item:block in-data-[state=collapsed]:group-focus-visible/item:block";
  const region =
    "invisible grid grid-rows-[0fr] transition-[grid-template-rows,visibility] duration-200 ease-out data-[state=open]:visible data-[state=open]:grid-rows-[1fr] in-data-[state=collapsed]:hidden";
  const regionInner = "min-h-0 overflow-hidden";
  const subList = "ml-5 grid gap-0.5 border-l border-line py-1 pr-1 pl-2";
  const subItem =
    "relative flex h-8 w-full items-center rounded-md px-2.5 text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] in-data-[state=closed]:[anchor-name:none]!";
  const content = "flex min-w-0 flex-1 flex-col";
  const mobileBar = "flex h-14 shrink-0 items-center border-b border-line px-3";
  const iconButton =
    "grid size-9 shrink-0 place-items-center rounded-md text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
  const dialogClass =
    "right-auto left-0 m-0 h-dvh max-h-dvh w-72 flex-col border-r border-line bg-surface p-0 text-sm text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 open:flex starting:open:-translate-x-full motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none";

  /** Hrefs with a scheme other than http, https, mailto, and tel (javascript: for example) become "#". Whitespace and control characters are ignored as in browsers. */
  const safeHref = (href: string) =>
    /^(?!https?:|mailto:|tel:)[a-z][\w+.-]*:/i.test(href.replace(/[\0- ]/g, ""))
      ? "#"
      : href;

  const linkProps = (entry: SidebarItem) =>
    entry.disabled
      ? { role: "link", "aria-disabled": "true" as const }
      : {
          href: safeHref(entry.href ?? "#"),
          "aria-current": entry.active ? ("page" as const) : undefined,
        };

  type Props = Omit<HTMLAttributes<HTMLDivElement>, "children"> & {
    sections?: SidebarSection[];
    /** Brand or workspace at the top. Rendered twice: in the sidebar and in the mobile dialog. */
    header?: Snippet;
    /** User profile at the bottom. Rendered twice like header. */
    footer?: Snippet;
    children?: Snippet;
    variant?: keyof typeof variants;
    /** Minimum container width for the sidebar to sit next to the content: sm 24rem, md 42rem, lg 56rem. */
    breakpoint?: keyof typeof showAside;
    /** Icon rail mode. Works with bind:collapsed. */
    collapsed?: boolean;
    navLabel?: string;
    collapseLabel?: string;
    expandLabel?: string;
    openLabel?: string;
    closeLabel?: string;
  };

  let {
    sections = [],
    header,
    footer,
    children,
    variant = "default",
    breakpoint = "md",
    collapsed = $bindable(false),
    navLabel = "Sidebar",
    collapseLabel = "Collapse sidebar",
    expandLabel = "Expand sidebar",
    openLabel = "Open sidebar",
    closeLabel = "Close sidebar",
    id,
    class: className,
    ...rest
  }: Props = $props();

  const generatedId = $props.id();
  const rootId = $derived(id ?? generatedId);
  let dialog = $state<HTMLDialogElement>();

  /** Sub-item groups start open when open is set or a sub-item is active. */
  const initialGroups = () =>
    Object.fromEntries(
      sections.flatMap((section, s) =>
        section.items.map((entry, i) => [
          `${s}-${i}`,
          entry.open ?? !!entry.children?.some((child) => child.active),
        ]),
      ),
    ) as Record<string, boolean>;
  let groups = $state(initialGroups());

  /** In the rail, a parent item expands the sidebar and opens its group. */
  function toggleGroup(key: string, rail: boolean) {
    if (rail) collapsed = false;
    groups = { ...groups, [key]: rail || !groups[key] };
  }

  function onDialogClick(
    event: MouseEvent & { currentTarget: HTMLDialogElement },
  ) {
    const target = event.target as Element;
    if (target === event.currentTarget || target.closest("a[href]"))
      event.currentTarget.close();
  }
</script>

{#snippet icon(d: string, iconClassName: string)}
  <svg
    class={iconClassName}
    viewBox="0 0 24 24"
    fill="none"
    stroke="currentColor"
    stroke-width="1.5"
    stroke-linecap="round"
    stroke-linejoin="round"
    aria-hidden="true"
  >
    <path {d} />
  </svg>
{/snippet}

<!-- Header or footer box, clipped at the content edge (see slotClass). -->
{#snippet box(boxClass: string, content: Snippet | undefined)}
  <div class={boxClass}>
    <div class={slotClass}>{@render content?.()}</div>
  </div>
{/snippet}

<!-- The same nav serves the desktop sidebar (prefix d) and the mobile dialog (prefix m). -->
{#snippet nav(prefix: string, rail: boolean)}
  <nav aria-label={navLabel} class={navClass}>
    <div class={listWrap}>
      <span aria-hidden="true" class={indicator}></span>
      {#each sections as section, s}
        <div class={sectionClass}>
          {#if section.title}
            <p aria-hidden="true" class={titleClass}>{section.title}</p>
          {/if}
          <ul aria-label={section.title} class={listClass}>
            {#each section.items as entry, i}
              {@const key = `${s}-${i}`}
              {@const regionId = `${rootId}-${prefix}-g${key}`}
              <li>
                <svelte:element
                  this={entry.children?.length ? "button" : "a"}
                  {...entry.children?.length
                    ? {
                        type: "button",
                        "aria-expanded": !!groups[key],
                        "aria-controls": regionId,
                        onclick: () => toggleGroup(key, rail),
                      }
                    : linkProps(entry)}
                  class={item}
                >
                  {#if entry.icon}{@render icon(entry.icon, iconClass)}{/if}
                  <span class={labelClass}>{entry.label}</span>
                  {#if entry.badge != null && entry.badge !== ""}
                    <span class={badgeClass}>{entry.badge}</span>
                    <span aria-hidden="true" class={dot}></span>
                  {/if}
                  {#if entry.children?.length}
                    {@render icon("m9 6 6 6-6 6", chevron)}
                  {/if}
                  <span aria-hidden="true" class={tip}>{entry.label}</span>
                </svelte:element>
                {#if entry.children?.length}
                  <div
                    id={regionId}
                    data-state={groups[key] ? "open" : "closed"}
                    class={region}
                  >
                    <div class={regionInner}>
                      <ul class={subList}>
                        {#each entry.children as child}
                          <li>
                            <a {...linkProps(child)} class={subItem}
                              >{child.label}</a
                            >
                          </li>
                        {/each}
                      </ul>
                    </div>
                  </div>
                {/if}
              </li>
            {/each}
          </ul>
        </div>
      {/each}
    </div>
  </nav>
{/snippet}

<div id={rootId} class={[root, className]} {...rest}>
  <aside
    id={`${rootId}-aside`}
    data-state={collapsed ? "collapsed" : "expanded"}
    class={[aside, variants[variant], showAside[breakpoint]]}
  >
    {#if header}{@render box(headerClass, header)}{/if}
    {@render nav("d", collapsed)}
    {#if footer}{@render box(footerClass, footer)}{/if}
    <button
      type="button"
      aria-label={collapsed ? expandLabel : collapseLabel}
      aria-expanded={!collapsed}
      aria-controls={`${rootId}-aside`}
      class={collapseButton}
      onclick={() => (collapsed = !collapsed)}
    >
      {@render icon("m15 6-6 6 6 6", collapseIcon)}
    </button>
  </aside>
  <dialog
    bind:this={dialog}
    id={`${rootId}-dialog`}
    aria-label={navLabel}
    class={dialogClass}
    onclick={onDialogClick}
  >
    <div class={headerClass}>
      <div class={slotClass}>{@render header?.()}</div>
      <form method="dialog">
        <button type="submit" aria-label={closeLabel} class={iconButton}>
          {@render icon("M18 6 6 18M6 6l12 12", iconClass)}
        </button>
      </form>
    </div>
    {@render nav("m", false)}
    {#if footer}{@render box(footerClass, footer)}{/if}
  </dialog>
  <div class={content}>
    <div class={[mobileBar, hideBar[breakpoint]]}>
      <button
        type="button"
        aria-label={openLabel}
        aria-haspopup="dialog"
        aria-controls={`${rootId}-dialog`}
        class={iconButton}
        onclick={() => dialog?.showModal()}
      >
        {@render icon("M4 6h16M4 12h16M4 18h16", iconClass)}
      </button>
    </div>
    {@render children?.()}
  </div>
</div>
```

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

  let collapsed = $state(false);
  // sections: bentuknya sama dengan contoh React
</script>

<Sidebar bind:collapsed {sections} class="h-dvh">
  {#snippet header()}MarkasUI{/snippet}
  {#snippet footer()}Rina Saputra{/snippet}
  <main class="flex-1 p-6">...</main>
</Sidebar>
```

### Astro

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

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

export type SidebarItem = {
  label: string;
  /** Link target. Ignored when the item has children. */
  href?: string;
  /** SVG path data (d attribute) for a 24x24 stroke icon. */
  icon?: string;
  badge?: string | number;
  /** Marks the current page. */
  active?: boolean;
  disabled?: boolean;
  /** Sub-items. The parent item becomes an open/close button. */
  children?: SidebarItem[];
  /** Sub-items start open. Default: open when a sub-item is active. */
  open?: boolean;
};

export type SidebarSection = { title?: string; items: SidebarItem[] };

const root = "@container flex overflow-hidden bg-canvas";
const aside =
  "relative hidden w-56 shrink-0 flex-col bg-surface text-sm transition-[width] duration-200 ease-out data-[state=collapsed]:w-16 motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none";
const variants = {
  default: "border-r border-line",
  floating: "m-2 rounded-xl border border-line",
};
const showAside = { sm: "@sm:flex", md: "@2xl:flex", lg: "@4xl:flex" };
const hideBar = { sm: "@sm:hidden", md: "@2xl:hidden", lg: "@4xl:hidden" };
const headerClass = "flex h-14 shrink-0 items-center border-b border-line px-4";
/** Header and footer content is clipped at the content edge so the rail shows only the first 32px. */
const slotClass =
  "flex min-w-0 flex-1 items-center gap-2 overflow-hidden whitespace-nowrap";
const footerClass = "shrink-0 border-t border-line px-4 py-3";
const collapseButton =
  "absolute top-4 -right-3 z-10 grid size-6 place-items-center rounded-full border border-line bg-surface text-muted transition-colors duration-150 ease-out hover:text-ink";
const collapseIcon =
  "size-3.5 transition-transform duration-200 ease-out in-data-[state=collapsed]:rotate-180";
const navClass =
  "min-h-0 flex-1 overflow-y-auto p-3 in-data-[state=collapsed]:overflow-visible";
const listWrap = "relative grid gap-3 [anchor-scope:--active,--hover]";
const indicator =
  "absolute inset-[anchor(--hover_top,anchor(--active_top))_anchor(--hover_right,anchor(--active_right))_anchor(--hover_bottom,anchor(--active_bottom))_anchor(--hover_left,anchor(--active_left))] rounded-md bg-subtle transition-[inset] duration-200 ease-out";
const sectionClass =
  "grid gap-0.5 border-t border-line pt-3 first-of-type:border-t-0 first-of-type:pt-0";
const titleClass =
  "px-2.5 pb-1 text-xs font-medium text-faint in-data-[state=collapsed]:sr-only";
const listClass = "grid gap-0.5";
const item =
  "group/item relative flex h-9 w-full items-center gap-3 rounded-md px-2.5 text-left text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] [&:has(+div_[aria-current=page])]:[anchor-name:--active]";
const iconClass = "size-5 shrink-0";
const labelClass = "min-w-0 flex-1 truncate in-data-[state=collapsed]:sr-only";
const badgeClass =
  "rounded-full bg-primary-soft px-1.5 py-0.5 text-xs leading-none font-medium text-primary in-data-[state=collapsed]:sr-only";
const dot =
  "absolute top-1.5 right-1.5 hidden size-2 rounded-full bg-primary in-data-[state=collapsed]:block";
const chevron =
  "size-4 shrink-0 text-faint transition-transform duration-200 ease-out group-aria-expanded/item:rotate-90 in-data-[state=collapsed]:hidden";
const tip =
  "absolute top-1/2 left-full ml-3 hidden -translate-y-1/2 rounded-md bg-ink px-2 py-1 text-xs whitespace-nowrap text-canvas shadow-overlay in-data-[state=collapsed]:group-hover/item:block in-data-[state=collapsed]:group-focus-visible/item:block";
const region =
  "invisible grid grid-rows-[0fr] transition-[grid-template-rows,visibility] duration-200 ease-out data-[state=open]:visible data-[state=open]:grid-rows-[1fr] in-data-[state=collapsed]:hidden";
const regionInner = "min-h-0 overflow-hidden";
const subList = "ml-5 grid gap-0.5 border-l border-line py-1 pr-1 pl-2";
const subItem =
  "relative flex h-8 w-full items-center rounded-md px-2.5 text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] in-data-[state=closed]:[anchor-name:none]!";
const content = "flex min-w-0 flex-1 flex-col";
const mobileBar = "flex h-14 shrink-0 items-center border-b border-line px-3";
const iconButton =
  "grid size-9 shrink-0 place-items-center rounded-md text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const dialogClass =
  "right-auto left-0 m-0 h-dvh max-h-dvh w-72 flex-col border-r border-line bg-surface p-0 text-sm text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 open:flex starting:open:-translate-x-full motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none";

/** Hrefs with a scheme other than http, https, mailto, and tel (javascript: for example) become "#". Whitespace and control characters are ignored as in browsers. */
const safeHref = (href: string) =>
  /^(?!https?:|mailto:|tel:)[a-z][\w+.-]*:/i.test(href.replace(/[\0- ]/g, ""))
    ? "#"
    : href;

const linkProps = (entry: SidebarItem) =>
  entry.disabled
    ? { role: "link" as const, "aria-disabled": "true" as const }
    : {
        href: safeHref(entry.href ?? "#"),
        "aria-current": entry.active ? ("page" as const) : undefined,
      };

/**
 * Header and footer render twice. Ids in the dialog copy get an m- prefix so components inside
 * (dropdown, command) stay unique and ids they derive at runtime (`${id}-trigger`) still match.
 */
const mobileCopy = (html: string) =>
  html.replace(
    /(?<=\s)(id|for|popovertarget|aria-(?:controls|labelledby|describedby|owns))="([^"]*)"/g,
    (_, name: string, refs: string) =>
      `${name}="${refs
        .trim()
        .split(/\s+/)
        .map((ref) => `m-${ref}`)
        .join(" ")}"`,
  );

type Props = HTMLAttributes<"div"> & {
  sections?: SidebarSection[];
  variant?: keyof typeof variants;
  /** Minimum container width for the sidebar to sit next to the content: sm 24rem, md 42rem, lg 56rem. */
  breakpoint?: keyof typeof showAside;
  /** Initial icon rail mode. Changes dispatch markas-collapsed-change. */
  collapsed?: boolean;
  navLabel?: string;
  collapseLabel?: string;
  expandLabel?: string;
  openLabel?: string;
  closeLabel?: string;
};

const {
  sections = [],
  variant = "default",
  breakpoint = "md",
  collapsed = false,
  navLabel = "Sidebar",
  collapseLabel = "Collapse sidebar",
  expandLabel = "Expand sidebar",
  openLabel = "Open sidebar",
  closeLabel = "Close sidebar",
  id,
  class: className,
  ...rest
} = Astro.props;

const rootId = id ?? `markas-sidebar-${crypto.randomUUID().slice(0, 8)}`;
const header = Astro.slots.has("header")
  ? await Astro.slots.render("header")
  : undefined;
const footer = Astro.slots.has("footer")
  ? await Astro.slots.render("footer")
  : undefined;
const hasBadge = (entry: SidebarItem) =>
  entry.badge != null && entry.badge !== "";
/** Sub-item groups start open when open is set or a sub-item is active. */
const isOpen = (entry: SidebarItem) =>
  entry.open ?? !!entry.children?.some((child) => child.active);
const svg = {
  viewBox: "0 0 24 24",
  fill: "none",
  stroke: "currentColor",
  "stroke-width": "1.5",
  "stroke-linecap": "round",
  "stroke-linejoin": "round",
  "aria-hidden": "true",
} as const;
/** The desktop sidebar (copy d) and the mobile dialog (copy m) share the same markup. */
const copies = [
  {
    prefix: "d",
    Tag: "aside",
    attrs: {
      id: `${rootId}-aside`,
      "data-state": collapsed ? "collapsed" : "expanded",
      class: [aside, variants[variant], showAside[breakpoint]].join(" "),
    },
    header,
    footer,
  },
  {
    prefix: "m",
    Tag: "dialog",
    attrs: {
      id: `${rootId}-dialog`,
      "aria-label": navLabel,
      "data-markas-sidebar-dialog": true,
      class: dialogClass,
    },
    header: mobileCopy(header ?? ""),
    footer: footer && mobileCopy(footer),
  },
] as const;
---

<div id={rootId} data-markas-sidebar class:list={[root, className]} {...rest}>
  {
    copies.map(({ prefix, Tag, attrs, header: top, footer: bottom }) => (
      <Tag {...attrs}>
        {prefix === "d" ? (
          top && (
            <div class={headerClass}>
              <div class={slotClass}>
                <Fragment set:html={top} />
              </div>
            </div>
          )
        ) : (
          <div class={headerClass}>
            <div class={slotClass}>
              <Fragment set:html={top} />
            </div>
            <form method="dialog">
              <button type="submit" aria-label={closeLabel} class={iconButton}>
                <svg class={iconClass} {...svg}>
                  <path d="M18 6 6 18M6 6l12 12" />
                </svg>
              </button>
            </form>
          </div>
        )}
        <nav aria-label={navLabel} class={navClass}>
          <div class={listWrap}>
            <span aria-hidden="true" class={indicator} />
            {sections.map((section, s) => (
              <div class={sectionClass}>
                {section.title && (
                  <p aria-hidden="true" class={titleClass}>
                    {section.title}
                  </p>
                )}
                <ul aria-label={section.title} class={listClass}>
                  {section.items.map((entry, i) => {
                    const key = `${s}-${i}`;
                    const regionId = `${rootId}-${prefix}-g${key}`;
                    const body = (
                      <Fragment>
                        {entry.icon && (
                          <svg class={iconClass} {...svg}>
                            <path d={entry.icon} />
                          </svg>
                        )}
                        <span class={labelClass}>{entry.label}</span>
                        {hasBadge(entry) && (
                          <span class={badgeClass}>{entry.badge}</span>
                        )}
                        {hasBadge(entry) && (
                          <span aria-hidden="true" class={dot} />
                        )}
                        {!!entry.children?.length && (
                          <svg class={chevron} {...svg}>
                            <path d="m9 6 6 6-6 6" />
                          </svg>
                        )}
                        <span aria-hidden="true" class={tip}>
                          {entry.label}
                        </span>
                      </Fragment>
                    );
                    return (
                      <li>
                        {entry.children?.length ? (
                          <Fragment>
                            <button
                              type="button"
                              aria-expanded={isOpen(entry) ? "true" : "false"}
                              aria-controls={regionId}
                              data-markas-sidebar-group={key}
                              class={item}
                            >
                              {body}
                            </button>
                            <div
                              id={regionId}
                              data-state={isOpen(entry) ? "open" : "closed"}
                              class={region}
                            >
                              <div class={regionInner}>
                                <ul class={subList}>
                                  {entry.children.map((child) => (
                                    <li>
                                      <a {...linkProps(child)} class={subItem}>
                                        {child.label}
                                      </a>
                                    </li>
                                  ))}
                                </ul>
                              </div>
                            </div>
                          </Fragment>
                        ) : (
                          <a {...linkProps(entry)} class={item}>
                            {body}
                          </a>
                        )}
                      </li>
                    );
                  })}
                </ul>
              </div>
            ))}
          </div>
        </nav>
        {bottom && (
          <div class={footerClass}>
            <div class={slotClass}>
              <Fragment set:html={bottom} />
            </div>
          </div>
        )}
        {prefix === "d" && (
          <button
            type="button"
            aria-label={collapsed ? expandLabel : collapseLabel}
            aria-expanded={collapsed ? "false" : "true"}
            aria-controls={`${rootId}-aside`}
            data-markas-sidebar-toggle
            data-collapse-label={collapseLabel}
            data-expand-label={expandLabel}
            class={collapseButton}
          >
            <svg class={collapseIcon} {...svg}>
              <path d="m15 6-6 6 6 6" />
            </svg>
          </button>
        )}
      </Tag>
    ))
  }
  <div class={content}>
    <div class:list={[mobileBar, hideBar[breakpoint]]}>
      <button
        type="button"
        aria-label={openLabel}
        aria-haspopup="dialog"
        aria-controls={`${rootId}-dialog`}
        data-markas-sidebar-open
        class={iconButton}
      >
        <svg class={iconClass} {...svg}>
          <path d="M4 6h16M4 12h16M4 18h16" />
        </svg>
      </button>
    </div>
    <slot />
  </div>
</div>

<script>
  // One listener per page serves every sidebar, including markup added later and pages
  // reached through view transitions.
  document.addEventListener("click", (event) => {
    const target = event.target as Element;
    const dialog = target.closest<HTMLDialogElement>(
      "[data-markas-sidebar-dialog]",
    );
    if (dialog && (target === dialog || target.closest("a[href]"))) {
      dialog.close();
      return;
    }
    const button = target.closest<HTMLElement>(
      "[data-markas-sidebar-toggle],[data-markas-sidebar-group],[data-markas-sidebar-open]",
    );
    const root = button?.closest<HTMLElement>("[data-markas-sidebar]");
    if (!button || !root) return;
    const byId = (id: string | null) => document.getElementById(id ?? "");
    const controlled = byId(button.getAttribute("aria-controls"));
    if (button.hasAttribute("data-markas-sidebar-open")) {
      (controlled as HTMLDialogElement).showModal();
      return;
    }
    const aside = byId(`${root.id}-aside`)!;
    const setCollapsed = (value: boolean) => {
      const toggle = aside.querySelector<HTMLElement>(
        ":scope > [data-markas-sidebar-toggle]",
      )!;
      aside.dataset.state = value ? "collapsed" : "expanded";
      toggle.ariaExpanded = String(!value);
      toggle.ariaLabel = value
        ? toggle.dataset.expandLabel!
        : toggle.dataset.collapseLabel!;
      root.dispatchEvent(
        new CustomEvent("markas-collapsed-change", {
          detail: value,
          bubbles: true,
        }),
      );
    };
    if (button.hasAttribute("data-markas-sidebar-toggle")) {
      setCollapsed(aside.dataset.state !== "collapsed");
      return;
    }
    // In the rail, a parent item expands the sidebar and opens its group. Both copies stay in sync.
    const rail = button.closest("aside")?.dataset.state === "collapsed";
    if (rail) setCollapsed(false);
    const open = rail || button.ariaExpanded !== "true";
    root
      .querySelectorAll<HTMLElement>(
        `[data-markas-sidebar-group="${button.dataset.markasSidebarGroup}"]`,
      )
      .forEach((group) => {
        group.ariaExpanded = String(open);
        byId(group.getAttribute("aria-controls"))!.dataset.state = open
          ? "open"
          : "closed";
      });
  });
</script>
```

```astro
---
import Sidebar from "@/components/markas/Sidebar.astro";
// sections: bentuknya sama dengan contoh React
---

<Sidebar sections={sections} class="h-dvh">
  <Fragment slot="header">MarkasUI</Fragment>
  <Fragment slot="footer">Rina Saputra</Fragment>
  <main class="flex-1 p-6">...</main>
</Sidebar>
```

Satu script kecil yang dibundel menangani tombol rail, grup sub-item, dan dialog seluler untuk semua sidebar di halaman. Dengarkan perubahan rail dengan `addEventListener("markas-collapsed-change", (e) => e.detail)`.

### Angular

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

```ts
import { NgTemplateOutlet } from "@angular/common";
import {
  booleanAttribute,
  ChangeDetectionStrategy,
  Component,
  computed,
  contentChild,
  type ElementRef,
  input,
  linkedSignal,
  output,
  TemplateRef,
  viewChild,
} from "@angular/core";

export type SidebarItem = {
  label: string;
  /** Link target. Ignored when the item has children. */
  href?: string;
  /** SVG path data (d attribute) for a 24x24 stroke icon. */
  icon?: string;
  badge?: string | number;
  /** Marks the current page. */
  active?: boolean;
  disabled?: boolean;
  /** Sub-items. The parent item becomes an open/close button. */
  children?: SidebarItem[];
  /** Sub-items start open. Default: open when a sub-item is active. */
  open?: boolean;
};

export type SidebarSection = { title?: string; items: SidebarItem[] };

const root = "@container flex overflow-hidden bg-canvas";
const aside =
  "relative hidden w-56 shrink-0 flex-col bg-surface text-sm transition-[width] duration-200 ease-out data-[state=collapsed]:w-16 motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none";
const variants = {
  default: "border-r border-line",
  floating: "m-2 rounded-xl border border-line",
};
const showAside = { sm: "@sm:flex", md: "@2xl:flex", lg: "@4xl:flex" };
const hideBar = { sm: "@sm:hidden", md: "@2xl:hidden", lg: "@4xl:hidden" };
const headerClass = "flex h-14 shrink-0 items-center border-b border-line px-4";
/** Header and footer content is clipped at the content edge so the rail shows only the first 32px. */
const slotClass =
  "flex min-w-0 flex-1 items-center gap-2 overflow-hidden whitespace-nowrap";
const footerClass = "shrink-0 border-t border-line px-4 py-3";
const collapseButton =
  "absolute top-4 -right-3 z-10 grid size-6 place-items-center rounded-full border border-line bg-surface text-muted transition-colors duration-150 ease-out hover:text-ink";
const collapseIcon =
  "size-3.5 transition-transform duration-200 ease-out in-data-[state=collapsed]:rotate-180";
const navClass =
  "min-h-0 flex-1 overflow-y-auto p-3 in-data-[state=collapsed]:overflow-visible";
const listWrap = "relative grid gap-3 [anchor-scope:--active,--hover]";
const indicator =
  "absolute inset-[anchor(--hover_top,anchor(--active_top))_anchor(--hover_right,anchor(--active_right))_anchor(--hover_bottom,anchor(--active_bottom))_anchor(--hover_left,anchor(--active_left))] rounded-md bg-subtle transition-[inset] duration-200 ease-out";
const sectionClass =
  "grid gap-0.5 border-t border-line pt-3 first-of-type:border-t-0 first-of-type:pt-0";
const titleClass =
  "px-2.5 pb-1 text-xs font-medium text-faint in-data-[state=collapsed]:sr-only";
const listClass = "grid gap-0.5";
const item =
  "group/item relative flex h-9 w-full items-center gap-3 rounded-md px-2.5 text-left text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] [&:has(+div_[aria-current=page])]:[anchor-name:--active]";
const iconClass = "size-5 shrink-0";
const labelClass = "min-w-0 flex-1 truncate in-data-[state=collapsed]:sr-only";
const badgeClass =
  "rounded-full bg-primary-soft px-1.5 py-0.5 text-xs leading-none font-medium text-primary in-data-[state=collapsed]:sr-only";
const dot =
  "absolute top-1.5 right-1.5 hidden size-2 rounded-full bg-primary in-data-[state=collapsed]:block";
const chevron =
  "size-4 shrink-0 text-faint transition-transform duration-200 ease-out group-aria-expanded/item:rotate-90 in-data-[state=collapsed]:hidden";
const tip =
  "absolute top-1/2 left-full ml-3 hidden -translate-y-1/2 rounded-md bg-ink px-2 py-1 text-xs whitespace-nowrap text-canvas shadow-overlay in-data-[state=collapsed]:group-hover/item:block in-data-[state=collapsed]:group-focus-visible/item:block";
const region =
  "invisible grid grid-rows-[0fr] transition-[grid-template-rows,visibility] duration-200 ease-out data-[state=open]:visible data-[state=open]:grid-rows-[1fr] in-data-[state=collapsed]:hidden";
const regionInner = "min-h-0 overflow-hidden";
const subList = "ml-5 grid gap-0.5 border-l border-line py-1 pr-1 pl-2";
const subItem =
  "relative flex h-8 w-full items-center rounded-md px-2.5 text-muted transition-colors duration-150 ease-out hover:text-ink aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-[current=page]:font-medium aria-[current=page]:text-ink hover:[anchor-name:--hover] focus-visible:[anchor-name:--hover] aria-[current=page]:[anchor-name:--active] in-data-[state=closed]:[anchor-name:none]!";
const content = "flex min-w-0 flex-1 flex-col";
const mobileBar = "flex h-14 shrink-0 items-center border-b border-line px-3";
const iconButton =
  "grid size-9 shrink-0 place-items-center rounded-md text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const dialogClass =
  "right-auto left-0 m-0 h-dvh max-h-dvh w-72 flex-col border-r border-line bg-surface p-0 text-sm text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 open:flex starting:open:-translate-x-full motion-reduce:transition-none **:focus-visible:outline-2 **:focus-visible:outline-offset-2 **:focus-visible:outline-primary motion-reduce:**:transition-none";

/** Hrefs with a scheme other than http, https, mailto, and tel (javascript: for example) become "#". Whitespace and control characters are ignored as in browsers. */
const safeHref = (href: string) =>
  /^(?!https?:|mailto:|tel:)[a-z][\w+.-]*:/i.test(href.replace(/[\0- ]/g, ""))
    ? "#"
    : href;

/** Static stroke icon markup, inlined into the template at compile time (ngc only evaluates plain constants). */
const chevronIcon = `<svg class="${chevron}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 6 6 6-6 6" /></svg>`;
const collapseSvg = `<svg class="${collapseIcon}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m15 6-6 6 6 6" /></svg>`;
const closeSvg = `<svg class="${iconClass}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" /></svg>`;
const menuSvg = `<svg class="${iconClass}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 6h16M4 12h16M4 18h16" /></svg>`;

/** Item content shared by links and group buttons (expects `entry` in scope). */
const body = `
  @if (entry.icon) {
    <svg class="${iconClass}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path [attr.d]="entry.icon" /></svg>
  }
  <span class="${labelClass}">{{ entry.label }}</span>
  @if (entry.badge != null && entry.badge !== "") {
    <span class="${badgeClass}">{{ entry.badge }}</span>
    <span aria-hidden="true" class="${dot}"></span>
  }
  @if (entry.children?.length) {
    ${chevronIcon}
  }
  <span aria-hidden="true" class="${tip}">{{ entry.label }}</span>
`;

let nextId = 0;

/**
 * Header and footer are templates (`<ng-template #header>`, `<ng-template #footer>`) because they
 * render twice: in the sidebar and in the mobile dialog. Everything else is the page content.
 * Host stays out of layout; id and class move to the root element.
 */
@Component({
  selector: "markas-sidebar",
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [NgTemplateOutlet],
  host: { class: "contents", "[attr.id]": "null" },
  template: `
    <!-- The same nav serves the desktop sidebar (prefix d) and the mobile dialog (prefix m). -->
    <ng-template #nav let-prefix let-rail="rail">
      <nav [attr.aria-label]="navLabel()" class="${navClass}">
        <div class="${listWrap}">
          <span aria-hidden="true" class="${indicator}"></span>
          @for (section of sections(); track $index; let s = $index) {
            <div class="${sectionClass}">
              @if (section.title) {
                <p aria-hidden="true" class="${titleClass}">
                  {{ section.title }}
                </p>
              }
              <ul
                [attr.aria-label]="section.title || null"
                class="${listClass}"
              >
                @for (entry of section.items; track $index; let i = $index) {
                  <li>
                    @if (entry.children?.length) {
                      <button
                        type="button"
                        [attr.aria-expanded]="!!groups()[s + '-' + i]"
                        [attr.aria-controls]="
                          rootId() + '-' + prefix + '-g' + s + '-' + i
                        "
                        class="${item}"
                        (click)="toggleGroup(s + '-' + i, rail)"
                      >
                        ${body}
                      </button>
                      <div
                        [id]="rootId() + '-' + prefix + '-g' + s + '-' + i"
                        [attr.data-state]="
                          groups()[s + '-' + i] ? 'open' : 'closed'
                        "
                        class="${region}"
                      >
                        <div class="${regionInner}">
                          <ul class="${subList}">
                            @for (child of entry.children; track $index) {
                              <li>
                                <a
                                  [attr.href]="
                                    child.disabled
                                      ? null
                                      : safeHref(child.href ?? '#')
                                  "
                                  [attr.aria-current]="
                                    !child.disabled && child.active
                                      ? 'page'
                                      : null
                                  "
                                  [attr.role]="child.disabled ? 'link' : null"
                                  [attr.aria-disabled]="
                                    child.disabled ? 'true' : null
                                  "
                                  class="${subItem}"
                                  >{{ child.label }}</a
                                >
                              </li>
                            }
                          </ul>
                        </div>
                      </div>
                    } @else {
                      <a
                        [attr.href]="
                          entry.disabled ? null : safeHref(entry.href ?? '#')
                        "
                        [attr.aria-current]="
                          !entry.disabled && entry.active ? 'page' : null
                        "
                        [attr.role]="entry.disabled ? 'link' : null"
                        [attr.aria-disabled]="entry.disabled ? 'true' : null"
                        class="${item}"
                      >
                        ${body}
                      </a>
                    }
                  </li>
                }
              </ul>
            </div>
          }
        </div>
      </nav>
    </ng-template>

    <div [id]="rootId()" [class]="rootClasses()">
      <aside
        [id]="rootId() + '-aside'"
        [attr.data-state]="isCollapsed() ? 'collapsed' : 'expanded'"
        [class]="asideClasses()"
      >
        @if (header(); as headerTpl) {
          <div class="${headerClass}">
            <div class="${slotClass}">
              <ng-container *ngTemplateOutlet="headerTpl" />
            </div>
          </div>
        }
        <ng-container
          *ngTemplateOutlet="
            nav;
            context: { $implicit: 'd', rail: isCollapsed() }
          "
        />
        @if (footer(); as footerTpl) {
          <div class="${footerClass}">
            <div class="${slotClass}">
              <ng-container *ngTemplateOutlet="footerTpl" />
            </div>
          </div>
        }
        <button
          type="button"
          [attr.aria-label]="isCollapsed() ? expandLabel() : collapseLabel()"
          [attr.aria-expanded]="!isCollapsed()"
          [attr.aria-controls]="rootId() + '-aside'"
          class="${collapseButton}"
          (click)="setCollapsed(!isCollapsed())"
        >
          ${collapseSvg}
        </button>
      </aside>
      <dialog
        #dialog
        [id]="rootId() + '-dialog'"
        [attr.aria-label]="navLabel()"
        class="${dialogClass}"
        (click)="onDialogClick($event)"
      >
        <div class="${headerClass}">
          <div class="${slotClass}">
            @if (header(); as headerTpl) {
              <ng-container *ngTemplateOutlet="headerTpl" />
            }
          </div>
          <form method="dialog">
            <button
              type="submit"
              [attr.aria-label]="closeLabel()"
              class="${iconButton}"
            >
              ${closeSvg}
            </button>
          </form>
        </div>
        <ng-container
          *ngTemplateOutlet="nav; context: { $implicit: 'm', rail: false }"
        />
        @if (footer(); as footerTpl) {
          <div class="${footerClass}">
            <div class="${slotClass}">
              <ng-container *ngTemplateOutlet="footerTpl" />
            </div>
          </div>
        }
      </dialog>
      <div class="${content}">
        <div [class]="mobileBarClasses()">
          <button
            type="button"
            [attr.aria-label]="openLabel()"
            aria-haspopup="dialog"
            [attr.aria-controls]="rootId() + '-dialog'"
            class="${iconButton}"
            (click)="dialogRef().nativeElement.showModal()"
          >
            ${menuSvg}
          </button>
        </div>
        <ng-content />
      </div>
    </div>
  `,
})
export class Sidebar {
  readonly sections = input<SidebarSection[]>([]);
  readonly variant = input<keyof typeof variants>("default");
  /** Minimum container width for the sidebar to sit next to the content: sm 24rem, md 42rem, lg 56rem. */
  readonly breakpoint = input<keyof typeof showAside>("md");
  /** Icon rail mode. Works with [(collapsed)]; a plain value sets the initial state. */
  readonly collapsed = input(false, { transform: booleanAttribute });
  readonly navLabel = input("Sidebar");
  readonly collapseLabel = input("Collapse sidebar");
  readonly expandLabel = input("Expand sidebar");
  readonly openLabel = input("Open sidebar");
  readonly closeLabel = input("Close sidebar");
  readonly id = input<string>();
  readonly userClass = input("", { alias: "class" });
  readonly collapsedChange = output<boolean>();

  protected readonly header = contentChild("header", { read: TemplateRef });
  protected readonly footer = contentChild("footer", { read: TemplateRef });
  protected readonly dialogRef =
    viewChild.required<ElementRef<HTMLDialogElement>>("dialog");

  protected readonly safeHref = safeHref;

  private readonly generatedId = `markas-sidebar-${nextId++}`;
  protected readonly rootId = computed(() => this.id() ?? this.generatedId);
  protected readonly isCollapsed = linkedSignal(() => this.collapsed());
  /** Sub-item groups start open when open is set or a sub-item is active. */
  protected readonly groups = linkedSignal<Record<string, boolean>>(() =>
    Object.fromEntries(
      this.sections().flatMap((section, s) =>
        section.items.map((entry, i) => [
          `${s}-${i}`,
          entry.open ?? !!entry.children?.some((child) => child.active),
        ]),
      ),
    ),
  );
  protected readonly rootClasses = computed(() =>
    [root, this.userClass()].filter(Boolean).join(" "),
  );
  protected readonly asideClasses = computed(
    () =>
      `${aside} ${variants[this.variant()]} ${showAside[this.breakpoint()]}`,
  );
  protected readonly mobileBarClasses = computed(
    () => `${mobileBar} ${hideBar[this.breakpoint()]}`,
  );

  protected setCollapsed(next: boolean) {
    this.isCollapsed.set(next);
    this.collapsedChange.emit(next);
  }

  /** In the rail, a parent item expands the sidebar and opens its group. */
  protected toggleGroup(key: string, rail: boolean) {
    if (rail) this.setCollapsed(false);
    this.groups.update((current) => ({
      ...current,
      [key]: rail || !current[key],
    }));
  }

  protected onDialogClick(event: MouseEvent) {
    const target = event.target as Element;
    const dialog = event.currentTarget as HTMLDialogElement;
    if (target === dialog || target.closest("a[href]")) dialog.close();
  }
}
```

```ts
import { Component, signal } from "@angular/core";
import { Sidebar } from "./markas/sidebar.component";

@Component({
  selector: "app-shell",
  imports: [Sidebar],
  template: `
    <markas-sidebar
      [(collapsed)]="collapsed"
      [sections]="sections"
      class="h-dvh"
    >
      <ng-template #header>MarkasUI</ng-template>
      <ng-template #footer>Rina Saputra</ng-template>
      <main class="flex-1 p-6">...</main>
    </markas-sidebar>
  `,
})
export class AppShell {
  readonly collapsed = signal(false);
  // sections: bentuknya sama dengan contoh React
}
```

`header` dan `footer` berupa `ng-template` karena dirender dua kali: di sidebar dan di dialog seluler.

## Props

| Nama | Tipe | Default | Keterangan |
| --- | --- | --- | --- |
| `sections` | `{ title?, items: { label, href?, icon?, badge?, active?, disabled?, open?, children? }[] }[]` | [] | Grup link. icon berisi path SVG (d) untuk ikon garis 24px. Item dengan children menjadi tombol buka/tutup. |
| `header` | `slot / ReactNode / snippet` | - | Brand atau workspace di atas. Di mode rail hanya 32px pertama yang terlihat. Angular: <ng-template #header>, karena dirender di sidebar dan dialog seluler. |
| `footer` | `slot / ReactNode / snippet` | - | Profil pengguna di bawah. Angular: <ng-template #footer>. |
| `children` | `slot / ReactNode / snippet` | - | Isi halaman yang tampil di samping sidebar. |
| `variant` | `"default" \| "floating"` | default | default menempel dengan border kanan, floating berupa panel membulat yang mengambang. |
| `breakpoint` | `"sm" \| "md" \| "lg"` | md | Lebar kontainer mulai sidebar tampil di samping konten: 24rem, 42rem, atau 56rem. Di bawahnya tombol membuka sidebar sebagai dialog. |
| `collapsed` | `boolean` | - | Mode rail ikon. React: terkontrol bersama onCollapsedChange. Vue: v-model:collapsed, atau nilai biasa untuk keadaan awal tidak terkontrol. Svelte: bind:collapsed atau nilai awal biasa. Angular: [(collapsed)] atau nilai awal biasa. Blade dan Astro: keadaan awal, perubahan mengirim event markas-collapsed-change. |
| `defaultCollapsed` | `boolean` | false | Mode rail awal saat tidak terkontrol (hanya React). |
| `collapsedChange` | `output<boolean>` | - | Khusus Angular. Dipancarkan dengan keadaan rail baru saat berubah. |
| `navLabel` | `string` | Sidebar | Label aksesibel nav dan dialog seluler. Isi "Sidebar" atau "Navigasi samping" untuk situs berbahasa Indonesia. |
| `collapseLabel` | `string` | Collapse sidebar | Label aksesibel tombol rail saat sidebar terbentang. Isi "Ciutkan sidebar". |
| `expandLabel` | `string` | Expand sidebar | Label aksesibel tombol rail saat sidebar diciutkan. Isi "Bentangkan sidebar". |
| `openLabel` | `string` | Open sidebar | Label aksesibel tombol yang membuka dialog seluler. Isi "Buka sidebar". |
| `closeLabel` | `string` | Close sidebar | Label aksesibel tombol tutup di dialog seluler. Isi "Tutup sidebar". |

## Aksesibilitas

- Link berada di nav berlabel navLabel, halaman saat ini diberi aria-current=page, dan setiap grup berjudul adalah list berlabel judulnya.
- Item dengan sub-item adalah tombol disclosure dengan aria-expanded dan aria-controls, sub-item yang tertutup tidak bisa difokus.
- Tombol rail memakai aria-expanded dan aria-controls yang menunjuk ke sidebar. Di mode rail label tetap terbaca pembaca layar dan tampil sebagai tooltip saat hover dan fokus.
- Di tata letak sempit sidebar terbuka di dialog modal native: Escape atau backdrop menutupnya dan fokus kembali ke tombol pembuka.
- Item nonaktif adalah link tanpa href dengan aria-disabled=true.

## Catatan

- Komponen ini adalah kerangka aplikasi utuh: taruh isi halaman di dalamnya. Lebarnya menentukan tata letak lewat container query. Mulai `breakpoint` (default `md`, 42rem) sidebar tampil di samping konten; di bawahnya tombol menu membuka link yang sama di `<dialog>` native yang meluncur dari kiri.
- Tombol bulat di tepi sidebar mengubahnya jadi rail ikon selebar 64px. Label lalu tampil sebagai tooltip dan badge sebagai titik. Secara default state-nya tidak terkontrol. Mulai dalam mode rail dengan `defaultCollapsed` di React, `:collapsed="true"` tanpa `v-model` di Vue dan Blade, atau nilai `collapsed` biasa di Svelte, Astro, dan Angular.
- Di mode rail, item induk membentangkan sidebar dan membuka sub-itemnya.
- Sorotan meluncur ke item yang di-hover atau difokus lalu kembali ke item aktif. Sorotan memakai CSS anchor positioning tanpa JavaScript; browser yang belum mendukungnya tetap menandai item aktif dengan teks tebal. Grup sub-item yang memuat halaman aktif terbuka di awal; isi `open` untuk mengubahnya.
- `header` dan `footer` dirender dua kali: di sidebar dan di dialog seluler. Pemilih workspace (DropdownMenu) atau pemicu pencarian (Command) berfungsi di kedua salinan; di Blade, id di salinan dialog diberi akhiran `-m` agar tetap unik (Astro: awalan `m-`).
- Sembunyikan bagian header atau footer di mode rail dengan `in-data-[state=collapsed]:hidden`, misalnya kartu upgrade.
- Label bawaan berbahasa Inggris: "Sidebar", "Collapse sidebar", "Expand sidebar", "Open sidebar", dan "Close sidebar". Terjemahkan lewat `navLabel`, `collapseLabel`, `expandLabel`, `openLabel`, dan `closeLabel` (Blade: `nav-label`, `collapse-label`, dan seterusnya), seperti contoh di atas.
