Modals.vue
135 lines
| 1 | <script lang="ts" setup> |
| 2 | import { computed, defineAsyncComponent } from "vue"; |
| 3 | |
| 4 | import Icon from "@/components/Icon/Icon.vue"; |
| 5 | import { useModal } from "@/composables"; |
| 6 | import { useModalStore } from "@/stores"; |
| 7 | |
| 8 | const { closeModal } = useModal(); |
| 9 | const modalStore = useModalStore(); |
| 10 | const activeModal = computed(() => modalStore.activeModal); |
| 11 | |
| 12 | const modalComponent = computed( |
| 13 | () => |
| 14 | activeModal.value && |
| 15 | defineAsyncComponent( |
| 16 | () => import(`@/components/Modals/${activeModal.value?.name}.vue`) |
| 17 | ) |
| 18 | ); |
| 19 | </script> |
| 20 | |
| 21 | <template> |
| 22 | <Transition name="fade"> |
| 23 | <div |
| 24 | v-if="activeModal" |
| 25 | class="modal__wrapper" |
| 26 | > |
| 27 | <div |
| 28 | class="modal__container" |
| 29 | :class="{ |
| 30 | 'modal__container--xxl': activeModal.settings?.isXXL, |
| 31 | 'modal__container--xl': activeModal.settings?.isXL, |
| 32 | 'modal__container--lg': activeModal.settings?.isLG, |
| 33 | }" |
| 34 | > |
| 35 | <Icon |
| 36 | v-if="activeModal.settings?.hasCloseButton" |
| 37 | name="icon-close" |
| 38 | class="modal__icon" |
| 39 | color="gray" |
| 40 | @click="closeModal" |
| 41 | /> |
| 42 | <div |
| 43 | class="modal__content" |
| 44 | :class="{ |
| 45 | 'modal__content--no-content-padding': |
| 46 | activeModal.settings?.noContentPadding, |
| 47 | 'modal__content--no-border': |
| 48 | activeModal.settings?.noBorder, |
| 49 | }" |
| 50 | > |
| 51 | <component |
| 52 | :is="modalComponent" |
| 53 | v-bind="activeModal.data" |
| 54 | /> |
| 55 | </div> |
| 56 | </div> |
| 57 | </div> |
| 58 | </Transition> |
| 59 | </template> |
| 60 | |
| 61 | <style lang="scss" scoped> |
| 62 | .modal { |
| 63 | &__wrapper { |
| 64 | --modal-backdrop: rgba(0, 0, 0, 0.3); |
| 65 | |
| 66 | overflow: auto; |
| 67 | position: fixed; |
| 68 | z-index: var(--z-index-modal); |
| 69 | height: 100%; |
| 70 | top: 0; |
| 71 | left: 0; |
| 72 | bottom: 0; |
| 73 | right: 0; |
| 74 | background-color: var(--modal-backdrop); |
| 75 | display: flex; |
| 76 | align-items: center; |
| 77 | justify-content: center; |
| 78 | |
| 79 | &.is-above-intercom { |
| 80 | z-index: var(--z-index-intercom-2); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | &__icon { |
| 85 | position: absolute; |
| 86 | top: 16px; |
| 87 | right: 16px; |
| 88 | cursor: pointer; |
| 89 | } |
| 90 | |
| 91 | &__container { |
| 92 | position: relative; |
| 93 | max-height: calc(100vh - 6rem); |
| 94 | width: 100%; |
| 95 | max-width: 500px; |
| 96 | |
| 97 | &--auto-width { |
| 98 | max-width: none !important; |
| 99 | width: auto; |
| 100 | } |
| 101 | |
| 102 | &--lg { |
| 103 | max-width: 600px; |
| 104 | } |
| 105 | |
| 106 | &--xl { |
| 107 | max-width: 800px; |
| 108 | } |
| 109 | |
| 110 | &--xxl { |
| 111 | max-width: 964px; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | &__content { |
| 116 | border: 1px solid var(--gray-border); |
| 117 | border-radius: 16px; |
| 118 | background-color: var(--light); |
| 119 | |
| 120 | padding: 32px 40px 40px; |
| 121 | @media screen and (max-width: 600px) { |
| 122 | padding: 32px 40px 40px; |
| 123 | } |
| 124 | |
| 125 | &--no-content-padding { |
| 126 | padding: 0; |
| 127 | } |
| 128 | |
| 129 | &--no-border { |
| 130 | border: none; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | </style> |
| 135 |