mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-26 18:00:43 +01:00
feat(Popover): manual mode & horizontal offset (#781)
Co-authored-by: Benjamin Canac <canacb1@gmail.com> Co-authored-by: Lnunu <62177121+Lnunu@users.noreply.github.com>
This commit is contained in:
18
docs/components/content/examples/PopoverExampleOpen.vue
Normal file
18
docs/components/content/examples/PopoverExampleOpen.vue
Normal file
@@ -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>
|
||||||
@@ -19,6 +19,12 @@ Use the `mode` prop to switch between `click` and `hover` modes.
|
|||||||
|
|
||||||
:component-example{component="popover-example-mode"}
|
:component-example{component="popover-example-mode"}
|
||||||
|
|
||||||
|
### Manual
|
||||||
|
|
||||||
|
Use the `open` prop to manually control showing the panel.
|
||||||
|
|
||||||
|
:component-example{component="popover-example-open"}
|
||||||
|
|
||||||
## Slots
|
## Slots
|
||||||
|
|
||||||
### `panel`
|
### `panel`
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<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
|
<HPopoverButton
|
||||||
ref="trigger"
|
ref="trigger"
|
||||||
as="div"
|
as="div"
|
||||||
@@ -8,17 +8,17 @@
|
|||||||
role="button"
|
role="button"
|
||||||
@mouseover="onMouseOver"
|
@mouseover="onMouseOver"
|
||||||
>
|
>
|
||||||
<slot :open="open" :close="close">
|
<slot :open="(open !== undefined) ? open : headlessOpen" :close="close">
|
||||||
<button :disabled="disabled">
|
<button :disabled="disabled">
|
||||||
Open
|
Open
|
||||||
</button>
|
</button>
|
||||||
</slot>
|
</slot>
|
||||||
</HPopoverButton>
|
</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">
|
<Transition appear v-bind="ui.transition">
|
||||||
<HPopoverPanel :class="[ui.base, ui.background, ui.ring, ui.rounded, ui.shadow]" static>
|
<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>
|
</HPopoverPanel>
|
||||||
</Transition>
|
</Transition>
|
||||||
</div>
|
</div>
|
||||||
@@ -53,6 +53,10 @@ export default defineComponent({
|
|||||||
default: 'click',
|
default: 'click',
|
||||||
validator: (value: string) => ['click', 'hover'].includes(value)
|
validator: (value: string) => ['click', 'hover'].includes(value)
|
||||||
},
|
},
|
||||||
|
open: {
|
||||||
|
type: Boolean,
|
||||||
|
default: undefined
|
||||||
|
},
|
||||||
disabled: {
|
disabled: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
@@ -103,8 +107,14 @@ export default defineComponent({
|
|||||||
|
|
||||||
const containerStyle = computed(() => {
|
const containerStyle = computed(() => {
|
||||||
const offsetDistance = (props.popper as PopperOptions)?.offsetDistance || (ui.value.popper as PopperOptions)?.offsetDistance || 8
|
const offsetDistance = (props.popper as PopperOptions)?.offsetDistance || (ui.value.popper as PopperOptions)?.offsetDistance || 8
|
||||||
|
const padding = `${offsetDistance}px`
|
||||||
|
|
||||||
return props.mode === 'hover' ? { paddingTop: `${offsetDistance}px`, paddingBottom: `${offsetDistance}px` } : {}
|
return props.mode === 'hover' ? {
|
||||||
|
paddingTop: padding,
|
||||||
|
paddingBottom: padding,
|
||||||
|
paddingLeft: padding,
|
||||||
|
paddingRight: padding
|
||||||
|
} : {}
|
||||||
})
|
})
|
||||||
|
|
||||||
function onMouseOver () {
|
function onMouseOver () {
|
||||||
|
|||||||
Reference in New Issue
Block a user