Open home widget create forms in popup modals
The Places tab already popped its create form up over the page; every other /stp widget swapped its contents for the form instead, which meant losing sight of the list you were adding to and a cramped form inside a grid cell. Extract the Places modal into a shared components/util/Modal.vue (teleported backdrop, click-outside and Escape to close) and use it for the Feed, Bookmarks, Favorites, Consumption and Rowing create forms as well. Widget headers keep their normal titles now that each form carries its own heading in the modal. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KcFtkisHcKJuTZAnv3fVzA
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
<script setup>
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
|
||||
// "+" / "x" button, shown to admins only. Toggles a home widget between its
|
||||
// normal view and its create form. Designed for <Header>'s #action slot.
|
||||
// "+" / "x" button, shown to admins only. Opens a home widget's create form in
|
||||
// a popup <Modal>. Designed for <Header>'s #action slot.
|
||||
const show = defineModel({ type: Boolean, default: false });
|
||||
const auth = useAuthStore();
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<script setup>
|
||||
import { watch, onUnmounted } from "vue";
|
||||
|
||||
// Popup modal: a dimmed backdrop over the page with the content floated on top.
|
||||
// Closes on backdrop click or Escape. Used by the home widgets so their create
|
||||
// forms pop up instead of replacing the widget's contents.
|
||||
const open = defineModel({ type: Boolean, default: false });
|
||||
|
||||
const props = defineProps({
|
||||
maxWidth: { type: String, default: "420px" },
|
||||
});
|
||||
|
||||
function onKeydown(e) {
|
||||
if (e.key === "Escape") open.value = false;
|
||||
}
|
||||
|
||||
watch(
|
||||
open,
|
||||
(isOpen) => {
|
||||
if (isOpen) {
|
||||
window.addEventListener("keydown", onKeydown);
|
||||
} else {
|
||||
window.removeEventListener("keydown", onKeydown);
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
onUnmounted(() => window.removeEventListener("keydown", onKeydown));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div v-if="open" class="modal-backdrop" @click.self="open = false">
|
||||
<div class="modal bdr-1" :style="{ maxWidth: props.maxWidth }">
|
||||
<slot />
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.modal-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background-color: rgba(0, 0, 0, 0.65);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 50;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.modal {
|
||||
background-color: var(--color-surface);
|
||||
padding: 16px;
|
||||
width: 100%;
|
||||
max-height: 90vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user