|
| 1 | +--- |
| 2 | +title: Recommended use |
| 3 | +description: 'Vue Final Modal is a renderless, stackable, detachable and lightweight modal component.' |
| 4 | +position: 3 |
| 5 | +category: Examples |
| 6 | +--- |
| 7 | + |
| 8 | +<alert> |
| 9 | + |
| 10 | +`VModal` is a wrapper component using `vue-final-modal`. |
| 11 | +You can copy and paste the example and adjust the `template`, `script`, `style` based on your needs. |
| 12 | + |
| 13 | +</alert> |
| 14 | + |
| 15 | +## Write a wrapper component |
| 16 | + |
| 17 | +### VModal.vue |
| 18 | + |
| 19 | +<show-code open> |
| 20 | + |
| 21 | +```vue |
| 22 | +<template> |
| 23 | + <vue-final-modal |
| 24 | + :value="value" |
| 25 | + v-bind="$attrs" |
| 26 | + classes="modal-container" |
| 27 | + content-class="modal-content" |
| 28 | + v-on="$listeners" |
| 29 | + > |
| 30 | + <button class="modal__close" @click="$emit('input', false)"> |
| 31 | + <mdi-close></mdi-close> |
| 32 | + </button> |
| 33 | + <span class="modal__title"> |
| 34 | + <slot name="title"></slot> |
| 35 | + </span> |
| 36 | + <div class="modal__content"> |
| 37 | + <slot></slot> |
| 38 | + </div> |
| 39 | + <div class="modal__action"> |
| 40 | + <button class="vfm-btn" @click="$emit('confirm')">confirm</button> |
| 41 | + <button class="vfm-btn" @click="$emit('cancel')">cancel</button> |
| 42 | + </div> |
| 43 | + </vue-final-modal> |
| 44 | +</template> |
| 45 | +
|
| 46 | +<script> |
| 47 | +export default { |
| 48 | + name: 'VModal', |
| 49 | + props: { |
| 50 | + value: { type: Boolean, default: false } |
| 51 | + } |
| 52 | +} |
| 53 | +</script> |
| 54 | +
|
| 55 | +<style scoped> |
| 56 | +::v-deep .modal-container { |
| 57 | + display: flex; |
| 58 | + justify-content: center; |
| 59 | + align-items: center; |
| 60 | +} |
| 61 | +::v-deep .modal-content { |
| 62 | + position: relative; |
| 63 | + display: flex; |
| 64 | + flex-direction: column; |
| 65 | + max-height: 90%; |
| 66 | + margin: 0 1rem; |
| 67 | + padding: 1rem; |
| 68 | + border: 1px solid #e2e8f0; |
| 69 | + border-radius: 0.25rem; |
| 70 | + background: #fff; |
| 71 | +} |
| 72 | +.modal__title { |
| 73 | + margin: 0 2rem 0 0; |
| 74 | + font-size: 1.5rem; |
| 75 | + font-weight: 700; |
| 76 | +} |
| 77 | +.modal__content { |
| 78 | + flex-grow: 1; |
| 79 | + overflow-y: auto; |
| 80 | +} |
| 81 | +.modal__action { |
| 82 | + display: flex; |
| 83 | + justify-content: center; |
| 84 | + align-items: center; |
| 85 | + flex-shrink: 0; |
| 86 | + padding: 1rem 0 0; |
| 87 | +} |
| 88 | +.modal__close { |
| 89 | + position: absolute; |
| 90 | + top: 0.5rem; |
| 91 | + right: 0.5rem; |
| 92 | +} |
| 93 | +</style> |
| 94 | +
|
| 95 | +<style scoped> |
| 96 | +.dark-mode div::v-deep .modal-content { |
| 97 | + border-color: #2d3748; |
| 98 | + background-color: #1a202c; |
| 99 | +} |
| 100 | +</style> |
| 101 | +``` |
| 102 | + |
| 103 | +</show-code> |
| 104 | + |
| 105 | +## How to use wrapper component |
| 106 | + |
| 107 | +### Live example |
| 108 | + |
| 109 | +<wrapper-example></wrapper-example> |
| 110 | + |
| 111 | +<show-code open class="pt-4"> |
| 112 | + |
| 113 | +```vue |
| 114 | +<template> |
| 115 | + <div> |
| 116 | + <v-modal v-model="show" @confirm="confirm" @cancel="cancel"> |
| 117 | + <template v-slot:title>Hello, vue-final-modal</template> |
| 118 | + <p> |
| 119 | + Vue Final Modal is a renderless, stackable, detachable and lightweight |
| 120 | + modal component. |
| 121 | + </p> |
| 122 | + </v-modal> |
| 123 | +
|
| 124 | + <button class="vfm-btn" @click="show = true">Open modal</button> |
| 125 | + </div> |
| 126 | +</template> |
| 127 | +
|
| 128 | +<script> |
| 129 | +export default { |
| 130 | + data: () => ({ |
| 131 | + show: false |
| 132 | + }), |
| 133 | + methods: { |
| 134 | + confirm() { |
| 135 | + // some code... |
| 136 | + this.show = false |
| 137 | + }, |
| 138 | + cancel() { |
| 139 | + // some code... |
| 140 | + this.show = false |
| 141 | + } |
| 142 | + } |
| 143 | +} |
| 144 | +</script> |
| 145 | +``` |
| 146 | + |
| 147 | +</show-code> |
0 commit comments