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

@dile/dile-overlay-mixin

v3.0.2

Published

Mixin function to esaily create overlay web components

Downloads

38

Readme

@dile/dile-overlay-mixin

Mixin to create overlay elements. It has the functionality to position custom elements in a various ways, and open or close the elements with a smooth animation.

Requirements

This mixin need two elements in the web component to make its work:

  • Overlay layer, to show / hide some content
  • Trigger element, to click and toggle the overlay state

Both elements should be in the shadow DOM of the element and need to have this ids:

  • #overlay for the overlay layer content
  • #trigger for the element to asign the close / hide functions

Also is necessary to asign some styles to the overlay element:

#overlay {
  display: none;
  position: absolute;
  opacity: 0;
}

Usually you may also prefer to asign some additional styles, to make a transition between hide / show states:

#overlay {
  display: none;
  position: absolute;
  opacity: 0;
  transition: ease 0.5s;
  transition-property: transform, opacity;
  transform: translateY(-10px);
}

To create the smooth animation there is also necessary to create a "opened" CSS class, to asing styles to the open state of the overlay layer.

#overlay.opened {
  opacity: 1;
  transform: translateY(0);
}

Of course, you can customize your own styles to create your preferred animations.

Usage

Install

npm install @dile/dile-overlay-mixin

Use the mixin

import { LitElement, html, css } from 'lit';
import { DileOverlayMixin } from '@dile/dile-overlay-mixin';

class NewComponent  extends DileOverlayMixin(LitElement) {

}

Properties

The mixin offers several properties to customize the the way it shows the overlay.

  • horizontalAlign: String property to set the horizontal position of the menu. Valid values are "under_left", "under_right", "left", "right" or "center". Default to "under_left".
  • verticalAlign: String property to set the vertical position of the menu. Valid values are "bottom", "center" or "top". Default to "bottom".
  • moveTop: Number of pixels to modify the default vertical position of the overlay. Accepts positive (move down) an negative (move up) values. Default 0.
  • moveLeft: Number of pixels to modify the default horizontal position of the overlay. Accepts positive (move right) an negative (move left) values. Default 0.

Overlay state

This mixin also includes a "state" property called "_overlayClass". In order to have the opened/closed state in the overlay layer you should assign the property into the class attribute.

<div id="overlay" class="${this._overlayClass}">
  I am the overlay layer
</div>

Methods

  • open(): Use it to open the menu overlay box
  • close(): Use it to close the menu overlay box
  • toggle(): Toggles the menu-overlay box

Important note: the trigger does not opens the menu by itself. You must call the open() or toggle() method to open the menu when you need. The trigger is used by default only for positioning the menu overlay.

For example, you can use the the toogle() method as a click handler on the trigger.

<span id="trigger" @click=${this.toggle}>This is the trigger</span>

Custom events

  • overlay-opened: dispatched when the overlay opens.
  • overlay-closed: dispatched when the overlay closes.