Components
@shadcn/react
@shadcn/helpers
Utilities
"use client"
import * as React from "react"关于#
抽屉组件基于 emilkowalski 的 Vaul 构建。
安装#
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>组合#
使用以下组合来构建 Drawer:
Drawer
├── DrawerTrigger
└── DrawerContent
├── DrawerHeader
│ ├── DrawerTitle
│ └── DrawerDescription
└── DrawerFooter可滚动内容#
保持操作可见,同时内容可滚动。
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"RTL#
要启用 shadcn/ui 的 RTL(从右向左)支持,请参阅 RTL 配置指南。
"use client"
import * as React from "react"API 参考#
完整 API 参考请参见 Vaul 文档。