Skip to content

Commit 61c95e6

Browse files
authored
Merge pull request #698 from plotly/fonts-as-props
Add fontOptions prop to api
2 parents b72b14e + c1c9ad0 commit 61c95e6

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
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">

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-chart-editor",
33
"description": "plotly.js chart editor react component UI",
4-
"version": "0.26.1",
4+
"version": "0.27.0",
55
"author": "Plotly, Inc.",
66
"bugs": {
77
"url": "https://github.com/plotly/react-chart-editor/issues"

src/EditorControls.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import isNumeric from 'fast-isnumeric';
1515
import nestedProperty from 'plotly.js/src/lib/nested_property';
1616
import {categoryLayout, traceTypes} from 'lib/traceTypes';
1717
import {ModalProvider} from 'components/containers';
18+
import {DEFAULT_FONTS} from 'lib/constants';
1819

1920
class EditorControls extends Component {
2021
constructor(props, context) {
@@ -55,6 +56,7 @@ class EditorControls extends Component {
5556
showFieldTooltips: this.props.showFieldTooltips,
5657
glByDefault: this.props.glByDefault,
5758
mapBoxAccess: this.props.mapBoxAccess,
59+
fontOptions: this.props.fontOptions,
5860
};
5961
}
6062

@@ -344,6 +346,7 @@ EditorControls.propTypes = {
344346
makeDefaultTrace: PropTypes.func,
345347
glByDefault: PropTypes.bool,
346348
mapBoxAccess: PropTypes.bool,
349+
fontOptions: PropTypes.array,
347350
};
348351

349352
EditorControls.defaultProps = {
@@ -354,6 +357,7 @@ EditorControls.defaultProps = {
354357
traces: _ => traceTypes(_),
355358
complex: true,
356359
},
360+
fontOptions: DEFAULT_FONTS,
357361
};
358362

359363
EditorControls.childContextTypes = {
@@ -383,6 +387,7 @@ EditorControls.childContextTypes = {
383387
showFieldTooltips: PropTypes.bool,
384388
glByDefault: PropTypes.bool,
385389
mapBoxAccess: PropTypes.bool,
390+
fontOptions: PropTypes.array,
386391
};
387392

388393
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;

src/components/fields/FontSelector.js

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)