0.4.8 • Published 1 year ago

@krestui/svelte-portal v0.4.8

Weekly downloads
-
License
SEE LICENSE in LI...
Repository
github
Last release
1 year 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

1 year ago

0.4.4

1 year ago

0.4.7

1 year ago

0.4.6

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.3.9

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.7

2 years ago

0.4.0

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago