Drawer · 模态抽屉
将 side 设置为 left 或 right 选择边缘,默认从右侧显示。抽屉在窄屏适应可用宽度,在宽屏受 comp.drawer.maxWidth 限制,默认最大宽度为 580px。较长的内容可在抽屉内滚动。
Live example
Open playground ↗App.tsx
'use client'
import { useState } from 'react'
import { Button, Drawer } from '@ancrel/ui'
import '@ancrel/tokens/css'
import '@ancrel/ui/styles.css'
export default function App() {
const [side, setSide] = useState<'left' | 'right' | null>(null)
return <>
<Button onClick={() => setSide('left')}>Inspect from left</Button>
<Button onClick={() => setSide('right')}>Inspect from right</Button>
<Drawer open={side !== null} side={side ?? 'right'} onOpenChange={() => setSide(null)}
title="Page details" description="Current page metadata">
<p>Language: English</p>
</Drawer>
</>
}
Expected behavior
Expected behavior
Open the drawer from either edge. The modal is named Page details. Its width follows the drawer maximum on wide screens and fits narrower screens. Escape and Close return to the opening control.
命名与关闭
给 title 提供能识别当前任务的文字,description 可补充一句操作说明。应用通过 open 和 onOpenChange 管理可见性。完成编辑可由页脚按钮直接更新应用状态。请求进行中设置 busy,关闭按钮、Escape 与外部按下都将等待。
在抽屉中打开下一层后,先关闭内层会回到抽屉内的触发按钮,再关闭抽屉会回到页面上的原始位置。
--ac-comp-drawer-maxWidth
Props
| Prop | Type | Required | Default |
|---|---|---|---|
busy | boolean | No | — |
children | ReactNode | No | — |
className | string | No | — |
description | ReactNode | No | — |
footer | ReactNode | No | — |
key | React.Key | null | undefined | No | — |
onOpenChange | (open: boolean) => void | Yes | — |
open | boolean | Yes | — |
ref | React.Ref<HTMLDivElement> | undefined | No | — |
side | 'right' | 'left' | No | — |
title | ReactNode | Yes | — |
State matrix
| State | Theme / density |
|---|---|
| default | dark/compact, dark/comfortable, light/compact, light/comfortable |
Constraints
- Choose a physical edge with side and supply a descriptive title.
- Use the comp.drawer.maxWidth token to customize the width ceiling.
Anti-patterns
- Stacking drawers by increasing numeric z-index.
- Leaving a background action responsible for closing a busy drawer.