Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-laag

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-laag

Visit the website for more examples and docs [here](https://www.react-laag.com).

  • 1.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13K
decreased by-79.05%
Maintainers
1
Weekly downloads
 
Created
Source
react-laag logo

NPM TYPESCRIPT BUNDLEPHOBIA Weekly downloads

Primitives to build things like tooltips, dropdown menu's and pop-overs.

Basically any kind of layer that can be toggled. Focus on what your layer should look like, and let react-laag take care of where and when to show it.

menu demo circular-menu demo

Documentation

Visit the website for more examples and docs here.

Features

  • Build your own tooltips / dropdown-menu's / pop-overs / etc...
  • Not opinionated regarding styling or animations
  • Highly customizable
  • Only ~5kb minified and gzipped
  • Zero dependencies
  • Built with typescript / ships with typescript definitions
  • Integrates well with other libraries
  • Automatically adjusts your layer's placement to fit the screen
  • Works with nested scroll-containers
  • Observes and reacts to changes in dimensions

Getting started

Installation

npm install --save react-laag

or

yarn add react-laag

A first component

import React from "react";
import { ToggleLayer, anchor } from "react-laag";

function Example() {
  return (
    <ToggleLayer
      // provide placement config
      placement={{ anchor: anchor.BOTTOM_CENTER }}
      // render-prop to render our layer
      renderLayer={({ layerProps, isOpen }) =>
        // only render on `isOpen`
        isOpen && (
          <div
            // for calculation stuff
            ref={layerProps.ref}
            style={{
              // inject calculated positional styles
              ...layerProps.style

              // add your own styles
            }}
          />
        )
      }
    >
      {({ toggle, triggerRef }) => (
        <div
          // only the `triggerRef` is required...
          ref={triggerRef}
          // ...the rest is up to you
          onClick={toggle}
          style={{}}
        />
      )}
    </ToggleLayer>
  );
}

...or use the hook:

import React from "react";
import { useToggleLayer, anchor } from "react-laag";

function Example() {
  const [element, toggleLayerProps] = useToggleLayer(
    // render the layer
    ({ layerProps, isOpen }) => isOpen && <div {...layerProps} />,
    // provide some options, like placement
    { placement: { anchor: anchor.BOTTOM_CENTER } }
  );

  return (
    <div>
      {element}
      <div onClick={toggleLayerProps.openFromMouseEvent}>Click me!</div>
    </div>
  );
}

License

MIT © everweij

FAQs

Package last updated on 03 Nov 2019

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