@@ -10,48 +10,10 @@ import {
1010 striptags ,
1111} from 'lib' ;
1212
13- class PlotlyFold extends Component {
14- constructor ( props , context ) {
15- super ( props , context ) ;
16-
17- this . foldVisible = false ;
18- this . determineVisibility ( props , context ) ;
19- }
20-
21- componentWillReceiveProps ( nextProps , nextContext ) {
22- this . determineVisibility ( nextProps , nextContext ) ;
23- }
24-
25- determineVisibility ( nextProps , nextContext ) {
26- this . foldVisible = false ;
27-
28- if ( nextProps . forceVisibility ) {
29- this . foldVisible = true ;
30- return ;
31- }
32-
33- React . Children . forEach ( nextProps . children , child => {
34- if ( ! child || this . foldVisible ) {
35- return ;
36- }
37-
38- if ( child . props . attr ) {
39- // attr components force fold open if they are visible
40- const plotProps = unpackPlotProps ( child . props , nextContext ) ;
41- if ( child . type . modifyPlotProps ) {
42- child . type . modifyPlotProps ( child . props , nextContext , plotProps ) ;
43- }
44-
45- this . foldVisible = this . foldVisible || plotProps . isVisible ;
46- return ;
47- }
48-
49- if ( ! ( child . type . plotly_editor_traits || { } ) . no_visibility_forcing ) {
50- // non-attr components force visibility (unless they don't via traits)
51- this . foldVisible = true ;
52- return ;
53- }
54- } ) ;
13+ export class Fold extends Component {
14+ constructor ( ) {
15+ super ( ) ;
16+ this . foldVisible = true ;
5517 }
5618
5719 render ( ) {
@@ -141,20 +103,63 @@ class PlotlyFold extends Component {
141103 }
142104}
143105
144- PlotlyFold . plotly_editor_traits = { foldable : true } ;
106+ Fold . plotly_editor_traits = { foldable : true } ;
145107
146- PlotlyFold . propTypes = {
108+ Fold . propTypes = {
147109 canDelete : PropTypes . bool ,
148110 children : PropTypes . node ,
149111 className : PropTypes . string ,
150- folded : PropTypes . bool . isRequired ,
151- toggleFold : PropTypes . func . isRequired ,
112+ folded : PropTypes . bool ,
113+ toggleFold : PropTypes . func ,
152114 hideHeader : PropTypes . bool ,
153115 icon : PropTypes . oneOfType ( [ PropTypes . node , PropTypes . func ] ) ,
154116 messageIfEmpty : PropTypes . string ,
155117 localize : PropTypes . func ,
156118 name : PropTypes . string ,
157- forceVisibility : PropTypes . bool ,
119+ } ;
120+
121+ class PlotlyFold extends Fold {
122+ constructor ( props , context ) {
123+ super ( props , context ) ;
124+
125+ this . foldVisible = false ;
126+ this . determineVisibility ( props , context ) ;
127+ }
128+
129+ componentWillReceiveProps ( nextProps , nextContext ) {
130+ this . determineVisibility ( nextProps , nextContext ) ;
131+ }
132+
133+ determineVisibility ( nextProps , nextContext ) {
134+ this . foldVisible = false ;
135+
136+ React . Children . forEach ( nextProps . children , child => {
137+ if ( ! child || this . foldVisible ) {
138+ return ;
139+ }
140+
141+ if ( child . props . attr ) {
142+ // attr components force fold open if they are visible
143+ const plotProps = unpackPlotProps ( child . props , nextContext ) ;
144+ if ( child . type . modifyPlotProps ) {
145+ child . type . modifyPlotProps ( child . props , nextContext , plotProps ) ;
146+ }
147+
148+ this . foldVisible = this . foldVisible || plotProps . isVisible ;
149+ return ;
150+ }
151+
152+ if ( ! ( child . type . plotly_editor_traits || { } ) . no_visibility_forcing ) {
153+ // non-attr components force visibility (unless they don't via traits)
154+ this . foldVisible = true ;
155+ return ;
156+ }
157+ } ) ;
158+ }
159+ }
160+
161+ PlotlyFold . plotly_editor_traits = {
162+ foldable : true ,
158163} ;
159164
160165PlotlyFold . contextTypes = Object . assign (
@@ -165,26 +170,3 @@ PlotlyFold.contextTypes = Object.assign(
165170) ;
166171
167172export default localize ( PlotlyFold ) ;
168-
169- export class Fold extends PlotlyFold { }
170-
171- Fold . plotly_editor_traits = {
172- foldable : true ,
173- } ;
174-
175- Fold . defaultProps = {
176- forceVisibility : true ,
177- } ;
178-
179- Fold . propTypes = {
180- children : PropTypes . node ,
181- className : PropTypes . string ,
182- folded : PropTypes . bool ,
183- toggleFold : PropTypes . func ,
184- hideHeader : PropTypes . bool ,
185- icon : PropTypes . oneOfType ( [ PropTypes . node , PropTypes . func ] ) ,
186- messageIfEmpty : PropTypes . string ,
187- localize : PropTypes . func ,
188- name : PropTypes . string ,
189- forceVisibility : PropTypes . bool ,
190- } ;
0 commit comments