Move edit form to modal dialog

This commit is contained in:
Adrian Gruntkowski 2024-12-08 20:11:30 +01:00
parent 890ae55334
commit 97365447e1
3 changed files with 42 additions and 10 deletions

View file

@ -77,7 +77,11 @@
</div> </div>
</note-form> </note-form>
<note-form mode="edit" id="edit-note" class="hidden"> <div id="notes"></div>
</div>
<dialog id="edit-note-dialog">
<note-form mode="edit" id="edit-note">
<div class="note"> <div class="note">
<p class="content"></p> <p class="content"></p>
<div class="toolbar"> <div class="toolbar">
@ -88,9 +92,7 @@
</div> </div>
</div> </div>
</note-form> </note-form>
</dialog>
<div id="notes"></div>
</div>
<template id="task-list-item"> <template id="task-list-item">
<div class="handle">||</div> <div class="handle">||</div>

View file

@ -95,6 +95,7 @@ if (notificationsAvailable()) {
const newNote = document.querySelector("#new-note"); const newNote = document.querySelector("#new-note");
const editNote = document.querySelector("#edit-note"); const editNote = document.querySelector("#edit-note");
const editNoteDialog = document.querySelector("#edit-note-dialog");
// Each save event originating from storage triggers a re-render // Each save event originating from storage triggers a re-render
// of notes list. // of notes list.
@ -113,17 +114,15 @@ newNote.addEventListener("addNote", async (e) => {
}); });
editNote.addEventListener("updateNote", async (e) => { editNote.addEventListener("updateNote", async (e) => {
newNote.classList.remove("hidden");
editNote.classList.add("hidden");
await Notes.update(e.detail); await Notes.update(e.detail);
Notes.saveStorage(); Notes.saveStorage();
editNoteDialog.close();
}); });
editNote.addEventListener("deleteNote", async (e) => { editNote.addEventListener("deleteNote", async (e) => {
newNote.classList.remove("hidden");
editNote.classList.add("hidden");
await Notes.remove(e.detail); await Notes.remove(e.detail);
Notes.saveStorage(); Notes.saveStorage();
editNoteDialog.close();
}); });
// The notes rendering routine is optimized to replace only // The notes rendering routine is optimized to replace only
@ -215,10 +214,9 @@ function renderNote(note) {
} }
container.addEventListener("click", async (e) => { container.addEventListener("click", async (e) => {
newNote.classList.add("hidden");
editNote.classList.remove("hidden");
const note = await Notes.get(container.id); const note = await Notes.get(container.id);
editNote.load(note); editNote.load(note);
editNoteDialog.showModal();
}); });
return container; return container;

View file

@ -1,6 +1,7 @@
/* Variables */ /* Variables */
:root { :root {
--backdrop-background: lightgray;
--gap-1: 10px; --gap-1: 10px;
--font-color: #222; --font-color: #222;
--button-text-color: #222; --button-text-color: #222;
@ -14,6 +15,7 @@
@media (prefers-color-scheme: dark) { @media (prefers-color-scheme: dark) {
:root { :root {
--backdrop-background: black;
--font-color: antiquewhite; --font-color: antiquewhite;
--button-text-color: black; --button-text-color: black;
--background: #222; --background: #222;
@ -37,11 +39,28 @@
margin: 0; margin: 0;
} }
dialog {
margin: auto;
border: 0;
background: transparent;
max-width: 100vw;
max-height: 100vh;
}
::backdrop {
background: var(--backdrop-background);
opacity: 0.75;
}
body { body {
line-height: 1.5; line-height: 1.5;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
} }
body:has(dialog[open]) {
overflow: hidden;
}
img, img,
picture, picture,
video, video,
@ -304,6 +323,19 @@ button {
color: var(--inactive-color); color: var(--inactive-color);
} }
@container (min-width: 700px) {
#edit-note-dialog {
width: 100vw;
margin: 0;
padding: 0;
}
}
#edit-note-dialog {
margin: auto;
width: 700px;
}
.hidden { .hidden {
display: none; display: none;
} }