Skip to content

Commit 4b6f652

Browse files
rename SubPanel -> MenuPanel and split MenuPanel
The underlying modal is useful to other dropdown like components so that has been split into something called ModalBox
1 parent fa5dcc5 commit 4b6f652

File tree

14 files changed

+152
-129
lines changed

14 files changed

+152
-129
lines changed

src/DefaultEditor.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
PanelMenuWrapper,
1515
Radio,
1616
Section,
17-
SubPanel,
17+
MenuPanel,
18+
SymbolSelector,
1819
TraceAccordion,
1920
TraceSelector,
2021
} from './components';
@@ -278,7 +279,7 @@ class DefaultEditor extends Component {
278279
/>
279280
</Section>
280281
<Section name={_('Positioning')}>
281-
<SubPanel>
282+
<MenuPanel>
282283
<Section name={_('Anchor Point')}>
283284
<Info>
284285
{_(
@@ -303,7 +304,7 @@ class DefaultEditor extends Component {
303304
]}
304305
/>
305306
</Section>
306-
</SubPanel>
307+
</MenuPanel>
307308
<Numeric
308309
label={_('X Position')}
309310
step={0.01}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import React, {Component} from 'react';
2+
import PropTypes from 'prop-types';
3+
import classnames from 'classnames';
4+
import ModalBox from './ModalBox';
5+
6+
export default class MenuPanel extends Component {
7+
constructor() {
8+
super();
9+
this.state = {isOpen: false};
10+
11+
this.togglePanel = this.togglePanel.bind(this);
12+
}
13+
14+
menupanelClasses() {
15+
if (this.props.iconClass) {
16+
return {
17+
iconClass: `menupanel__icon ${this.props.iconClass}`,
18+
spanClass: 'menupanel__icon-span',
19+
};
20+
} else if (this.props.question) {
21+
return {
22+
iconClass: 'menupanel__icon plotlyjs_editor__icon-question-circle',
23+
spanClass: `menupanel__icon-span menupanel__icon-span--question`,
24+
};
25+
}
26+
return {
27+
iconClass: 'menupanel__icon plotlyjs_editor__icon-cog',
28+
spanClass: 'menupanel__icon-span menupanel__icon-span--cog',
29+
};
30+
}
31+
32+
togglePanel() {
33+
this.setState({isOpen: !this.state.isOpen});
34+
}
35+
36+
render() {
37+
const isOpen = this.props.show || this.state.isOpen;
38+
const containerClass = classnames('menupanel', {
39+
'menupanel--ownline': this.props.ownline,
40+
});
41+
42+
const {iconClass, spanClass} = this.menupanelClasses();
43+
44+
return (
45+
<div className={containerClass}>
46+
<span className={spanClass}>
47+
<span>{this.props.label}</span>
48+
<i className={iconClass} onClick={this.togglePanel} />
49+
</span>
50+
{isOpen ? (
51+
<ModalBox onClose={this.togglePanel}>{this.props.children}</ModalBox>
52+
) : null}
53+
</div>
54+
);
55+
}
56+
}
57+
58+
MenuPanel.propTypes = {
59+
children: PropTypes.node,
60+
iconClass: PropTypes.string,
61+
show: PropTypes.bool,
62+
ownline: PropTypes.bool,
63+
question: PropTypes.bool,
64+
label: PropTypes.string,
65+
};

src/components/containers/ModalBox.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React, {Component} from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
export default class ModalBox extends Component {
5+
render() {
6+
let style;
7+
if (this.props.backgroundColor) {
8+
style = {backgroundColor: this.props.backgroundColor};
9+
}
10+
11+
return (
12+
<div className="modalbox" style={style}>
13+
<div className="modalbox__cover" onClick={this.props.onClose} />
14+
<div>{this.props.children}</div>
15+
</div>
16+
);
17+
}
18+
}
19+
20+
ModalBox.propTypes = {
21+
backgroundColor: PropTypes.string,
22+
children: PropTypes.node,
23+
onClose: PropTypes.func,
24+
};

src/components/containers/Section.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import SubPanel from './SubPanel';
1+
import MenuPanel from './MenuPanel';
22
import React, {Component, cloneElement} from 'react';
33
import PropTypes from 'prop-types';
44
import unpackPlotProps from '../../lib/unpackPlotProps';
@@ -12,7 +12,7 @@ class Section extends Component {
1212
super(props, context);
1313

1414
this.children = null;
15-
this.subPanel = null;
15+
this.menuPanel = null;
1616

1717
this.processAndSetChildren(context);
1818
}
@@ -28,19 +28,19 @@ class Section extends Component {
2828
}
2929

3030
const attrChildren = [];
31-
let subPanel = null;
31+
let menuPanel = null;
3232

3333
for (let i = 0; i < children.length; i++) {
3434
const child = children[i];
3535
if (!child) {
3636
continue;
3737
}
38-
if (child.type === SubPanel) {
39-
// Process the first subPanel. Ignore the rest.
40-
if (subPanel) {
38+
if (child.type === MenuPanel) {
39+
// Process the first menuPanel. Ignore the rest.
40+
if (menuPanel) {
4141
continue;
4242
}
43-
subPanel = child;
43+
menuPanel = child;
4444
continue;
4545
}
4646

@@ -54,19 +54,19 @@ class Section extends Component {
5454
}
5555

5656
this.children = attrChildren.length ? attrChildren : null;
57-
this.subPanel = subPanel;
57+
this.menuPanel = menuPanel;
5858
}
5959

6060
render() {
6161
const hasVisibleChildren =
6262
(this.children && this.children.some(childIsVisible)) ||
63-
Boolean(this.subPanel);
63+
Boolean(this.menuPanel);
6464

6565
return hasVisibleChildren ? (
6666
<div className="section">
6767
<div className="section__heading">
6868
{this.props.name}
69-
{this.subPanel}
69+
{this.menuPanel}
7070
</div>
7171
{this.children}
7272
</div>

src/components/containers/SubPanel.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

src/components/containers/__tests__/Section-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import Section from '../Section';
3-
import SubPanel from '../SubPanel';
3+
import MenuPanel from '../MenuPanel';
44
import {Flaglist, Info, Numeric} from '../../fields';
55
import {TestEditor, fixtures, plotly} from '../../../lib/test-utils';
66
import {connectTraceToPlot} from '../../../lib';
@@ -91,20 +91,20 @@ describe('Section', () => {
9191
expect(wrapper.find(Numeric).exists()).toBe(false);
9292
});
9393

94-
it('will render first subPanel even with no visible attrs', () => {
94+
it('will render first menuPanel even with no visible attrs', () => {
9595
const wrapper = mount(
9696
<TestEditor
9797
plotly={plotly}
9898
onUpdate={jest.fn()}
9999
{...fixtures.scatter({deref: true})}
100100
>
101101
<Section name="test-section">
102-
<SubPanel show>
102+
<MenuPanel show>
103103
<Info>INFO</Info>
104-
</SubPanel>
105-
<SubPanel show>
104+
</MenuPanel>
105+
<MenuPanel show>
106106
<Info>MISINFORMATION</Info>
107-
</SubPanel>
107+
</MenuPanel>
108108
</Section>
109109
</TestEditor>
110110
).find('[name="test-section"]');

src/components/containers/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import SubPanel from './SubPanel';
1+
import MenuPanel from './MenuPanel';
22
import Fold from './Fold';
33
import Panel from './Panel';
44
import Section from './Section';
55
import TraceAccordion from './TraceAccordion';
66

7-
export {SubPanel, Fold, Panel, Section, TraceAccordion};
7+
export {MenuPanel, Fold, Panel, Section, TraceAccordion};

src/components/fields/Field.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PropTypes from 'prop-types';
22
import React, {Component} from 'react';
3-
import SubPanel from '../containers/SubPanel';
3+
import MenuPanel from '../containers/MenuPanel';
44
import classnames from 'classnames';
55
import {bem, localize} from '../../lib';
66
import {multiValueText} from '../../lib/constants';
@@ -48,11 +48,11 @@ class Field extends Component {
4848
<div className={fieldClass}>
4949
{children}
5050
{multiValued ? (
51-
<SubPanel label={_(multiValueText.title)} ownline question>
51+
<MenuPanel label={_(multiValueText.title)} ownline question>
5252
<div className="info__title">{_(multiValueText.title)}</div>
5353
<div className="info__text">{_(multiValueText.text)}</div>
5454
<div className="info__sub-text">{_(multiValueText.subText)}</div>
55-
</SubPanel>
55+
</MenuPanel>
5656
) : null}
5757
</div>
5858
{postfix ? (

src/components/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import {
1111
TraceSelector,
1212
} from './fields';
1313

14-
import {SubPanel, Fold, Panel, Section, TraceAccordion} from './containers';
14+
import {MenuPanel, Fold, Panel, Section, TraceAccordion} from './containers';
1515
import PanelMenuWrapper from './PanelMenuWrapper';
1616

1717
export {
1818
AxesSelector,
1919
AxesRange,
20-
SubPanel,
20+
MenuPanel,
2121
ColorPicker,
2222
DataSelector,
2323
Dropdown,

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {EDITOR_ACTIONS} from './constants';
1212
import {
1313
AxesRange,
1414
AxesSelector,
15-
SubPanel,
1615
ColorPicker,
1716
DataSelector,
1817
Dropdown,
@@ -25,14 +24,15 @@ import {
2524
PanelMenuWrapper,
2625
Radio,
2726
Section,
27+
MenuPanel,
2828
TraceAccordion,
2929
TraceSelector,
3030
} from './components';
3131

3232
export {
3333
AxesRange,
3434
AxesSelector,
35-
SubPanel,
35+
MenuPanel,
3636
ColorPicker,
3737
DataSelector,
3838
Dropdown,

src/styles/components/containers/_main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
@import "section";
44
@import "menupanel";
55
@import "info";
6+
@import "modalbox";

0 commit comments

Comments
 (0)