All Projects → ryanseddon → React Frame Component

ryanseddon / React Frame Component

Licence: mit
Render your React app to an iFrame

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Frame Component

Zoid
Cross domain components
Stars: ✭ 1,672 (+43.77%)
Mutual labels:  component, iframe
Vue Autonumeric
A Vue.js component that wraps the awesome autoNumeric input formatter library
Stars: ✭ 68 (-94.15%)
Mutual labels:  component
React Qmap
💡react腾讯地图开源组件
Stars: ✭ 60 (-94.84%)
Mutual labels:  component
Daggraph
Dagger dependency graph generator for Android Developers
Stars: ✭ 1,140 (-1.98%)
Mutual labels:  component
Dzhtmltext
Delphi and Lazarus HTML Label component
Stars: ✭ 60 (-94.84%)
Mutual labels:  component
Vue Clock2
vue clock component 😀
Stars: ✭ 67 (-94.24%)
Mutual labels:  component
Region Picker
A region picker based on Vue and ElementUI.
Stars: ✭ 59 (-94.93%)
Mutual labels:  component
Utils
🛠 Lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.
Stars: ✭ 1,158 (-0.43%)
Mutual labels:  component
React Native X Bar
🎩 A flexible, lightweight bar component for common UI patterns in React Native
Stars: ✭ 68 (-94.15%)
Mutual labels:  component
Vue Virtual Keyboard
⌨️ Vue Virtual Keyboard
Stars: ✭ 65 (-94.41%)
Mutual labels:  component
Class Loader
[DEPRECATED] The ClassLoader component provides tools to autoload your classes and cache their locations for performance.
Stars: ✭ 1,131 (-2.75%)
Mutual labels:  component
Stf Vue Select
stf vue select - most flexible and customized select
Stars: ✭ 61 (-94.75%)
Mutual labels:  component
Made With Love
🚀 An experimental project which demonstrates an Angular Package which contains Angular Elements and Schematics
Stars: ✭ 67 (-94.24%)
Mutual labels:  component
Redemo
react demo component
Stars: ✭ 60 (-94.84%)
Mutual labels:  component
Prelodr
A simple Material preloader inspired by Google Inbox.
Stars: ✭ 68 (-94.15%)
Mutual labels:  component
Vue Seamless Scroll
🔰A simple, seamless scrolling for Vue.js vue无缝滚动component
Stars: ✭ 1,106 (-4.9%)
Mutual labels:  component
React Pin Field
📟 React component for entering PIN codes.
Stars: ✭ 63 (-94.58%)
Mutual labels:  component
Horsey
🐴 Progressive and customizable autocomplete component
Stars: ✭ 1,146 (-1.46%)
Mutual labels:  component
French Press Editor
☕ An offline-first rich text editor component.
Stars: ✭ 69 (-94.07%)
Mutual labels:  component
Security Guard
The Guard component brings many layers of authentication together, making it much easier to create complex authentication systems where you have total control.
Stars: ✭ 1,157 (-0.52%)
Mutual labels:  component

React <Frame /> component

NPM version Build Status Dependency Status

This component allows you to encapsulate your entire React application or per component in an iFrame.

npm install --save react-frame-component

How to use:

import Frame from 'react-frame-component';

Go check out the demo.

const Header = ({ children }) => (
  <Frame>
    <h1>{children}</h1>
  </Frame>
);

ReactDOM.render(<Header>Hello</Header>, document.body);

Or you can wrap it at the render call.

ReactDOM.render(
  <Frame>
    <Header>Hello</Header>
  </Frame>,
  document.body
);
Props:
head

head: PropTypes.node

The head prop is a dom node that gets inserted before the children of the frame. Note that this is injected into the body of frame (see the blog post for why). This has the benefit of being able to update and works for stylesheets.

initialContent

initialContent: PropTypes.string

Defaults to '<!DOCTYPE html><html><head></head><body><div></div></body></html>'

The initialContent props is the initial html injected into frame. It is only injected once, but allows you to insert any html into the frame (e.g. a head tag, script tags, etc). Note that it does not update if you change the prop. Also at least one div is required in the body of the html, which we use to render the react dom into.

mountTarget

mountTarget: PropTypes.string

The mountTarget props is a css selector (#target/.target) that specifies where in the initialContent of the iframe, children will be mounted.

<Frame
  initialContent='<!DOCTYPE html><html><head></head><body><h1>i wont be changed</h1><div id="mountHere"></div></body></html>'
  mountTarget='#mountHere'
  >
</Frame>
contentDidMount and contentDidUpdate

contentDidMount: PropTypes.func contentDidUpdate: PropTypes.func

contentDidMount and contentDidUpdate are conceptually equivalent to componentDidMount and componentDidUpdate, respectively. The reason these are needed is because internally we call ReactDOM.render which starts a new set of lifecycle calls. This set of lifecycle calls are sometimes triggered after the lifecycle of the parent component, so these callbacks provide a hook to know when the frame contents are mounted and updated.

Accessing the iframe's window and document

The iframe's window and document may be accessed via the FrameContextConsumer.

import Frame, { FrameContextConsumer } from 'react-frame-component'

const MyComponent = (props, context) => (
  <Frame>
    <FrameContextConsumer>
      {
        // Callback is invoked with iframe's window and document instances
        ({document, window}) => {
          // Render Children
        }
      }
    </FrameContextConsumer>
  </Frame>
);

More info

I wrote a blog post about building this component.

License

Copyright 2014, Ryan Seddon. This content is released under the MIT license http://ryanseddon.mit-license.org

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