advent22/ui/src/components/bulma/Secret.vue

69 lines
1.2 KiB
Vue
Raw Normal View History

<template>
<slot v-if="show" name="default" />
<span v-else>***</span>
2023-09-14 13:54:23 +00:00
<BulmaButton
:class="`tag icon is-${button_class} ml-2`"
:icon="`fa-solid fa-${button_icon}`"
:busy="busy"
@click="on_click"
/>
</template>
<script lang="ts">
import { Options, Vue } from "vue-class-component";
2023-09-14 13:54:23 +00:00
import BulmaButton from "./Button.vue";
enum ClickState {
Green = 0,
Yellow = 1,
Red = 2,
}
@Options({
2023-09-14 13:54:23 +00:00
components: {
BulmaButton,
},
emits: ["load"],
})
export default class extends Vue {
2023-09-14 04:00:04 +00:00
public state = ClickState.Green;
public on_click(): void {
2023-09-14 04:00:04 +00:00
this.state++;
this.state %= 3;
2023-09-14 04:00:04 +00:00
if (this.state === ClickState.Red) {
this.$emit("load");
}
}
public get show(): boolean {
2023-09-14 04:00:04 +00:00
return this.state === ClickState.Red;
}
2023-09-14 13:54:23 +00:00
public get busy(): boolean {
return this.state === ClickState.Yellow;
}
public get button_class(): string {
2023-09-14 04:00:04 +00:00
switch (this.state) {
case ClickState.Red:
return "danger";
case ClickState.Yellow:
return "warning";
default:
return "primary";
}
}
public get button_icon(): string {
2023-09-14 04:00:04 +00:00
if (this.state === ClickState.Red) {
return "eye-slash";
} else {
return "eye";
}
}
}
</script>