0.2.6 • Published 2 years ago

@irispixel/svelte-portal v0.2.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Portal

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

License

The code is issued under MIT License.

Installation

package.json

  "dependencies": {
    "@irispixel/svelte-portal": "^0.2.5",
  }

Problem Statement

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

Usage and Example

Example.svelte

<script lang="ts">
  import Portal from '@irispixel/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.2.6

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago