Skip to content

Commit

Permalink
Backport template too
Browse files Browse the repository at this point in the history
  • Loading branch information
mrleblanc101 authored Nov 5, 2024
1 parent df5f3b7 commit 17fee03
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 89 deletions.
77 changes: 32 additions & 45 deletions stubs/inertia-vue-ts/resources/js/Components/Modal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, onMounted, onUnmounted, watch } from 'vue';
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
const props = withDefaults(
defineProps<{
Expand All @@ -15,15 +15,18 @@ const props = withDefaults(
);
const emit = defineEmits(['close']);
const dialog = ref();
const showSlot = ref(props.show);
watch(() => props.show, () => {
if (props.show) {
document.body.style.overflow = 'hidden';
showSlot.value = true;
dialog.value?.showModal();
} else {
document.body.style.overflow = null;
setTimeout(() => {
dialog.value?.close();
showSlot.value = false;
}, 200);
}
Expand Down Expand Up @@ -64,49 +67,33 @@ const maxWidthClass = computed(() => {
</script>

<template>
<Teleport to="body">
<Transition leave-active-class="duration-200">
<div
v-show="show"
class="fixed inset-0 z-50 overflow-y-auto px-4 py-6 sm:px-0"
scroll-region
<dialog class="z-50 m-0 min-h-full min-w-full overflow-y-auto bg-transparent backdrop:bg-transparent" ref="dialog">
<div class="fixed inset-0 overflow-y-auto px-4 py-6 sm:px-0 z-50" scroll-region>
<Transition
enter-active-class="ease-out duration-300"
enter-from-class="opacity-0"
enter-to-class="opacity-100"
leave-active-class="ease-in duration-200"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<Transition
enter-active-class="ease-out duration-300"
enter-from-class="opacity-0"
enter-to-class="opacity-100"
leave-active-class="ease-in duration-200"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<div
v-show="show"
class="fixed inset-0 transform transition-all"
@click="close"
>
<div
class="absolute inset-0 bg-gray-500 opacity-75 dark:bg-gray-900"
/>
</div>
</Transition>
<div v-show="show" class="fixed inset-0 transform transition-all" @click="close">
<div class="absolute inset-0 bg-gray-500 dark:bg-gray-900 opacity-75" />
</div>
</Transition>

<Transition
enter-active-class="ease-out duration-300"
enter-from-class="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enter-to-class="opacity-100 translate-y-0 sm:scale-100"
leave-active-class="ease-in duration-200"
leave-from-class="opacity-100 translate-y-0 sm:scale-100"
leave-to-class="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<div
v-show="show"
class="mb-6 transform overflow-hidden rounded-lg bg-white shadow-xl transition-all sm:mx-auto sm:w-full dark:bg-gray-800"
:class="maxWidthClass"
>
<slot v-if="showSlot" />
</div>
</Transition>
</div>
</Transition>
</Teleport>
</template>
<Transition
enter-active-class="ease-out duration-300"
enter-from-class="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enter-to-class="opacity-100 translate-y-0 sm:scale-100"
leave-active-class="ease-in duration-200"
leave-from-class="opacity-100 translate-y-0 sm:scale-100"
leave-to-class="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<div v-show="show" class="mb-6 bg-white dark:bg-gray-800 rounded-lg overflow-hidden shadow-xl transform transition-all sm:w-full sm:mx-auto" :class="maxWidthClass">
<slot v-if="showSlot"/>
</div>
</Transition>
</div>
</dialog>
</template>
75 changes: 31 additions & 44 deletions stubs/inertia-vue/resources/js/Components/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ const props = defineProps({
});
const emit = defineEmits(['close']);
const dialog = ref();
const showSlot = ref(props.show);
watch(() => props.show, () => {
if (props.show) {
document.body.style.overflow = 'hidden';
showSlot.value = true;
dialog.value?.showModal();
} else {
document.body.style.overflow = null;
setTimeout(() => {
dialog.value?.close();
showSlot.value = false;
}, 200);
}
Expand Down Expand Up @@ -66,49 +69,33 @@ const maxWidthClass = computed(() => {
</script>
<template>
<Teleport to="body">
<Transition leave-active-class="duration-200">
<div
v-show="show"
class="fixed inset-0 z-50 overflow-y-auto px-4 py-6 sm:px-0"
scroll-region
<dialog class="z-50 m-0 min-h-full min-w-full overflow-y-auto bg-transparent backdrop:bg-transparent" ref="dialog">
<div class="fixed inset-0 overflow-y-auto px-4 py-6 sm:px-0 z-50" scroll-region>
<Transition
enter-active-class="ease-out duration-300"
enter-from-class="opacity-0"
enter-to-class="opacity-100"
leave-active-class="ease-in duration-200"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<Transition
enter-active-class="ease-out duration-300"
enter-from-class="opacity-0"
enter-to-class="opacity-100"
leave-active-class="ease-in duration-200"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<div
v-show="show"
class="fixed inset-0 transform transition-all"
@click="close"
>
<div
class="absolute inset-0 bg-gray-500 opacity-75 dark:bg-gray-900"
/>
</div>
</Transition>
<div v-show="show" class="fixed inset-0 transform transition-all" @click="close">
<div class="absolute inset-0 bg-gray-500 dark:bg-gray-900 opacity-75" />
</div>
</Transition>
<Transition
enter-active-class="ease-out duration-300"
enter-from-class="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enter-to-class="opacity-100 translate-y-0 sm:scale-100"
leave-active-class="ease-in duration-200"
leave-from-class="opacity-100 translate-y-0 sm:scale-100"
leave-to-class="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<div
v-show="show"
class="mb-6 transform overflow-hidden rounded-lg bg-white shadow-xl transition-all sm:mx-auto sm:w-full dark:bg-gray-800"
:class="maxWidthClass"
>
<slot v-if="showSlot" />
</div>
</Transition>
</div>
</Transition>
</Teleport>
</template>
<Transition
enter-active-class="ease-out duration-300"
enter-from-class="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
enter-to-class="opacity-100 translate-y-0 sm:scale-100"
leave-active-class="ease-in duration-200"
leave-from-class="opacity-100 translate-y-0 sm:scale-100"
leave-to-class="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
>
<div v-show="show" class="mb-6 bg-white dark:bg-gray-800 rounded-lg overflow-hidden shadow-xl transform transition-all sm:w-full sm:mx-auto" :class="maxWidthClass">
<slot v-if="showSlot"/>
</div>
</Transition>
</div>
</dialog>
</template>

0 comments on commit 17fee03

Please sign in to comment.