BaseModal.vue
97 lines
| 1 | <script lang="ts" setup> |
| 2 | import { onMounted, onUnmounted } from 'vue'; |
| 3 | |
| 4 | import { useScrollLock } from '@/composables/useScrollLock'; |
| 5 | |
| 6 | interface Props { |
| 7 | title?: string; |
| 8 | subtitle?: string; |
| 9 | titleAlignment?: 'centered' | 'left'; |
| 10 | disableScroll?: boolean; |
| 11 | } |
| 12 | |
| 13 | const props = withDefaults(defineProps<Props>(), { |
| 14 | titleAlignment: 'left', |
| 15 | disableScroll: true |
| 16 | }); |
| 17 | |
| 18 | const { lockScroll, unlockScroll } = useScrollLock(); |
| 19 | |
| 20 | onMounted(() => { |
| 21 | if (props.disableScroll) { |
| 22 | lockScroll(); |
| 23 | } |
| 24 | }); |
| 25 | |
| 26 | onUnmounted(() => { |
| 27 | if (props.disableScroll) { |
| 28 | unlockScroll(); |
| 29 | } |
| 30 | }); |
| 31 | </script> |
| 32 | |
| 33 | <template> |
| 34 | <div class="base-modal"> |
| 35 | <div class="base-modal__header"> |
| 36 | <slot name="back-button"></slot> |
| 37 | <span |
| 38 | class="base-modal__title-container" |
| 39 | :class="{ |
| 40 | 'base-modal__title-container--centered': titleAlignment === 'centered' |
| 41 | }" |
| 42 | > |
| 43 | <slot name="title-icon"></slot> |
| 44 | <h2 v-if="title" class="base-modal__title">{{ title }}</h2> |
| 45 | </span> |
| 46 | </div> |
| 47 | <p |
| 48 | v-if="subtitle" |
| 49 | class="base-modal__subtitle" |
| 50 | :class="{ |
| 51 | 'base-modal__subtitle--centered': titleAlignment === 'centered' |
| 52 | }" |
| 53 | > |
| 54 | {{ subtitle }} |
| 55 | </p> |
| 56 | <slot></slot> |
| 57 | </div> |
| 58 | </template> |
| 59 | |
| 60 | <style lang="scss" scoped> |
| 61 | .base-modal { |
| 62 | &__header { |
| 63 | position: relative; |
| 64 | margin-bottom: 8px; |
| 65 | margin-top: -4px; |
| 66 | } |
| 67 | |
| 68 | &__title-container { |
| 69 | display: flex; |
| 70 | align-items: center; |
| 71 | justify-content: flex-start; |
| 72 | |
| 73 | &--centered { |
| 74 | justify-content: center; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | &__title { |
| 79 | font-size: 20px; |
| 80 | color: var(--neutral--700); |
| 81 | margin: 0; |
| 82 | font-weight: 700; |
| 83 | } |
| 84 | |
| 85 | &__subtitle { |
| 86 | font-size: 14px; |
| 87 | margin-top: 4px; |
| 88 | margin-bottom: 24px; |
| 89 | color: var(--neutral--500); |
| 90 | |
| 91 | &--centered { |
| 92 | text-align: center; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | </style> |
| 97 |