Skip to content

Commit 8688032

Browse files
authored
Merge pull request #226 from plotly/no-foldIndex
Make panel component set the foldIndex prop on its direct Fold children
2 parents fce64c0 + 47441a0 commit 8688032

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

package-lock.json

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

src/DefaultEditor.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class DefaultEditor extends Component {
167167
</TraceAccordion>
168168
</Panel>
169169
<LayoutPanel group="Style" name={_('Layout')}>
170-
<Fold name={_('Canvas')} foldIndex={0} key={0}>
170+
<Fold name={_('Canvas')}>
171171
<Radio
172172
attr="autosize"
173173
options={[
@@ -180,7 +180,7 @@ class DefaultEditor extends Component {
180180
<ColorPicker label={_('Plot Background')} attr="plot_bgcolor" />
181181
<ColorPicker label={_('Margin Color')} attr="paper_bgcolor" />
182182
</Fold>
183-
<Fold name={_('Title and Fonts')} foldIndex={1} key={1}>
183+
<Fold name={_('Title and Fonts')}>
184184
<Section name={_('Title')}>
185185
<MultiFormatTextEditor attr="title" />
186186
<FontSelector
@@ -205,7 +205,7 @@ class DefaultEditor extends Component {
205205
<ColorPicker label={_('Font Color')} attr="font.color" />
206206
</Section>
207207
</Fold>
208-
<Fold name={_('Margins and Padding')} foldIndex={2} key={2}>
208+
<Fold name={_('Margins and Padding')}>
209209
<Numeric label={_('Top')} attr="margin.t" units="px" />
210210
<Numeric label={_('Bottom')} attr="margin.b" units="px" />
211211
<Numeric label={_('Left')} attr="margin.l" units="px" />
@@ -293,15 +293,15 @@ class DefaultEditor extends Component {
293293
</AnnotationAccordion>
294294
</LayoutPanel>
295295
<LayoutPanel group="Style" name={_('Axes')}>
296-
<AxesFold name={_('Titles')} foldIndex={0} key={0}>
296+
<AxesFold name={_('Titles')}>
297297
<AxesSelector />
298298
<MultiFormatTextEditor attr="title" />
299299
<FontSelector label={_('Typeface')} attr="titlefont.family" />
300300
<Numeric label={_('Font Size')} attr="titlefont.size" units="px" />
301301
<ColorPicker label={_('Font Color')} attr="titlefont.color" />
302302
</AxesFold>
303303

304-
<AxesFold name={_('Range')} foldIndex={1} key={1}>
304+
<AxesFold name={_('Range')}>
305305
<AxesSelector />
306306
<Section name={_('Selection')}>
307307
<Radio
@@ -323,29 +323,29 @@ class DefaultEditor extends Component {
323323
</Section>
324324
</AxesFold>
325325

326-
<AxesFold name={_('Lines')} foldIndex={2} key={2}>
326+
<AxesFold name={_('Lines')}>
327327
<AxesSelector />
328328
</AxesFold>
329-
<AxesFold name={_('Tick Labels')} foldIndex={3} key={3}>
329+
<AxesFold name={_('Tick Labels')}>
330330
<AxesSelector />
331331
<Section name={_('Tick Labels')}>
332332
<FontSelector label={_('Typeface')} attr="tickfont.family" />
333333
<Numeric label={_('Font Size')} attr="tickfont.size" units="px" />
334334
<ColorPicker label={_('Font Color')} attr="tickfont.color" />
335335
</Section>
336336
</AxesFold>
337-
<AxesFold name={_('Tick Markers')} foldIndex={4} key={4}>
337+
<AxesFold name={_('Tick Markers')}>
338338
<AxesSelector />
339339
</AxesFold>
340-
<AxesFold name={_('Zoom Interactivity')} foldIndex={5} key={5}>
340+
<AxesFold name={_('Zoom Interactivity')}>
341341
<AxesSelector />
342342
</AxesFold>
343-
<AxesFold name={_('Layout')} foldIndex={6} key={6}>
343+
<AxesFold name={_('Layout')}>
344344
<AxesSelector />
345345
</AxesFold>
346346
</LayoutPanel>
347347
<LayoutPanel group="Style" name={_('Legend')}>
348-
<Fold hideHeader foldIndex={0} key={0}>
348+
<Fold hideHeader>
349349
<Section name={_('Legend')}>
350350
<Radio
351351
attr="showlegend"

src/components/containers/Panel.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PanelHeader from './PanelHeader';
22
import PropTypes from 'prop-types';
3-
import React, {Component} from 'react';
3+
import React, {Component, cloneElement} from 'react';
44
import update from 'immutability-helper';
55
import {bem} from 'lib';
66

@@ -63,14 +63,15 @@ export default class Panel extends Component {
6363
}
6464

6565
render() {
66-
const {visible, children} = this.props;
66+
const {visible} = this.props;
6767
const {individualFoldStates, nbOfFolds} = this.state;
6868
const hasOpen =
6969
individualFoldStates.length > 0 &&
7070
individualFoldStates.some(s => s === false);
7171
const {onUpdate, layout, updateContainer} = this.context;
7272

7373
if (visible) {
74+
let children = this.props.children;
7475
let action = null;
7576
let onAction = () => {};
7677

@@ -86,6 +87,19 @@ export default class Panel extends Component {
8687
children.type.prototype.addAnnotation(layout, updateContainer);
8788
}
8889

90+
if (Array.isArray(children)) {
91+
children = children.map((child, index) => {
92+
if (child.type.displayName.indexOf('Fold') >= 0) {
93+
return cloneElement(child, {
94+
...child.props,
95+
foldIndex: index,
96+
key: index,
97+
});
98+
}
99+
return child;
100+
});
101+
}
102+
89103
return (
90104
<div className={bem('panel')}>
91105
<PanelHeader

src/styles/components/containers/_panel.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
&__collapse {
2222
font-size: var(--font-size-medium);
2323
float: left;
24-
color: var(--color-rhino-core);
24+
color: var(--color-text-base);
2525
display: flex;
2626
align-items: center;
2727
height: 100%;
2828
cursor: pointer;
2929
svg {
3030
width: 16px !important;
3131
height: 16px !important;
32-
fill: var(--color-rhino-core);
32+
fill: var(--color-text-light);
3333
padding-right: 3px;
3434
}
3535
}

0 commit comments

Comments
 (0)