|
1 | 1 | <template> |
2 | | - <div |
3 | | - v-if="isOpen" |
4 | | - class="fixed inset-0 bg-black bg-opacity-15 flex justify-center items-center z-[99]" |
5 | | - @click.self="closeModal" /> |
6 | | - <Transition name="modal"> |
| 2 | + <Teleport to="#modal"> |
7 | 3 | <div |
8 | 4 | v-if="isOpen" |
9 | | - class="bg-white rounded-lg shadow-lg px-8 py-8 fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[99]"> |
10 | | - <div class="flex flex-col gap-8 w-[300px]"> |
11 | | - <div class="flex flex-col gap-6"> |
12 | | - <div class="flex flex-col items-center gap-2"> |
13 | | - <CommonIcons |
14 | | - v-if="type == 'successType'" |
15 | | - :name="successIcon" /> |
16 | | - <CommonIcons |
17 | | - v-if="type == 'failType' || type == 'inputType' || type === 'terminate'" |
18 | | - :name="failIcon" /> |
19 | | - <CommonIcons |
20 | | - v-if="type == 'warningType'" |
21 | | - :name="warningIcon" /> |
22 | | - <LoadingIcon v-if="type == 'loadingType'" /> |
23 | | - <div |
24 | | - v-if="$slots.header" |
25 | | - class="flex text-2xl font-semibold justify-center whitespace-pre-wrap text-center"> |
26 | | - <slot name="header"></slot> |
27 | | - </div> |
| 5 | + class="fixed inset-0 bg-black bg-opacity-15 flex justify-center items-center z-[99]" |
| 6 | + @click.self="closeModal" /> |
| 7 | + <Transition name="modal"> |
| 8 | + <div |
| 9 | + v-if="isOpen" |
| 10 | + class="bg-white rounded-lg shadow-lg px-8 py-8 fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[99]"> |
| 11 | + <div class="flex flex-col gap-8 w-[300px]"> |
| 12 | + <div class="flex flex-col gap-6"> |
| 13 | + <div class="flex flex-col items-center gap-2"> |
| 14 | + <CommonIcons |
| 15 | + v-if="type == 'successType'" |
| 16 | + :name="successIcon" /> |
| 17 | + <CommonIcons |
| 18 | + v-if="type == 'failType' || type == 'inputType' || type === 'terminate'" |
| 19 | + :name="failIcon" /> |
| 20 | + <CommonIcons |
| 21 | + v-if="type == 'warningType'" |
| 22 | + :name="warningIcon" /> |
| 23 | + <LoadingIcon v-if="type == 'loadingType'" /> |
| 24 | + <div |
| 25 | + v-if="$slots.header" |
| 26 | + class="flex text-2xl font-semibold justify-center whitespace-pre-wrap text-center"> |
| 27 | + <slot name="header"></slot> |
| 28 | + </div> |
28 | 29 |
|
29 | | - <div |
30 | | - v-if="type != 'inputType' && $slots.body" |
31 | | - class="flex text-sm font-semibold text-body justify-center whitespace-pre-wrap text-center"> |
32 | | - <slot name="body"></slot> |
| 30 | + <div |
| 31 | + v-if="type != 'inputType' && $slots.body" |
| 32 | + class="flex text-sm font-semibold text-body justify-center whitespace-pre-wrap text-center"> |
| 33 | + <slot name="body"></slot> |
| 34 | + </div> |
33 | 35 | </div> |
| 36 | + <textarea |
| 37 | + v-if="type == 'inputType' || type === 'terminate'" |
| 38 | + v-model="textValue" |
| 39 | + :placeholder=" |
| 40 | + type === 'terminate' ? '종료 사유를 입력해주세요' : '반려 사유를 입력해주세요' |
| 41 | + " |
| 42 | + :class="{ 'border border-red-1 placeholder-red-500': isEmpty }" |
| 43 | + class="flex border w-full border-border-1 px-4 py-3 focus:outline-none resize-none h-[120px]" /> |
34 | 44 | </div> |
35 | | - <textarea |
36 | | - v-if="type == 'inputType' || type === 'terminate'" |
37 | | - v-model="textValue" |
38 | | - :placeholder=" |
39 | | - type === 'terminate' ? '종료 사유를 입력해주세요' : '반려 사유를 입력해주세요' |
40 | | - " |
41 | | - :class="{ 'border border-red-1 placeholder-red-500': isEmpty }" |
42 | | - class="flex border w-full border-border-1 px-4 py-3 focus:outline-none resize-none h-[120px]" /> |
43 | | - </div> |
44 | | - |
45 | | - <button |
46 | | - type="button" |
47 | | - class="button-large-primary" |
48 | | - v-if="type == 'successType'" |
49 | | - @click="closeModal"> |
50 | | - 확인 |
51 | | - </button> |
52 | 45 |
|
53 | | - <button |
54 | | - type="button" |
55 | | - class="button-large-default" |
56 | | - v-if="type == 'failType'" |
57 | | - @click="closeModal"> |
58 | | - 확인 |
59 | | - </button> |
60 | | - |
61 | | - <div |
62 | | - class="flex items-center gap-6" |
63 | | - v-if="type == 'warningType' || type == 'inputType' || type === 'terminate'"> |
64 | 46 | <button |
65 | 47 | type="button" |
66 | | - class="button-large-default" |
| 48 | + class="button-large-primary" |
| 49 | + v-if="type == 'successType'" |
67 | 50 | @click="closeModal"> |
68 | | - 취소 |
| 51 | + 확인 |
69 | 52 | </button> |
| 53 | + |
70 | 54 | <button |
71 | 55 | type="button" |
72 | | - class="button-large-red" |
73 | | - @click="confirmModal"> |
74 | | - {{ type === 'inputType' ? '반려' : type === 'terminate' ? '종료' : '삭제' }} |
| 56 | + class="button-large-default" |
| 57 | + v-if="type == 'failType'" |
| 58 | + @click="closeModal"> |
| 59 | + 확인 |
75 | 60 | </button> |
| 61 | + |
| 62 | + <div |
| 63 | + class="flex items-center gap-6" |
| 64 | + v-if="type == 'warningType' || type == 'inputType' || type === 'terminate'"> |
| 65 | + <button |
| 66 | + type="button" |
| 67 | + class="button-large-default" |
| 68 | + @click="closeModal"> |
| 69 | + 취소 |
| 70 | + </button> |
| 71 | + <button |
| 72 | + type="button" |
| 73 | + class="button-large-red" |
| 74 | + @click="confirmModal"> |
| 75 | + {{ type === 'inputType' ? '반려' : type === 'terminate' ? '종료' : '삭제' }} |
| 76 | + </button> |
| 77 | + </div> |
76 | 78 | </div> |
77 | 79 | </div> |
78 | | - </div> |
79 | | - </Transition> |
| 80 | + </Transition> |
| 81 | + </Teleport> |
80 | 82 | </template> |
81 | 83 |
|
82 | 84 | <script setup lang="ts"> |
83 | 85 | import { failIcon, successIcon, warningIcon } from '@/constants/iconPath' |
84 | | -import { preventEnter } from '@/utils/preventEnter' |
85 | 86 | import { onUnmounted, ref, watch } from 'vue' |
86 | 87 | import CommonIcons from './CommonIcons.vue' |
87 | 88 | import LoadingIcon from './LoadingIcon.vue' |
| 89 | +import { useIsOverlayOpenStore } from '@/stores/isOverlayOpen' |
88 | 90 |
|
89 | 91 | const { isOpen, type, modelValue, isEmpty } = defineProps<{ |
90 | 92 | isOpen: boolean |
@@ -114,22 +116,20 @@ const confirmModal = () => { |
114 | 116 | emit('click') |
115 | 117 | } |
116 | 118 |
|
| 119 | +const { setIsOverlayOpen } = useIsOverlayOpenStore() |
117 | 120 | watch( |
118 | 121 | () => isOpen, |
119 | 122 | () => { |
120 | 123 | if (isOpen) { |
121 | 124 | textValue.value = '' |
122 | | - document.body.style.overflow = 'hidden' |
123 | | - window.addEventListener('keydown', preventEnter) |
| 125 | + setIsOverlayOpen(true) |
124 | 126 | } else { |
125 | | - document.body.style.overflow = '' |
126 | | - window.removeEventListener('keydown', preventEnter) |
| 127 | + setIsOverlayOpen(false) |
127 | 128 | } |
128 | 129 | } |
129 | 130 | ) |
130 | 131 |
|
131 | 132 | onUnmounted(() => { |
132 | | - document.body.style.overflow = '' |
133 | | - window.removeEventListener('keydown', preventEnter) |
| 133 | + setIsOverlayOpen(false) |
134 | 134 | }) |
135 | 135 | </script> |
0 commit comments