onClick()}>
@@ -23,6 +23,7 @@ const Header = ({style, node}) => {
Header.propTypes = {
node: PropTypes.object,
style: PropTypes.object,
+ onClick: PropTypes.func,
};
export default Header;
diff --git a/example/app.js b/example/app.js
index 725a382..79f3745 100644
--- a/example/app.js
+++ b/example/app.js
@@ -14,10 +14,11 @@ class DemoTree extends PureComponent {
super(props);
this.state = {data};
this.onToggle = this.onToggle.bind(this);
+ this.onClickHeader = this.onClickHeader.bind(this);
}
onToggle(node, toggled) {
- const {cursor, data} = this.state;
+ const {data, cursor} = this.state;
if (cursor) {
this.setState(() => ({cursor, active: false}));
@@ -28,7 +29,11 @@ class DemoTree extends PureComponent {
node.toggled = toggled;
}
- this.setState(() => ({cursor: node, data: Object.assign({}, data)}));
+ this.setState(() => ({data: Object.assign({}, data)}));
+ }
+
+ onClickHeader(node) {
+ this.setState(() => ({cursor: node}));
}
onFilterMouseUp({target: {value}}) {
@@ -62,7 +67,9 @@ class DemoTree extends PureComponent {
diff --git a/src/components/Decorators/Container.js b/src/components/Decorators/Container.js
index 88d21ae..6c054c7 100644
--- a/src/components/Decorators/Container.js
+++ b/src/components/Decorators/Container.js
@@ -21,19 +21,22 @@ class Container extends PureComponent {
}
renderToggleDecorator() {
- const {style, decorators} = this.props;
- return
;
+ const {style, decorators, onClickToggle} = this.props;
+ return onClickToggle() : null}/>;
}
render() {
- const {style, decorators, terminal, onClick, node} = this.props;
+ const {style, decorators, terminal, onClick, onClickHeader, node} = this.props;
return (
onClick() : null}
style={node.active ? {...style.container} : {...style.link}}
>
{!terminal ? this.renderToggle() : null}
-
+
);
}
@@ -43,12 +46,14 @@ Container.propTypes = {
style: PropTypes.object.isRequired,
decorators: PropTypes.object.isRequired,
terminal: PropTypes.bool.isRequired,
- onClick: PropTypes.func.isRequired,
+ onClick: PropTypes.func,
+ onClickToggle: PropTypes.func,
+ onClickHeader: PropTypes.func,
animations: PropTypes.oneOfType([
PropTypes.object,
- PropTypes.bool
+ PropTypes.bool,
]).isRequired,
- node: PropTypes.object.isRequired
+ node: PropTypes.object.isRequired,
};
export default Container;
diff --git a/src/components/Decorators/Header.js b/src/components/Decorators/Header.js
index 5f9c1fd..b3668ef 100644
--- a/src/components/Decorators/Header.js
+++ b/src/components/Decorators/Header.js
@@ -3,8 +3,8 @@ import PropTypes from 'prop-types';
import {Div} from '../common';
-const Header = ({node, style}) => (
-
+const Header = ({node, style, onClick}) => (
+
onClick() : null}>
{node.name}
@@ -13,7 +13,8 @@ const Header = ({node, style}) => (
Header.propTypes = {
style: PropTypes.object,
- node: PropTypes.object.isRequired
+ node: PropTypes.object.isRequired,
+ onClick: PropTypes.func,
};
export default Header;
diff --git a/src/components/Decorators/Toggle.js b/src/components/Decorators/Toggle.js
index 2873dd6..fbce403 100644
--- a/src/components/Decorators/Toggle.js
+++ b/src/components/Decorators/Toggle.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, {useCallback} from 'react';
import PropTypes from 'prop-types';
import styled from '@emotion/styled';
@@ -8,13 +8,18 @@ const Polygon = styled('polygon', {
shouldForwardProp: prop => ['className', 'children', 'points'].indexOf(prop) !== -1
})((({style}) => style));
-const Toggle = ({style}) => {
+const Toggle = ({onClick, style}) => {
const {height, width} = style;
const midHeight = height * 0.5;
const points = `0,0 0,${height} ${width},${midHeight}`;
+ const click = useCallback(() => {
+ if (onClick) {
+ onClick();
+ }
+ }, [onClick]);
return (
-
+