# Drawer · 模态抽屉

将 `side` 设置为 `left` 或 `right` 选择边缘，默认从右侧显示。抽屉在窄屏适应可用宽度，在宽屏受 `comp.drawer.maxWidth` 限制，默认最大宽度为 580px。较长的内容可在抽屉内滚动。

```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:

### 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`

| `Context` | `--ac-comp-drawer-maxWidth` |
| - | - |
| `dark/compact` | `36.25rem` |
| `dark/comfortable` | `36.25rem` |
| `light/compact` | `36.25rem` |
| `light/comfortable` | `36.25rem` |

| `Prop` | `Type` | `Required` | `Default` |
| - | - | - | - |
| `busy` | `boolean` | `false` | `—` |
| `children` | `ReactNode` | `false` | `—` |
| `className` | `string` | `false` | `—` |
| `description` | `ReactNode` | `false` | `—` |
| `footer` | `ReactNode` | `false` | `—` |
| `key` | `React.Key \| null \| undefined` | `false` | `—` |
| `onOpenChange` | `(open: boolean) => void` | `true` | `—` |
| `open` | `boolean` | `true` | `—` |
| `ref` | `React.Ref<HTMLDivElement> \| undefined` | `false` | `—` |
| `side` | `'right' \| 'left'` | `false` | `—` |
| `title` | `ReactNode` | `true` | `—` |

```ts
import * as React from 'react';
import type { DrawerProps } from './types.js';
export declare const Drawer: React.ForwardRefExoticComponent<DrawerProps & React.RefAttributes<HTMLDivElement>>;
```

* default — dark/compact, dark/comfortable, light/compact, light/comfortable
