Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Popover): manual mode & horizontal offset #781

Merged
merged 10 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
11 changes: 11 additions & 0 deletions docs/components/content/examples/PopoverExampleSlot.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<template>
<UPopover>
<UButton color="white" label="Open" trailing-icon="i-heroicons-chevron-down-20-solid" />

<template #panel="{ close }">
<div class="p-8">
<UButton label="Close" @click="close" />
</div>
</template>
</UPopover>
</template>
4 changes: 2 additions & 2 deletions docs/content/1.getting-started/3.theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default defineAppConfig({

Thanks to [tailwind-merge](https://github.com/dcastil/tailwind-merge), the `app.config.ts` is smartly merged with the default config. This means you don't have to rewrite everything.

You can change this behaviour by setting `strategy` to `override` in your `app.config.ts`: :u-badge{label="New" class="!rounded-full" variant="subtle"}
You can change this behaviour by setting `strategy` to `override` in your `app.config.ts`:

```ts [app.config.ts]
export default defineAppConfig({
Expand Down Expand Up @@ -146,7 +146,7 @@ To change the font of the `label`, you only need to write:

This will smartly replace the `font-medium` by `font-semibold` and prevent any class duplication and any class priority issue.

You can change this behaviour by setting `strategy` to `override` inside the `ui` prop: :u-badge{label="New" class="!rounded-full" variant="subtle"}
You can change this behaviour by setting `strategy` to `override` inside the `ui` prop:

```vue
<UButton
Expand Down
2 changes: 1 addition & 1 deletion docs/content/1.getting-started/4.shortcuts.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ description: 'Learn how to display and define keyboard shortcuts in your app.'
Some components like [Dropdown](/elements/dropdown), [Command Palette](/navigation/command-palette) and [Tooltip](/overlays/tooltip) support the display of keyboard shortcuts.

```vue
<UDropdown :items="[{ label: 'Edit', shortcuts: ['E'] }]" />
<UDropdown :items="[[{ label: 'Edit', shortcuts: ['E'] }]]" />
```

Shortcuts are displayed and styled through the [Kbd](/elements/kbd) component.
Expand Down
10 changes: 5 additions & 5 deletions docs/content/3.forms/9.form-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ code: >-

## Slots

### `label` :u-badge{label="New" class="align-middle ml-2 !rounded-full" variant="subtle"}
### `label`

Use the `#label` slot to set the custom content for label.

Expand All @@ -210,7 +210,7 @@ slots:
:u-input{model-value="benjamincanac" placeholder="[email protected]"}
::

### `description` :u-badge{label="New" class="align-middle ml-2 !rounded-full" variant="subtle"}
### `description`

Use the `#description` slot to set the custom content for description.

Expand All @@ -230,7 +230,7 @@ props:
:u-input{model-value="benjamincanac" placeholder="[email protected]"}
::

### `hint` :u-badge{label="New" class="align-middle ml-2 !rounded-full" variant="subtle"}
### `hint`

Use the `#hint` slot to set the custom content for hint.

Expand All @@ -250,7 +250,7 @@ props:
:u-input{model-value="benjamincanac" placeholder="[email protected]"}
::

### `help` :u-badge{label="New" class="align-middle ml-2 !rounded-full" variant="subtle"}
### `help`

Use the `#help` slot to set the custom content for help.

Expand All @@ -270,7 +270,7 @@ props:
:u-input{model-value="benjamincanac" placeholder="[email protected]"}
::

### `error` :u-badge{label="New" class="align-middle ml-2 !rounded-full" variant="subtle"}
### `error`

Use the `#error` slot to set the custom content for error.

Expand Down
2 changes: 1 addition & 1 deletion docs/content/4.data/1.table.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ excludedProps:
---
::

## Styling :u-badge{label="New" class="align-middle ml-2 !rounded-full" variant="subtle"}
## Styling

You can apply styles to `tr` and `td` elements by passing a `class` to rows.

Expand Down
51 changes: 50 additions & 1 deletion docs/content/6.overlays/3.popover.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ links:
::component-example
#default
:popover-example

#code
```vue
<template>
Expand All @@ -35,6 +36,7 @@ Use the `mode` prop to switch between `click` and `hover` modes.
::component-example
#default
:popover-example-mode

#code
```vue
<template>
Expand All @@ -49,11 +51,58 @@ Use the `mode` prop to switch between `click` and `hover` modes.
```
::

### Manual

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

::component-example
#default
:popover-example-open

#code
```vue
<script setup>
const open = ref(false)
</script>

<template>
<UToggle v-model="open" />
<UPopover :open="open">
<UButton color="white" label="Open" trailing-icon="i-heroicons-chevron-down-20-solid" />

<template #panel>
<!-- Content -->
</template>
</UPopover>
</template>
```
::

## Slots

### `panel`

Use the `#panel` slot to fill the content of the panel.
Use the `#panel` slot to fill the content of the panel. You will have access to the `open` property and the `close` method in the slot scope.

::component-example
#default
:popover-example-slot

#code
```vue
<template>
<UPopover>
<UButton color="white" label="Open" trailing-icon="i-heroicons-chevron-down-20-solid" />

<template #panel="{ close }">
<div class="p-8">
<UButton label="Close" @click="close" />
</div>
</template>
</UPopover>
</template>
```
::

## Props

Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@nuxt/content": "^2.8.5",
"@nuxt/devtools": "^0.8.5",
"@nuxt/eslint-config": "^0.2.0",
"@nuxt/ui-pro": "npm:@nuxt/[email protected]",
"@nuxt/ui-pro": "^0.1.0",
"@nuxthq/studio": "^0.14.1",
"@nuxtjs/fontaine": "^0.4.1",
"@nuxtjs/google-fonts": "^3.0.2",
Expand Down
62 changes: 31 additions & 31 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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="headlessOpen" :close="close">
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't it be :open="(open !== undefined) ? open : headlessOpen" for both slots?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep I think so. Made those changes.

<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="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