Giter Site home page Giter Site logo

treeinput's Introduction

TreeInput

A TreeInput Component for React

Features

  • Using schema to generate complex nested forms easily
  • Stringify all kinds of types including 64bit numbers
  • Documentation tips
  • Filter empty values
  • Pretty UI with color schema

Preview

Preview

Install

npm i -S tree-input

Example

import React from 'react';
import { render } from 'react-dom';
import { TreeInput, format, formatToJS } from 'tree-input';

const schema = [
    { tag: 1, name: 'uin', label: 'OPTIONAL', type: 'uint64', value: 12345678987654 },
    { tag: 2, ame: 'uid_type', documentation: '用户类型', label: 'OPTIONAL', type: 'int32' },
    { tag: 3, name: 'course_info', label: 'OPTIONAL', type: 'message',fieldInfo: [
        { tag: 1, name: 'aid', documentation: '机构id', label: 'OPTIONAL', type: 'int32' },
        { tag: 2, name: 'cid', documentation: '课程id', label: 'OPTIONAL', type: 'uint32' },
        { tag: 3, name: 'name', documentation: '课程名称', label: 'OPTIONAL', type: 'string' },
        { tag: 4, name: 'get_all', label: 'OPTIONAL', type: 'boolean', value: false }]
    },
    {
        tag: 4, name: 'type', label: 'REQUIRED', type: 'enum',
        value: [{ tag: 1, name: 'STRING_VALUE' }],
        fieldInfo: [
            { tag: 0, name: 'LONG_VALUE' },
            { tag: 1, name: 'STRING_VALUE' }
        ]
    }
];

function handleChange(e, rawValue) {
  // Filter empty value
  const filterEmpty = true;
  // format to json string
  console.log(format(rawValue, filterEmpty));
  // format to js object
  console.log(formatToJS(rawValue, filterEmpty));
}

const App = () => (
  <TreeInput
    schema={schema}
    collapsed={2}
    onChange={handleChange}
    rootName="ROOT"
  />
);

const container = document.createElement('div');
document.body.appendChild(container);

render(<App />, container);

More Example

PropTypes

  • schema: Array Field infos

  • rootName: String (Optional) Displayed name of root node

  • collapsed: Boolean | Int (Optional) "True" to collapse all nodes; "False" to expand all nodes, number to expand nodes with the specified nested depth

  • onChange: Function (Optional) onChange(event, formatedValue, rawValue)

treeinput's People

Contributors

elliothux avatar

Stargazers

pengxiaolong avatar  avatar

Watchers

James Cloos 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.