npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lit-portal

v1.0.5

Published

The `<lit-portal/>` component enables you to seamlessly _teleport_ your HTML to a different part of the DOM, while retaining all the benefits of [Lit](https://lit.dev) framework's state management, shadow DOM encapsulation, and other features. With this c

Downloads

966

Readme

Lit Portal

The <lit-portal/> component enables you to seamlessly teleport your HTML to a different part of the DOM, while retaining all the benefits of Lit framework's state management, shadow DOM encapsulation, and other features. With this component, you can easily create dynamic UI elements such as modals, notifications, tooltips, and more.

Install

npm

npm i lit-portal

yarn

yarn add lit-portal

Usage

  1. Write the import statement
  2. Use <lit-portal /> component with the to property to specify where you want the contents to be portaled to.
  3. Use .body property to specify the contents.
import { LitElement, html } from "lit";
import { customElement } from "lit/decorators.js";

import "lit-portal";

@customElement("my-page")
export class MyPage extends LitElement {
  render() {
    return html`
      <p>This Renders Inline</p>

      <lit-portal
        to="portal-root"
        .body=${html`<p>This renders in a div with the ID "portal-root"</p>`}
      ></lit-portal>
    `;
  }
}

Props

  • to

    • Type: string
    • Optional: Yes
    • Notes:
      • If you do not specify this property, the contents will be portaled to the end (before the </body> tag)
      • If the ID provided is not present in the DOM, a div will be created with that ID and added to the end (before the </body> tag)
      • If this property is changed dynamically, the elements will be unmounted / removed from the old destination and remounted into the new destination. Any state within them will be lost and life cycle methods like disconnectedCallback will be run on the old instance and connectedCallback will be run on the new instance.
  • containerClass

    • Type: string
    • Optional: Yes
    • Notes: This class name will be given to the container div that will contain your body.
  • .body

    • Type: TemplateResult
    • Notes:
      • Use the html function to render.
      • Make sure to add . before body otherwise you'll just see [object Object] as the output.

Limitations & Quirks

  • Shadow DOM Issues

    • This component uses document.getElementById() to find the destination (to) element and render the body within it. If your destination is within a shadow root, getElementById() returns null. This is the default behavior in shadow DOMs and there is no feasible work around to this. Your destination MUST be in document and not within a shadow root.
    • The .body that you pass itself can have a shadow DOM. So you won't need to make any changes within your existing shadow DOM components that are being portaled. Only the destination shouldn't be in a shadow DOM.
  • Use Arrow Functions For Events

    • For any event listeners attached within the .body, make sure they are arrow functions otherwise this doesn't work. A sample code below for your reference:
    • Sample Code
  • Container Wrapped

    • You can use the <lit-portal /> multiple times in your layout. Each instance of it can also be portaled to the same destination element.
    • BUT each instance creates one div (with a unique ID) inside the destination element within which the body is rendered. This is done to keep track and clean up the elements as and when required.
    • If you want to style this container, you can use the containerClass attribute, give it a unique class name and add your CSS on that.

If you come across any other limiations OR know fixes to any of the above, feel free to create a PR!

License

MIT