🌐 Nodejs.cn

React 的抽屉组件。

"use client"

import * as React from "react"

关于

🌐 About

Drawer 是由 emilkowalski 基于 Vaul 构建的。

🌐 Drawer is built on top of Vaul by emilkowalski.

安装

🌐 Installation

pnpm dlx shadcn@latest add drawer

用法

🌐 Usage

import {
  Drawer,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from "@/components/ui/drawer"
<Drawer>
  <DrawerTrigger>Open</DrawerTrigger>
  <DrawerContent>
    <DrawerHeader>
      <DrawerTitle>Are you absolutely sure?</DrawerTitle>
      <DrawerDescription>This action cannot be undone.</DrawerDescription>
    </DrawerHeader>
    <DrawerFooter>
      <Button>Submit</Button>
      <DrawerClose>
        <Button variant="outline">Cancel</Button>
      </DrawerClose>
    </DrawerFooter>
  </DrawerContent>
</Drawer>

示例

🌐 Examples

可滚动内容

🌐 Scrollable Content

在内容滚动时保持操作可见。

🌐 Keep actions visible while the content scrolls.

import { Button } from "@/components/ui/button"
import {
  Drawer,

🌐 Sides

使用 direction 属性来设置抽屉的侧面。可用选项有 toprightbottomleft

🌐 Use the direction prop to set the side of the drawer. Available options are top, right, bottom, and left.

import { Button } from "@/components/ui/button"
import {
  Drawer,

响应式对话框

🌐 Responsive Dialog

你可以将 DialogDrawer 组件结合起来创建一个响应式对话框。这将在桌面上渲染 Dialog 组件,在移动设备上渲染 Drawer 组件。

🌐 You can combine the Dialog and Drawer components to create a responsive dialog. This renders a Dialog component on desktop and a Drawer on mobile.

"use client"

import * as React from "react"

从右到左

🌐 RTL

要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南

🌐 To enable RTL support in shadcn/ui, see the RTL configuration guide.

"use client"

import * as React from "react"

API参考

🌐 API Reference

请参阅 Vaul 文档 了解完整的 API 参考。

🌐 See the Vaul documentation for the full API reference.