1.0.4 • Published 3 years ago

@jswork/react-ant-tree v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

react-ant-tree

Ant tree wrapper.

version license size download

installation

npm install -S @jswork/react-ant-tree

properties

NameTypeRequiredDefaultDescription
classNamestringfalse-The extended className for component.
directoryboolfalsefalseIf show directory icon.
itemsarrayfalse[]The tree data.
templatefuncfalse-The item template function.
itemsKeyunionfalse'children'The items key.

usage

  1. import css

    @import "~@jswork/react-ant-tree/dist/style.css";
    
    // or use sass
    @import "~@jswork/react-ant-tree/dist/style.scss";
    
    // customize your styles:
    $react-ant-tree-options: ()
  2. import js

    import ReactDemokit from '@jswork/react-demokit';
    import React from 'react';
    import ReactDOM from 'react-dom';
    import ReactAntTree from '@jswork/react-ant-tree';
    import { Tree } from 'antd';
    import './assets/style.scss';
    
    class App extends React.Component {
      constructor(inProps) {
        super(inProps);
        this.state = {
          items: [
            {
              label: '0-0',
              value: '0-0',
              children: [
                {
                  label: '0-0-0',
                  value: '0-0-0',
                  children: [
                    { label: '0-0-0-0', value: '0-0-0-0' },
                    { label: '0-0-0-1', value: '0-0-0-1' },
                    { label: '0-0-0-2', value: '0-0-0-2' }
                  ]
                },
                {
                  label: '0-0-1',
                  value: '0-0-1',
                  children: [
                    { label: '0-0-1-0', value: '0-0-1-0' },
                    { label: '0-0-1-1', value: '0-0-1-1' },
                    { label: '0-0-1-2', value: '0-0-1-2' }
                  ]
                },
                {
                  label: '0-0-2',
                  value: '0-0-2'
                }
              ]
            },
            {
              label: '0-1',
              value: '0-1',
              children: [
                { label: '0-1-0-0', value: '0-1-0-0' },
                { label: '0-1-0-1', value: '0-1-0-1' },
                { label: '0-1-0-2', value: '0-1-0-2' }
              ]
            },
            {
              label: '0-2',
              value: '0-2'
            }
          ]
        };
      }
    
      template = ({ item }, cb) => {
        const { value, label, independent } = item;
        return (
          <Tree.TreeNode key={value} value={value} title={label}>
            {cb()}
          </Tree.TreeNode>
        );
      };
    
      onSelect = (s, e) => {
        console.log('s,e', s, e);
      };
    
      render() {
        return (
          <ReactDemokit
            className="p-3 app-container"
            url="https://github.com/afeiship/react-ant-tree">
            <ReactAntTree
              onSelect={this.onSelect}
              showLine
              items={this.state.items}
              template={this.template}
            />
          </ReactDemokit>
        );
      }
    }
    
    ReactDOM.render(<App />, document.getElementById('app'));

documentation

license

Code released under the MIT license.