Giter Club home page Giter Club logo

jsoneditor-react's Introduction

jsoneditor-react

Version Licence Known Vulnerabilities

react wrapper implementation for josdejong/jsoneditor

Installation

npm install --save jsoneditor jsoneditor-react

jsoneditor-react using minimalist version of jsoneditor to minimize flat bundle size, so if you want to use Ajv or Ace Editor install them as well

Bundling

Version 3.0.0 and higher provide only es build. Also you need some loaders (in terms of webpack) to load json editor icons and css, e.g.:

module.exports = {
  module: {
    rules: [
      {test: /\.css$/, loader: 'css-loader'},
      {test: /\.svg$/, loader: 'file-loader'}
    ]
  }
};

Usage

import { JsonEditor as Editor } from 'jsoneditor-react';
import 'jsoneditor-react/es/editor.min.css';

later in render method:

render() {
    return (
        <Editor
            value={yourJson}
            onChange={this.handleChange}
        />
    );
}

If you want use with Ajv:

import Ajv from 'ajv';

const ajv = new Ajv({ allErrors: true, verbose: true });

...

render() {
    return (
        <Editor
            value={yourJson}
            onChange={this.handleChange}
            ajv={ajv}
            schema={yourSchema}
        />
    );
}

If you want use with Ace Editor:

import ace from 'brace';
import 'brace/mode/json';
import 'brace/theme/github';

...

render() {
    return (
        <Editor
            value={yourJson}
            onChange={this.handleChange}
            ace={ace}
            theme="ace/theme/github"
            schema={yourSchema}
        />
    );
}

Or:

import 'brace';
import 'brace/mode/json';
import 'brace/theme/github';

...

render() {
    return (
        <Editor
            value={yourJson}
            onChange={this.handleChange}
            theme="ace/theme/github"
            schema={yourSchema}
        />
    );
}

Or define your own ace theme

Async component

If you using webpack and es6 dynamic imports you can load jsoneditor-react asynchronously. You can use react-imported-component or your own implementation

import importedComponent from 'react-imported-component';

const JsonEditor = importedComponent(() => import(/* webpackChunkName:'jsoneditor' */'jsoneditor-react'));

Or with Ajv and Ace Editor:

const JsonEditor = importedComponent(() => Promise.all([
    import(/* webpackChunkName:'jsoneditor' */'jsoneditor-react'),
    import(/* webpackChunkName:'jsoneditor' */'brace'),
    import(/* webpackChunkName:'jsoneditor' */'ajv'),
    import(/* webpackChunkName:'jsoneditor' */'brace/mode/json'),
    import(/* webpackChunkName:'jsoneditor' */'brace/theme/github')
]).then(([{ JsonEditor: Editor }, ace, Ajv ]) => {
    const ajv = new Ajv();
    return function EditorHoc(props) {
        return (
            <Editor
                ace={ace}
                ajv={ajv}
                theme="ace/theme/github"
                {...props}
            />
        );
    }
}));

Playground

You can view usage of jsoneditor-react using our storybook.

Steps to run storybook

  • fork or clone repository
  • npm run dev
  • View http://localhost:9001

Right now only one story exporting in storybook: /stories/Editor.jsx, to add more use /.storybook/config.js

Api

Working on docs folder. Right now you can use props declaration

Test

Will be soon!๐Ÿ˜

jsoneditor-react's People

Contributors

vankop avatar dependabot[bot] avatar iamnotstone avatar meneman avatar fiskus avatar treavorphilyaw avatar tocttou avatar emmanuelgautier avatar italoayres avatar shmck 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.