2023-09-09 22:18:16 +00:00
|
|
|
<template>
|
2023-09-10 03:38:24 +00:00
|
|
|
<div class="card">
|
2023-09-14 03:36:42 +00:00
|
|
|
<header class="card-header is-unselectable">
|
2023-09-12 15:39:54 +00:00
|
|
|
<p class="card-header-title" @click="toggle">{{ header }}</p>
|
2023-09-13 15:58:15 +00:00
|
|
|
|
2023-09-12 15:46:45 +00:00
|
|
|
<p v-if="refreshable" class="card-header-icon px-0">
|
2023-09-12 15:58:56 +00:00
|
|
|
<button class="tag button icon is-info" @click="refresh">
|
2023-09-12 20:39:31 +00:00
|
|
|
<font-awesome-icon
|
|
|
|
icon="fa-solid fa-arrows-rotate"
|
2023-09-14 03:59:33 +00:00
|
|
|
:spin="is_open && loading"
|
2023-09-12 20:39:31 +00:00
|
|
|
/>
|
2023-09-12 15:46:45 +00:00
|
|
|
</button>
|
|
|
|
</p>
|
2023-09-13 15:58:15 +00:00
|
|
|
|
2023-09-12 15:39:54 +00:00
|
|
|
<button class="card-header-icon" @click="toggle">
|
2023-09-09 23:19:46 +00:00
|
|
|
<span class="icon">
|
2023-09-09 22:18:16 +00:00
|
|
|
<font-awesome-icon
|
2023-09-09 23:19:46 +00:00
|
|
|
:icon="'fa-solid fa-angle-' + (is_open ? 'down' : 'right')"
|
2023-09-09 22:18:16 +00:00
|
|
|
/>
|
|
|
|
</span>
|
2023-09-10 03:38:24 +00:00
|
|
|
</button>
|
|
|
|
</header>
|
|
|
|
|
2023-09-12 15:10:54 +00:00
|
|
|
<template v-if="is_open">
|
2023-09-14 03:59:33 +00:00
|
|
|
<div v-if="loading" class="card-content">
|
|
|
|
<progress class="progress is-info" max="100" />
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
v-else-if="failed"
|
|
|
|
class="card-content has-text-danger has-text-centered"
|
|
|
|
>
|
2023-09-13 15:58:15 +00:00
|
|
|
<span class="icon is-large">
|
|
|
|
<font-awesome-icon icon="fa-solid fa-ban" size="3x" />
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<slot v-else name="default" />
|
2023-09-12 15:10:54 +00:00
|
|
|
</template>
|
2023-09-09 22:18:16 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-09-10 00:54:29 +00:00
|
|
|
import { Options, Vue } from "vue-class-component";
|
2023-09-09 22:18:16 +00:00
|
|
|
|
2023-09-14 03:59:33 +00:00
|
|
|
export enum DrawerState {
|
|
|
|
Loading,
|
|
|
|
Ready,
|
|
|
|
Failed,
|
|
|
|
}
|
|
|
|
|
2023-09-10 00:54:29 +00:00
|
|
|
@Options({
|
|
|
|
props: {
|
2023-09-14 12:51:30 +00:00
|
|
|
header: String,
|
2023-09-12 15:39:54 +00:00
|
|
|
refreshable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2023-09-10 00:54:29 +00:00
|
|
|
},
|
2023-09-12 15:39:54 +00:00
|
|
|
emits: ["open"],
|
2023-09-10 00:54:29 +00:00
|
|
|
})
|
2023-09-09 22:18:16 +00:00
|
|
|
export default class extends Vue {
|
2023-09-10 00:54:29 +00:00
|
|
|
public header!: string;
|
2023-09-12 15:39:54 +00:00
|
|
|
public refreshable!: boolean;
|
2023-09-12 15:10:54 +00:00
|
|
|
|
|
|
|
public is_open = false;
|
2023-09-14 12:51:30 +00:00
|
|
|
public state = DrawerState.Loading;
|
2023-09-12 15:10:54 +00:00
|
|
|
|
|
|
|
public toggle() {
|
|
|
|
this.is_open = !this.is_open;
|
2023-09-14 12:51:30 +00:00
|
|
|
|
|
|
|
if (this.is_open) {
|
|
|
|
this.state = DrawerState.Loading;
|
|
|
|
|
|
|
|
this.$emit(
|
|
|
|
"open",
|
|
|
|
() => (this.state = DrawerState.Ready),
|
|
|
|
() => (this.state = DrawerState.Failed),
|
|
|
|
);
|
|
|
|
}
|
2023-09-12 15:39:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public refresh() {
|
2023-09-12 16:11:03 +00:00
|
|
|
this.is_open = false;
|
|
|
|
this.toggle();
|
2023-09-12 15:10:54 +00:00
|
|
|
}
|
2023-09-14 03:59:33 +00:00
|
|
|
|
|
|
|
public get loading(): boolean {
|
|
|
|
return this.state === DrawerState.Loading;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get failed(): boolean {
|
|
|
|
return this.state === DrawerState.Failed;
|
|
|
|
}
|
2023-09-09 22:18:16 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2023-09-10 14:09:50 +00:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
div.card {
|
|
|
|
&:not(:last-child) {
|
|
|
|
margin-bottom: 1.5rem;
|
|
|
|
}
|
|
|
|
> .card-header {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2023-09-09 22:18:16 +00:00
|
|
|
}
|
|
|
|
</style>
|