improve hiding form elements

This commit is contained in:
dogeystamp 2022-12-30 14:32:27 -05:00
parent 2bcfefbd2a
commit 31c6958277
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
2 changed files with 45 additions and 18 deletions

View File

@ -1,5 +1,21 @@
class Form { class Element {
#hidden = false;
get hidden() {
return this.#hidden;
}
set hidden(x) {
this.#hidden = x;
this.handle.hidden = this.hidden;
if (this.label !== undefined) {
this.label.hidden = this.hidden;
}
}
}
class Form extends Element {
constructor({id, formTag}) { constructor({id, formTag}) {
super();
this.id = id; this.id = id;
if (formTag !== undefined) { if (formTag !== undefined) {
@ -48,7 +64,7 @@ function bufToB64 (buf) {
return btoa(ascii); return btoa(ascii);
} }
class FormElement { class FormElement extends Element {
#enabled = true; #enabled = true;
get enabled() { get enabled() {
return this.#enabled; return this.#enabled;
@ -58,20 +74,8 @@ class FormElement {
this.handle.disabled = !this.#enabled; this.handle.disabled = !this.#enabled;
} }
#hidden = true;
get hidden() {
return this.#hidden;
}
set hidden(x) {
this.#hidden = x;
this.handle.hidden = this.hidden;
if (this.label !== undefined) {
this.label.hidden = this.hidden;
}
}
constructor({id, type, form, label="", dataType="plaintext", advanced=false, enabled=true}) { constructor({id, type, form, label="", dataType="plaintext", advanced=false, enabled=true}) {
super();
this.id = id; this.id = id;
this.advanced = advanced; this.advanced = advanced;
@ -160,8 +164,11 @@ class FormElement {
case "plaintext": case "plaintext":
return this.handle.value; return this.handle.value;
case "b64": case "b64":
// TODO: error handling try {
return b64ToBuf(this.handle.value); return b64ToBuf(this.handle.value);
} catch (e) {
// TODO
}
case "none": case "none":
return undefined; return undefined;
} }

View File

@ -27,6 +27,10 @@ textarea {
resize: none; resize: none;
} }
input {
height: 100%;
}
label, input, button, textarea { label, input, button, textarea {
display: block; display: block;
margin-top: 1em; margin-top: 1em;
@ -52,8 +56,24 @@ textarea:disabled, input:disabled {
} }
[hidden] { [hidden] {
height: 0; animation: fadeOut 0.2s, disappear 0.3s;
opacity: 0; opacity: 0;
visibility: hidden;
max-height: 0;
margin: 0;
}
@keyframes fadeOut {
0% {opacity: 1; visibility: visible;}
100% {opacity: 0; visibility: hidden;}
}
@keyframes disappear {
0% {
max-height: 100em;
}
100% {
max-height: 0;
margin: 0;
}
} }
p { p {