Skip to content

Commit

Permalink
feat(Popover): manual mode & horizontal offset (#781)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
Co-authored-by: Lnunu <62177121+Lnunu@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 12, 2023
1 parent 827f2f4 commit 92b8618
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
18 changes: 18 additions & 0 deletions docs/components/content/examples/PopoverExampleOpen.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script setup>
const open = ref(false)
</script>

<template>
<div class="flex gap-4 items-center">
<UToggle v-model="open" />
<UPopover :open="open">
<UButton color="white" label="Open" trailing-icon="i-heroicons-chevron-down-20-solid" />

<template #panel>
<div class="p-4">
<Placeholder class="h-20 w-48" />
</div>
</template>
</UPopover>
</div>
</template>
6 changes: 6 additions & 0 deletions docs/content/6.overlays/3.popover.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ Use the `mode` prop to switch between `click` and `hover` modes.

:component-example{component="popover-example-mode"}

### Manual

Use the `open` prop to manually control showing the panel.

:component-example{component="popover-example-open"}

## Slots

### `panel`
Expand Down
22 changes: 16 additions & 6 deletions src/runtime/components/overlays/Popover.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<HPopover ref="popover" v-slot="{ open, close }" :class="ui.wrapper" v-bind="attrs" @mouseleave="onMouseLeave">
<HPopover ref="popover" v-slot="{ open: headlessOpen, close }" :class="ui.wrapper" v-bind="attrs" @mouseleave="onMouseLeave">
<HPopoverButton
ref="trigger"
as="div"
Expand All @@ -8,17 +8,17 @@
role="button"
@mouseover="onMouseOver"
>
<slot :open="open" :close="close">
<slot :open="(open !== undefined) ? open : headlessOpen" :close="close">
<button :disabled="disabled">
Open
</button>
</slot>
</HPopoverButton>

<div v-if="open" ref="container" :class="[ui.container, ui.width]" :style="containerStyle" @mouseover="onMouseOver">
<div v-if="(open !== undefined) ? open : headlessOpen" ref="container" :class="[ui.container, ui.width]" :style="containerStyle" @mouseover="onMouseOver">
<Transition appear v-bind="ui.transition">
<HPopoverPanel :class="[ui.base, ui.background, ui.ring, ui.rounded, ui.shadow]" static>
<slot name="panel" :open="open" :close="close" />
<slot name="panel" :open="(open !== undefined) ? open : headlessOpen" :close="close" />
</HPopoverPanel>
</Transition>
</div>
Expand Down Expand Up @@ -53,6 +53,10 @@ export default defineComponent({
default: 'click',
validator: (value: string) => ['click', 'hover'].includes(value)
},
open: {
type: Boolean,
default: undefined
},
disabled: {
type: Boolean,
default: false
Expand Down Expand Up @@ -103,8 +107,14 @@ export default defineComponent({
const containerStyle = computed(() => {
const offsetDistance = (props.popper as PopperOptions)?.offsetDistance || (ui.value.popper as PopperOptions)?.offsetDistance || 8
return props.mode === 'hover' ? { paddingTop: `${offsetDistance}px`, paddingBottom: `${offsetDistance}px` } : {}
const padding = `${offsetDistance}px`
return props.mode === 'hover' ? {
paddingTop: padding,
paddingBottom: padding,
paddingLeft: padding,
paddingRight: padding
} : {}
})
function onMouseOver () {
Expand Down

1 comment on commit 92b8618

@vercel
Copy link

@vercel vercel bot commented on 92b8618 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-git-dev-nuxt-js.vercel.app
ui.nuxt.com
ui-nuxt-js.vercel.app

Please sign in to comment.