From b6590ecfe6090a6a9b0bc9dcf40a8b92d082ebe3 Mon Sep 17 00:00:00 2001 From: Thorsten Luenborg Date: Sun, 18 Dec 2022 16:50:50 +0100 Subject: [PATCH 1/2] feat: new wrapper slots: - #itemWrapper (each vnode) - #sourceWrapper (per each portal source) - #outerWrapper (one wrapper around all content of this portalTarget --- docs/api/portal-target.md | 109 ++++++++++++-- .../components/transitions/transitions.vue | 2 +- .../__snapshots__/portal-target.spec.ts.snap | 5 - .../__snapshots__/the-portal.spec.ts.snap | 5 - src/__tests__/portal-target.spec.ts | 139 ++++++++++++++++-- src/__tests__/the-portal.spec.ts | 4 +- src/__tests__/wormhole.spec.ts | 7 +- src/components/portal-target.ts | 64 ++++---- src/wormhole.ts | 4 +- 9 files changed, 269 insertions(+), 70 deletions(-) delete mode 100644 src/__tests__/__snapshots__/portal-target.spec.ts.snap delete mode 100644 src/__tests__/__snapshots__/the-portal.spec.ts.snap diff --git a/docs/api/portal-target.md b/docs/api/portal-target.md index 13f1c94..cfd32b0 100644 --- a/docs/api/portal-target.md +++ b/docs/api/portal-target.md @@ -138,29 +138,116 @@ Example:

This is rendered when no other content is available.

``` -### `wrapper` +### `v-slot:sourceWrapper` -This slot can be used to define markup that should wrap the content received from a ``. This is usually only useful in combination with [`multiple`](#multiple), as for content from a single portal, you can just wrap the `` as a whole. +This Slot allows to wrap each individual item from a portal (or `multiple` portals) in additional markup. The slot receives an array of `VNodes`: + +```html + +

Some inline content

+

Some more content

+
+ + +

Some content from a second portal

+
-The slot receives an array as its only prop, which contains the raw vnodes representing the content sent from the source portal(s). +
+ + + +
+``` -These vnodes can be rendered with Vue's dynamic component syntax: +**Result** + +```html +
+
+

Some inline content

+

Some more content

+
+
+

Some content from a second portal

+
+ +
+``` + +### `v-slot:itemWrapper` + +This slot can be used to define markup that should wrap the content received from a ``. This is usually only useful in combination with [`multiple`](#multiple), as for content from a single portal, you can just wrap the `` as a whole. + +The slot receives a single vnode as its only prop. These vnodes can be rendered with Vue's dynamic component syntax: `` -Example: +```html + +

Some inline content

+

Some more content

+
+ + +

Some content from a second portal

+
+ +
+ + + +
+``` + +**Result** + +```html +
+
+

Some inline content

+
+
+

Some more content

+
+
+

Some content from a second portal

+
+ +
+``` + +### `v-slot:outerWrapper` + +This slot is similar to `itemWrapper`, but it will be called only once, and receive *all* vnodes in an array. That allows you to wrap all received content in a shared wrapper element. + +Usually, this slot is not very useful as you can instead just put the wrapper around the ``itself. But it's useful for transition groups which would otherwie conflict with the ``'s own root element: -**Source** - ```html - -