# Drawer

> Bottom sheet yang muncul dari bawah di HP.

Drawer adalah bottom sheet: panel yang muncul dari bawah layar HP, untuk mengurutkan, filter, atau pilihan singkat.

## Kapan dipakai

- Pakai di HP untuk mengurutkan, filter, dan pilihan singkat, dekat dengan jempol.
- Pakai [Sheet](https://design.sosialoka.tech/id/components/sheet/) dari samping di web. Aplikasi web yang juga harus jalan di HP membuka Sheet mulai `md` dan Drawer di bawahnya.
- Pakai [Dialog](https://design.sosialoka.tech/id/components/dialog/) untuk keputusan yang butuh perhatian penuh.
- Isi yang panjang di-scroll di dalam drawer; drawer tidak pernah menutupi lebih dari 85% layar.

_Pratinjau langsung versi React dan Vue: https://design.sosialoka.tech/id/components/drawer/_

## Anatomi

1. Pegangan
2. Bottom sheet
3. Halaman di belakang, diredupkan

Pegangan 48×6px di atas, header berisi judul dan satu kalimat deskripsi, isi, lalu footer berisi aksi utama. Panelnya berlatar `popover` dengan `radius-xl` hanya di sudut atas, `border` di atas, dan token `overlay` di belakangnya. Padding bawahnya menjauhi garis home di HP (`env(safe-area-inset-bottom)`).

## Varian

Hanya ada satu gaya, dari bawah. Tepi lain bisa dipakai, tapi gunakan Sheet untuk panel samping.

## Props

| React | Vue | Flutter | Tipe | Default | Kegunaan |
| --- | --- | --- | --- | --- | --- |
| `open` / `onOpenChange` | `v-model:open` | `showShadSheet(side: ShadSheetSide.bottom)` | boolean | `false` | Membuka lewat kode. |
| `showSwipeHandle` | selalu tampil dari bawah | kotak `muted` 48×6 | boolean | `true` | Pegangan geser. |
| `DrawerTitle`, `DrawerDescription` | sama | `title`, `description` | teks | tidak ada | Nama panel. |
| `DrawerFooter` | `DrawerFooter` | `actions` | elemen | tidak ada | Aksi utama. |

## Kode

**React**
```tsx
import { useId } from "react"
import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"

const orders = [
  { value: "newest", label: "Terbaru" },
  { value: "oldest", label: "Terlama" },
  { value: "title", label: "Judul A–Z" },
]

export default function DrawerDemo() {
  const id = useId()
  return (
    <Drawer>
      <DrawerTrigger render={<Button variant="outline" />}>Urutkan</DrawerTrigger>
      <DrawerContent>
        <DrawerHeader>
          <DrawerTitle>Urutkan rilis</DrawerTitle>
          <DrawerDescription>Pilih urutan daftar rilismu.</DrawerDescription>
        </DrawerHeader>
        <RadioGroup defaultValue="newest" aria-label="Urutan" className="px-4">
          {orders.map((o) => (
            <div key={o.value} className="flex items-center gap-3">
              <RadioGroupItem value={o.value} id={`${id}-${o.value}`} />
              <Label htmlFor={`${id}-${o.value}`}>{o.label}</Label>
            </div>
          ))}
        </RadioGroup>
        <DrawerFooter>
          <DrawerClose render={<Button />}>Terapkan</DrawerClose>
        </DrawerFooter>
      </DrawerContent>
    </Drawer>
  )
}
```

**Vue**
```vue
<script setup lang="ts">
import { useId } from "vue"
import { Button } from "@/components/ui/button"
import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"

const orders = [
  { value: "newest", label: "Terbaru" },
  { value: "oldest", label: "Terlama" },
  { value: "title", label: "Judul A–Z" },
]
const id = useId()
</script>

<template>
  <Drawer>
    <DrawerTrigger as-child>
      <Button variant="outline">Urutkan</Button>
    </DrawerTrigger>
    <DrawerContent>
      <DrawerHeader>
        <DrawerTitle>Urutkan rilis</DrawerTitle>
        <DrawerDescription>Pilih urutan daftar rilismu.</DrawerDescription>
      </DrawerHeader>
      <RadioGroup default-value="newest" aria-label="Urutan" class="px-4">
        <div v-for="o in orders" :key="o.value" class="flex items-center gap-3">
          <RadioGroupItem :id="`${id}-${o.value}`" :value="o.value" />
          <Label :for="`${id}-${o.value}`">{{ o.label }}</Label>
        </div>
      </RadioGroup>
      <DrawerFooter>
        <DrawerClose as-child>
          <Button>Terapkan</Button>
        </DrawerClose>
      </DrawerFooter>
    </DrawerContent>
  </Drawer>
</template>
```

**Flutter**
```dart
import 'package:flutter/widgets.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

const sortOrders = [('newest', 'Terbaru'), ('oldest', 'Terlama'), ('title', 'Judul A–Z')];

// A bottom sheet: the shadcn_ui sheet from the bottom edge, with a drag handle on top.
class DrawerDemo extends StatelessWidget {
  const DrawerDemo({super.key});

  @override
  Widget build(BuildContext context) {
    return ShadButton.outline(
      child: const Text('Urutkan'),
      onPressed: () => showShadSheet(
        context: context,
        side: ShadSheetSide.bottom,
        builder: (context) {
          final theme = ShadTheme.of(context);
          final handle = ExcludeSemantics(
            child: Center(
              child: Container(
                width: 48,
                height: 6,
                decoration: BoxDecoration(color: theme.colorScheme.muted, borderRadius: BorderRadius.circular(3)),
              ),
            ),
          );
          // draggable lets the handle swipe the sheet closed; the handle sits above the title.
          return ShadSheet(
            draggable: true,
            radius: const BorderRadius.vertical(top: Radius.circular(16)),
            title: Column(spacing: 12, children: [handle, const Text('Urutkan rilis')]),
            description: const Text('Pilih urutan daftar rilismu.'),
            actions: [ShadButton(child: const Text('Terapkan'), onPressed: () => Navigator.of(context).pop())],
            child: Column(
              mainAxisSize: MainAxisSize.min,
              crossAxisAlignment: CrossAxisAlignment.start,
              spacing: 16,
              children: [
                ShadRadioGroup<String>(
                  initialValue: 'newest',
                  items: [for (final (value, label) in sortOrders) ShadRadio(value: value, label: Text(label))],
                ),
              ],
            ),
          );
        },
      ),
    );
  }
}
```

## Pasang

**React**
```bash
npx shadcn@latest add https://design.sosialoka.tech/r/react/drawer.json
```

**Vue**
```bash
npx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/drawer.json
```

## Aksesibilitas

- Drawer berupa dialog yang dinamai judulnya; fokus masuk ke dalamnya dan kembali ke pemicu saat tertutup.
- Menggeser pegangan ke bawah, Escape, dan ketukan di overlay menutupnya. Pegangan hanya hiasan dan tidak pernah menerima fokus, jadi tetap sediakan tombol untuk menutup atau menerapkan.
- Halaman di belakangnya tidak bisa dijangkau sampai drawer tertutup.
