Skip to content

Commit

Permalink
Backport JetStream enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
mrleblanc101 authored Nov 5, 2024
1 parent 2c7c669 commit df5f3b7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 36 deletions.
42 changes: 24 additions & 18 deletions stubs/inertia-vue-ts/resources/js/Components/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ const props = withDefaults(
);
const emit = defineEmits(['close']);
const showSlot = ref(props.show);
watch(
() => props.show,
() => {
if (props.show) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = 'visible';
}
},
);
watch(() => props.show, () => {
if (props.show) {
document.body.style.overflow = 'hidden';
showSlot.value = true;
} else {
document.body.style.overflow = null;
setTimeout(() => {
showSlot.value = false;
}, 200);
}
});
const close = () => {
if (props.closeable) {
Expand All @@ -34,24 +36,28 @@ const close = () => {
};
const closeOnEscape = (e: KeyboardEvent) => {
if (e.key === 'Escape' && props.show) {
close();
if (e.key === 'Escape') {
e.preventDefault();
if (props.show) {
close();
}
}
};
onMounted(() => document.addEventListener('keydown', closeOnEscape));
onUnmounted(() => {
document.removeEventListener('keydown', closeOnEscape);
document.body.style.overflow = 'visible';
document.body.style.overflow = null;
});
const maxWidthClass = computed(() => {
return {
sm: 'sm:max-w-sm',
md: 'sm:max-w-md',
lg: 'sm:max-w-lg',
xl: 'sm:max-w-xl',
'sm': 'sm:max-w-sm',
'md': 'sm:max-w-md',
'lg': 'sm:max-w-lg',
'xl': 'sm:max-w-xl',
'2xl': 'sm:max-w-2xl',
}[props.maxWidth];
});
Expand Down Expand Up @@ -97,7 +103,7 @@ const maxWidthClass = computed(() => {
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="show" />
<slot v-if="showSlot" />
</div>
</Transition>
</div>
Expand Down
42 changes: 24 additions & 18 deletions stubs/inertia-vue/resources/js/Components/Modal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { computed, onMounted, onUnmounted, watch } from 'vue';
import { computed, onMounted, onUnmounted, ref, watch } from 'vue';
const props = defineProps({
show: {
Expand All @@ -17,17 +17,19 @@ const props = defineProps({
});
const emit = defineEmits(['close']);
const showSlot = ref(props.show);
watch(
() => props.show,
() => {
if (props.show) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = null;
}
},
);
watch(() => props.show, () => {
if (props.show) {
document.body.style.overflow = 'hidden';
showSlot.value = true;
} else {
document.body.style.overflow = null;
setTimeout(() => {
showSlot.value = false;
}, 200);
}
});
const close = () => {
if (props.closeable) {
Expand All @@ -36,8 +38,12 @@ const close = () => {
};
const closeOnEscape = (e) => {
if (e.key === 'Escape' && props.show) {
close();
if (e.key === 'Escape') {
e.preventDefault();
if (props.show) {
close();
}
}
};
Expand All @@ -50,10 +56,10 @@ onUnmounted(() => {
const maxWidthClass = computed(() => {
return {
sm: 'sm:max-w-sm',
md: 'sm:max-w-md',
lg: 'sm:max-w-lg',
xl: 'sm:max-w-xl',
'sm': 'sm:max-w-sm',
'md': 'sm:max-w-md',
'lg': 'sm:max-w-lg',
'xl': 'sm:max-w-xl',
'2xl': 'sm:max-w-2xl',
}[props.maxWidth];
});
Expand Down Expand Up @@ -99,7 +105,7 @@ const maxWidthClass = computed(() => {
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="show" />
<slot v-if="showSlot" />
</div>
</Transition>
</div>
Expand Down

0 comments on commit df5f3b7

Please sign in to comment.