Skip to content

Popover

Rich content tooltip

Usage

Simple Usage

Remove?
preview
vue
<template>
  <p-popover>
    <template #activator="{ show }">
      <a href="javascript:void" @click.prevent="show">
        Remove?
      </a>
    </template>
    <template #default="{ hide }">
      <div class="space-x-2">
        <span>Are you sure?</span>
        <p-button color="success" size="xs" @click="hide">
          Yes
        </p-button>
        <p-button color="danger" size="xs" @click="hide">
          Cancel
        </p-button>
      </div>
    </template>
  </p-popover>
</template>

Async Usage

Remove?
preview
vue
<template>
  <p-popover v-bind="popoverPromise.bind()">
    <template #activator>
      <a href="javascript:void" @click.prevent="confirmDelete()">
        Remove?
      </a>
    </template>
    <template #default>
      <div class="flex items-center space-x-2">
        <span>Are you sure?</span>
        <p-button color="success" size="xs" @click="popoverPromise.finish(true)">
          Yes
        </p-button>
        <p-button color="danger" size="xs" @click="popoverPromise.finish(false)">
          Cancel
        </p-button>
      </div>
    </template>
  </p-popover>
</template>

<script lang="ts" setup>
import { dialog, usePopoverPromise } from '@privyid/persona/core'

const popoverPromise = usePopoverPromise<boolean>()

async function confirmDelete () {
  const result = await popoverPromise.start()

  if (result === true) {
    dialog.alert({
      title: 'Info',
      text : 'Deleted',
    })
  }
}
</script>

Color

You can change popover color using props color, valid value is white and black, default is white

White
Black
preview

Placement

You can change popup placement via placement prop. Valid options is:

  • top
  • bottom
  • right
  • left
Top
Bottom
Left
Right
preview
vue
<template>
  <p-popover placement="top">
    <template #activator="{ show }">
      <a href="javascript:void" @click.prevent="show">
        Top
      </a>
    </template>
    <template #default="{ hide }">
      <div class="flex items-center space-x-2">
        <span>Are you sure?</span>
        <p-button color="success" size="xs" @click="hide">
          Yes
        </p-button>
        <p-button color="danger" size="xs" @click="hide">
          Cancel
        </p-button>
      </div>
    </template>
  </p-popover>
  <p-popover placement="bottom">
    <template #activator="{ show }">
      <a href="javascript:void" @click.prevent="show">
        Bottom
      </a>
    </template>
    <template #default="{ hide }">
      <div class="flex items-center space-x-2">
        <span>Are you sure?</span>
        <p-button color="success" size="xs" @click="hide">
          Yes
        </p-button>
        <p-button color="danger" size="xs" @click="hide">
          Cancel
        </p-button>
      </div>
    </template>
  </p-popover>
  <p-popover placement="left">
    <template #activator="{ show }">
      <a href="javascript:void" @click.prevent="show">
        Left
      </a>
    </template>
    <template #default="{ hide }">
      <div class="flex items-center space-x-2">
        <span>Are you sure?</span>
        <p-button color="success" size="xs" @click="hide">
          Yes
        </p-button>
        <p-button color="danger" size="xs" @click="hide">
          Cancel
        </p-button>
      </div>
    </template>
  </p-popover>
  <p-popover placement="right">
    <template #activator="{ show }">
      <a href="javascript:void" @click.prevent="show">
        Right
      </a>
    </template>
    <template #default="{ hide }">
      <div class="flex items-center space-x-2">
        <span>Are you sure?</span>
        <p-button color="success" size="xs" @click="hide">
          Yes
        </p-button>
        <p-button color="danger" size="xs" @click="hide">
          Cancel
        </p-button>
      </div>
    </template>
  </p-popover>
</template>

Placement Align

You can combine placement with suffix *-start and *-end to set popup position align

Bottom
Bottom Start
Bottom End
preview
vue
<template>
  <p-popover placement="bottom">
    <template #activator="{ show }">
      <a href="javascript:void" @click.prevent="show">
        Bottom
      </a>
    </template>
    <template #default="{ hide }">
      <div class="flex items-center space-x-2">
        <span>Are you sure?</span>
        <p-button color="success" size="xs" @click="hide">
          Yes
        </p-button>
        <p-button color="danger" size="xs" @click="hide">
          Cancel
        </p-button>
      </div>
    </template>
  </p-popover>
  <p-popover placement="bottom-start">
    <template #activator="{ show }">
      <a href="javascript:void" @click.prevent="show">
        Bottom Start
      </a>
    </template>
    <template #default="{ hide }">
      <div class="flex items-center space-x-2">
        <span>Are you sure?</span>
        <p-button color="success" size="xs" @click="hide">
          Yes
        </p-button>
        <p-button color="danger" size="xs" @click="hide">
          Cancel
        </p-button>
      </div>
    </template>
  </p-popover>
  <p-popover placement="bottom-end">
    <template #activator="{ show }">
      <a href="javascript:void" @click.prevent="show">
        Bottom End
      </a>
    </template>
    <template #default="{ hide }">
      <div class="flex items-center space-x-2">
        <span>Are you sure?</span>
        <p-button color="success" size="xs" @click="hide">
          Yes
        </p-button>
        <p-button color="danger" size="xs" @click="hide">
          Cancel
        </p-button>
      </div>
    </template>
  </p-popover>
</template>

Binding v-model

You can programmatically toggle popover using v-model

Popover
preview
vue
<template>
  <p-checkbox v-model="show">Show Popover</p-checkbox>
  <p-popover placement="bottom" v-model="show">
    <template #activator="{ show }">
      <a href="javascript:void" @click.prevent="show">
        Popover
      </a>
    </template>
    <template #default="{ hide }">
      <div class="flex items-center space-x-2">
        <span>Are you sure?</span>
        <p-button color="success" size="xs" @click="hide">
          Yes
        </p-button>
        <p-button color="danger" size="xs" @click="hide">
          Cancel
        </p-button>
      </div>
    </template>
  </p-popover>
</template>

API

Props

PropsTypeDefaultDescription
colorStringprimaryPopover color variant, valid value is white, black
disabledBooleanfalseDisable state
placementStringtopPopover placement, valid value is
top, top-start, top-end,
bottom, bottom-start, bottom-end,
right, right-start, right-end,
left, left-start, left-end
modelValueBooleanfalsev-model value for show and hide

Slots

NameDescription
defaultPopover menu content
activatorPopover target content

Events

NameArgumentsDescription
show-Event when popover shown
hide-Event when popover hidden

See Also

Released under the MIT License.