Skip to content
This repository was archived by the owner on May 15, 2022. It is now read-only.

Commit 610d494

Browse files
author
Lior Ben-David
committed
Add an optional 'closed' prop to DatFolder
1 parent bce95dd commit 610d494

File tree

7 files changed

+25
-48
lines changed

7 files changed

+25
-48
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,5 @@ node_modules
9393

9494
# Linux trash folder which might appear on any partition or disk
9595
.Trash-*
96+
97+
.idea

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ Component which wraps other components to render them within an expandable/colla
159159
* `title: string` - The folder title eg., `<DatFolder title='MyAwesomeFolder' />`
160160
* `children: array` - The child components to render
161161

162+
###### optional
163+
164+
* `closed: boolean` - Whether the initial state of the folder is closed, defaults to `true`
165+
162166
#### `DatNumber`
163167

164168
A number component for updating numeric values. Will render a slider if `min`, `max` and `step` props are supplied.

build/react-dat-gui.js

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6615,8 +6615,6 @@ Object.defineProperty(exports, "__esModule", {
66156615
value: true
66166616
});
66176617

6618-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
6619-
66206618
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
66216619

66226620
var _react = __webpack_require__(0);
@@ -6633,8 +6631,6 @@ var _classnames2 = _interopRequireDefault(_classnames);
66336631

66346632
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
66356633

6636-
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
6637-
66386634
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
66396635

66406636
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
@@ -6656,7 +6652,7 @@ var DatFolder = function (_Component) {
66566652
}
66576653

66586654
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = DatFolder.__proto__ || Object.getPrototypeOf(DatFolder)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
6659-
closed: true
6655+
closed: _this.props.closed
66606656
}, _this.handleClick = function () {
66616657
var closed = !_this.state.closed;
66626658

@@ -6665,24 +6661,12 @@ var DatFolder = function (_Component) {
66656661
}
66666662

66676663
_createClass(DatFolder, [{
6668-
key: 'renderChildren',
6669-
value: function renderChildren() {
6670-
// Disable this rule to take title out of the props so nested folders can have unique titles.
6671-
// eslint-disable-next-line no-unused-vars
6672-
var _props = this.props,
6673-
children = _props.children,
6674-
title = _props.title,
6675-
rest = _objectWithoutProperties(_props, ['children', 'title']);
6676-
6677-
return _react2.default.Children.map(children, function (child) {
6678-
return (0, _react.cloneElement)(child, _extends({}, rest));
6679-
});
6680-
}
6681-
}, {
66826664
key: 'render',
66836665
value: function render() {
66846666
var closed = this.state.closed;
6685-
var title = this.props.title;
6667+
var _props = this.props,
6668+
title = _props.title,
6669+
children = _props.children;
66866670

66876671

66886672
return _react2.default.createElement(
@@ -6699,7 +6683,7 @@ var DatFolder = function (_Component) {
66996683
_react2.default.createElement(
67006684
'ul',
67016685
null,
6702-
this.renderChildren()
6686+
children
67036687
)
67046688
)
67056689
);
@@ -6713,7 +6697,8 @@ DatFolder.propTypes = {
67136697
title: _propTypes2.default.string.isRequired
67146698
};
67156699
DatFolder.defaultProps = {
6716-
title: 'Folder'
6700+
title: 'Folder',
6701+
closed: true
67176702
};
67186703
exports.default = DatFolder;
67196704
module.exports = exports['default'];

build/react-dat-gui.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/src/react-dat-gui/components/DatFolder.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React, { Component, cloneElement } from 'react';
1+
import React, { Component } from 'react';
22

33
import PropTypes from 'prop-types';
44
import cx from 'classnames';
55

66
export default class DatFolder extends Component {
77
state = {
8-
closed: true,
8+
closed: this.props.closed,
99
}
1010

1111
static propTypes = {
@@ -14,6 +14,7 @@ export default class DatFolder extends Component {
1414

1515
static defaultProps = {
1616
title: 'Folder',
17+
closed: true
1718
}
1819

1920
handleClick = () => {
@@ -22,17 +23,9 @@ export default class DatFolder extends Component {
2223
this.setState({ closed });
2324
}
2425

25-
renderChildren() {
26-
// Disable this rule to take title out of the props so nested folders can have unique titles.
27-
// eslint-disable-next-line no-unused-vars
28-
const { children, title, ...rest } = this.props;
29-
30-
return React.Children.map(children, child => cloneElement(child, {...rest}));
31-
}
32-
3326
render() {
3427
const { closed } = this.state;
35-
const { title } = this.props;
28+
const { title, children } = this.props;
3629

3730
return (
3831
<li className={cx('folder', { 'closed': closed })}>
@@ -41,7 +34,7 @@ export default class DatFolder extends Component {
4134
{title}
4235
</div>
4336
<ul>
44-
{this.renderChildren()}
37+
{children}
4538
</ul>
4639
</div>
4740
</li>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-dat-gui",
3-
"version": "1.0.2",
3+
"version": "1.1.2",
44
"description": "dat.GUI reimagined for React",
55
"main": "build/react-dat-gui.js",
66
"style": "build/react-dat-gui.css",

src/components/DatFolder.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React, { Component, cloneElement } from 'react';
1+
import React, { Component } from 'react';
22

33
import PropTypes from 'prop-types';
44
import cx from 'classnames';
55

66
export default class DatFolder extends Component {
77
state = {
8-
closed: true,
8+
closed: this.props.closed,
99
}
1010

1111
static propTypes = {
@@ -14,6 +14,7 @@ export default class DatFolder extends Component {
1414

1515
static defaultProps = {
1616
title: 'Folder',
17+
closed: true
1718
}
1819

1920
handleClick = () => {
@@ -22,17 +23,9 @@ export default class DatFolder extends Component {
2223
this.setState({ closed });
2324
}
2425

25-
renderChildren() {
26-
// Disable this rule to take title out of the props so nested folders can have unique titles.
27-
// eslint-disable-next-line no-unused-vars
28-
const { children, title, ...rest } = this.props;
29-
30-
return React.Children.map(children, child => cloneElement(child, {...rest}));
31-
}
32-
3326
render() {
3427
const { closed } = this.state;
35-
const { title } = this.props;
28+
const { title, children } = this.props;
3629

3730
return (
3831
<li className={cx('folder', { 'closed': closed })}>
@@ -41,7 +34,7 @@ export default class DatFolder extends Component {
4134
{title}
4235
</div>
4336
<ul>
44-
{this.renderChildren()}
37+
{children}
4538
</ul>
4639
</div>
4740
</li>

0 commit comments

Comments
 (0)