在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):fiffty/react-treeview-mui开源软件地址(OpenSource Url):https://github.com/fiffty/react-treeview-mui开源编程语言(OpenSource Language):JavaScript 100.0%开源软件介绍(OpenSource Introduction):React Treeview with Material UIA Treeview React Component that can use material-ui's styling. Installation
import import React, {Component, PropTypes} from 'react'
// With material-ui
// be sure to have <MuiTreeList /> inside <MuiThemeProvider />
import {MuiTreeList} from 'react-treeview-mui'
// Without material-ui styling
import {TreeList} from 'react-treeview-mui'
// UI state (e.g., expanded list items) is tracked locally
const listItems = [...,{title: 'List Item'},...]
class MyComponent extends Component {
render() {
<MuiTreeList
listItems={listItems}
contentKey={'title'} />
}
}
// UI state is tracked outside of <MuiTreeList />
// Maybe through Redux
class MySecondComponent extends Component {
render() {
<MuiTreeList
listItems={listItems}
contentKey={'title'}
useFolderIcons={true}
haveSearchbar={true}
listItemIsEnabled={this.props.listItemIsEnabled}
expandedListItems={this.props.expandedListItems}
activeListItem={this.props.activeListItem}
handleTouchTap={this.props.handleTouchTap}
handleTouchTapInSearchMode={this.props.handleTouchTapInSearchMode}
handleSearch={this.props.handleSearch}
searchTerm={this.props.searchTerm} />
}
} UsageData for nodesOne of the required props for the Component is the data for the list items. Instead of an object data structure with child list items nested inside parent list items, the Component takes in an array of list item objects. To accomodate this structure, the objects have a few required keys as following: const listItems = [
{
// Each list item is tracked by its index in the master array
depth: 0, // Used to style the list item. Items with 0 depth will not be rendered and act as the root parent
children: [1, 3, 10] // Indexes for child list items. If undefined, list item will be treated as leaf
}
...,
{
depth: 1,
children: [12,16],
parentIndex: 0, // Index of parent list item
disabled: false // false by default, disables click event listeners for disabled list items
},{
depth: 2,
children: [13,14,15],
parentIndex: 11,
disabled: false
},
...
] Why use an Array? First off, it's faster. But unless you're rendering hundreds and hundreds of list items, speed wouldn't be your concern. Apart from that, it comes from personal preference. I found it to be easier to reason about how the Component should react to change in state. Specifically, I found that it aligned well with "the Redux-way" of thinking about state management with reducers. Props
AnimationThe Component uses ReactCSSTransitionGroup to animate the items inside the treeview. It exposes the classes example .tree-list-enter {
animation-name: tree-list-enter;
animation-duration: 0.3s;
animation-fill-mode: forwards;
transform: translateZ(0);
}
.tree-list-leave {
animation-name: tree-list-leave;
animation-duration: 0.2s;
animation-fill-mode: forwards;
}
@keyframes tree-list-enter {
0% {
height: 0px;
opacity: 0.01;
}
100% {
height: 32px;
opacity: 1;
}
}
@keyframes tree-list-leave {
0% {
height: 32px;
opacity: 1;
}
100% {
height: 0px;
opacity: 0.01;
}
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论