Components
"use client"
import * as React from "react"关于
抽屉组件基于 Vaul 由 emilkowalski 构建。
安装
pnpm dlx shadcn@latest add drawer
使用
import {
Drawer,
DrawerClose,
DrawerContent,
DrawerDescription,
DrawerFooter,
DrawerHeader,
DrawerTitle,
DrawerTrigger,
} from "@/components/ui/drawer"<Drawer>
<DrawerTrigger>打开</DrawerTrigger>
<DrawerContent>
<DrawerHeader>
<DrawerTitle>你确定吗?</DrawerTitle>
<DrawerDescription>此操作无法撤销。</DrawerDescription>
</DrawerHeader>
<DrawerFooter>
<Button>提交</Button>
<DrawerClose>
<Button variant="outline">取消</Button>
</DrawerClose>
</DrawerFooter>
</DrawerContent>
</Drawer>示例
可滚动内容
保持操作按钮可见,同时内容可滚动。
import { Button } from "@/components/ui/button"
import {
Drawer,位置
使用 direction 属性设置抽屉出现的位置。可选项有 top、right、bottom 和 left。
import { Button } from "@/components/ui/button"
import {
Drawer,响应式对话框
你可以将 Dialog 和 Drawer 组件结合使用,创建响应式对话框。在桌面端渲染 Dialog 组件,在移动端渲染 Drawer 组件。
"use client"
import * as React from "react"API 参考
请参阅 Vaul 文档 获取完整的 API 参考。