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

@zensen/popover

v1.0.0

Published

A Redux-based popover manager for native web components

Downloads

3

Readme

zensen-popover

A Redux-based popover manager in LitElement.

Features

  • Provides a single manager element to handle all of your popovers
  • It will automatically replace the current popover if opening a popover while one is open
  • Provides a way to set coordinates
  • The Popover base component class provides a way to render popovers in window space
  • Disables scrolling while popovers are available
  • Has an intuitive interface for pushing and retrieving data to and from popovers

Install

Using npm:

$ npm install @zensen/popover

Using yarn:

$ yarn add @zensen/popover

Configuring, Creating, and Registering Popover Components

Configuring the popover manager component by providing a redux store object

import { configure } from '@zensen/popover'

configure(store)

Create your own popover components by extending this package's Popover base class

import { Popover } from '@zensen/popover'
import { css, html } from 'lit-element'

class CalendarPopover extends Popover {
  // TODO: provide your implementation here
}

window.customElements.define('x-popover-calendar', CalendarPopover)

The next step is to create a map of popover renderer functions that will be used to register each type of popover component with the popover stack:

export const POPOVER_CALENDAR = 'confirm'

export const RENDERER_POPOVERS = {
  [POPOVER_CALENDAR]: (layout, model, target, closeHandler) => html`
    <x-popover-calendar
      .layout="${layout}"
      .model="${model}"
      .target="${target}"
      .onClose="${closeHandler}"
    ></x-popover-calendar>
  `,
}

Then, we instantiate the popover stack component in our app, assigning our renderers to it.

NOTE: It's usually a good idea to put this towards the top of your app's DOM towards as the last child of its containing element.

class App extends LitElement {
  static get styles () {
    return css`
      :host {
        display: block;
      }

      .container {
        display: flex;
        width: 100%;
        height: 100%;
      }
    `
  }

  render () {
    return html`
      <div class="container">
        <!-- PUT APP CONTENT HERE -->
      </div>

      <zen-popover-manager .renderers="${RENDERER_POPOVERS}"></zen-popover-manager>
    `
  }
}

window.customElements.define('x-app', App)

API

We can open popovers like so:

import { openPopover } from '@zensen/popover'
import { POPOVER_CALENDAR } from './popover-renderers'

const el = document.getElementById('input-calendar')
const model = { date: new Date() }

const result = await openPopover(POPOVER_CALENDAR, el, model)

openPopover() returns a promise, so it can be awaited. It will resolve once the popover calls its this.onClose() callback. openPopover() will return whatever is passed into this.onClose(). In the case of our Calendar Popover, it will return true when the Confirm button is clicked, or false when the Cancel button is clicked.

We can also manually remove the last popover from the stack like so:

import { dismissPopover } from '@zensen/popover'

dismissPopover()