Skip to content

Commit f11af7b

Browse files
teritePietro
authored and
Pietro
committed
add spellCheck support (#155)
1 parent de084af commit f11af7b

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import TranscriptEditor from '@bbc/react-transcript-editor';
6464
transcriptData=// Transcript json
6565
mediaUrl=// string url to media file - audio or video
6666
isEditable={true}// set to true if you want to be able to edit the text
67+
spellCheck={false}// set to true if you want the browser to spell check this transcript
6768
sttJsonType={ 'bbckaldi' } // the type of STT Json transcript supported.
6869
handleAnalyticsEvents={ this.handleAnalyticsEvents } // optional - if you want to collect analytics events.
6970
fileName=// optional - used for saving and retrieving local storage blob files

demo/app.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class App extends React.Component {
2020
transcriptData: null,
2121
mediaUrl: null,
2222
isTextEditable: true,
23+
spellCheck: false,
2324
sttType: 'bbckaldi',
2425
analyticsEvents: [],
2526
title: '',
@@ -83,10 +84,16 @@ class App extends React.Component {
8384
}
8485
}
8586

86-
handleIsTextEditable = () => {
87-
this.setState(prevState => ({
88-
isTextEditable: prevState.isTextEditable !== true
89-
}));
87+
handleIsTextEditable = (e) => {
88+
this.setState({
89+
isTextEditable: e.target.checked
90+
});
91+
};
92+
93+
handleSpellCheck = (e) => {
94+
this.setState({
95+
spellCheck: e.target.checked
96+
});
9097
};
9198

9299
// https://stackoverflow.com/questions/21733847/react-jsx-selecting-selected-on-selected-select-option
@@ -226,11 +233,21 @@ class App extends React.Component {
226233
<input
227234
id={ 'textIsEditableCheckbox' }
228235
type="checkbox"
229-
defaultChecked="true"
236+
checked={ this.state.isTextEditable }
230237
onChange={ this.handleIsTextEditable }
231238
/>
232239
</div>
233240

241+
<div className={ style.checkbox }>
242+
<label className={ style.editableLabel } htmlFor={ 'spellCheckCheckbox' }>Spell Check</label>
243+
<input
244+
id={ 'spellCheckCheckbox' }
245+
type="checkbox"
246+
checked={ this.state.spellCheck }
247+
onChange={ this.handleSpellCheck }
248+
/>
249+
</div>
250+
234251
<button className={ style.warningButton } onClick={ () => this.clearLocalStorage() }>Clear Local Storage</button>
235252
</section>
236253
</div>
@@ -240,6 +257,7 @@ class App extends React.Component {
240257
fileName={ this.state.fileName }
241258
mediaUrl={ this.state.mediaUrl }
242259
isEditable={ this.state.isTextEditable }
260+
spellCheck={ this.state.spellCheck }
243261
sttJsonType={ this.state.sttType }
244262
handleAnalyticsEvents={ this.handleAnalyticsEvents }
245263
title={ this.state.title }

packages/components/timed-text-editor/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ class TimedTextEditor extends React.Component {
509509
blockRendererFn={ this.renderBlockWithTimecodes }
510510
handleKeyCommand={ command => this.handleKeyCommand(command) }
511511
keyBindingFn={ e => this.customKeyBindingFn(e) }
512+
spellCheck={ this.props.spellCheck }
512513
/>
513514
</section>
514515
);
@@ -547,6 +548,7 @@ TimedTextEditor.propTypes = {
547548
transcriptData: PropTypes.object,
548549
mediaUrl: PropTypes.string,
549550
isEditable: PropTypes.bool,
551+
spellCheck: PropTypes.bool,
550552
onWordClick: PropTypes.func,
551553
sttJsonType: PropTypes.string,
552554
isPlaying: PropTypes.func,

packages/components/timed-text-editor/stories/index.stories.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ storiesOf('TimedTextEditor', module)
1717
transcriptData: bbcKaldiTranscript,
1818
mediaUrl: text('mediaUrl', mediaUrl),
1919
isEditable: boolean('isEditable', true),
20+
spellCheck: boolean('spellCheck', false),
2021
onWordClick: action('onWordClick'),
2122
sttJsonType: text('sttJsonType', 'bbckaldi'),
2223
isPlaying: action('isPlaying'),

packages/components/transcript-editor/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ class TranscriptEditor extends React.Component {
342342
isPlaying={ this.handleIsPlaying }
343343
currentTime={ this.state.currentTime }
344344
isEditable={ this.props.isEditable }
345+
spellCheck={ this.props.spellCheck }
345346
sttJsonType={ this.props.sttJsonType }
346347
mediaUrl={ this.props.mediaUrl }
347348
isScrollIntoViewOn={ this.state.isScrollIntoViewOn }
@@ -454,6 +455,7 @@ TranscriptEditor.propTypes = {
454455
title: PropTypes.string,
455456
mediaUrl: PropTypes.string,
456457
isEditable: PropTypes.bool,
458+
spellCheck: PropTypes.bool,
457459
sttJsonType: PropTypes.string,
458460
handleAnalyticsEvents: PropTypes.func,
459461
fileName: PropTypes.string,

packages/components/transcript-editor/stories/index.stories.js

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ storiesOf('TranscriptEditor', module)
1616
mediaUrl: text('mediaUrl', 'https://download.ted.com/talks/KateDarling_2018S-950k.mp4'),
1717
sttJsonType: text('sttJsonType', 'bbckaldi' ),
1818
isEditable: boolean('isEditable', true ),
19+
spellCheck: boolean('spellCheck', false ),
1920
fileName: text('fileName', 'KateDarling_2018S-950k.mp4' ),
2021
transcriptData: object('transcriptData', bbcKaldiTranscript),
2122
handleAnalyticsEvents: action('Analytics event')

0 commit comments

Comments
 (0)