公司需要做一个IDE,要做IDE当然少不了文件列表了。下面我就来展示一下刚刚研究的一个库。

下面是链接:https://react.rocks/example/react-ui-tree

至于如何导入module,官方文档都写的很清楚我就不再贴出。

这里由于给的介绍太过简单。我就将我的代码贴出:

第一个文件就是我们组件文件:

var cx = require('classnames');
var React = require('react');
var ReactDOM = require('react-dom');
var Tree = require('react-ui-tree');
var tree = require('./tree');
require('react-ui-tree/dist/react-ui-tree.css')
require('./css.css') var UiTree = React.createClass({
getInitialState() {
return {
active: null,
tree: tree
};
}, renderNode(node) {
return (
<span className={cx('node', {
'is-active': node === this.state.active
})} onClick={this.onClickNode.bind(null, node)}>
{node.module}
</span>
);
}, onClickNode(node) {
this.setState({
active: node
});
}, render() {
return (
<div className="app">
<div className="tree">
<Tree
paddingLeft={20}
tree={this.state.tree}
onChange={this.handleChange}
isNodeCollapsed={this.isNodeCollapsed}
renderNode={this.renderNode}
/>
</div>
<div className="inspector">
<button onClick={this.updateTree}>update tree</button>
<pre>
{JSON.stringify(this.state.tree, null, ' ')}
</pre>
</div>
</div>
);
}, handleChange(tree) {
this.setState({
tree: tree
});
}, updateTree() {
var tree = this.state.tree;
tree.children.push({module: 'test'});
this.setState({
tree: tree
});
}
}); module.exports = UiTree;

下面是数据:

module.exports = {
module: 'react-ui-tree',
children: [{
module: 'dist',
collapsed: true,
children: [{
module: 'node.js',
leaf: true
}, {
module: 'react-ui-tree.css',
leaf: true
}, {
module: 'react-ui-tree.js',
leaf: true
}, {
module: 'tree.js',
leaf: true
}]
}, {
module: 'example',
children: [{
module: 'app.js',
leaf: true
}, {
module: 'app.less',
leaf: true
}, {
module: 'index.html',
leaf: true
}]
}, {
module: 'lib',
children: [{
module: 'node.js',
leaf: true
}, {
module: 'react-ui-tree.js',
leaf: true
}, {
module: 'react-ui-tree.less',
leaf: true
}, {
module: 'tree.js',
leaf: true
}]
}, {
module: '.gitiignore',
leaf: true
}, {
module: 'index.js',
leaf: true
}, {
module: 'LICENSE',
leaf: true
}, {
module: 'Makefile',
leaf: true
}, {
module: 'package.json',
leaf: true
}, {
module: 'README.md',
leaf: true
}, {
module: 'webpack.config.js',
leaf: true
}]
}

这里有个坑,就是当我们将程序运行起来的时候发现样式是不对的,查阅它的源码才知道他是将样式放入了“.less”的文件之中,所以我们需要将文件先转化成css文件,然后添加文件手动导入:

.tree {
position: fixed;
top:;
left:;
bottom:;
width: 300px;
overflow-x: hidden;
overflow-y: auto;
background-color: #21252B;
}
.m-node.placeholder {
border: 1px dashed #1385e5;
}
.m-node .inner {
color: #9DA5B4;
font-size: 12px;
font-family: Menlo;
}
.m-node .node {
display: inline-block;
width: 100%;
padding: 4px 5px;
}
.m-node .node.is-active {
background-color: #31363F;
}
.m-node .children {
transition: 1s;
} *,
*:before,
*:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
margin:;
padding:;
font-size: 100%;
}
.inspector {
margin-left: 400px;
}
.inspector pre {
font-family: Menlo;
font-size: 13px;
}

最后还有一个坑就是他跟bootstrap是有冲突的,所以如果你使用了bootstrap再使用它,可能样式会有所改变。

demo可以从我的github上看到:

https://github.com/weifengzz/react-ui-tree-demo

React react-ui-tree的使用的更多相关文章

  1. [React] react+redux+router+webpack+antd环境搭建一版

    好久之前搭建的一个react执行环境,受历史影响是webpack3.10.0和webpack-dev-server2.7.1的环境,新项目准备用webpack4重新弄弄了,旧的记录就合并发布了(在没有 ...

  2. React/React Native 的ES5 ES6写法对照表

    //es6与es5的区别很多React/React Native的初学者都被ES6的问题迷惑:各路大神都建议我们直接学习ES6的语法(class Foo extends React.Component ...

  3. React/React Native 的ES5 ES6写法对照表-b

    很多React/React Native的初学者都被ES6的问题迷惑:各路大神都建议我们直接学习ES6的语法(class Foo extends React.Component),然而网上搜到的很多教 ...

  4. [React] React Fundamentals: Integrating Components with D3 and AngularJS

    Since React is only interested in the V (view) of MVC, it plays well with other toolkits and framewo ...

  5. Element ui tree树形控件获取当前节点id和父节点id

    低版本Element ui tree树形控件获取当前节点id和父节点id的方法:点击查看 最新版本Element ui tree树形控件获取当前节点id和父节点id教程: 1.找到node_modul ...

  6. React: React组件的生命周期

    一.简介 在前面的第二篇博文中对组件的生命周期虽然做了一个大略介绍,但总感觉说的过于简单,毕竟生命周期是React组件的核心部分.在我们熟练使用React挂载和合成组件来创建应用表现层的过程中,针对数 ...

  7. React: React的属性验证机制

    一.简介 在开发中,属性变量类型的验证,几乎是任何语言都必须关注的问题,因为如果传入的数据类型不对,轻者程序运行仅仅是给出警告⚠️,严重的会直接导致程序中断,APP闪退或者web页面挂掉,这是很严重的 ...

  8. React/react相关小结

    React React组件由React元素组成,React组件使用React.Component或React.PureComponent来生成:React元素使用JSX的语法来编写或使用React.c ...

  9. 使用CRA开发的基于React的UI组件发布到内网NPM上去

    前言:构建的ES组件使用CNPM发布内网上过程 1. 使用Create-React-APP开的组件 如果直接上传到NPM,你引用的时候会报: You may need an appropriate l ...

  10. [React] Optimistic UI update in React using setState()

    In this lesson we will refactor an existing UI update from a typical loading approach to an optimist ...

随机推荐

  1. win7 安装vs2010报错 Error code -939523550 for this component is not recognizedHi

    When i try to install VS2010, Its not installing. I'm getting an error.  It just try to install the ...

  2. Java 访问控制符

    Java提供了3个访问控制符:private.protected和public,分别代表了3个访问控制级别,另外还有一个不加任何访问控制符的访问控制级别,提供了4个访问控制级别.Java的访问控制级别 ...

  3. c++11-bind的用法

    bind函数 在c++11之前,要绑定某个函数.函数对象或者成员函数的不同参数值需要用到不同的转换器,如bind1st.bind2nd.fun_ptr.mem_fun和mem_fun_ref等.在c+ ...

  4. android 开发中判断网络是否连接的代码

    在android的开发中,尤其是与访问网络有关的开发,都要判断一下手机是否连接上了网络,下面是一个判断是否连接网络的嗲吗片段: package cn.com.karl.util; import com ...

  5. phantomjs 渲染

    phantomjs 可以将web页面渲染并保存为扩展名为PNG,GIF,JPEG,PDF的指定文件 render viewportSize可以改变可视窗体大小 zoomFactor调整缩放比例 cli ...

  6. 一个好玩的jq+php实现转盘抽奖程序

    前台页面: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <met ...

  7. Lua 字符串 匹配模式 总结

    字符类 %a --字母alpha %d --数字double %l --小写字母lower %u --大写字母upper %w --字母和数字word %x -- 十六进制 %z --代表0 zero ...

  8. Python中range的用法

    函数原型:range(start, end, scan): 参数含义:start:计数从start开始.默认是从0开始.例如range(5)等价于range(0, 5); end:技术到end结束,但 ...

  9. C和C++的学习过程总结

    总是被同学们问到,如何学习C和C++才不茫然,才不是乱学,想了一下,这里给出一个总的回复. 一家之言,欢迎拍砖哈. 1.可以考虑先学习C. 大多数时候,我们学习语言的目的,不是为了成为一个语言专家,而 ...

  10. android map高德地图显示多个点,并且每个marker点可以响应鼠标点击事件,处理跳转页面

    定义一个数组,然后将要显示的markers放进数组里面,让后循环每个marke对象,赋予监听事件,在监听事件里面写其它需要的功能: js举例: var arr = new Arry(); var ma ...