feat. alert, confirm 모달 추가

This commit is contained in:
clkim
2025-10-16 10:34:42 +09:00
parent fb8b418b52
commit d61f5aa875
31 changed files with 317 additions and 275 deletions

View File

@@ -0,0 +1,59 @@
<script setup lang="ts">
interface props {
isShowDimmed?: boolean
contentText?: string
confirmButtonText?: string
isOutsideClose?: boolean
className?: string
}
const props = withDefaults(defineProps<props>(), {
isShowDimmed: false,
isOutsideClose: true,
})
const emit = defineEmits(['confirmButtonEvent'])
const isOpen = defineModel<boolean>('isOpen', { default: false })
const setButtonEvent = (event?: () => void | void) => {
if (typeof event === 'function') {
return event()
}
isOpen.value = false
}
const handleOutsideClick = () => {
if (props.isOutsideClose) {
isOpen.value = false
}
}
</script>
<template>
<Transition name="opacity-on">
<div
v-if="isOpen"
:class="['modal-wrap', { dimmed: props.isShowDimmed }, props.className]"
@click="handleOutsideClick"
>
<div class="modal-area" @click.stop>
<div class="modal-content">
<p
v-if="props.contentText"
v-dompurify-html="props.contentText"
class="content-text"
></p>
<slot></slot>
<div class="content-btns">
<AtomsButtonModal
@click="setButtonEvent(() => emit('confirmButtonEvent'))"
>
{{ props.confirmButtonText || '확인' }}
</AtomsButtonModal>
</div>
</div>
</div>
</div>
</Transition>
</template>

View File

@@ -0,0 +1,66 @@
<script setup lang="ts">
interface props {
isShowDimmed?: boolean
contentText?: string
confirmButtonText?: string
cancelButtonText?: string
isOutsideClose?: boolean
className?: string
}
const props = withDefaults(defineProps<props>(), {
isShowDimmed: false,
isOutsideClose: true,
})
const emit = defineEmits(['cancelButtonEvent', 'confirmButtonEvent'])
const isOpen = defineModel<boolean>('isOpen', { default: false })
const setButtonEvent = (event: () => void | void) => {
if (event) {
return event()
}
isOpen.value = false
}
const handleOutsideClick = () => {
if (props.isOutsideClose) {
isOpen.value = false
}
}
</script>
<template>
<Transition name="opacity-on">
<div
v-if="isOpen"
:class="['modal-wrap', { dimmed: props.isShowDimmed }, props.className]"
@click="handleOutsideClick"
>
<div class="modal-area" @click.stop>
<div class="modal-content">
<p
v-if="props.contentText"
v-dompurify-html="props.contentText"
class="content-text"
></p>
<slot></slot>
<div class="content-btns">
<AtomsButtonModal
variant="outlined"
@click="setButtonEvent(() => emit('cancelButtonEvent'))"
>
{{ props.cancelButtonText || '취소' }}
</AtomsButtonModal>
<AtomsButtonModal
@click="setButtonEvent(() => emit('confirmButtonEvent'))"
>
{{ props.confirmButtonText || '확인' }}
</AtomsButtonModal>
</div>
</div>
</div>
</div>
</Transition>
</template>

View File

@@ -1,3 +1,52 @@
<script setup lang="ts">
import { getYouTubeEmbedUrl } from '#layers/utils/youtube'
interface Props {
youtubeUrl: string
isOutsideClose?: boolean
className?: string
}
const props = withDefaults(defineProps<Props>(), {
youtubeUrl: '',
isOutsideClose: true,
})
const emit = defineEmits(['closeButtonEvent'])
const isOpen = defineModel<boolean>('isOpen', { default: false })
const embedUrl = computed(() => {
return getYouTubeEmbedUrl(props.youtubeUrl)
})
const handleCloseModal = () => {
isOpen.value = false
emit('closeButtonEvent')
}
const handleKeydown = (event: KeyboardEvent) => {
if (event.key === 'Escape' && isOpen.value) {
handleCloseModal()
}
}
const handleOutsideClick = () => {
if (props.isOutsideClose) {
handleCloseModal()
}
}
// 키보드 이벤트 리스너 등록/해제
onMounted(() => {
document.addEventListener('keydown', handleKeydown)
})
onUnmounted(() => {
document.removeEventListener('keydown', handleKeydown)
})
</script>
<template>
<Transition
enter-active-class="transition duration-300 ease-out"
@@ -10,10 +59,10 @@
<div
v-if="isOpen"
class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-75"
@click="handleBackdropClick"
:class="props.className"
@click="handleOutsideClick"
>
<div
v-if="isOpen"
class="relative mx-4 my-4"
style="
width: min(896px, 90vw, calc((90vh - 2rem) * 16 / 9));
@@ -26,7 +75,7 @@
<button
class="text-white rounded-full transition-colors"
aria-label="모달 닫기"
@click="closeModal"
@click="handleCloseModal"
>
<AtomsIconsCloseLine />
</button>
@@ -48,61 +97,3 @@
</div>
</Transition>
</template>
<script setup lang="ts">
import { getYouTubeEmbedUrl } from '#layers/utils/youtube'
interface Props {
isOpen: boolean
youtubeUrl: string
title?: string
description?: string
closeOnBackdrop?: boolean
}
interface Emits {
(e: 'closeButtonEvent'): void
}
const props = withDefaults(defineProps<Props>(), {
isOpen: false,
youtubeUrl: '',
title: '',
description: '',
closeOnBackdrop: true,
})
const emit = defineEmits<Emits>()
const embedUrl = computed(() => {
return getYouTubeEmbedUrl(props.youtubeUrl)
})
// ESC 키로 모달 닫기
const handleKeydown = (event: KeyboardEvent) => {
if (event.key === 'Escape' && props.isOpen) {
closeModal()
}
}
// 배경 클릭으로 모달 닫기
const handleBackdropClick = () => {
if (props.closeOnBackdrop) {
closeModal()
}
}
// 모달 닫기 함수
const closeModal = () => {
emit('closeButtonEvent')
}
// 키보드 이벤트 리스너 등록/해제
onMounted(() => {
document.addEventListener('keydown', handleKeydown)
})
onUnmounted(() => {
document.removeEventListener('keydown', handleKeydown)
})
</script>