Browse Source

feat(gui-v2): extend overlay props

pull/2972/head
braks 2 years ago
parent
commit
50217bcc40
  1. 28
      packages/nc-gui-v2/components/general/Overlay.vue

28
packages/nc-gui-v2/components/general/Overlay.vue

@ -1,9 +1,16 @@
<script lang="ts" setup> <script lang="ts" setup>
import { onKeyDown } from '@vueuse/core' import { onKeyDown } from '@vueuse/core'
import type { TeleportProps } from '@vue/runtime-core'
import { useVModel, watch } from '#imports' import { useVModel, watch } from '#imports'
interface Props { interface Props {
modelValue?: any modelValue?: any
/** if true, overlay will use `position: absolute` instead of `position: fixed` */
inline?: boolean
/** target to teleport to */
target?: TeleportProps['to']
teleportDisabled?: TeleportProps['disabled']
transition?: boolean
} }
interface Emits { interface Emits {
@ -12,11 +19,11 @@ interface Emits {
(event: 'open'): void (event: 'open'): void
} }
const props = defineProps<Props>() const { transition = true, teleportDisabled = false, inline = false, target, ...rest } = defineProps<Props>()
const emits = defineEmits<Emits>() const emits = defineEmits<Emits>()
const vModel = useVModel(props, 'modelValue', emits) const vModel = useVModel(rest, 'modelValue', emits)
onKeyDown('Escape', () => { onKeyDown('Escape', () => {
vModel.value = false vModel.value = false
@ -28,11 +35,22 @@ watch(vModel, (nextVal) => {
}) })
</script> </script>
<script lang="ts">
export default {
inheritAttrs: false,
}
</script>
<template> <template>
<teleport to="body"> <teleport :disabled="teleportDisabled || (inline && !target)" :to="target || 'body'">
<div <div
:class="[vModel ? 'opacity-100' : 'opacity-0 pointer-events-none']" v-bind="$attrs"
class="transition-opacity duration-200 ease-in-out fixed z-100 top-0 left-0 bottom-0 right-0 bg-gray-700/75" :class="[
vModel ? 'opacity-100' : 'opacity-0 pointer-events-none',
inline ? 'absolute' : 'fixed',
transition ? 'transition-opacity duration-200 ease-in-out' : '',
]"
class="z-100 top-0 left-0 bottom-0 right-0 bg-gray-700/75"
> >
<slot :is-open="vModel" /> <slot :is-open="vModel" />
</div> </div>

Loading…
Cancel
Save