0.4.8 • Published 2 years ago

@krestui/svelte-portal v0.4.8

Weekly downloads
-
License
SEE LICENSE in LI...
Repository
github
Last release
2 years ago

Portal

@krestui/svelte-portal is a svelte component to implement Portal functionality.

Installation

package.json

  "dependencies": {
    "@krestui/svelte-portal": "^0.4.8",
  }

Problem Statement

Portals are used to display HTML elements that need not be necessarily in the document flow.

Usage and Example

Example.svelte

<script lang="ts">
  import Portal from '@krestui/svelte-portal/Portal.svelte';
  let isOpen = false;

  function enter() {
    isOpen = true;
  }

  function leave() {
    isOpen = false;
  }
</script>

<button type="button" on:mouseenter={enter} on:mouseleave={leave}
  >Hover over me to enable and disable portal
</button>
<Portal {isOpen}>
  <span>Some Portal Content</span>
</Portal>

In the example above, the Portal content appears and disappears accordingly when we hover over the button.

Internals

By default, the Portal svelte component looks for a div by id portals in the current HTML document .

In case the div does not exist before, it can be created as a child at the root of the HTML document, right under <body> as - <div id="portals" />.

An example is illustrated below.

<body>
  ...
  <div id="portals" />
</body>

It appends the slot as a child to the <div id='portals'> .

Use Cases

Some of the popular applications include popovers, dropdowns and modals as in most of these cases they need not be in the document flow.

0.4.8

2 years ago

0.4.4

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.4.1

3 years ago

0.3.9

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.7

3 years ago

0.4.0

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago