All Projects → jpgorman → react-append-to-body

jpgorman / react-append-to-body

Licence: other
React Higher order component that allows you to attach components to the DOM outside of the main app.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-append-to-body

osmcz
JS mapová appka pro openstreetmap.cz (osmcz-app)
Stars: ✭ 35 (+16.67%)
Mutual labels:  portal
Instahelp
Instahelp is a Q&A portal website similar to Quora
Stars: ✭ 21 (-30%)
Mutual labels:  portal
react-stick
React component to stick a portaled node to an anchor node
Stars: ✭ 51 (+70%)
Mutual labels:  portal
recks
🐶 React-like RxJS-based framework
Stars: ✭ 133 (+343.33%)
Mutual labels:  dom
anim8js
The ultimate animation library for javascript - animate everything!
Stars: ✭ 33 (+10%)
Mutual labels:  dom
hsx
Static HTML sites with JSX and webpack (no React).
Stars: ✭ 15 (-50%)
Mutual labels:  dom
grase-www-portal
Grase WWW Portal (Main Package)
Stars: ✭ 50 (+66.67%)
Mutual labels:  portal
sapa
sapa is a library that creates a UI with a simple event system.
Stars: ✭ 65 (+116.67%)
Mutual labels:  dom
svelte-portal
Svelte component for rendering outside the DOM of parent component
Stars: ✭ 261 (+770%)
Mutual labels:  portal
CDom
Simple HTML/XML/BBCode DOM component for PHP.
Stars: ✭ 26 (-13.33%)
Mutual labels:  dom
YetiForcePortal2
The Customer Portal complements YetiForce CRM and is the most effective communication tool for your customers. It’s easy to use and delivers many new functions. You can reduce operating expenses by providing support 24 hours a day. YetiForce Portal platform delivers also greater customer experiences as your clients can see all relevant informati…
Stars: ✭ 28 (-6.67%)
Mutual labels:  portal
lego
🚀 Web-components made lightweight & Future-Proof.
Stars: ✭ 69 (+130%)
Mutual labels:  dom
trident
Trident is a trusted and secure communication platform for enabling better communication between groups of trusted parties
Stars: ✭ 21 (-30%)
Mutual labels:  portal
zig-wasm-dom
Zig + WebAssembly + JS + DOM
Stars: ✭ 81 (+170%)
Mutual labels:  dom
paginathing
a jQuery plugin to paginate your DOM easily.
Stars: ✭ 23 (-23.33%)
Mutual labels:  dom
godot-portal-demo
Experimenting with portals in Godot Engine
Stars: ✭ 66 (+120%)
Mutual labels:  portal
object-dom
HTML Object Declarative Dom
Stars: ✭ 20 (-33.33%)
Mutual labels:  dom
rem
An HTML parsing library, written in Zig.
Stars: ✭ 56 (+86.67%)
Mutual labels:  dom
WebproxyPortlet
No description or website provided.
Stars: ✭ 14 (-53.33%)
Mutual labels:  portal
bolsa
Biblioteca feita em Python com o objetivo de facilitar o acesso a dados de seus investimentos na bolsa de valores(B3/CEI) através do Portal CEI.
Stars: ✭ 46 (+53.33%)
Mutual labels:  portal

Build Status npm version

React higher order component append to body

React Higher order component that allows you to attach components to the DOM outside of the main app. Supports React 16 and React 15 and less, so works with and without ReactDOM.createPortal.

Installation

npm i react-append-to-body --save

Use

import { componentWillAppendToBody } from "react-append-to-body";

/* Some component that you want to attach to the DOM */
function MyComponent({ children }) {
  return <div className="myClassName">{children}</div>;
}

const AppendedMyComponent = componentWillAppendToBody(MyComponent);

class MyApp extends React.Component {
  render() {
    return (
      <div>
        // this content will be rendered in the main app Some content on my page
        // this content will be rendered outside of the main app
        <AppendedMyComponent>
          The content for my appended component
        </AppendedMyComponent>
      </div>
    );
  }
}
/* template */
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta content="width=device-width,initial-scale=1" name="viewport">
</head>
<body class="body">
  <div id="my-app"></div>
  <script src="/app.js"></script>
</html>
/* output */
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta content="width=device-width,initial-scale=1" name="viewport">
</head>
<body class="body">
  <div id="my-app">
    <div>
    // this content will be rendered in the main app
    Some content on my page
    </div>
  </div>
  <div id="append-element-container">
    <div class="myClassName">
      The content for my appended component
    </div>
  </div>
  <script src="/app.js"></script>
</html>

Appending to a named DOM node

const AppendedMyComponent = componentWillAppendToBody(MyComponent);
class MyApp extends React.Component {
  render() {
    return (
      <div>
        Some content on my page // this content will be rendered in the main app
        <AppendedMyComponent
          subtreeContainer={"#my-named-element-to-append-with"}
        >
          The content for my appended component
        </AppendedMyComponent> // this content will be rendered outside of the main
        app
      </div>
    );
  }
}
/* template */
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta content="width=device-width,initial-scale=1" name="viewport">
</head>
<body class="body">
  <div id="my-app"></div>
  /* dom node that content will be appended to */
  <div id="my-named-element-to-append-with"></div>
  <script src="/app.js"></script>
</html>
/* output */
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta content="width=device-width,initial-scale=1" name="viewport">
</head>
<body class="body">
  <div id="my-app">
    <div>
    // this content will be rendered in the main app
    Some content on my page
    </div>
  </div>
  <div id="my-named-element-to-append-with">
    <div class="myClassName">
      The content for my appended component
    </div>
  </div>
  <script src="/app.js"></script>
</html>

With Context

If you want to persist Context into the appended component you can do this by simple setting the contextTypes on the appended component.

// using React Router

const Modal = componentWillAppendToBody(Modal);
Modal.contextTypes = {
  router: React.PropTypes.any.isRequired
};

API

subtreeContainer a string that should contain a selector that will work with document.querySelector [MDN]: https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector

Tests

npm run test

Demo

npm run demo

Then open up your browser at http://localhost:8777

See React docs for examples for your environment.

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].