🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

placement.js

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

placement.js

A tiny library for positioning overlays. Useful for tooltips, popovers etc.

1.0.0-beta.3
Source
npm
Version published
Weekly downloads
819
-22.3%
Maintainers
1
Weekly downloads
 
Created
Source

Placement.js

A tiny library for positioning overlays. Useful for tooltips, popovers etc.

Size

Demo

Why? Positioning UI overlays like popovers and tooltips can be challenging. If you position them with CSS, then at some stage you are likely to run into problems with z-indices, parent overflows, or content going off the edge of the screen. JavaScript to the rescue!

Placement.js addresses a single use-case: positioning an overlay to one side of an anchor element, optimizing the placement depending on the size of the overlay:

  • If the overlay is too big, it may flip to the other side if there is more room available.
  • The dimensions of the overlay will be capped so that it will never go off-screen.

Small filesize is a priority for Placement.js so that it can be included in web components. For a more powerful, configurable library, check out Popper.js.

Installation

npm install placement.js --save

Usage

import { place } from 'placement.js';

place(
    anchor: HTMLElement,
    overlay: HTMLElement,
    options?: Options
);

type Options = {
    placement?: Placement // defaults to 'bottom'
};

type Placement =
    | 'top'
    | 'top-start'
    | 'top-end'
    | 'bottom'
    | 'bottom-start'
    | 'bottom-end'
    | 'right'
    | 'right-start'
    | 'right-end'
    | 'left'
    | 'left-start'
    | 'left-end';

Check out the demo to see it in action.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

FAQs

Package last updated on 02 Mar 2021

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