All Projects → ae0f → react-layer-stack

ae0f / react-layer-stack

Licence: MIT license
Layering system for React. Useful for popover/modals/tooltip/dnd application

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-layer-stack

React Layer Stack
Layering system for React. Useful for popover/modals/tooltip/dnd application
Stars: ✭ 152 (-3.8%)
Mutual labels:  react-component, popover, transportation, overlay, modal, lightbox, tooltip, popup, portal, dropdown, layer, window
React Cool Portal
😎 🍒 React hook for Portals, which renders modals, dropdowns, tooltips etc. to <body> or else.
Stars: ✭ 458 (+189.87%)
Mutual labels:  popover, modal, lightbox, tooltip, portal, dropdown
toppy
Overlay library for Angular 7+
Stars: ✭ 81 (-48.73%)
Mutual labels:  popover, overlay, modal, tooltip, dropdown
React Useportal
🌀 React hook for Portals
Stars: ✭ 698 (+341.77%)
Mutual labels:  modal, lightbox, tooltip, portal, dropdown
Jbox
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.
Stars: ✭ 1,251 (+691.77%)
Mutual labels:  modal, lightbox, tooltip, popup
Ng Bootstrap
Angular powered Bootstrap
Stars: ✭ 7,872 (+4882.28%)
Mutual labels:  popover, modal, tooltip, dropdown
Jquery Popup Overlay
jQuery plugin for responsive and accessible modal windows and tooltips
Stars: ✭ 511 (+223.42%)
Mutual labels:  overlay, modal, tooltip, popup
Tippyjs
Tooltip, popover, dropdown, and menu library
Stars: ✭ 9,433 (+5870.25%)
Mutual labels:  popover, tooltip, popup, dropdown
Popupdialog
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.
Stars: ✭ 3,709 (+2247.47%)
Mutual labels:  overlay, modal, popup
React Native Loading Spinner Overlay
💈 React Native loading spinner overlay
Stars: ✭ 1,369 (+766.46%)
Mutual labels:  overlay, modal, portal
Popper Core
🍿 JavaScript positioning library for tooltips, popovers, dropdowns, and more
Stars: ✭ 18,903 (+11863.92%)
Mutual labels:  popover, tooltip, dropdown
react-spring-bottom-sheet
Accessible ♿️, Delightful ✨, & Fast 🚀
Stars: ✭ 604 (+282.28%)
Mutual labels:  overlay, modal, popup
Django Admin Interface
django's default admin interface made customizable. popup windows replaced by modals. :mage: ⚡️
Stars: ✭ 717 (+353.8%)
Mutual labels:  modal, popup, window
React Laag
Hooks to build things like tooltips, dropdown menu's and popovers in React
Stars: ✭ 568 (+259.49%)
Mutual labels:  popover, tooltip, dropdown
Tippyjs React
React component for Tippy.js (official)
Stars: ✭ 1,081 (+584.18%)
Mutual labels:  popover, tooltip, dropdown
floating-ui
A low-level toolkit to create floating elements. Tooltips, popovers, dropdowns, and more
Stars: ✭ 23,485 (+14763.92%)
Mutual labels:  popover, tooltip, dropdown
Basiclightbox
The lightest lightbox ever made.
Stars: ✭ 299 (+89.24%)
Mutual labels:  modal, lightbox, popup
React Popper Tooltip
A React hook to effortlessly build smart tooltips.
Stars: ✭ 149 (-5.7%)
Mutual labels:  popover, overlay, tooltip
Reactjs Popup
React Popup Component - Modals,Tooltips and Menus —  All in one
Stars: ✭ 1,211 (+666.46%)
Mutual labels:  react-component, modal, tooltip
Popover
Popover component for Angular
Stars: ✭ 187 (+18.35%)
Mutual labels:  popover, overlay, popup

DEPRICATED

Live demo

Chat

Rationale

react/react-dom comes with 2 basic assumptions/ideas:

  • every UI is hierarchical naturally. This why we have the idea of "components wrap each other"
  • react-dom mounts (physically) child component to its parent DOM node by default

The problem is that sometimes the second property isn't what you want in your specific case. Sometimes you want to mount your component into the different physical DOM node and hold the logical parent-child connection at the same time.

Canonical example is a Tooltip-like component: at some point, during development process, you could find that you need to add some description for your UI element: it'll be rendered in some fixed layer and it should know its coordinates (which are corresponding UI element coord or mouse coords) and at the same time it needs information whether it should be shown right now or not, its content and some context from parent components.

import React, { Component } from 'react';
import { Layer, LayerToggle } from 'react-layer-stack';
import FixedLayer from './demo/components/FixedLayer';

class Demo extends Component {
  render() {
    return (
      <div>
        <Layer to="screen" id="lightbox2">{ (_, content) => // Layer should have an unique ID
          <FixedLayer style={ { marginRight: '15px', marginBottom: '15px' } }>
            { content }
          </FixedLayer>
        }</Layer>

        <LayerToggle for="lightbox2">{({ show, hide }) => ( // Layer is accessible from any part of the tree. 
                                                            // There could be several Toggles for one Layer.
            <button onMouseLeave={ hide } onMouseMove={ ({ pageX, pageY }) => {
              show(
                <div style={{
                      left: pageX, top: pageY + 20, position: "absolute",
                      padding: '10px',
                      background: 'rgba(0,0,0,0.7)', color: '#fff', borderRadius: '5px',
                      boxShadow: '0px 0px 50px 0px rgba(0,0,0,0.60)'}}>
                   “There has to be message triage. If you say three things, you don’t say anything.”
                </div>)
            }}>Yet another button. Move your pointer to it.</button> )}
          </LayerToggle>
      </div>
    )
  }
}

Another option could be use one of dozens complete implementations with different properties: https://js.coach/?search=popover

More examples

https://github.com/fckt/react-layer-stack/blob/master/demo/src/Demo.js

Live demo

https://fckt.github.io/react-layer-stack/

Installation

npm install --save react-layer-stack

API

3 components with a few properties.

<Layer />

id: string - a Layer identificator. There could be only one layer with the same id

to (optional) - the mount point to mount to. If to is not defined the layer will be rendered right in place

use: Array (optional) - array with context (closure) variables. Useful if you want to update the Layer if closure variables are changed

defaultArgs: Array (optional) - initial arguments for a Layer

defaultShow: Boolean (optional)

children: callback({ isActive, show: callback(args), showOnlyMe, hide, hideAll }, ...args): ReactElement - will be rendered into

<LayerToggle />

LayerToggle is a helper to have an access for show/hide callbacks and the current state of the layer. There could be multiple LayerToggles for the same Layer.

for: string - a Layer identificator which LayerToggle corresponds to

children: callback({ isActive, show: callback(args), showOnlyMe, hide, hideAll }): ReactElement - will be mounted (rendered) directly to its parent

<LayerStackMountPoint />

This is a mount point for Layers.

id: string (optional) - you can have multiple LayerStackMountPoint which could have different ID's

children: callback({ views, displaying, show: callback(id, args), hide, hideAll, mountPointId, mountPointArgs }): ReactElement - you can choose different strategies how to render Layers in LayerStackMountPoint instead of the default one

Real-world usage example

Public API consist 2 key components: Layer, LayerStackMountPoint and 1 additional: LayerToggle (sometimes toggle needs to know which popover is open now). Set the LayerStackMountPoint somewhere on the top of the tree:

import { LayerStackProvider, LayerStackMountPoint } from 'react-layer-stack'
// ...
//  render() {
        return (
            <LayerStackProvider>
              <Container>
                <LayerStackMountPoint id="screen"/>
                <AppBar />
                <Container className={styles.container}>
                  {children}
                </Container>
              </Container>
            </LayerStackProvider>
        )
//  }

Define your Layer. This example shows how to propagate variables from lexical context (https://developer.mozilla.org/en/docs/Web/JavaScript/Closures) to the Layer, which will be displayed in the LayerStackMountPoint. Each layer should have an id and use properties. use property is needed to determine if we should update the lexical context of the anonymous function which renders Modal into Layer if Cell is updated.

import { Layer, LayerToggle } from 'react-layer-stack'
// ... for each `object` in array of `objects`
const modalId = 'DeleteObjectConfirmation' + objects[rowIndex].id
return (
    <Cell {...props}>
        // the layer definition. The content will show up in the LayerStackMountPoint when `show(modalId)` be fired in LayerToggle
        <Layer to="screen" use={[objects[rowIndex], rowIndex]} id={modalId}> {({
            hide, // alias for `hide(modalId)`
            index } // useful to know to set zIndex, for example
            , e) => // access to the arguments (click event data in this example)
          <Modal onClick={ hide } zIndex={(index + 1) * 1000}>
            <ConfirmationDialog
              title={ 'Delete' }
              message={ "You're about to delete to " + '"' + objects[rowIndex].name + '"' }
              confirmButton={ <Button type="primary">DELETE</Button> }
              onConfirm={ this.handleDeleteObject.bind(this, objects[rowIndex].name, hide) } // hide after confirmation
              close={ hide } />
          </Modal> }
        </Layer>
        
        // this is the toggle for Layer with `id === modalId` can be defined everywhere in the components tree
        <LayerToggle for={ modalId }> {({show}) => // show is alias for `show(modalId)`
          <div style={styles.iconOverlay} onClick={ (e) => show(e) }> // additional arguments can be passed (like event)
            <Icon type="trash" />
          </div> }
        </LayerToggle>
    </Cell>)
// ...

ReactDOM.unstable_createPortal

Facebook team is working on the similar feature called "portals" (by analogy with https://github.com/tajo/react-portal). That approach uses ReactDOM (API) which is fatal if browser is not the only target. There are other considerations also.

Alternatives

The is a lot of alternative ways to archive the desirable bottom-to-up link b/w components.

The most obvious (and naiive as well) way is to use redux (or another flux/data lib) as a transport to send data from one DOM branch to another. It's good and robust solution, but the problem is that it just feels like overkill. It seems not universal also, could consume some additional time to implement and grasp afterwards, not because of complications, but because you have to reinvent the same pattern again and again (slightly different in each case, see https://stackoverflow.com/questions/35623656/how-can-i-display-a-modal-dialog-in-redux-that-performs-asynchronous-actions).

Another solution is to use on of ready-to-use components. But sometimes are you need slightly different behavior/look and more productive to implement home-grown ad-hock solution.

And the last option is to find library like https://github.com/tajo/react-portal or https://react-bootstrap.github.io/react-overlays/, designed to address the needs of bottom-to-up communication. These libs are often quite opinionated to their cases and doesn't solve the problem in its roots. The goal of react-layer-stack is to give an answer how to organize bottom-to-up communication in the most natural, reasonable and flexible way.

The future

Obviously there is a lot of applications for the Layer API (https://github.com/fckt/react-layer-stack/blob/master/README.md#layer-). So, you can declare the entire React app as a Layer and manage it from the outer app!

Images to understand the whole thing

View layers stack

Symlink

Layer id and "use" property (sym/soft link)

Symlink

Related Stackoverflow q&a

The easiest way to support react-layer-stack is to upvote the answers below.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].