PXD

Overlay

Highlight certain contents.

Default

<script setup>
import { ref } from 'vue'

const isVisible = ref(false)

function onClickToClose() {
  isVisible.value = false
}
</script>

<template>
  <PButton @click="isVisible = true">Open</PButton>
  <POverlay v-model="isVisible" @click="onClickToClose" />
</template>

Blurred

When variant="blurred" is set, the overlay will be blurred.

<script setup>
import { ref } from 'vue'

const isVisible = ref(false)

function onClickToClose() {
  isVisible.value = false
}
</script>

<template>
  <PButton @click="isVisible = true">Open</PButton>
  <POverlay v-model="isVisible" variant="blurred" @click="onClickToClose" />
</template>

With shown element

Highlight and display a certain element.

<script setup>
import { ref, useTemplateRef } from 'vue'

const btn = useTemplateRef('button')
const isVisible = ref(false)

function onClickToClose() {
  isVisible.value = false
}
</script>

<template>
  <PStack>
    <PButton @click="isVisible = true">Open</PButton>
    <PButton
      ref="button"
      variant="error"
      :disabled="!isVisible"
      @click="onClickToClose"
    >
      Close
    </PButton>
  </PStack>

  <POverlay
    v-model="isVisible"
    :shown-element="btn"
    :close-on-press-escape="false"
  />
</template>

Props

NameTypeDefaultDescription
z-indexnumber-Stacking order of the overlay, applied through the --overlay-index variable
variant'default' | 'blurred' | 'transparent'-Backdrop treatment; blurred adds a backdrop blur, transparent fades out
model-valuebooleanfalseWhether the overlay is visible
show-overlaybooleantrueRender the backdrop; false keeps only the slotted content
append-to-bodybooleantrueTeleport the content to body to escape overflow containers
shown-elementstring | object-Element or selector kept above the overlay, cut out with a clip-path
close-on-press-escapebooleantrueClose the overlay when Esc is pressed
close-on-click-overlaybooleanfalseClose the overlay when the backdrop is clicked
lock-scroll-on-visiblebooleantruePrevent the page behind the overlay from scrolling

Events

NameTypeDescription
click(event: PointerEvent) => voidEmitted when the backdrop is clicked.
escape(event: KeyboardEvent) => voidEmitted when the Escape key is pressed while this overlay is the topmost open one and close-on-press-escape is set.
update:modelValue(value: boolean) => voidEmitted with false after Escape, or after a backdrop click when close-on-click-overlay is set.

Slots

NameDescription
defaultDefault slot

Source

Source