New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@lion/overlays

Package Overview
Dependencies
Maintainers
1
Versions
128
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lion/overlays

Overlays System using lit-html for rendering

  • 0.32.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.1K
decreased by-19.17%
Maintainers
1
Weekly downloads
 
Created
Source

Systems >> Overlays >> Overview ||10

Supports different types of overlays like dialogs, toasts, tooltips, dropdown, etc.

Manages their position on the screen relative to other elements, including other overlays.

Its purpose is to make it easy to use our Overlay System declaratively. It can be easily extended where needed, to override event listeners and more.

See lion-dialog and lion-tooltip for example Web Component implementations using the Overlay System.

Features

  • local rendering (at dom location)
    • positioning with popper.js
  • global rendering (at body level)
  • fully accessible
  • flexible to build multiple overlay components
  • lion-overlay web component:
    • Show content when clicking the invoker
    • Have a .config object to set or update the OverlayController's configuration
  • OverlaysManager, a global repository keeping track of all different types of overlays
  • OverlayController, a single controller class for handling overlays
  • OverlayMixin, a mixin that can be used to create webcomponents that use the OverlayController under the hood

Usually you will use lion-dialog (or lion-tooltip if this makes more sense).

Installation

npm i --save @lion/overlays
npm i --save @lion/dialog

Example

import '@lion/dialog/define';

html`
  <lion-dialog .config=${{
    placementMode: 'global',
    viewportConfig: { placement: 'bottom-right' },
  }}>
    <div slot="content">
      This is an overlay
      <button
        @click=${e => e.target.dispatchEvent(new Event('close-overlay', { bubbles: true }))}
      >x</button>
    <div>
    <button slot="invoker">
      Click me
    </button>
  </lion-dialog>
`;

Or by creating a controller yourself

import { OverlayController } from '@lion/overlays';

const ctrl = new OverlayController({
  ...withModalDialogConfig(),
  invokerNode,
  contentNode,
});

Or creating your own Web Component which uses the Overlay System

import { LitElement, html } from '@lion/core';
import { OverlayMixin, withModalDialogConfig } from '@lion/overlays';

class MyOverlayComponent extends OverlayMixin(LitElement) {
  _defineOverlayConfig() {
    return {
      ...withModalDialogConfig(),
    };
  }

  _setupOpenCloseListeners() {
    super._setupOpenCloseListeners();
    this.__toggle = () => {
      this.opened = !this.opened;
    };

    if (this._overlayInvokerNode) {
      this._overlayInvokerNode.addEventListener('click', this.__toggle);
    }
  }

  _teardownOpenCloseListeners() {
    super._teardownOpenCloseListeners();

    if (this._overlayInvokerNode) {
      this._overlayInvokerNode.removeEventListener('click', this.__toggle);
    }
  }

  render() {
    return html`
      <slot name="invoker"></slot>
      <div id="overlay-content-node-wrapper">
        <slot name="content"></slot>
      </div>
    `;
  }
}

Rationales

Please check the system rationals folder, where we go more in-depth.

Aria roles

  • No aria-controls as support for it is not quite there yet
  • No aria-haspopup. People knowing the haspopup and hear about it don’t expect a dialog to open (at this moment in time) but expect a sub-menu. Until support for the dialog value has better implementation, it’s probably best to not use aria-haspopup on the element that opens the modal dialog.

Keywords

FAQs

Package last updated on 06 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc