Dialog pops up a dialog box, and it's quite customizable.
Set model-value / v-model attribute with a Boolean, and Dialog shows when it is true. The Dialog has two parts: body and footer, and the latter requires a slot named footer. The optional title attribute (empty by default) is for defining a title. Finally, this example demonstrates how before-close is used.
<template><b-buttonsmall@click.prevent="dialogVisible = true">Open Dialog</b-button><b-dialogv-model="dialogVisible"title="Tips"width="30%":before-close="handleClose"><span>This is a message</span><template#footer><divclass="flex justify-end"><b-buttonclass="mr-4"@click="dialogVisible = false">Cancel</b-button><b-buttontype="primary"@click="dialogVisible = false">Confirm</b-button></div></template></b-dialog></template><scriptlang="ts"setup>import{ ref }from'vue'import{ BMessageBox }from'bigin-ui'const dialogVisible =ref(false)consthandleClose=(done:()=>void)=>{
BMessageBox.confirm('Are you sure to close this dialog?').then(()=>{done()}).catch(()=>{// catch error})}</script>
TIP
before-close only works when user clicks the close icon or the backdrop. If you have buttons that close the Dialog in the footer named slot, you can add what you would do with before-close in the buttons' click event handler.
The header slot can be used to customize the area where the title is displayed. In order to maintain accessibility, use the title attribute in addition to using this slot, or use the titleId slot property to specify which element should be read out as the dialog title.
<template><b-buttonsmall@click="visible = true">
Open Dialog with customized header
</b-button><b-dialogv-model="visible":show-close="false"><template#header="{ close, titleId, titleClass }"><divclass="flex w-full items-center justify-between"><h4:id="titleId":class="titleClass">This is a custom header!</h4><b-buttondangersmall:prefix-icon="Close"@click="close">
Close
</b-button></div></template>
This is dialog content.
</b-dialog></template><scriptlang="ts"setup>import{ ref }from'vue'import{ Close }from'@bigin/icons-vue'const visible =ref(false)</script>
If a Dialog is nested in another Dialog, append-to-body is required.
Normally we do not recommend using nested Dialog. If you need multiple Dialogs rendered on the page, you can simply flat them so that they're siblings to each other. If you must nest a Dialog inside another Dialog, set append-to-body of the nested Dialog to true, and it will append to body instead of its parent node, so both Dialogs can be correctly rendered.
Setting center to true will center dialog's header and footer horizontally. center only affects Dialog's header and footer. The body of Dialog can be anything, so sometimes it may not look good when centered. You need to write some CSS if you wish to center the body as well.
<template><b-buttonsmall@click="centerDialogVisible = true">Open Dialog</b-button><b-dialogv-model="centerDialogVisible"title="Warning"size="small"center><span>It should be noted that the content will not be aligned in center by
default</span><template#footer><spanclass="flex justify-end"><b-buttonclass="mr-4"@click="centerDialogVisible = false">Cancel</b-button><b-buttontype="primary"@click="centerDialogVisible = false">Confirm</b-button></span></template></b-dialog></template><scriptlang="ts"setup>import{ ref }from'vue'const centerDialogVisible =ref(false)</script>
When this is feature is enabled, the content under default slot will be destroyed with a v-if directive. Enable this when you have perf concerns.
Note that by enabling this feature, the content will not be rendered before transition.beforeEnter dispatched, there will only be overlay header(if any) footer(if any).
<template><b-buttonsmall@click="centerDialogVisible = true">Open Dialog</b-button><b-dialogv-model="centerDialogVisible"title="Notice"width="30%"destroy-on-closecenter><span>Notice: before dialog gets opened for the first time this node and the
one bellow will not be rendered</span><div><strong>Extra content (Not rendered)</strong></div><template#footer><spanclass="flex justify-end"><b-buttonclass="mr-4"@click="centerDialogVisible = false">Cancel</b-button><b-buttontype="primary"@click="centerDialogVisible = false">Confirm</b-button></span></template></b-dialog></template><scriptlang="ts"setup>import{ ref }from'vue'const centerDialogVisible =ref(false)</script>
When using modal = false, please make sure that append-to-body was set to true, because Dialog was positioned by position: relative, when modal gets removed, Dialog will position itself based on the current position in the DOM, instead of Document.Body, thus the style will be messed up.