advent22/ui/src/components/LoginModal.vue

100 lines
2.2 KiB
Vue
Raw Normal View History

2022-12-14 02:39:32 +00:00
<template>
2023-09-11 23:36:36 +00:00
<div class="modal is-active">
2022-12-14 02:39:32 +00:00
<div class="modal-background" />
<div class="modal-card">
2023-09-11 23:36:36 +00:00
<header class="modal-card-head">
<p class="modal-card-title">Login</p>
2023-09-11 23:41:45 +00:00
<button class="delete" @click.left="cancel" />
2023-09-11 23:36:36 +00:00
</header>
2022-12-14 02:39:32 +00:00
2023-09-11 23:36:36 +00:00
<section class="modal-card-body">
<div class="field">
<label class="label">Username</label>
<div class="control">
<input
ref="username_input"
class="input"
type="text"
v-model="username"
/>
2022-12-14 02:39:32 +00:00
</div>
2023-09-11 23:36:36 +00:00
</div>
2022-12-14 02:39:32 +00:00
2023-09-11 23:36:36 +00:00
<div class="field">
<label class="label">Passwort</label>
<div class="control">
<input class="input" type="password" v-model="password" />
2022-12-14 02:39:32 +00:00
</div>
2023-09-11 23:36:36 +00:00
</div>
</section>
2023-09-10 00:10:11 +00:00
2023-09-10 00:25:22 +00:00
<footer class="modal-card-foot is-flex is-justify-content-space-around">
2023-09-10 00:10:11 +00:00
<BulmaButton
2023-09-20 22:03:57 +00:00
class="is-success"
2023-09-11 23:41:45 +00:00
@click.left="submit"
2023-09-10 00:10:11 +00:00
icon="fa-solid fa-unlock"
text="Login"
/>
<BulmaButton
2023-09-20 22:03:57 +00:00
class="is-danger"
2023-09-11 23:41:45 +00:00
@click.left="cancel"
2023-09-10 00:10:11 +00:00
icon="fa-solid fa-circle-xmark"
text="Abbrechen"
/>
</footer>
2022-12-14 02:39:32 +00:00
</div>
</div>
</template>
<script lang="ts">
2023-09-10 00:10:11 +00:00
import { Options, Vue } from "vue-class-component";
import BulmaButton from "./bulma/Button.vue";
2022-12-14 02:39:32 +00:00
2023-09-10 00:10:11 +00:00
@Options({
components: {
BulmaButton,
},
2023-09-11 23:36:36 +00:00
props: {
visible: Boolean,
},
emits: ["cancel", "submit"],
2023-09-10 00:10:11 +00:00
})
2023-01-24 23:18:09 +00:00
export default class extends Vue {
2023-09-06 16:25:35 +00:00
public username = "";
public password = "";
2022-12-14 02:39:32 +00:00
2023-09-07 02:33:45 +00:00
declare $refs: {
2023-09-14 14:20:21 +00:00
username_input: HTMLInputElement | unknown;
2023-09-07 02:33:45 +00:00
};
2023-09-11 23:36:36 +00:00
private on_keydown(e: KeyboardEvent) {
2023-09-11 23:41:45 +00:00
if (e.key == "Enter") this.submit();
else if (e.key == "Escape") this.cancel();
2022-12-21 23:51:25 +00:00
}
2023-09-11 23:36:36 +00:00
public mounted(): void {
window.addEventListener("keydown", this.on_keydown);
2022-12-14 02:39:32 +00:00
2023-09-11 23:36:36 +00:00
this.$nextTick(() => {
if (this.$refs.username_input instanceof HTMLInputElement) {
this.$refs.username_input.focus();
}
});
2022-12-14 02:39:32 +00:00
}
2023-09-11 23:36:36 +00:00
public beforeUnmount(): void {
window.removeEventListener("keydown", this.on_keydown);
2022-12-14 02:39:32 +00:00
}
2023-09-11 23:41:45 +00:00
public submit(): void {
this.$emit("submit", this.username, this.password);
}
public cancel(): void {
this.$emit("cancel");
}
2022-12-14 02:39:32 +00:00
}
</script>