AlertDialog
带明确说明、安全取消焦点与操作确认意图的 Duostrap 模态确认对话框。
Duostrap AlertDialog 沿用经典 .modal.fade 与 .modal-backdrop.fade 样式与过渡,打开时自动将焦点定位到安全的取消按钮,并阻止点击遮罩意外关闭。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-duostrap-alert-dialog-root>
<wc-duostrap-alert-dialog-trigger>
Show Dialog
</wc-duostrap-alert-dialog-trigger>
<wc-duostrap-alert-dialog-mask></wc-duostrap-alert-dialog-mask>
<wc-duostrap-alert-dialog-content>
<wc-duostrap-alert-dialog-title>
Are you absolutely sure?
</wc-duostrap-alert-dialog-title>
<wc-duostrap-alert-dialog-description>
This action cannot be undone. This will permanently delete
your account and remove your data from our servers.
</wc-duostrap-alert-dialog-description>
<wc-duostrap-alert-dialog-footer>
<wc-duostrap-alert-dialog-cancel>
Cancel
</wc-duostrap-alert-dialog-cancel>
<wc-duostrap-alert-dialog-action>
Continue
</wc-duostrap-alert-dialog-action>
</wc-duostrap-alert-dialog-footer>
</wc-duostrap-alert-dialog-content>
</wc-duostrap-alert-dialog-root>将于 0.3.0-rc.1 及后续版本中提供(@proto.ui/prototypes-duostrap)。
import { BootstrapAlertDialogRoot, BootstrapAlertDialogTrigger, BootstrapAlertDialogMask, BootstrapAlertDialogContent, BootstrapAlertDialogTitle, BootstrapAlertDialogDescription, BootstrapAlertDialogFooter, BootstrapAlertDialogCancel, BootstrapAlertDialogAction,} from '../proto-ui/components/react';
export function Example() { return ( <BootstrapAlertDialogRoot> <BootstrapAlertDialogTrigger>Show Dialog</BootstrapAlertDialogTrigger> <BootstrapAlertDialogMask /> <BootstrapAlertDialogContent> <BootstrapAlertDialogTitle>Are you absolutely sure?</BootstrapAlertDialogTitle> <BootstrapAlertDialogDescription> This action cannot be undone. This will permanently delete your account. </BootstrapAlertDialogDescription> <BootstrapAlertDialogFooter> <BootstrapAlertDialogCancel>Cancel</BootstrapAlertDialogCancel> <BootstrapAlertDialogAction>Continue</BootstrapAlertDialogAction> </BootstrapAlertDialogFooter> </BootstrapAlertDialogContent> </BootstrapAlertDialogRoot> );}由 Root、Trigger、Mask、Content、Title、Description、Footer、Cancel 和 Action 组成:
- 焦点与模态:
Mask提供 150ms 淡入淡出的 0.8 透明黑遮罩;Content提供 300ms 下滑与淡入过渡、约束焦点在对话框内,不响应外部点击关闭,并在打开时优先聚焦Cancel。 - Footer:对应 Bootstrap
.modal-footer,带顶部分隔线与次级灰底,右对齐排列Cancel与Action。 - 确认与关闭:点击
Action会先触发action事件再请求关闭;按Escape或点击Cancel直接请求关闭。支持在Trigger与Action上选择经典 Bootstrap 按钮变体(如variant="danger")。
紧凑尺寸(Small)
Section titled “紧凑尺寸(Small)”设置 size="sm" 使用 360px 紧凑宽度模态框。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-duostrap-alert-dialog-root>
<wc-duostrap-alert-dialog-trigger>
Show Compact Dialog
</wc-duostrap-alert-dialog-trigger>
<wc-duostrap-alert-dialog-mask></wc-duostrap-alert-dialog-mask>
<wc-duostrap-alert-dialog-content size="sm">
<wc-duostrap-alert-dialog-title>
Allow accessory to connect?
</wc-duostrap-alert-dialog-title>
<wc-duostrap-alert-dialog-description>
Do you want to allow the USB accessory to connect to this
device?
</wc-duostrap-alert-dialog-description>
<wc-duostrap-alert-dialog-footer>
<wc-duostrap-alert-dialog-cancel>
Don't allow
</wc-duostrap-alert-dialog-cancel>
<wc-duostrap-alert-dialog-action>
Allow
</wc-duostrap-alert-dialog-action>
</wc-duostrap-alert-dialog-footer>
</wc-duostrap-alert-dialog-content>
</wc-duostrap-alert-dialog-root>危险操作(Danger)
Section titled “危险操作(Danger)”在 Trigger 与 Action 上使用 variant="danger" 呈现经典的 Duostrap 红色渐变 .btn-danger 样式。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-duostrap-alert-dialog-root>
<wc-duostrap-alert-dialog-trigger variant="danger">
Delete Chat
</wc-duostrap-alert-dialog-trigger>
<wc-duostrap-alert-dialog-mask></wc-duostrap-alert-dialog-mask>
<wc-duostrap-alert-dialog-content size="sm">
<wc-duostrap-alert-dialog-title>
Delete chat?
</wc-duostrap-alert-dialog-title>
<wc-duostrap-alert-dialog-description>
This will permanently delete this chat conversation and remove
any saved memories.
</wc-duostrap-alert-dialog-description>
<wc-duostrap-alert-dialog-footer>
<wc-duostrap-alert-dialog-cancel>
Cancel
</wc-duostrap-alert-dialog-cancel>
<wc-duostrap-alert-dialog-action variant="danger">
Delete
</wc-duostrap-alert-dialog-action>
</wc-duostrap-alert-dialog-footer>
</wc-duostrap-alert-dialog-content>
</wc-duostrap-alert-dialog-root>受控状态(Controlled)
Section titled “受控状态(Controlled)”传入 open 并监听 openChange 与 action 事件,由父组件同步状态。
Web Components React Vue Vue 2
正在加载交互示例… 正文和源码已可阅读,交互控件就绪后会显示在这里。
<wc-duostrap-alert-dialog-root id="bs-controlled">
<wc-duostrap-alert-dialog-trigger>
Archive Workspace
</wc-duostrap-alert-dialog-trigger>
<wc-duostrap-alert-dialog-mask></wc-duostrap-alert-dialog-mask>
<wc-duostrap-alert-dialog-content>
<wc-duostrap-alert-dialog-title>
Archive this workspace?
</wc-duostrap-alert-dialog-title>
<wc-duostrap-alert-dialog-description>
Members will keep read-only access until an administrator
restores the workspace.
</wc-duostrap-alert-dialog-description>
<wc-duostrap-alert-dialog-footer>
<wc-duostrap-alert-dialog-cancel>
Cancel
</wc-duostrap-alert-dialog-cancel>
<wc-duostrap-alert-dialog-action>
Archive
</wc-duostrap-alert-dialog-action>
</wc-duostrap-alert-dialog-footer>
</wc-duostrap-alert-dialog-content>
</wc-duostrap-alert-dialog-root>
<script type="module">
import { setElementProps } from '@proto.ui/adapter-web-component';
const root = document.querySelector('#bs-controlled');
setElementProps(root, { open: false });
root.addEventListener('openChange', (e) =>
setElementProps(root, { open: e.detail.open })
);
</script>| 属性 / 事件 / 方法 | 类型 | 默认值 |
|---|---|---|
open | boolean | undefined(非受控) |
defaultOpen | boolean | false |
disabled | boolean | false |
a11yLabel | string | '' |
openChange(事件) | { open: boolean; reason: string null; focusReason: string null } | — |
openAlertDialog / close / toggle(方法) | (reason?: string) => void | — |
Content、Mask、Footer 与命令部件
Section titled “Content、Mask、Footer 与命令部件”| 部件与属性 / 事件 | 类型 | 默认值 |
|---|---|---|
Content.size | 'default' 'sm' | 'default'(560px) |
Content.enterDuration / leaveDuration | number | 300 |
Mask.passthrough | boolean | false |
Mask.enterDuration / leaveDuration | number | 150 |
Footer | 被动容器(无独立属性) | — |
Trigger.variant | 'default' 'primary' 'warning' 'danger' 'success' 'info' 'inverse' | 'default' |
Action.variant | 'default' 'primary' 'warning' 'danger' 'success' 'info' 'inverse' | 'primary' |
Trigger / Cancel / Action.disabled | boolean | false |
Action.action(事件) | { reason: string } | — |