koel/resources/assets/js/components/ui/Overlay.vue

71 lines
1.7 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2024-04-04 22:20:42 +00:00
<dialog
ref="el"
:class="state.type"
2024-04-18 20:04:33 +00:00
class="border-0 p-0 bg-transparent backdrop:bg-black/80 outline-0"
2024-04-04 22:20:42 +00:00
data-testid="overlay"
@cancel.prevent="onCancel"
>
2024-04-18 20:04:33 +00:00
<span class="flex items-baseline justify-center gap-3">
2022-12-02 16:17:37 +00:00
<SoundBars v-if="state.type === 'loading'" />
2023-11-10 13:16:06 +00:00
<Icon v-if="state.type === 'error'" :icon="faCircleExclamation" />
<Icon v-if="state.type === 'warning'" :icon="faWarning" />
<Icon v-if="state.type === 'info'" :icon="faCircleInfo" />
<Icon v-if="state.type === 'success'" :icon="faCircleCheck" />
2022-04-15 14:24:30 +00:00
2022-12-02 16:17:37 +00:00
<span class="message" v-html="state.message" />
2024-04-18 20:04:33 +00:00
</span>
</dialog>
2022-04-15 14:24:30 +00:00
</template>
2022-04-15 17:00:08 +00:00
<script lang="ts" setup>
2022-07-15 07:23:55 +00:00
import { faCircleCheck, faCircleExclamation, faCircleInfo, faWarning } from '@fortawesome/free-solid-svg-icons'
import { defineAsyncComponent, reactive, ref } from 'vue'
2022-04-15 14:24:30 +00:00
2022-08-01 08:58:25 +00:00
const SoundBars = defineAsyncComponent(() => import('@/components/ui/SoundBars.vue'))
2022-04-15 14:24:30 +00:00
const el = ref<HTMLDialogElement>()
2022-04-15 17:00:08 +00:00
const state = reactive<OverlayState>({
dismissible: false,
type: 'loading',
message: '',
2022-04-15 17:00:08 +00:00
})
2022-04-15 14:24:30 +00:00
const show = (options: Partial<OverlayState> = {}) => {
Object.assign(state, options)
el.value?.open || el.value?.showModal()
2022-04-15 17:00:08 +00:00
}
const hide = () => el.value?.close()
const onCancel = () => state.dismissible && hide()
2022-04-15 17:00:08 +00:00
defineExpose({ show, hide })
2022-04-15 14:24:30 +00:00
</script>
2024-04-04 20:13:35 +00:00
<style lang="postcss" scoped>
dialog {
2024-04-04 22:20:42 +00:00
/* since the texts are placed directly on a dark backdrop, the colors should be a bit washed out */
2024-04-23 21:01:27 +00:00
2022-04-15 14:24:30 +00:00
&.error {
2024-04-04 22:20:42 +00:00
@apply text-red-400;
2022-04-15 14:24:30 +00:00
}
&.success {
2024-04-04 22:20:42 +00:00
@apply text-green-400;
2022-04-15 14:24:30 +00:00
}
&.info {
2024-04-04 22:20:42 +00:00
@apply text-blue-400;
2022-04-15 14:24:30 +00:00
}
&.loading {
2024-04-04 22:20:42 +00:00
@apply text-k-text-secondary;
2022-04-15 14:24:30 +00:00
}
&.warning {
2024-04-04 22:20:42 +00:00
@apply text-orange-400;
2022-04-15 14:24:30 +00:00
}
}
</style>