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

78 lines
1.7 KiB
Vue
Raw Normal View History

2022-04-15 14:24:30 +00:00
<template>
2022-12-02 16:17:37 +00:00
<dialog ref="el" :class="state.type" data-testid="overlay" @cancel.prevent="onCancel">
<div class="wrapper">
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" />
2022-04-15 14:24:30 +00:00
</div>
</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>
<style lang="scss" scoped>
dialog {
border: 0;
padding: 0;
background: transparent;
2022-04-15 14:24:30 +00:00
&::backdrop {
background: rgba(0, 0, 0, 0.8);
}
.wrapper {
2022-08-01 08:58:25 +00:00
display: flex;
align-items: baseline;
justify-content: center;
gap: 6px;
2022-04-15 14:24:30 +00:00
}
&.error {
color: var(--color-red);
}
&.success {
color: var(--color-green);
}
&.info {
color: var(--color-blue);
}
&.loading {
color: var(--color-text-secondary);
}
&.warning {
color: var(--color-orange);
2022-04-15 14:24:30 +00:00
}
}
</style>