Skip to content

Commit

Permalink
Added user configurable text editor font size
Browse files Browse the repository at this point in the history
  • Loading branch information
magjac committed Sep 15, 2018
1 parent c26e83b commit 329506b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/SettingsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ const styles = theme => ({
},
holdOffInput: {
width: '7em',
}
},
fontSizeInput: {
width: '5em',
},
});

class SettingsDialog extends React.Component {
Expand All @@ -67,6 +70,10 @@ class SettingsDialog extends React.Component {
this.props.onHoldOffChange(event.target.value);
};

handleFontSizeChange = (event) => {
this.props.onFontSizeChange(event.target.value);
};

render() {
const { classes } = this.props;
return (
Expand Down Expand Up @@ -127,13 +134,35 @@ class SettingsDialog extends React.Component {
/>
</FormGroup>
</DialogContent>
<DialogTitle id="form-dialog-title">Other</DialogTitle>
<DialogTitle id="form-dialog-title">Text Editor</DialogTitle>
<DialogContent classes={{root: classes.root}}>
<FormControl
className={classes.formControl}
aria-describedby="font-size-helper-text"
>
<InputLabel shrink={true}>Font size</InputLabel>
<Input
className={classes.fontSizeInput}
id="font-size"
type="number"
value={this.props.fontSize}
onChange={this.handleFontSizeChange}
endAdornment={<InputAdornment position="end"> px</InputAdornment>}
inputProps={{
'aria-label': 'FontSize',
min: 1,
max: 99,
step: 1,
}}
/>
</FormControl>
</DialogContent>
<DialogContent classes={{root: classes.root}}>
<FormControl
className={classes.formControl}
aria-describedby="holdoff-helper-text"
>
<InputLabel shrink={true}>Editor hold-off time</InputLabel>
<InputLabel shrink={true}>Hold-off time</InputLabel>
<Input
className={classes.holdOffInput}
id="holdoff"
Expand Down
1 change: 1 addition & 0 deletions src/TextEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class TextEditor extends React.Component {
<AceEditor
mode="dot"
theme="github"
fontSize={this.props.fontSize + 'px'}
onChange={this.handleChange}
onBeforeLoad={this.handleBeforeLoad}
onLoad={this.handleLoad}
Expand Down
10 changes: 10 additions & 0 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Index extends React.Component {
defaultEdgeAttributes: JSON.parse(localStorage.getItem('defaultEdgeAttributes')) || {},
error: null,
holdOff: localStorage.getItem('holdOff') || 0.2,
fontSize: localStorage.getItem('fontSize') || 12,
selectedGraphComponents: [],
};
}
Expand Down Expand Up @@ -184,6 +185,12 @@ class Index extends React.Component {
});
}

handleFontSizeChange = (fontSize) => {
this.setPersistentState({
fontSize: fontSize,
});
}

handleNodeShapeClick = (shape) => {
let x0 = null;
let y0 = null;
Expand Down Expand Up @@ -389,6 +396,8 @@ class Index extends React.Component {
onFitGraphSwitchChange={this.handleFitGraphSwitchChange}
holdOff={this.state.holdOff}
onHoldOffChange={this.handleHoldOffChange}
fontSize={this.state.fontSize}
onFontSizeChange={this.handleFontSizeChange}
onSettingsClose={this.handleSettingsClose}
/>
<Grid container
Expand Down Expand Up @@ -428,6 +437,7 @@ class Index extends React.Component {
error={this.state.error}
selectedGraphComponents={this.state.selectedGraphComponents}
holdOff={this.state.holdOff}
fontSize={this.state.fontSize}
registerUndo={this.registerUndo}
registerRedo={this.registerRedo}
/>
Expand Down

0 comments on commit 329506b

Please sign in to comment.