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

react-page-layers

v0.4.0

Published

Manage Layers in React as an alternative to Portals.

Downloads

7

Readme

react-page-layers

npm version

While other libraries exist that provide portal like capabilities, I personally had some issues with a few of them. I wanted functionality to handle layers but didn't like the idea of appending to the body of my DOM as I started to see issues where some failed to clean up after themselves.

The concept is fairly simple. It should NOT be used as an alternative to the top-down approach that React provides. This library definitely has the potential to do so and it was not how it was meant to be used (and you will get in trouble if you use it that way).

Essentially this simply allows you to "teleport" parts of your components to different places to be rendered. This way you can render your modal locally with your local variables and state but have it render in a place that it can be put on top of all other elements easily.

Install

yarn add react-page-layers

OR

npm install --save react-page-layers

Configuration

Configuration should be very straight forward.

<LayerProvider />

Wrap your App with LayerProvider. It doesn't have to be at the top-level, it just has to be above all <Layer /> and <OnLayer /> components.


import LayerProvider from 'react-page-layers/LayerProvider'
// or import { LayerProvider } from 'react-page-layers'

ReactDOM.render(
  <LayerProvider>
    <App />
  </LayerProvider>,
  document.querySelector('#app')
)

<Layer />


import Layer from 'react-page-layers/Layer'
// or import { Layer } from 'react-page-layers'

const MyComponent = () => (
  <div>
    <h1>MyComponent Header</h1>
    <Layer id='UnderHeader' />
  </div>
)

A Layer is a point in the DOM you want to be able to render your child elements.
You will be able to "mount" components onto layers from anywhere within the App. It should not have any children (well, they will just be ignored).

| Prop | Type(s) | Description | | ------------- |:-------------:| ----- | | layerID | string | Required unique id which is not shared with any other <Layer /> in your app. | | show | boolean | Optional boolean to hide/show the layers children |

<OnLayer />


import OnLayer from 'react-page-layers/OnLayer'
// or import { OnLayer } from 'react-page-layers'

const AnotherComopnent = () => (
  <div>
    <OnLayer layerID='UnderHeader' childID='FromAnotherComponent' show={true}>
      <div>Another Component says Hi on MyComponent!</div>
    </OnLayer>
  </div>
)

<OnLayer /> is where you specify content that should be rendered into your <Layer />. Simply provide it with the layerID of the Layer it should render into. Each <OnLayer /> must have its own unique ID that is not shared with any other OnLayer (although this is only enforced for the layer it renders onto). You must also provide a boolean value to show to determine if the content should be rendered or not.

| Prop | Type(s) | Description | | ------------- |:-------------:| ----- | | layerID | string | Required ID of the <Layer /> we should render into. | | childID | string | Required Unique ID for your <OnLayer /> which is not shared with any other child. | | show | boolean | Required boolean indicating if we should render the children into the <Layer /> |