Drawer
支持从上下左右四个边缘滑出的模态抽屉组件,内置内容自适应、滚动与拖拽吸附控制。
可从屏幕上下左右四个边缘滑出的模态抽屉面板,支持内容自适应高度、纵向滚动以及可拖拽吸附档位。本页示例采用 Shadcn Rhea 风格。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-drawer-root
style-profile="rhea"
a11y-label="Daily activity goal"
>
<wc-shadcn-drawer-trigger style-profile="rhea">
<wc-shadcn-button style-profile="rhea" variant="outline">
Open Drawer
</wc-shadcn-button>
</wc-shadcn-drawer-trigger>
<wc-shadcn-drawer-mask
style-profile="rhea"
></wc-shadcn-drawer-mask>
<wc-shadcn-drawer-content style-profile="rhea" side="bottom">
<wc-shadcn-drawer-handle
style-profile="rhea"
a11y-label="Resize drawer"
></wc-shadcn-drawer-handle>
<div class="mx-auto w-full max-w-sm">
<wc-shadcn-drawer-header style-profile="rhea">
<wc-shadcn-drawer-title style-profile="rhea">
Move Goal
</wc-shadcn-drawer-title>
<wc-shadcn-drawer-description style-profile="rhea">
Set your daily activity goal.
</wc-shadcn-drawer-description>
</wc-shadcn-drawer-header>
<div class="px-4 py-3 text-center">
<div class="text-4xl font-bold tabular-nums">350</div>
<div class="text-xs uppercase text-muted-foreground">
Calories / day
</div>
</div>
<wc-shadcn-drawer-footer style-profile="rhea">
<wc-shadcn-button style-profile="rhea">
Submit
</wc-shadcn-button>
<wc-shadcn-drawer-close style-profile="rhea">
<wc-shadcn-button style-profile="rhea" variant="outline">
Cancel
</wc-shadcn-button>
</wc-shadcn-drawer-close>
</wc-shadcn-drawer-footer>
</div>
</wc-shadcn-drawer-content>
</wc-shadcn-drawer-root>将于 0.3.0-rc.1 及后续版本中提供(@proto.ui/prototypes-shadcn/drawer)。
import { ShadcnButton, ShadcnDrawerRoot, ShadcnDrawerTrigger, ShadcnDrawerMask, ShadcnDrawerContent, ShadcnDrawerHandle, ShadcnDrawerHeader, ShadcnDrawerTitle, ShadcnDrawerDescription, ShadcnDrawerFooter, ShadcnDrawerClose,} from '../proto-ui/components/react';<ShadcnDrawerRoot styleProfile="rhea"> <ShadcnDrawerTrigger styleProfile="rhea"> <ShadcnButton styleProfile="rhea" variant="outline"> Open Drawer </ShadcnButton> </ShadcnDrawerTrigger> <ShadcnDrawerMask styleProfile="rhea" /> <ShadcnDrawerContent styleProfile="rhea" side="bottom"> <ShadcnDrawerHandle styleProfile="rhea" /> <ShadcnDrawerHeader styleProfile="rhea"> <ShadcnDrawerTitle styleProfile="rhea">Move Goal</ShadcnDrawerTitle> <ShadcnDrawerDescription styleProfile="rhea"> Set your daily activity goal. </ShadcnDrawerDescription> </ShadcnDrawerHeader> <div className="flex-1 overflow-y-auto px-4">{/* Content */}</div> <ShadcnDrawerFooter styleProfile="rhea"> <ShadcnButton styleProfile="rhea">Submit</ShadcnButton> <ShadcnDrawerClose styleProfile="rhea"> <ShadcnButton styleProfile="rhea" variant="outline"> Cancel </ShadcnButton> </ShadcnDrawerClose> </ShadcnDrawerFooter> </ShadcnDrawerContent></ShadcnDrawerRoot>DrawerRoot├── DrawerTrigger├── DrawerMask└── DrawerContent ├── DrawerHandle ├── DrawerHeader │ ├── DrawerTitle │ └── DrawerDescription └── DrawerFooter └── DrawerClose- 触发与关闭按钮:在
rhea等现代风格下,Trigger与Close保持无样式语义封装,直接嵌套Button提供交互外观;在new-york-v4下默认自带 outline 按钮外观(长文案可启用wrap)。 - 尺寸约束:通过
Content的minExtent/maxExtent控制面板尺寸(支持'logical'、'root-text'、'available'与'available-minus-root-text')。上下抽屉默认自适应内容高度并受安全可用区域限制;左右抽屉默认宽度上限为20个root-text单位。 - 吸附与无障碍:提供
(0, 1]比例数组snapPoints后,Handle具备具名separator语义并支持方向键及Home/End调整档位;按下Escape或点击遮罩可关闭抽屉,关闭后焦点自动归还触发器。
四个弹出方向
Section titled “四个弹出方向”通过 Content 的 side 属性指定 'top'、'right'、'bottom' 或 'left':
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<div class="flex flex-wrap gap-3">
<wc-shadcn-drawer-root
style-profile="rhea"
a11y-label="Right Drawer"
>
<wc-shadcn-drawer-trigger style-profile="rhea">
<wc-shadcn-button style-profile="rhea" variant="outline">
Right
</wc-shadcn-button>
</wc-shadcn-drawer-trigger>
<wc-shadcn-drawer-mask
style-profile="rhea"
></wc-shadcn-drawer-mask>
<wc-shadcn-drawer-content style-profile="rhea" side="right">
<wc-shadcn-drawer-handle
style-profile="rhea"
></wc-shadcn-drawer-handle>
<wc-shadcn-drawer-header style-profile="rhea">
<wc-shadcn-drawer-title style-profile="rhea">
Right Drawer
</wc-shadcn-drawer-title>
<wc-shadcn-drawer-description style-profile="rhea">
Slides in from the right edge.
</wc-shadcn-drawer-description>
</wc-shadcn-drawer-header>
<wc-shadcn-drawer-footer style-profile="rhea">
<wc-shadcn-drawer-close style-profile="rhea">
<wc-shadcn-button style-profile="rhea" variant="outline">
Close
</wc-shadcn-button>
</wc-shadcn-drawer-close>
</wc-shadcn-drawer-footer>
</wc-shadcn-drawer-content>
</wc-shadcn-drawer-root>
</div>将正文包裹在 flex-1 overflow-y-auto 容器中,即可在固定标题栏与底部操作区的同时平滑滚动:
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-drawer-root
style-profile="rhea"
a11y-label="Release notes"
>
<wc-shadcn-drawer-trigger style-profile="rhea">
<wc-shadcn-button style-profile="rhea" variant="outline">
Scrollable Content
</wc-shadcn-button>
</wc-shadcn-drawer-trigger>
<wc-shadcn-drawer-mask
style-profile="rhea"
></wc-shadcn-drawer-mask>
<wc-shadcn-drawer-content style-profile="rhea" side="bottom">
<wc-shadcn-drawer-handle
style-profile="rhea"
></wc-shadcn-drawer-handle>
<wc-shadcn-drawer-header style-profile="rhea">
<wc-shadcn-drawer-title style-profile="rhea">
Release Highlights
</wc-shadcn-drawer-title>
<wc-shadcn-drawer-description style-profile="rhea">
Scroll through the notes while keeping header and footer
anchored.
</wc-shadcn-drawer-description>
</wc-shadcn-drawer-header>
<div class="flex-1 overflow-y-auto px-4 py-2 space-y-3">
<!-- Scrollable body items -->
</div>
<wc-shadcn-drawer-footer style-profile="rhea">
<wc-shadcn-drawer-close style-profile="rhea">
<wc-shadcn-button style-profile="rhea" variant="outline">
Close
</wc-shadcn-button>
</wc-shadcn-drawer-close>
</wc-shadcn-drawer-footer>
</wc-shadcn-drawer-content>
</wc-shadcn-drawer-root>吸附档位(Snap Points)
Section titled “吸附档位(Snap Points)”配置 snapPoints 与 defaultSnapPoint(或受控 snapPoint / snapPointChange),用户可通过拖拽把手或键盘方向键在不同高度比例间切换:
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-drawer-root
style-profile="rhea"
a11y-label="Snap points drawer"
>
<wc-shadcn-drawer-trigger style-profile="rhea">
<wc-shadcn-button style-profile="rhea" variant="outline">
Open Snap Drawer
</wc-shadcn-button>
</wc-shadcn-drawer-trigger>
<wc-shadcn-drawer-mask
style-profile="rhea"
></wc-shadcn-drawer-mask>
<wc-shadcn-drawer-content
id="snap-drawer-content"
style-profile="rhea"
side="bottom"
>
<wc-shadcn-drawer-handle
style-profile="rhea"
a11y-label="Resize drawer height"
></wc-shadcn-drawer-handle>
<wc-shadcn-drawer-header style-profile="rhea">
<wc-shadcn-drawer-title style-profile="rhea">
Snap Points
</wc-shadcn-drawer-title>
<wc-shadcn-drawer-description style-profile="rhea">
Drag the handle or press Arrow Up / Down to switch between
50% and full height.
</wc-shadcn-drawer-description>
</wc-shadcn-drawer-header>
<wc-shadcn-drawer-footer style-profile="rhea">
<wc-shadcn-drawer-close style-profile="rhea">
<wc-shadcn-button style-profile="rhea" variant="outline">
Close
</wc-shadcn-button>
</wc-shadcn-drawer-close>
</wc-shadcn-drawer-footer>
</wc-shadcn-drawer-content>
</wc-shadcn-drawer-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#snap-drawer-content'), {
styleProfile: 'rhea',
side: 'bottom',
snapPoints: [0.5, 1],
defaultSnapPoint: 0.5,
});
</script>自定义尺寸与禁用拖拽关闭
Section titled “自定义尺寸与禁用拖拽关闭”通过 maxExtent 约束侧边抽屉宽度,并设置 dragDismissible={false} 防止误触滑动关闭(关闭按钮、Escape 与点击外部仍保持可用):
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-shadcn-drawer-root
style-profile="rhea"
a11y-label="Custom sized drawer"
>
<wc-shadcn-drawer-trigger style-profile="rhea">
<wc-shadcn-button style-profile="rhea" variant="outline">
Custom Size & Locked Drag
</wc-shadcn-button>
</wc-shadcn-drawer-trigger>
<wc-shadcn-drawer-mask
style-profile="rhea"
></wc-shadcn-drawer-mask>
<wc-shadcn-drawer-content
id="sized-drawer-content"
style-profile="rhea"
side="right"
>
<wc-shadcn-drawer-header style-profile="rhea">
<wc-shadcn-drawer-title style-profile="rhea">
Inspector Panel
</wc-shadcn-drawer-title>
<wc-shadcn-drawer-description style-profile="rhea">
Capped at 420px with drag dismissal disabled.
</wc-shadcn-drawer-description>
</wc-shadcn-drawer-header>
<wc-shadcn-drawer-footer style-profile="rhea">
<wc-shadcn-drawer-close style-profile="rhea">
<wc-shadcn-button style-profile="rhea" variant="outline">
Close
</wc-shadcn-button>
</wc-shadcn-drawer-close>
</wc-shadcn-drawer-footer>
</wc-shadcn-drawer-content>
</wc-shadcn-drawer-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
setElementProps(document.querySelector('#sized-drawer-content'), {
styleProfile: 'rhea',
side: 'right',
maxExtent: { unit: 'logical', value: 420 },
dragDismissible: false,
});
</script>传入 open 进入受控模式,并通过 openChange 监听状态变更请求;同时暴露 openDrawer()、close() 与 toggle() 方法。
| 属性 | 类型 | 默认值 |
|---|---|---|
open | boolean | — |
defaultOpen | boolean | false |
disabled | boolean | false |
a11yLabel | string | '' |
styleProfile | ShadcnStyleProfile | 'inherit' |
Content
Section titled “Content”暴露 open、snapPoint、dragging、dragProgress、offsetPercentage、extentValid 状态、requestSnapPoint() 方法及 snapPointChange 事件。
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
side | 'top' 'right' 'bottom' 'left' | 'bottom' | — |
snapPoints | number[] | — | — |
snapPoint | number | — | — |
defaultSnapPoint | number | — | — |
minExtent | AvailableLayoutLength | { unit: 'logical', value: 0 } | — |
maxExtent | AvailableLayoutLength | 按方向默认 | 上下 { unit: 'available-minus-root-text', value: 6 } / 左右 { unit: 'root-text', value: 20 } |
dragDismissible | boolean | true | — |
dragDismissThreshold | number | 0.25 | — |
enterDuration | number | 500 | — |
leaveDuration | number | 500 | — |
styleProfile | ShadcnStyleProfile | 'inherit' | — |
| 属性 | 类型 | 默认值 |
|---|---|---|
passthrough | boolean | false |
enterDuration | number | 500 |
leaveDuration | number | 500 |
styleProfile | ShadcnStyleProfile | 'inherit' |
Handle / Trigger / Close
Section titled “Handle / Trigger / Close”| 属性 | 类型 | 默认值 |
|---|---|---|
Handle.disabled | boolean | false |
Handle.a11yLabel | string | 'Resize drawer' |
Trigger / Close.disabled | boolean | false |
Trigger / Close.wrap | boolean | false |
styleProfile | ShadcnStyleProfile | 'inherit' |
Header、Footer、Title 与 Description 仅接受可选的 styleProfile 属性。