GithubHelp home page GithubHelp logo

lukeburns / component-editor Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 902 KB

a react component for building react components from react components

License: MIT License

JavaScript 99.94% CSS 0.06%

component-editor's Introduction

component-editor

a react component that exposes a graphical interface for building react components from a palette of react components

npm i component-editor

api

const { Editor } = require('component-editor')
<Editor
  builders={builders}
  update={handleUpdate}
  export={handleExport}
/>

instantiates an editor with builders as a palette. handleUpdate allows you to control the editor preview, and handleExport let's you to manage export.

run npm start and see the example directory for a working example that uses a number of builders and widgets.

builders

a builder is a react component along with specification of the widgets used to control its inputs. for instance,

const Article = ({ title, body }) => (
  <article>
    <h1>{title}</h1>
    <p>{body}</h1>
  </article>
)

along with the widget configuration

Article.Widgets = {
  title: InputWidget,
  body: TextAreaWidget
}

constitutes a builder.

widgets

widgets are react components with the following structure: (1) have a getState method and (2) call props.onChange when its state changes. for example, InputWidget used in the example above might be of the following form. TextAreaWidget is almost identical.

class InputWidget extends React.Component {
  constructor (props) {
    super(props)
    this.state = { value: '' }
    this.handleChange = this.handleChange.bind(this)
  }
  getState () {
    return this.state.value
  }
  handleChange (event) {
    this.setState({ value: event.target.value }, function () {
      if (this.props.onChange) {
        this.props.onChange(this.getState())
      }
    })
  }
  render () {
    return (
      <input type='text' value={this.state.value} onChange={this.handleChange} placeholder={this.props.label} />
    )
  }
}

See example for more complex widgets.

component-editor's People

Contributors

ibrand avatar lukeburns avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.