diff --git a/src/demos/components/treeviews.jsx b/src/demos/components/treeviews.jsx new file mode 100644 index 0000000..ac01506 --- /dev/null +++ b/src/demos/components/treeviews.jsx @@ -0,0 +1,91 @@ +/** + * Copyright (c) 2015-present, CWB SAS + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import React, { Component } from "react"; +import TreeView from "../../libs/components/treeView"; + +export default class TreeViews extends Component { + state = { + items: [ + { + id: "i1", + name: "Item 1", + icon: "folder", + color: "gray", + children: [ + { + id: "i2a", + name: "SubItem 1", + icon: "insert_drive_file", + color: "gray", + }, + { + id: "i2b", + name: "SubItem 2", + icon: "folder", + color: "gray", + children: [ + { + id: "i2aa", + name: "SubItem 1", + icon: "insert_drive_file", + color: "gray", + }, + ], + }, + ], + }, + { + id: "i2", + name: "Item 2", + icon: "insert_drive_file", + color: "gray", + }, + { + id: "i3", + name: "Item 3", + icon: "folder", + color: "gray", + children: [], + }, + ], + }; + + collapseChild(items, itemId) { + const its = items; + items.forEach((item, index) => { + if (item.id === itemId) { + its[index].collapsed = !item.collapsed; + } else if (item.children) { + this.collapseChild(item.children, itemId); + } + }); + return its; + } + + handleCollapse = (index, level, itemId) => { + const { items } = this.state; + this.collapseChild(items, itemId); + this.setState({ items }); + }; + + render() { + const { items } = this.state; + return ( +
+

TreeView examples

+
+ {}} + onCollapse={this.handleCollapse} + /> +
+
+ ); + } +} diff --git a/src/demos/main.jsx b/src/demos/main.jsx index 8779014..85690d2 100644 --- a/src/demos/main.jsx +++ b/src/demos/main.jsx @@ -13,6 +13,7 @@ import SubToolbars from "./components/subToolbars"; import Lists from "./components/lists"; import FileInputs from "./components/fileInputs"; import Tooltips from "./components/tooltips"; +import TreeViews from "./components/treeviews"; const Main = ({ children }) => (
@@ -20,6 +21,7 @@ const Main = ({ children }) => ( + diff --git a/src/libs/components/list/listDragItem.jsx b/src/libs/components/list/listDragItem.jsx index 6f48dd3..5b4041b 100644 --- a/src/libs/components/list/listDragItem.jsx +++ b/src/libs/components/list/listDragItem.jsx @@ -4,10 +4,11 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -import React, { Component, Children } from "react"; +import React, { Component } from "react"; +import { findDOMNode } from "react-dom"; import PropTypes from "prop-types"; import { DragSource, DropTarget } from "react-dnd"; -import Zrmc, { Icon } from "zrmc"; +import { ListItem } from "zrmc"; const MDC_LISTITEM = "mdc-list-item"; @@ -107,70 +108,30 @@ export default class ListDragItem extends Component { delete otherProps.onDrop; delete otherProps.isDragging; - let classes = MDC_LISTITEM; - let graphic; - if (activated) { - classes += " mdc-list-item--activated"; - } - if (icon) { - graphic = ( -