Skip to content

Commit 7d03193

Browse files
committed
Add fontOptions prop to api
1 parent b72b14e commit 7d03193

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

dev/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class App extends Component {
147147
// glByDefault
148148
// traceTypesConfig={traceTypesConfig}
149149
// makeDefaultTrace={() => ({type: 'scattergl', mode: 'markers'})}
150+
// fontOptions={[{label:'Arial', value: 'arial'}]}
150151
>
151152
<DefaultEditor>
152153
<Panel group="Dev" name="JSON">

src/EditorControls.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class EditorControls extends Component {
5555
showFieldTooltips: this.props.showFieldTooltips,
5656
glByDefault: this.props.glByDefault,
5757
mapBoxAccess: this.props.mapBoxAccess,
58+
fontOptions: this.props.fontOptions,
5859
};
5960
}
6061

@@ -344,6 +345,7 @@ EditorControls.propTypes = {
344345
makeDefaultTrace: PropTypes.func,
345346
glByDefault: PropTypes.bool,
346347
mapBoxAccess: PropTypes.bool,
348+
fontOptions: PropTypes.array,
347349
};
348350

349351
EditorControls.defaultProps = {
@@ -383,6 +385,7 @@ EditorControls.childContextTypes = {
383385
showFieldTooltips: PropTypes.bool,
384386
glByDefault: PropTypes.bool,
385387
mapBoxAccess: PropTypes.bool,
388+
fontOptions: PropTypes.array,
386389
};
387390

388391
export default EditorControls;

src/PlotlyEditor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {Component} from 'react';
22
import createPlotComponent from 'react-plotly.js/factory';
33
import EditorControls from './EditorControls';
44
import PropTypes from 'prop-types';
5+
import {DEFAULT_FONTS} from 'lib/constants';
56

67
class PlotlyEditor extends Component {
78
constructor(props) {
@@ -31,6 +32,7 @@ class PlotlyEditor extends Component {
3132
mapBoxAccess={Boolean(
3233
this.props.config && this.props.config.mapboxAccessToken
3334
)}
35+
fontOptions={this.props.fontOptions}
3436
>
3537
{this.props.children}
3638
</EditorControls>
@@ -82,11 +84,13 @@ PlotlyEditor.propTypes = {
8284
}),
8385
makeDefaultTrace: PropTypes.func,
8486
glByDefault: PropTypes.bool,
87+
fontOptions: PropTypes.array,
8588
};
8689

8790
PlotlyEditor.defaultProps = {
8891
hideControls: false,
8992
showFieldTooltips: false,
93+
fontOptions: DEFAULT_FONTS,
9094
};
9195

9296
export default PlotlyEditor;
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
import Dropdown from './Dropdown';
22
import React from 'react';
3-
import {DEFAULT_FONTS} from 'lib/constants';
3+
import PropTypes from 'prop-types';
44

55
/* eslint-disable react/prop-types */
66
const styledRenderer = ({value, label}) => (
77
<span style={{fontFamily: value}}>{label}</span>
88
);
99
/* eslint-enable react/prop-types */
1010

11-
const FontSelector = props => {
12-
let options;
13-
if (Array.isArray(props.options)) {
14-
options = props.options;
15-
} else {
16-
options = [...DEFAULT_FONTS];
17-
}
11+
const FontSelector = (props, context) => {
1812
return (
1913
<Dropdown
2014
{...props}
21-
options={options}
15+
options={context.fontOptions}
2216
valueRenderer={styledRenderer}
2317
optionRenderer={styledRenderer}
2418
/>
@@ -33,4 +27,8 @@ FontSelector.defaultProps = {
3327
clearable: false,
3428
};
3529

30+
FontSelector.contextTypes = {
31+
fontOptions: PropTypes.array,
32+
};
33+
3634
export default FontSelector;

0 commit comments

Comments
 (0)