# react-page-layers

> Manage Layers in React as an alternative to Portals.

Latest version **0.4.0** (published 2017-01-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-page-layers
pnpm add react-page-layers
yarn add react-page-layers
bun add react-page-layers
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2017-01-21 |
| First published | 2017-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Braden R. Napier |
| Maintainers | bradynapier |
| Keywords | react, portal, layer, provider, page-layer |

## Links

- npm: https://www.npmjs.com/package/react-page-layers
- Repository: https://github.com/Dash-OS/react-page-layers
- Homepage: https://github.com/Dash-OS/react-page-layers#readme
- Issues: https://github.com/Dash-OS/react-page-layers/issues
- npm.io page: https://npm.io/package/react-page-layers

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2017-01-21
- 0.3.0 — 2017-01-20
- 0.2.0 — 2017-01-20
- 0.1.0 — 2017-01-20

## README

# react-page-layers

[![npm version](https://badge.fury.io/js/react-page-layers.svg)](https://badge.fury.io/js/react-page-layers)

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

```bash
yarn add react-page-layers
```

**OR**

```bash
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.

```javascript

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

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

```

***

### `<Layer />`

```javascript

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 />`

```javascript

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 />` |

---
_Source: https://npm.io/package/react-page-layers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
