All Projects → FormidableLabs → Component Playground

FormidableLabs / Component Playground

Licence: mit
A component for rendering React components with editable source and live preview

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Component Playground

Wonders
🌈 Declarative JavaScript framework to build command-line applications.
Stars: ✭ 34 (-97.04%)
Mutual labels:  jsx
React Native Hotels App
⛺️ Hotels App: A simple react-native App exercise with nodeJS API consumption
Stars: ✭ 50 (-95.64%)
Mutual labels:  jsx
Jsx Render
Lightweight util to render JSX without react
Stars: ✭ 60 (-94.77%)
Mutual labels:  jsx
Rich Text To Jsx
📄 Opinionated JSX renderer for the Contentful rich text field type.
Stars: ✭ 39 (-96.6%)
Mutual labels:  jsx
Chatblocks
Declarative Messenger chatbot framework
Stars: ✭ 48 (-95.82%)
Mutual labels:  jsx
Cascade
A modern library for creating user interfaces.
Stars: ✭ 50 (-95.64%)
Mutual labels:  jsx
Babel Plugin Jsx Two Way Binding
🍺 A two-way data binding solution for React
Stars: ✭ 15 (-98.69%)
Mutual labels:  jsx
Sowing Machine
🌱A React UI toolchain & JSX alternative
Stars: ✭ 64 (-94.43%)
Mutual labels:  jsx
Gatsby Plugin Mdx
gatsby v1 mdx plugin, for gatsby v2 see https://github.com/ChristopherBiscardi/gatsby-mdx
Stars: ✭ 50 (-95.64%)
Mutual labels:  jsx
Markdown To Jsx
🏭 The most lightweight, customizable React markdown component.
Stars: ✭ 1,079 (-6.01%)
Mutual labels:  jsx
Jsx Lite
Write components once, run everywhere. Compiles to Vue, React, Solid, Angular, Svelte, and Liquid.
Stars: ✭ 1,015 (-11.59%)
Mutual labels:  jsx
React Es6 Padawan To Jedi Book
Uma introdução simples e completa para React usando ES6 e Babel.
Stars: ✭ 46 (-95.99%)
Mutual labels:  jsx
Js Toolbox
CLI tool to simplify the development of JavaScript apps/libraries with little to no configuration. (WORK IN PROGRESS/PACKAGE NOT PUBLISHED).
Stars: ✭ 53 (-95.38%)
Mutual labels:  jsx
Cattous
CSS in JSX for lazy developers, built using styled-components and styled-system
Stars: ✭ 38 (-96.69%)
Mutual labels:  jsx
Instrinsicreactjsx
example for kontraktor react/jsx SPA without nodejs (java implementation of jsx, npm and bundling)
Stars: ✭ 61 (-94.69%)
Mutual labels:  jsx
Preact
⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
Stars: ✭ 30,527 (+2559.15%)
Mutual labels:  jsx
Universal React Demo
ES6 demo of a simple but scalable React app with react-router, code splitting, server side rendering, and tree shaking.
Stars: ✭ 50 (-95.64%)
Mutual labels:  jsx
One Punch Fitness
A "One Punch Man"-inspired workout app!
Stars: ✭ 64 (-94.43%)
Mutual labels:  jsx
Svg2jsx
🍃 Transform SVG to valid JSX.
Stars: ✭ 1,116 (-2.79%)
Mutual labels:  jsx
Calendar Graph
Calendar graph like github using jsx support SVG, Canvas and SSR
Stars: ✭ 58 (-94.95%)
Mutual labels:  jsx

Build Status Maintenance Status

component-playground

A component for rendering React Components and ES6 code with editable source and live preview

Component Playground

Installation

npm install component-playground

Set up

In the head of your html document, either add the css files from the demo or from a CDN like:

<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.0.0/codemirror.min.css"/>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.0.0/theme/monokai.min.css"/>

In your JSX, require the component and use it like this:

'use strict';

var React = require('react/addons');
var ReactDOM = require('react-dom');
var Playground = require('component-playground');
var Button = require('./components/button');

var componentExample = require("raw!./examples/component.example");

var Index = React.createClass({
  render() {
    return (
      <div className="component-documentation">
        <Playground codeText={componentExample} scope={{React: React, Button: Button}}/>
      </div>
    );
  }
});

ReactDOM.render(<Index/>, document.getElementById('root'));

Props

codeText

React.PropTypes.string.isRequired

codeText takes a string of JSX markup as its value. While you can just pass it a string, I find it is easier to make a separate file and use Webpack's raw loader to load in the raw source. In the example above I use the .example extension, and an examples folder to organize my samples.

An example file would look like:

<Button style={{background: '#3498db'}}>Hi</Button>

scope

React.PropTypes.object.isRequired

When evaluating the JSX, it needs to be provided a scope object. At the very least, React needs to be provided to the scope, if any custom tags aren't being used. See below:

<Playground codeText={componentExample} scope={{React: React}}/>

Any module/component that is used inside the playground needs to be added to the scope object. See /demo for an example of how this works.

theme

React.PropTypes.string

String specifying which CodeMirror theme to initialize with. Defaults to 'monokai'.

collapsableCode

React.PropTypes.bool

Allows the user to collapse the code block.

<Playground collapsableCode={true} codeText={componentExample} scope={{React: React}}/>

initiallyExpanded

React.PropTypes.bool

Makes collapsable code block initially expanded.

<Playground
  collapsableCode={true}
  initiallyExpanded={true}
  codeText={componentExample}
  scope={{React: React}}/>

docClass

React.PropTypes.node

A component class that will be used to auto-generate docs based on that component's propTypes. See propDescriptionMap below for how to annotate the generate prop docs.

<Playground docClass={MyComponent} codeText={componentExample} scope={{React: React}}/>

propDescriptionMap

React.PropTypes.string

Annotation map for the docClass. The key is the prop to annotate, the value is the description of that prop.

<Playground
  docClass={MyComponent}
  propDescriptionMap={{
    collapsableCode: "Allows the user to collapse the code block"
  }}
  codeText={componentExample}
  scope={{React: React}}/>

es6Console

React.PropTypes.bool

Turns preview into a simple console for testing out ES6 code. Use console.log() in the playground to generate output.

<Playground
  es6Console={true}
  codeText={es6Example} />

noRender

React.PropTypes.bool

Defaults to true. If set to false, allows you bypass the component-playground's component wrapper and render method. You can use this option to write higher order components directly in your example code and use your own Render method. NOTE: This option requires that the React.render method be in your code

var ComponentExample = React.createClass({
  render: function() {
    return (
        <p>Hi</p>
    )
  }
});

React.render(<ComponentExample/>, mountNode);

Comparison to react-live

There are multiple options when it comes to live, editable React component environments. Formidable actually has two first class projects to help you out: component-playground and react-live. Let's briefly look at the libraries, use cases, and factors that might help in deciding which is right for you.

Here's a high-level decision tree:

  • If you want fast and easy setup and integration, then component-playground may be the ticket!
  • If you want a smaller bundle, SSR, and more flexibility, then react-live is for you!

Here are the various factors at play:

  • Build: component-playground uses babel-standalone, react-live uses bublé. (Note: react-live might make transpiler customizable in the future).
  • Bundle size: component-playground has a larger bundle, but uses a more familiar editor setup. react-live is smaller, but more customized editor around prism.
  • Ease vs. flexibility: react-live is more modular/customizable, while component-playground is easier/faster to set up.
  • SSR: component-playground is not server-side renderable, react-live is.
  • Extra features: component-playground supports raw evaluation and pretty-printed output out-of-the-box, while react-live does not.
  • Error handling: component-playground might have more predictable error handling than react-live in some cases (due to react-dom, although this might change with React 16).

Maintenance Status

Archived: This project is no longer maintained by Formidable. We are no longer responding to issues or pull requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own!

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