2022-11-23 12:48:01 +09:00
|
|
|
<script setup lang='ts'>
|
2022-11-27 10:52:46 +09:00
|
|
|
import { useFocusTrap } from '@vueuse/integrations/useFocusTrap'
|
|
|
|
|
|
|
|
type DialogType = 'top' | 'right' | 'bottom' | 'left' | 'dialog'
|
|
|
|
|
|
|
|
const {
|
|
|
|
type = 'dialog',
|
|
|
|
} = defineProps<{
|
|
|
|
type?: DialogType
|
|
|
|
}>()
|
|
|
|
|
2022-11-23 12:48:01 +09:00
|
|
|
const { modelValue } = defineModel<{
|
|
|
|
modelValue: boolean
|
|
|
|
}>()
|
2022-11-24 17:04:53 +09:00
|
|
|
|
2022-11-27 10:52:46 +09:00
|
|
|
const positionClass = computed(() => {
|
|
|
|
switch (type) {
|
|
|
|
case 'dialog':
|
|
|
|
return 'border rounded top-1/2 -translate-y-1/2 left-1/2 -translate-x-1/2'
|
|
|
|
case 'bottom':
|
|
|
|
return 'bottom-0 left-0 right-0 border-t'
|
|
|
|
case 'top':
|
|
|
|
return 'top-0 left-0 right-0 border-b'
|
|
|
|
case 'left':
|
|
|
|
return 'bottom-0 left-0 top-0 border-r'
|
|
|
|
case 'right':
|
|
|
|
return 'bottom-0 top-0 right-0 border-l'
|
|
|
|
default:
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const transform = computed(() => {
|
|
|
|
switch (type) {
|
|
|
|
case 'bottom':
|
|
|
|
return 'translateY(100%)'
|
|
|
|
case 'top':
|
|
|
|
return 'translateY(-100%)'
|
|
|
|
case 'left':
|
|
|
|
return 'translateX(-100%)'
|
|
|
|
case 'right':
|
|
|
|
return 'translateX(100%)'
|
|
|
|
default:
|
|
|
|
return ''
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const target = ref<HTMLElement | null>(null)
|
|
|
|
const { activate, deactivate } = useFocusTrap(target)
|
|
|
|
|
|
|
|
watchEffect(() => {
|
|
|
|
if (modelValue)
|
|
|
|
activate()
|
|
|
|
else
|
|
|
|
deactivate()
|
|
|
|
})
|
|
|
|
|
2022-11-24 20:48:31 +09:00
|
|
|
let init = $ref(modelValue)
|
2022-11-24 17:04:53 +09:00
|
|
|
watchOnce(modelValue, () => {
|
|
|
|
init = true
|
|
|
|
})
|
2022-11-23 12:48:01 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
2022-11-27 10:52:46 +09:00
|
|
|
fixed top-0 bottom-0 left-0 right-0 z-40
|
2022-11-23 12:48:01 +09:00
|
|
|
:class="modelValue ? '' : 'pointer-events-none'"
|
|
|
|
>
|
|
|
|
<div
|
2022-11-27 10:52:46 +09:00
|
|
|
bg-base bottom-0 left-0 right-0 top-0 absolute transition-opacity duration-500 ease-out
|
2022-11-23 12:48:01 +09:00
|
|
|
:class="modelValue ? 'opacity-85' : 'opacity-0'"
|
|
|
|
@click="modelValue = false"
|
|
|
|
/>
|
|
|
|
<div
|
2022-11-27 10:52:46 +09:00
|
|
|
ref="target" bg-base border-base absolute transition-all duration-200
|
|
|
|
ease-out
|
|
|
|
:class="positionClass"
|
|
|
|
:style="modelValue ? {} : { transform }"
|
2022-11-23 12:48:01 +09:00
|
|
|
>
|
2022-11-24 17:04:53 +09:00
|
|
|
<slot v-if="init" />
|
2022-11-23 12:48:01 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|