Skip to content

模态框与 confirm() ​

符合无障碍要求的模态对话框(焦点陷阱、滚动锁定、Esc、点击遮罩)、抽屉,以及基于 Promise 的 confirm()。

Modal
vue
<div class="thl-demo-row">
  <ThlButton v-for="s in ['sm','md','lg','xl']" :key="s" variant="primary" @click="size = s; open = true">{{ s }}</ThlButton>
  <ThlModal v-model:open="open" :size="size" :title="`Modal ${size}`"><p>Cras mattis consectetur purus sit amet fermentum.</p><template #footer="{ close }"><ThlButton @click="close">Close</ThlButton><ThlButton variant="primary" @click="close">Save</ThlButton></template></ThlModal>
</div>
tsx
const [open, setOpen] = useState(false);
<Button variant="primary" onClick={() => setOpen(true)}>Open</Button>
<Modal open={open} onClose={() => setOpen(false)} size="lg" title="Modal"
  footer={<><Button onClick={() => setOpen(false)}>Close</Button><Button variant="primary">Save</Button></>}>
  <p>Cras mattis consectetur purus sit amet fermentum.</p>
</Modal>
html
<button thl-button variant="primary" (click)="open.set(true)">Open</button>
<thl-modal [(open)]="open" size="lg" title="Modal">
  <p>Cras mattis consectetur purus sit amet fermentum.</p>
  <div thlModalFooter><button thl-button (click)="open.set(false)">Close</button></div>
</thl-modal>

confirm() 与 Drawer ​

confirm() 与 Drawer
vue
<div class="thl-demo-row">
  <ThlButton variant="danger" icon="trash-2" @click="del">Delete…</ThlButton>
  <ThlButton variant="info" @click="confirm({ icon: 'success', title: 'Good job!', showCancel: false })">Success</ThlButton>
  <ThlButton @click="drawer = true">Open drawer</ThlButton>
  <ThlDrawer v-model:open="drawer" title="Drawer"><p>Side content.</p></ThlDrawer>
</div>
tsx
import { confirm } from '@thl-ui/react';
if (await confirm({ icon: 'warning', title: 'Delete this file?' })) remove();

<Drawer open={drawer} onClose={() => setDrawer(false)} title="Drawer">Side content.</Drawer>
html
readonly modals = inject(ThlModalService);
async del() { if (await this.modals.confirm({ icon: 'warning', title: 'Delete this file?' })) this.remove(); }

<thl-drawer [(open)]="drawer" title="Drawer">Side content.</thl-drawer>

confirm(options) 的选项:title、text、icon(warning · danger · success · info · question)、confirmText、cancelText、confirmVariant、showCancel。默认文案来自 i18n(modal.confirmTitle、common.ok…)。需要挂载一个 ConfirmHost(AppLayout 中已包含)。

API ​

Modal

<ThlModal> · import { ThlModal } from '@thl-ui/vue'

Prop类型默认值
openboolean—
titlestring—
sizestring—
closeOnBackdropboolean—
closeOnEscboolean—
centeredboolean—
scrollableboolean—
hideCloseboolean—
modalClassstring—

事件: update:openclose

插槽: titledefaultfooter

ConfirmHost

<ThlConfirmHost> · import { ThlConfirmHost } from '@thl-ui/vue'

Prop类型默认值

Drawer

<ThlDrawer> · import { ThlDrawer } from '@thl-ui/vue'

Prop类型默认值
openboolean—
titlestring—
sidestring"end"
wideboolean—

事件: update:openclose

插槽: default