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

40 lines
1 KiB
Vue
Raw Normal View History

<!-- eslint-disable vue/multi-word-component-names -->
<template>
<slot v-if="state === 'visible'" name="default" />
<span v-else>***</span>
2023-09-14 13:54:23 +00:00
<BulmaButton
:class="`is-small is-${record.color} ml-2`"
:icon="['fas', `${record.icon}`]"
:busy="state === 'clicked'"
2023-09-14 13:54:23 +00:00
@click="on_click"
/>
</template>
<script setup lang="ts">
import { computed, ref } from "vue";
2024-08-27 00:25:42 +00:00
2023-09-14 13:54:23 +00:00
import BulmaButton from "./Button.vue";
const emit = defineEmits<{
(event: "load"): void;
}>();
type State = "hidden" | "clicked" | "visible";
const state = ref<State>("hidden");
const state_map: Record<State, { color: string; icon: string; next: State }> = {
hidden: { color: "primary", icon: "eye-slash", next: "clicked" },
clicked: { color: "warning", icon: "eye-slash", next: "visible" },
visible: { color: "danger", icon: "eye", next: "hidden" },
} as const;
const record = computed(() => state_map[state.value] ?? state_map.hidden);
function on_click(): void {
state.value = record.value.next;
if (state.value === "visible") {
emit("load");
}
}
</script>