Mỗi ví dụ là một file Vue hoàn chỉnh. Chép vào app đã cài registry, hoặc mở trong StackBlitz. Bấm một nút, rồi kéo drawer về cạnh của nó, nhấn Esc hoặc bấm Hủy.
Từ cạnh dưới
Mặc định. Thanh kéo cho biết drawer vuốt xuống được. Chọn một trong vài lựa chọn, rồi Lưu.
DrawerBottom.vue
<script setup lang="ts">
import { ref } 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 choices = [
{ value: '15m', label: '15 phút một lần' },
{ value: '1h', label: 'Mỗi giờ' },
{ value: '1d', label: 'Mỗi ngày một lần' },
]
const chosen = ref('1h')
</script>
<template>
<Drawer>
<DrawerTrigger as-child>
<Button variant="outline">Lịch đồng bộ</Button>
</DrawerTrigger>
<DrawerContent>
<div class="mx-auto w-full max-w-sm">
<DrawerHeader>
<DrawerTitle>Lịch đồng bộ</DrawerTitle>
<DrawerDescription>Bao lâu thì đơn hàng chuyển từ cửa hàng online sang ERP một lần.</DrawerDescription>
</DrawerHeader>
<RadioGroup v-model="chosen" class="px-(--bh-space-modal)" aria-label="Lịch đồng bộ">
<div v-for="choice in choices" :key="choice.value" class="flex items-center gap-(--bh-space-100)">
<RadioGroupItem :id="`schedule-${choice.value}`" :value="choice.value" />
<Label :for="`schedule-${choice.value}`">{{ choice.label }}</Label>
</div>
</RadioGroup>
<DrawerFooter>
<DrawerClose as-child>
<Button variant="outline">Hủy</Button>
</DrawerClose>
<DrawerClose as-child>
<Button>Lưu</Button>
</DrawerClose>
</DrawerFooter>
</div>
</DrawerContent>
</Drawer>
</template>Từ cạnh bên
swipe-direction="right" đưa drawer vào từ cạnh cuối, không có thanh kéo.
DrawerSide.vue
<script setup lang="ts">
import { ListFilter } from '@lucide/vue'
import { ref } from 'vue'
import { Button } from '@/components/ui/button'
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from '@/components/ui/drawer'
const statuses = ['Mới', 'Đã thanh toán', 'Đã giao', 'Đồng bộ lỗi']
const shown = ref<string[]>(['Mới', 'Đã thanh toán'])
function toggle(status: string) {
shown.value = shown.value.includes(status)
? shown.value.filter(s => s !== status)
: [...shown.value, status]
}
</script>
<template>
<!-- swipe-direction="right": the drawer comes in from the end edge and is swiped back to it. -->
<Drawer swipe-direction="right">
<DrawerTrigger as-child>
<Button variant="outline"><ListFilter />Bộ lọc</Button>
</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>Lọc đơn hàng</DrawerTitle>
<DrawerDescription>Hiện đơn hàng có các trạng thái này.</DrawerDescription>
</DrawerHeader>
<div class="flex flex-wrap gap-(--bh-space-100) px-(--bh-space-modal)">
<Button
v-for="status in statuses"
:key="status"
variant="outline"
size="sm"
:aria-pressed="shown.includes(status)"
@click="toggle(status)"
>
{{ status }}
</Button>
</div>
<DrawerFooter>
<DrawerClose as-child>
<Button variant="outline">Hủy</Button>
</DrawerClose>
<DrawerClose as-child>
<Button>Áp dụng</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>
</template>