2.7 KiB
RModal and dialogs
RModal inherits Naive UI Modal's show, preset, close events, and slots, then adds preset widths and fullscreen cards. Control declarative modals with show and onUpdateShow or v-model:show.
import { RModal } from '@/components'
import { NButton } from 'naive-ui'
import { defineComponent, ref } from 'vue'
export default defineComponent({
setup() {
const show = ref(false)
return () => (
<>
<NButton
onClick={() => {
show.value = true
}}
>
View report
</NButton>
<RModal
show={show.value}
onUpdateShow={(value) => {
show.value = value
}}
preset="card"
title="Inventory report"
cardWidth={960}
>
Report contents
</RModal>
</>
)
},
})
| Prop | Default | Applies to |
|---|---|---|
width |
600 |
Width without a preset. |
cardWidth |
600 |
Width with preset="card". |
dialogWidth |
446 |
Width with preset="dialog". |
fullscreen |
false |
Card preset only. |
Widths accept numbers or CSS dimensions. fullscreen stretches the card across the viewport and scrolls overflowing body content. It is a layout mode outside the browser Fullscreen API. Slots such as default, header, and footer are forwarded with their Naive UI preset behavior.
Interactive example
::: details View example source <<< @/../admin/src/views/demo/modal-demo/index.tsx :::
Imperative modals
useModal() from @/components is deprecated. Legacy integrations can still call create(options) and destroyAll(). create returns a Naive UI modal handle and accepts compatibility options such as fullscreen, width, cardWidth, and dialogWidth. New code can import useModal from naive-ui and call it inside an NModalProvider. Use declarative RModal for the template's fullscreen styles. The global Dialog provider can also confirm destructive actions.