# Drawer

Panel samping setinggi layar berbasis elemen dialog native, muncul dari kanan atau kiri.

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

## Kapan dipakai

Panel samping untuk filter, detail item, atau form yang lebih panjang tanpa meninggalkan halaman.

- Tombol di footer yang harus menutup drawer wajib type=submit
- Untuk konfirmasi singkat gunakan Modal, bukan Drawer
- Jangan membuka drawer di dalam drawer

## Kode

### Blade

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

```blade
@props([
    'title',
    'side' => 'right',
    'closeLabel' => 'Close',
])

@php
    $dialog = 'fixed inset-y-0 m-0 h-dvh max-h-dvh w-full max-w-sm border-line bg-surface p-0 text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 motion-reduce:transition-none';
    $sides = [
        'right' => 'right-0 left-auto border-l starting:open:translate-x-full',
        'left' => 'right-auto left-0 border-r starting:open:-translate-x-full',
    ];
    $panel = 'flex h-full flex-col gap-4 p-6';
    $header = 'flex items-start justify-between gap-4';
    $titleClass = 'text-lg font-semibold text-ink';
    $body = 'flex-1 overflow-y-auto text-sm text-muted';
    $footerClass = 'flex flex-wrap justify-end gap-2';
    $close = 'inline-flex size-8 shrink-0 items-center justify-center rounded-md text-muted transition-colors duration-150 ease-out hover:bg-subtle hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none';

    // Same id on every render, so Livewire's morph (which matches elements by id) keeps the element. Pass `id` to set it.
    $idKey = 'markas-drawer|'.(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-drawer-'.hash('xxh32', $idKey.$idIndex);
@endphp

{{-- wire:model and x-model bind the open state (x-modelable), so a boolean property can open and close the dialog. --}}
<div
    class="contents"
    x-data="{
        open: false,
        init() {
            this.$watch('open', (value) => {
                const dialog = this.$refs.dialog;
                if (value && ! dialog.open) dialog.showModal();
                if (! value && dialog.open) dialog.close();
            });
        },
    }"
    x-modelable="open"
    {{ $attributes->whereStartsWith(['wire:model', 'x-model']) }}
>
    @isset($trigger)
        <div class="contents" @click="$refs.dialog.showModal(); open = true">{{ $trigger }}</div>
    @endisset
    <dialog
        wire:ignore.self
        x-ref="dialog"
        :data-state="open ? 'open' : 'closed'"
        @close="open = false"
        @click.self="$refs.dialog.close()"
        {{ $attributes->whereDoesntStartWith(['wire:model', 'x-model'])->merge(['id' => $id, 'aria-labelledby' => $id.'-title', 'data-state' => 'closed'])->class([$dialog, $sides[$side]]) }}
    >
        <div class="{{ $panel }}">
            <div class="{{ $header }}">
                <h2 id="{{ $id }}-title" class="{{ $titleClass }}">{{ $title }}</h2>
                <form method="dialog">
                    <button type="submit" class="{{ $close }}" aria-label="{{ $closeLabel }}">
                        <svg class="size-4" 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>
                    </button>
                </form>
            </div>
            <div class="{{ $body }}">{{ $slot }}</div>
            @isset($footer)
                <form method="dialog" class="{{ $footerClass }}">{{ $footer }}</form>
            @endisset
        </div>
    </dialog>
</div>
```

```blade
<x-markas.drawer title="Filter produk" close-label="Tutup">
    <x-slot:trigger>
        <x-markas.button variant="secondary">Buka filter</x-markas.button>
    </x-slot:trigger>

    Pilih kategori dan rentang harga untuk menyaring daftar produk.

    <x-slot:footer>
        <x-markas.button variant="secondary" type="submit" value="batal">Batal</x-markas.button>
        <x-markas.button type="submit" value="terapkan">Terapkan</x-markas.button>
    </x-slot:footer>
</x-markas.drawer>
```

Butuh Alpine.js. Livewire 3 dan 4 sudah membawa Alpine, jadi tidak perlu dipasang lagi.

### Livewire

```blade
<x-markas.drawer title="Filters" wire:model="showFilters">
    ...
</x-markas.drawer>
```

`wire:model` terhubung ke status terbuka, sama seperti modal. Menutup drawer mengembalikan properti ke `false`.

### React

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

```tsx
"use client";

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

const dialogClass =
  "fixed inset-y-0 m-0 h-dvh max-h-dvh w-full max-w-sm border-line bg-surface p-0 text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 motion-reduce:transition-none";
const sides = {
  right: "right-0 left-auto border-l starting:open:translate-x-full",
  left: "right-auto left-0 border-r starting:open:-translate-x-full",
};
const panel = "flex h-full flex-col gap-4 p-6";
const header = "flex items-start justify-between gap-4";
const titleClass = "text-lg font-semibold text-ink";
const body = "flex-1 overflow-y-auto text-sm text-muted";
const footerClass = "flex flex-wrap justify-end gap-2";
const close =
  "inline-flex size-8 shrink-0 items-center justify-center rounded-md text-muted transition-colors duration-150 ease-out hover:bg-subtle hover:text-ink 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(" ");

export type DrawerProps = Omit<
  ComponentProps<"dialog">,
  "title" | "ref" | "open"
> & {
  title: ReactNode;
  side?: keyof typeof sides;
  trigger?: ReactNode;
  footer?: ReactNode;
  /** Label aksesibel tombol tutup. */
  closeLabel?: string;
};

export function Drawer({
  title,
  side = "right",
  closeLabel = "Close",
  trigger,
  footer,
  id,
  className,
  children,
  onClose,
  onClick,
  ...props
}: DrawerProps) {
  const generatedId = useId();
  const dialogId = id ?? generatedId;
  const dialogRef = useRef<HTMLDialogElement>(null);
  const [open, setOpen] = useState(false);

  const show = () => {
    dialogRef.current?.showModal();
    setOpen(true);
  };
  const handleClick = (event: MouseEvent<HTMLDialogElement>) => {
    if (event.target === event.currentTarget) dialogRef.current?.close();
    onClick?.(event);
  };

  return (
    <div className="contents">
      {trigger && (
        <div className="contents" onClick={show}>
          {trigger}
        </div>
      )}
      <dialog
        ref={dialogRef}
        id={dialogId}
        aria-labelledby={`${dialogId}-title`}
        data-state={open ? "open" : "closed"}
        className={cx(dialogClass, sides[side], className)}
        onClose={(event) => {
          setOpen(false);
          onClose?.(event);
        }}
        onClick={handleClick}
        {...props}
      >
        <div className={panel}>
          <div className={header}>
            <h2 id={`${dialogId}-title`} className={titleClass}>
              {title}
            </h2>
            <form method="dialog">
              <button type="submit" className={close} aria-label={closeLabel}>
                <svg
                  className="size-4"
                  viewBox="0 0 24 24"
                  fill="none"
                  stroke="currentColor"
                  strokeWidth="1.5"
                  strokeLinecap="round"
                  strokeLinejoin="round"
                  aria-hidden="true"
                >
                  <path d="M18 6 6 18M6 6l12 12" />
                </svg>
              </button>
            </form>
          </div>
          <div className={body}>{children}</div>
          {footer && (
            <form method="dialog" className={footerClass}>
              {footer}
            </form>
          )}
        </div>
      </dialog>
    </div>
  );
}
```

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

<Drawer
  title="Filter produk"
  closeLabel="Tutup"
  trigger={<Button variant="secondary">Buka filter</Button>}
  footer={
    <>
      <Button variant="secondary" type="submit" value="batal">
        Batal
      </Button>
      <Button type="submit" value="terapkan">
        Terapkan
      </Button>
    </>
  }
  onClose={(e) => console.log(e.currentTarget.returnValue)}
>
  Pilih kategori dan rentang harga untuk menyaring daftar produk.
</Drawer>;
```

### Vue

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

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

defineOptions({ inheritAttrs: false });

const sides = {
  right: "right-0 left-auto border-l starting:open:translate-x-full",
  left: "right-auto left-0 border-r starting:open:-translate-x-full",
};

const props = withDefaults(
  defineProps<{
    title: string;
    side?: keyof typeof sides;
    id?: string;
    closeLabel?: string;
  }>(),
  { side: "right", id: undefined, closeLabel: "Close" },
);

const dialogClass =
  "fixed inset-y-0 m-0 h-dvh max-h-dvh w-full max-w-sm border-line bg-surface p-0 text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 motion-reduce:transition-none";
const panel = "flex h-full flex-col gap-4 p-6";
const header = "flex items-start justify-between gap-4";
const titleClass = "text-lg font-semibold text-ink";
const body = "flex-1 overflow-y-auto text-sm text-muted";
const footerClass = "flex flex-wrap justify-end gap-2";
const close =
  "inline-flex size-8 shrink-0 items-center justify-center rounded-md text-muted transition-colors duration-150 ease-out hover:bg-subtle hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";

const generatedId = useId();
const dialogId = computed(() => props.id ?? generatedId);
const dialog = useTemplateRef<HTMLDialogElement>("dialog");
const open = ref(false);

function show() {
  dialog.value?.showModal();
  open.value = true;
}
</script>

<template>
  <div class="contents">
    <div v-if="$slots.trigger" class="contents" @click="show">
      <slot name="trigger" />
    </div>
    <dialog
      :id="dialogId"
      ref="dialog"
      :aria-labelledby="`${dialogId}-title`"
      :data-state="open ? 'open' : 'closed'"
      :class="[dialogClass, sides[props.side]]"
      v-bind="$attrs"
      @close="open = false"
      @click.self="dialog?.close()"
    >
      <div :class="panel">
        <div :class="header">
          <h2 :id="`${dialogId}-title`" :class="titleClass">
            {{ props.title }}
          </h2>
          <form method="dialog">
            <button type="submit" :class="close" :aria-label="props.closeLabel">
              <svg
                class="size-4"
                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>
            </button>
          </form>
        </div>
        <div :class="body"><slot /></div>
        <form v-if="$slots.footer" method="dialog" :class="footerClass">
          <slot name="footer" />
        </form>
      </div>
    </dialog>
  </div>
</template>
```

```vue
<template>
  <Drawer title="Filter produk" close-label="Tutup">
    <template #trigger>
      <Button variant="secondary">Buka filter</Button>
    </template>

    Pilih kategori dan rentang harga untuk menyaring daftar produk.

    <template #footer>
      <Button variant="secondary" type="submit" value="batal">Batal</Button>
      <Button type="submit" value="terapkan">Terapkan</Button>
    </template>
  </Drawer>
</template>
```

### Svelte

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

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

  const dialogClass =
    "fixed inset-y-0 m-0 h-dvh max-h-dvh w-full max-w-sm border-line bg-surface p-0 text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 motion-reduce:transition-none";
  const sides = {
    right: "right-0 left-auto border-l starting:open:translate-x-full",
    left: "right-auto left-0 border-r starting:open:-translate-x-full",
  };
  const panel = "flex h-full flex-col gap-4 p-6";
  const header = "flex items-start justify-between gap-4";
  const titleClass = "text-lg font-semibold text-ink";
  const body = "flex-1 overflow-y-auto text-sm text-muted";
  const footerClass = "flex flex-wrap justify-end gap-2";
  const close =
    "inline-flex size-8 shrink-0 items-center justify-center rounded-md text-muted transition-colors duration-150 ease-out hover:bg-subtle hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";

  type Props = Omit<HTMLDialogAttributes, "title" | "open"> & {
    title: string;
    side?: keyof typeof sides;
    /** Accessible label of the close button. */
    closeLabel?: string;
    trigger?: Snippet;
    footer?: Snippet;
    children?: Snippet;
  };

  let {
    title,
    side = "right",
    closeLabel = "Close",
    id,
    class: className,
    trigger,
    footer,
    children,
    onclose,
    onclick,
    ...rest
  }: Props = $props();

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

  function show() {
    dialog?.showModal();
    open = true;
  }

  function handleClose(event: Event & { currentTarget: HTMLDialogElement }) {
    open = false;
    onclose?.(event);
  }

  function handleClick(
    event: MouseEvent & { currentTarget: HTMLDialogElement },
  ) {
    if (event.target === event.currentTarget) dialog?.close();
    onclick?.(event);
  }
</script>

<div class="contents">
  {#if trigger}
    <!-- svelte-ignore a11y_click_events_have_key_events -->
    <!-- svelte-ignore a11y_no_static_element_interactions -->
    <div class="contents" onclick={show}>{@render trigger()}</div>
  {/if}
  <dialog
    bind:this={dialog}
    id={dialogId}
    aria-labelledby={`${dialogId}-title`}
    data-state={open ? "open" : "closed"}
    class={[dialogClass, sides[side], className]}
    onclose={handleClose}
    onclick={handleClick}
    {...rest}
  >
    <div class={panel}>
      <div class={header}>
        <h2 id={`${dialogId}-title`} class={titleClass}>{title}</h2>
        <form method="dialog">
          <button type="submit" class={close} aria-label={closeLabel}>
            <svg
              class="size-4"
              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>
          </button>
        </form>
      </div>
      <div class={body}>{@render children?.()}</div>
      {#if footer}
        <form method="dialog" class={footerClass}>{@render footer()}</form>
      {/if}
    </div>
  </dialog>
</div>
```

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

<Drawer title="Filter produk" closeLabel="Tutup">
  {#snippet trigger()}
    <Button variant="secondary">Buka filter</Button>
  {/snippet}

  Pilih kategori dan rentang harga untuk menyaring daftar produk.

  {#snippet footer()}
    <Button variant="secondary" type="submit" value="cancel">Batal</Button>
    <Button type="submit" value="apply">Terapkan</Button>
  {/snippet}
</Drawer>
```

### Astro

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

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

const dialogClass =
  "fixed inset-y-0 m-0 h-dvh max-h-dvh w-full max-w-sm border-line bg-surface p-0 text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 motion-reduce:transition-none";
const sides = {
  right: "right-0 left-auto border-l starting:open:translate-x-full",
  left: "right-auto left-0 border-r starting:open:-translate-x-full",
};
const panel = "flex h-full flex-col gap-4 p-6";
const header = "flex items-start justify-between gap-4";
const titleClass = "text-lg font-semibold text-ink";
const body = "flex-1 overflow-y-auto text-sm text-muted";
const footerClass = "flex flex-wrap justify-end gap-2";
const close =
  "inline-flex size-8 shrink-0 items-center justify-center rounded-md text-muted transition-colors duration-150 ease-out hover:bg-subtle hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";

type Props = Omit<HTMLAttributes<"dialog">, "title" | "open"> & {
  title: string;
  side?: keyof typeof sides;
  /** Accessible label of the close button. */
  closeLabel?: string;
};

const {
  title,
  side = "right",
  closeLabel = "Close",
  id,
  class: className,
  ...rest
} = Astro.props;
const dialogId = id ?? `markas-drawer-${crypto.randomUUID().slice(0, 8)}`;
---

<div class="contents">
  {
    Astro.slots.has("trigger") && (
      <div class="contents" data-markas-drawer-trigger={dialogId}>
        <slot name="trigger" />
      </div>
    )
  }
  <dialog
    id={dialogId}
    aria-labelledby={`${dialogId}-title`}
    data-state="closed"
    data-markas-drawer
    class:list={[dialogClass, sides[side], className]}
    {...rest}
  >
    <div class={panel}>
      <div class={header}>
        <h2 id={`${dialogId}-title`} class={titleClass}>{title}</h2>
        <form method="dialog">
          <button type="submit" class={close} aria-label={closeLabel}>
            <svg
              class="size-4"
              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"></path>
            </svg>
          </button>
        </form>
      </div>
      <div class={body}><slot /></div>
      {
        Astro.slots.has("footer") && (
          <form method="dialog" class={footerClass}>
            <slot name="footer" />
          </form>
        )
      }
    </div>
  </dialog>
</div>

<script>
  // One listener per page serves every drawer, including markup added later and pages
  // reached through view transitions.
  const isDrawer = (node: EventTarget | null): node is HTMLDialogElement =>
    node instanceof HTMLDialogElement && node.hasAttribute("data-markas-drawer");

  document.addEventListener("click", (event) => {
    const target = event.target as Element;
    const trigger = target.closest<HTMLElement>("[data-markas-drawer-trigger]");
    if (trigger) {
      const dialog = document.getElementById(
        trigger.dataset.markasDrawerTrigger ?? "",
      );
      if (isDrawer(dialog)) {
        dialog.showModal();
        dialog.dataset.state = "open";
      }
      return;
    }
    // A click on the dialog itself (not its content) is a click on the backdrop.
    if (isDrawer(target)) target.close();
  });

  // The close event does not bubble, so listen in the capture phase.
  document.addEventListener(
    "close",
    (event) => {
      if (isDrawer(event.target)) event.target.dataset.state = "closed";
    },
    true,
  );
</script>
```

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

<Drawer title="Filter produk" closeLabel="Tutup">
  <Button slot="trigger" variant="secondary">Buka filter</Button>

  Pilih kategori dan rentang harga untuk menyaring daftar produk.

  <Fragment slot="footer">
    <Button variant="secondary" type="submit" value="cancel">Batal</Button>
    <Button type="submit" value="apply">Terapkan</Button>
  </Fragment>
</Drawer>
```

Satu script kecil yang dibundel Astro membuka semua drawer di halaman, termasuk setelah view transition.

### Angular

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

```ts
import {
  afterNextRender,
  ChangeDetectionStrategy,
  Component,
  computed,
  type ElementRef,
  input,
  output,
  signal,
  viewChild,
} from "@angular/core";

const dialogClass =
  "fixed inset-y-0 m-0 h-dvh max-h-dvh w-full max-w-sm border-line bg-surface p-0 text-ink shadow-overlay transition-transform duration-200 ease-out backdrop:bg-ink/40 motion-reduce:transition-none";
const sides = {
  right: "right-0 left-auto border-l starting:open:translate-x-full",
  left: "right-auto left-0 border-r starting:open:-translate-x-full",
};
const panel = "flex h-full flex-col gap-4 p-6";
const header = "flex items-start justify-between gap-4";
const titleClass = "text-lg font-semibold text-ink";
const body = "flex-1 overflow-y-auto text-sm text-muted";
const footerClass = "flex flex-wrap justify-end gap-2";
const close =
  "inline-flex size-8 shrink-0 items-center justify-center rounded-md text-muted transition-colors duration-150 ease-out hover:bg-subtle hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";

export type DrawerSide = keyof typeof sides;

let nextId = 0;

/**
 * Slots: an element with the `trigger` attribute opens the drawer, an element with the `footer`
 * attribute (an ng-container works) fills the action row, everything else is the body.
 * Host stays out of layout; id, title, and class move to the dialog.
 */
@Component({
  selector: "markas-drawer",
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: "contents", "[attr.id]": "null", "[attr.title]": "null" },
  template: `
    <div class="contents" (click)="show()">
      <ng-content select="[trigger]" />
    </div>
    <dialog
      #dialog
      [id]="dialogId()"
      [attr.aria-labelledby]="dialogId() + '-title'"
      [attr.data-state]="open() ? 'open' : 'closed'"
      [class]="dialogClasses()"
      (close)="handleClose()"
      (click)="handleClick($event)"
    >
      <div [class]="panel">
        <div [class]="header">
          <h2 [id]="dialogId() + '-title'" [class]="titleClass">
            {{ title() }}
          </h2>
          <form method="dialog">
            <button
              type="submit"
              [class]="close"
              [attr.aria-label]="closeLabel()"
            >
              <svg
                class="size-4"
                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>
            </button>
          </form>
        </div>
        <div [class]="body"><ng-content /></div>
        <form
          #footer
          method="dialog"
          [class]="footerClass"
          [hidden]="!hasFooter()"
        >
          <ng-content select="[footer]" />
        </form>
      </div>
    </dialog>
  `,
})
export class Drawer {
  readonly title = input.required<string>();
  readonly side = input<DrawerSide>("right");
  /** Accessible label of the close button. */
  readonly closeLabel = input("Close");
  readonly id = input<string>();
  readonly userClass = input("", { alias: "class" });
  readonly closed = output<void>();

  protected readonly panel = panel;
  protected readonly header = header;
  protected readonly titleClass = titleClass;
  protected readonly body = body;
  protected readonly footerClass = footerClass;
  protected readonly close = close;
  protected readonly open = signal(false);
  protected readonly hasFooter = signal(false);
  private readonly generatedId = `markas-drawer-${nextId++}`;
  protected readonly dialogId = computed(() => this.id() ?? this.generatedId);
  protected readonly dialogClasses = computed(() =>
    [dialogClass, sides[this.side()], this.userClass()]
      .filter(Boolean)
      .join(" "),
  );
  private readonly dialog =
    viewChild.required<ElementRef<HTMLDialogElement>>("dialog");
  private readonly footer =
    viewChild.required<ElementRef<HTMLFormElement>>("footer");

  constructor() {
    // Projected content is only known after the first render.
    afterNextRender(() =>
      this.hasFooter.set(this.footer().nativeElement.childElementCount > 0),
    );
  }

  /** Opens the drawer. Also callable from a template reference: drawer.show(). */
  show() {
    this.dialog().nativeElement.showModal();
    this.open.set(true);
  }

  protected handleClose() {
    this.open.set(false);
    this.closed.emit();
  }

  protected handleClick(event: MouseEvent) {
    // A click on the dialog itself (not its content) is a click on the backdrop.
    if (event.target === event.currentTarget)
      this.dialog().nativeElement.close();
  }
}
```

```ts
import { Component } from "@angular/core";
import { Button } from "./markas/button.component";
import { Drawer } from "./markas/drawer.component";

@Component({
  selector: "app-filters",
  imports: [Button, Drawer],
  template: `
    <markas-drawer
      title="Filter produk"
      closeLabel="Tutup"
      (closed)="onClosed()"
    >
      <button markas-button trigger variant="secondary">Buka filter</button>

      Pilih kategori dan rentang harga untuk menyaring daftar produk.

      <ng-container footer>
        <button markas-button variant="secondary" type="submit" value="cancel">
          Batal
        </button>
        <button markas-button type="submit" value="apply">Terapkan</button>
      </ng-container>
    </markas-drawer>
  `,
})
export class Filter {
  onClosed() {}
}
```

## Props

| Nama | Tipe | Default | Keterangan |
| --- | --- | --- | --- |
| `title` | `string` | - | Judul drawer, dipakai juga sebagai aria-labelledby. |
| `side` | `right \| left` | right | Sisi layar tempat drawer muncul. |
| `trigger` | `slot / ReactNode / snippet` | - | Elemen yang membuka drawer saat diklik. Angular: elemen dengan atribut trigger. |
| `footer` | `slot / ReactNode / snippet` | - | Area aksi. Dibungkus form method=dialog, jadi tombol type=submit menutup drawer. Angular: elemen dengan atribut footer. |
| `id` | `string` | auto | Id dialog. Bisa dipakai untuk membuka drawer dari luar lewat showModal(). |
| `closeLabel` | `string` | Close | Label aksesibel tombol tutup. Isi "Tutup" untuk situs berbahasa Indonesia. |
| `closed` | `output<void>` | - | Khusus Angular. Dipancarkan saat drawer tertutup. |

## Aksesibilitas

- Memakai dialog dan showModal(), jadi fokus terkunci di dalam drawer dan konten di belakangnya inert.
- Escape menutup drawer dan fokus kembali ke elemen pemicu.
- Klik di luar panel (backdrop) menutup drawer.
- Tombol tutup punya aria-label dari closeLabel (default Close).

## Catatan

- Pakai `side="left"` untuk drawer dari sisi kiri.
- Nilai `value` tombol yang dipakai menutup drawer tersedia di `dialog.returnValue` saat event `close`.
- Label tombol tutup default dalam bahasa Inggris ("Close"). Isi `closeLabel` (Blade: `close-label`) dengan "Tutup" untuk situs berbahasa Indonesia.
