feat: highlight currently selected editor tab
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
ad059dc49c
commit
1e1a0939ab
@ -136,9 +136,11 @@ class Editor extends Component {
|
|||||||
|
|
||||||
const { challengeFiles } = this.props;
|
const { challengeFiles } = this.props;
|
||||||
|
|
||||||
// NOTE: for consitency with this.data (and this.options) currentFileKey
|
// NOTE: the ARIA state is controlled by fileKey, so changes to it must
|
||||||
// is just a property, not state.
|
// trigger a re-render. Hence state:
|
||||||
this.currentFileKey = sortFiles(challengeFiles)[0].key;
|
this.state = {
|
||||||
|
fileKey: sortFiles(challengeFiles)[0].key
|
||||||
|
};
|
||||||
|
|
||||||
this.options = {
|
this.options = {
|
||||||
fontSize: '18px',
|
fontSize: '18px',
|
||||||
@ -192,7 +194,7 @@ class Editor extends Component {
|
|||||||
modeMap[challengeFiles[key].ext]
|
modeMap[challengeFiles[key].ext]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return { model: this.data[this.currentFileKey].model };
|
return { model: this.data[this.state.fileKey].model };
|
||||||
};
|
};
|
||||||
|
|
||||||
// Updates the model if the contents has changed. This is only necessary for
|
// Updates the model if the contents has changed. This is only necessary for
|
||||||
@ -282,11 +284,11 @@ class Editor extends Component {
|
|||||||
|
|
||||||
onChange = editorValue => {
|
onChange = editorValue => {
|
||||||
const { updateFile } = this.props;
|
const { updateFile } = this.props;
|
||||||
updateFile({ key: this.currentFileKey, editorValue });
|
updateFile({ key: this.state.fileKey, editorValue });
|
||||||
};
|
};
|
||||||
|
|
||||||
changeTab = fileKey => {
|
changeTab = newFileKey => {
|
||||||
this.currentFileKey = fileKey;
|
this.setState({ fileKey: newFileKey });
|
||||||
const editor = this._editor;
|
const editor = this._editor;
|
||||||
const currentState = editor.saveViewState();
|
const currentState = editor.saveViewState();
|
||||||
|
|
||||||
@ -301,8 +303,8 @@ class Editor extends Component {
|
|||||||
this.data.indexjsx.state = currentState;
|
this.data.indexjsx.state = currentState;
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.setModel(this.data[fileKey].model);
|
editor.setModel(this.data[newFileKey].model);
|
||||||
editor.restoreViewState(this.data[fileKey].state);
|
editor.restoreViewState(this.data[newFileKey].state);
|
||||||
editor.focus();
|
editor.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -319,7 +321,7 @@ class Editor extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.currentFileKey = null;
|
this.setState({ fileKey: null });
|
||||||
this.data = null;
|
this.data = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,6 +337,7 @@ class Editor extends Component {
|
|||||||
<div className='monaco-editor-tabs'>
|
<div className='monaco-editor-tabs'>
|
||||||
{challengeFiles['indexjsx'] && (
|
{challengeFiles['indexjsx'] && (
|
||||||
<button
|
<button
|
||||||
|
aria-selected={this.state.fileKey === 'indexjsx'}
|
||||||
className='monaco-editor-tab'
|
className='monaco-editor-tab'
|
||||||
onClick={() => this.changeTab('indexjsx')}
|
onClick={() => this.changeTab('indexjsx')}
|
||||||
role='tab'
|
role='tab'
|
||||||
@ -344,6 +347,7 @@ class Editor extends Component {
|
|||||||
)}
|
)}
|
||||||
{challengeFiles['indexhtml'] && (
|
{challengeFiles['indexhtml'] && (
|
||||||
<button
|
<button
|
||||||
|
aria-selected={this.state.fileKey === 'indexhtml'}
|
||||||
className='monaco-editor-tab'
|
className='monaco-editor-tab'
|
||||||
onClick={() => this.changeTab('indexhtml')}
|
onClick={() => this.changeTab('indexhtml')}
|
||||||
role='tab'
|
role='tab'
|
||||||
@ -353,6 +357,7 @@ class Editor extends Component {
|
|||||||
)}
|
)}
|
||||||
{challengeFiles['indexjs'] && (
|
{challengeFiles['indexjs'] && (
|
||||||
<button
|
<button
|
||||||
|
aria-selected={this.state.fileKey === 'indexjs'}
|
||||||
className='monaco-editor-tab'
|
className='monaco-editor-tab'
|
||||||
onClick={() => this.changeTab('indexjs')}
|
onClick={() => this.changeTab('indexjs')}
|
||||||
role='tab'
|
role='tab'
|
||||||
@ -362,6 +367,7 @@ class Editor extends Component {
|
|||||||
)}
|
)}
|
||||||
{challengeFiles['indexcss'] && (
|
{challengeFiles['indexcss'] && (
|
||||||
<button
|
<button
|
||||||
|
aria-selected={this.state.fileKey === 'indexcss'}
|
||||||
className='monaco-editor-tab'
|
className='monaco-editor-tab'
|
||||||
onClick={() => this.changeTab('indexcss')}
|
onClick={() => this.changeTab('indexcss')}
|
||||||
role='tab'
|
role='tab'
|
||||||
|
@ -14,6 +14,11 @@
|
|||||||
background-color: var(--secondary-background);
|
background-color: var(--secondary-background);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button.monaco-editor-tab:hover {
|
||||||
|
color: var(--quaternary-color);
|
||||||
|
background-color: var(--quaternary-background);
|
||||||
|
}
|
||||||
|
|
||||||
.monaco-editor-tab:first-child {
|
.monaco-editor-tab:first-child {
|
||||||
border-left: 2px solid var(--primary-color);
|
border-left: 2px solid var(--primary-color);
|
||||||
}
|
}
|
||||||
@ -22,3 +27,9 @@
|
|||||||
background-color: var(--primary-background);
|
background-color: var(--primary-background);
|
||||||
border-bottom: 2px solid var(--primary-background);
|
border-bottom: 2px solid var(--primary-background);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.monaco-editor-tab[role='tab'][aria-selected='true'] {
|
||||||
|
border-color: var(--secondary-color);
|
||||||
|
background-color: var(--secondary-color);
|
||||||
|
color: var(--secondary-background);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user