form input

master
km0 3 years ago
parent 9e2862b0fd
commit 39807bfd87

@ -2,7 +2,7 @@
const container = document.getElementById("container"); const container = document.getElementById("container");
const editor = document.getElementById("editor"); const editor = document.getElementById("editor");
const textForm = document.getElementById("text-form"); const textForm = document.getElementsByClassName("text-input")[0];
const input = document.getElementById("input"); const input = document.getElementById("input");
const insert = document.getElementById("insert"); const insert = document.getElementById("insert");
const cancel = document.getElementById("cancel"); const cancel = document.getElementById("cancel");
@ -96,12 +96,18 @@ function drawLabel() {
if (width > minimumSizeX && height > minimumSizeY) { if (width > minimumSizeX && height > minimumSizeY) {
// Create a label and push it into the array of labels // Create a label and push it into the array of labels
let temporaryLabel = createLabel(minX, minY, width, height, labels.length);
temporaryLabel.classList.add("temporary");
temporaryLabel.id = "temporary-label";
container.appendChild(temporaryLabel);
new Promise(function (resolve, reject) { new Promise(function (resolve, reject) {
// TODO: show the modal for text input in overlay // TODO: show the modal for text input in overlay
// TODO: temp editor freeze before the label is created
// then if the user click insert and there is a value in the input-- > resolve the promise and return the text input to create the label, // then if the user click insert and there is a value in the input-- > resolve the promise and return the text input to create the label,
// if the user click cancel-- > reject the promise and don't create the label // if the user click cancel-- > reject the promise and don't create the label
textForm.classList.add("visible");
input.focus(); input.focus();
// Insert button // Insert button
@ -116,6 +122,7 @@ function drawLabel() {
cancel.addEventListener("click", (e) => { cancel.addEventListener("click", (e) => {
e.preventDefault(); e.preventDefault();
reject("no input"); reject("no input");
textForm.classList.remove("visible");
}); });
}).then(() => { }).then(() => {
// Create the label // Create the label
@ -127,12 +134,15 @@ function drawLabel() {
text.innerHTML = input.value; text.innerHTML = input.value;
label.appendChild(text); label.appendChild(text);
// labels.push(label); labels.push(label);
container.appendChild(label); container.appendChild(label);
// Reset the modal // Reset the modal
input.value = ""; input.value = "";
input.blur(); input.blur();
let tempLabel = document.getElementById("temporary-label");
container.removeChild(tempLabel);
textForm.classList.remove("visible");
}); });
} }
} }

@ -36,6 +36,17 @@ body {
overflow: hidden; overflow: hidden;
} }
.label.temporary {
background: none;
border: 1px dashed tomato;
box-shadow: none;
}
.label.temporary .label--number,
.label.temporary .label--close {
display: none;
}
.label--number { .label--number {
display: inline-block; display: inline-block;
margin: 0; margin: 0;
@ -72,11 +83,21 @@ body {
} }
.text-input { .text-input {
display: none;
position: absolute;
z-index: 200;
width: 100%; width: 100%;
height: 100vh; height: 100vh;
display: flex; /* display: flex; */
justify-content: center; justify-content: center;
align-items: center; align-items: center;
background-color: rgba(250, 93, 65, 0.9);
}
.text-input.visible {
display: flex;
} }
.modal { .modal {

Loading…
Cancel
Save