|
| 1 | +--- |
| 2 | +head.title: 'Modal Long Scroll | Examples' |
| 3 | +--- |
| 4 | + |
| 5 | +# Modal Long Scroll |
| 6 | + |
| 7 | +A long scrollable modal example like [Bootstrap Modal scrolling-long-content](https://getbootstrap.com/docs/5.3/components/modal/#scrolling-long-content) |
| 8 | + |
| 9 | +## Preview |
| 10 | + |
| 11 | +::code-group |
| 12 | + ::code-block{label="Preview" preview} |
| 13 | + ::modal-long-scroll-preview |
| 14 | + :: |
| 15 | + :: |
| 16 | + |
| 17 | + ```vue [Preview.vue] |
| 18 | + <script setup lang="ts"> |
| 19 | + import { ModalsContainer, useModal } from 'vue-final-modal' |
| 20 | + import ModalLongScroll from './ModalLongScroll.vue' |
| 21 | +
|
| 22 | + const p = `<p> |
| 23 | + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras ullamcorper, |
| 24 | + ex at blandit iaculis, nibh urna lacinia tellus, a auctor lorem libero a |
| 25 | + lectus. Nulla bibendum mollis sapien, nec euismod mi mattis cursus. |
| 26 | + Curabitur accumsan erat eu viverra fringilla. Interdum et malesuada fames |
| 27 | + ac ante ipsum primis in faucibus. Phasellus ut neque eu diam vehicula |
| 28 | + efficitur. Vivamus ultricies purus facilisis augue porttitor vestibulum a |
| 29 | + non neque. Nunc egestas risus elit, sed fringilla velit posuere et. |
| 30 | + </p>` |
| 31 | +
|
| 32 | + const { open, close } = useModal({ |
| 33 | + component: ModalLongScroll, |
| 34 | + attrs: { |
| 35 | + title: 'Hello World!', |
| 36 | + onConfirm: () => close(), |
| 37 | + }, |
| 38 | + slots: { |
| 39 | + default: p + p + p + p + p + p + p + p + p + p + p + p, |
| 40 | + }, |
| 41 | + }) |
| 42 | + </script> |
| 43 | +
|
| 44 | + <template> |
| 45 | + <VButton @click="open"> |
| 46 | + Open Modal |
| 47 | + </VButton> |
| 48 | +
|
| 49 | + <ModalsContainer /> |
| 50 | + </template> |
| 51 | +
|
| 52 | + ``` |
| 53 | +:: |
| 54 | + |
| 55 | +## `<ModalLongScroll>` component |
| 56 | + |
| 57 | +::code-group |
| 58 | + ```vue [ModalLongScroll.vue] |
| 59 | + <script setup lang="ts"> |
| 60 | + import { VueFinalModal } from 'vue-final-modal' |
| 61 | +
|
| 62 | + defineProps<{ |
| 63 | + title?: string |
| 64 | + }>() |
| 65 | +
|
| 66 | + const emit = defineEmits<{ |
| 67 | + (e: 'update:modelValue', modelValue: boolean): void |
| 68 | + (e: 'confirm'): void |
| 69 | + }>() |
| 70 | + </script> |
| 71 | +
|
| 72 | + <template> |
| 73 | + <VueFinalModal |
| 74 | + content-transition="vfm-fade" |
| 75 | + overlay-transition="vfm-fade" |
| 76 | + content-class="absolute inset-0" |
| 77 | + @update:model-value="(val) => emit('update:modelValue', val)" |
| 78 | + > |
| 79 | + <div |
| 80 | + class="absolute inset-0 h-full overflow-auto" |
| 81 | + @click.self="() => emit('update:modelValue', false)" |
| 82 | + > |
| 83 | + <div class="flex flex-col max-w-xl my-12 mx-auto p-4 bg-white dark:bg-gray-900 border dark:border-gray-700 rounded-lg space-y-2"> |
| 84 | + <h1 class="text-xl"> |
| 85 | + {{ title }} |
| 86 | + </h1> |
| 87 | + <slot /> |
| 88 | + <button class="mt-1 ml-auto px-2 border rounded-lg" @click="() => emit('confirm')"> |
| 89 | + Confirm |
| 90 | + </button> |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + </VueFinalModal> |
| 94 | + </template> |
| 95 | + ``` |
| 96 | +:: |
0 commit comments