forked from claus/react-dat-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatFolder.js
More file actions
60 lines (52 loc) · 1.46 KB
/
DatFolder.js
File metadata and controls
60 lines (52 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, { Component, cloneElement } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
export default class DatFolder extends Component {
static propTypes = {
className: PropTypes.string,
style: PropTypes.object,
title: PropTypes.string,
closed: PropTypes.bool,
children: PropTypes.element.isRequired
};
static defaultProps = {
className: null,
style: null,
title: 'Folder',
closed: true
};
constructor(props) {
super(props);
this.state = { closed: props.closed };
}
handleClick = () =>
this.setState(prevState => ({ closed: !prevState.closed }));
renderChildren() {
// Disable this rule to take title out of the props so nested folders can have unique titles.
// eslint-disable-next-line no-unused-vars
const { children, title, ...rest } = this.props;
return React.Children.map(children, child =>
cloneElement(child, { ...rest })
);
}
render() {
const { closed } = this.state;
const { title, className, style } = this.props;
return (
<li className={cx('folder', { closed }, className)} style={style}>
<div className="dg">
<div
className="title"
onClick={this.handleClick}
onKeyPress={this.handleClick}
role="button"
tabIndex={0}
>
{title}
</div>
<ul>{this.renderChildren()}</ul>
</div>
</li>
);
}
}