This repository was archived by the owner on May 15, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed
dev/src/react-dat-gui/components Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change 1
- import React , { Component } from 'react' ;
1
+ import React , { Component , cloneElement } from 'react' ;
2
2
3
3
import PropTypes from 'prop-types' ;
4
4
import cx from 'classnames' ;
@@ -23,9 +23,17 @@ export default class DatFolder extends Component {
23
23
this . setState ( { closed } ) ;
24
24
}
25
25
26
+ renderChildren ( ) {
27
+ // Disable this rule to take title out of the props so nested folders can have unique titles.
28
+ // eslint-disable-next-line no-unused-vars
29
+ const { children, title, ...rest } = this . props ;
30
+
31
+ return React . Children . map ( children , child => cloneElement ( child , { ...rest } ) ) ;
32
+ }
33
+
26
34
render ( ) {
27
35
const { closed } = this . state ;
28
- const { title, children } = this . props ;
36
+ const { title } = this . props ;
29
37
30
38
return (
31
39
< li className = { cx ( 'folder' , { 'closed' : closed } ) } >
@@ -34,7 +42,7 @@ export default class DatFolder extends Component {
34
42
{ title }
35
43
</ div >
36
44
< ul >
37
- { children }
45
+ { this . renderChildren ( ) }
38
46
</ ul >
39
47
</ div >
40
48
</ li >
Original file line number Diff line number Diff line change 1
- import React , { Component } from 'react' ;
1
+ import React , { Component , cloneElement } from 'react' ;
2
2
3
3
import PropTypes from 'prop-types' ;
4
4
import cx from 'classnames' ;
@@ -23,9 +23,17 @@ export default class DatFolder extends Component {
23
23
this . setState ( { closed } ) ;
24
24
}
25
25
26
+ renderChildren ( ) {
27
+ // Disable this rule to take title out of the props so nested folders can have unique titles.
28
+ // eslint-disable-next-line no-unused-vars
29
+ const { children, title, ...rest } = this . props ;
30
+
31
+ return React . Children . map ( children , child => cloneElement ( child , { ...rest } ) ) ;
32
+ }
33
+
26
34
render ( ) {
27
35
const { closed } = this . state ;
28
- const { title, children } = this . props ;
36
+ const { title } = this . props ;
29
37
30
38
return (
31
39
< li className = { cx ( 'folder' , { 'closed' : closed } ) } >
@@ -34,7 +42,7 @@ export default class DatFolder extends Component {
34
42
{ title }
35
43
</ div >
36
44
< ul >
37
- { children }
45
+ { this . renderChildren ( ) }
38
46
</ ul >
39
47
</ div >
40
48
</ li >
You can’t perform that action at this time.
0 commit comments