|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { TeleportProps, TransitionProps } from 'vue' |
| 3 | +import { ModalsContainer, VueFinalModal, useModal } from 'vue-final-modal' |
| 4 | +
|
| 5 | +const initValues = { |
| 6 | + teleportTo: 'body', |
| 7 | + modelValue: false, |
| 8 | + displayDirective: 'if', |
| 9 | + hideOverlay: false, |
| 10 | + overlayTransition: { name: 'vfm' }, |
| 11 | + contentTransition: { name: 'vfm' }, |
| 12 | + clickToClose: true, |
| 13 | + escToClose: true, |
| 14 | + background: 'non-interactive', |
| 15 | + lockScroll: true, |
| 16 | +} as const |
| 17 | +
|
| 18 | +const modalId = Symbol('modalId') |
| 19 | +
|
| 20 | +const modelValue = ref<boolean>(initValues.modelValue) |
| 21 | +const teleportTo = ref<string>(initValues.teleportTo) |
| 22 | +const displayDirective = ref<'if' | 'show'>(initValues.displayDirective) |
| 23 | +const hideOverlay = ref(initValues.hideOverlay) |
| 24 | +const overlayTransition = ref<TransitionProps>(initValues.overlayTransition) |
| 25 | +const contentTransition = ref<TransitionProps>(initValues.contentTransition) |
| 26 | +const clickToClose = ref(initValues.clickToClose) |
| 27 | +const escToClose = ref(initValues.escToClose) |
| 28 | +const background = ref<'non-interactive' | 'interactive'>(initValues.background) |
| 29 | +const lockScroll = ref(initValues.lockScroll) |
| 30 | +
|
| 31 | +function reset() { |
| 32 | + modelValue.value = initValues.modelValue |
| 33 | + teleportTo.value = initValues.teleportTo |
| 34 | + displayDirective.value = initValues.displayDirective |
| 35 | + hideOverlay.value = initValues.hideOverlay |
| 36 | + overlayTransition.value = initValues.overlayTransition |
| 37 | + contentTransition.value = initValues.contentTransition |
| 38 | + clickToClose.value = initValues.clickToClose |
| 39 | + escToClose.value = initValues.escToClose |
| 40 | + background.value = initValues.background |
| 41 | + lockScroll.value = initValues.lockScroll |
| 42 | +} |
| 43 | +</script> |
| 44 | + |
| 45 | +<template> |
| 46 | + <div class="grid grid-cols-[150px_1fr] gap-y-2"> |
| 47 | + <h3>modelValue:</h3> |
| 48 | + <NSwitch v-model="modelValue" /> |
| 49 | + |
| 50 | + <h3>hideOverlay:</h3> |
| 51 | + <NSwitch v-model="hideOverlay" /> |
| 52 | + |
| 53 | + <h3>clickToClose:</h3> |
| 54 | + <NSwitch v-model="clickToClose" /> |
| 55 | + |
| 56 | + <h3>escToClose:</h3> |
| 57 | + <NSwitch v-model="escToClose" /> |
| 58 | + |
| 59 | + <h3>lockScroll:</h3> |
| 60 | + <NSwitch v-model="lockScroll" /> |
| 61 | + |
| 62 | + <h3>displayDirective: </h3> |
| 63 | + <div class="flex space-x-4 whitespace-nowrap"> |
| 64 | + <NRadio v-model="displayDirective" name="name" value="if"> |
| 65 | + if |
| 66 | + </NRadio> |
| 67 | + <NRadio |
| 68 | + v-model="displayDirective" |
| 69 | + name="name" |
| 70 | + value="show" |
| 71 | + > |
| 72 | + show |
| 73 | + </NRadio> |
| 74 | + </div> |
| 75 | + |
| 76 | + <h3>background: </h3> |
| 77 | + <div class="flex space-x-4 whitespace-nowrap"> |
| 78 | + <NRadio v-model="background" name="name" value="interactive"> |
| 79 | + interactvie |
| 80 | + </NRadio> |
| 81 | + <NRadio |
| 82 | + v-model="background" |
| 83 | + name="name" |
| 84 | + value="non-interactive" |
| 85 | + > |
| 86 | + non-interactvie |
| 87 | + </NRadio> |
| 88 | + </div> |
| 89 | + </div> |
| 90 | + |
| 91 | + <div class="mt-4 space-x-4"> |
| 92 | + <NButton n="sm" class="ml-auto" @click="modelValue = true"> |
| 93 | + Open modal |
| 94 | + </NButton> |
| 95 | + <NButton n="sm" @click="reset"> |
| 96 | + Reset |
| 97 | + </NButton> |
| 98 | + </div> |
| 99 | + |
| 100 | + <VueFinalModal |
| 101 | + v-model="modelValue" |
| 102 | + :modal-id="modalId" |
| 103 | + :teleport-to="teleportTo" |
| 104 | + :display-directive="displayDirective" |
| 105 | + :hide-overlay="hideOverlay" |
| 106 | + :overlay-transition="overlayTransition" |
| 107 | + :content-transition="contentTransition" |
| 108 | + :click-to-close="clickToClose" |
| 109 | + :esc-to-close="escToClose" |
| 110 | + :background="background" |
| 111 | + :lock-scroll="lockScroll" |
| 112 | + class="flex justify-center items-center" |
| 113 | + content-class="max-w-xl mx-4 p-4 bg-white dark:bg-gray-900 border dark:border-gray-700 rounded-lg space-y-2" |
| 114 | + > |
| 115 | + <h1 class="text-xl"> |
| 116 | + Hello World! |
| 117 | + </h1> |
| 118 | + <p>Magna deserunt nulla aliquip velit aute. Et occaecat elit nulla excepteur labore cupidatat. Duis culpa mollit commodo dolor qui Lorem qui laborum elit elit Lorem occaecat. Commodo eiusmod esse voluptate officia amet quis occaecat aliqua. Proident do irure amet ut occaecat dolor laboris consectetur.</p> |
| 119 | + <NButton @click="modelValue = false"> |
| 120 | + Close |
| 121 | + </NButton> |
| 122 | + </VueFinalModal> |
| 123 | + |
| 124 | + <ModalsContainer /> |
| 125 | +</template> |
0 commit comments