This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f31632
commit b5195e3
Showing
8 changed files
with
188 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"presets": [ | ||
"es2015", | ||
"react", | ||
[ "env", { | ||
"targets": { | ||
"browsers": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React, { Component } from 'preact-compat'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export default class PlaybackButton extends Component { | ||
render() { | ||
const style = { | ||
fontFamily: '"Apple Color Emoji","Segoe UI Emoji","NotoColorEmoji","Segoe UI Symbol","Android Emoji","EmojiSymbols"', | ||
background: 'none', | ||
border: 'none', | ||
cursor: 'pointer', | ||
}; | ||
return ( | ||
<button type="button" aria-label={ this.props.label } style={ style } onClick={ this.props.onClick }> | ||
{ this.props.icon } | ||
</button> | ||
); | ||
} | ||
} | ||
|
||
PlaybackButton.propTypes = { | ||
label: PropTypes.string.isRequired, | ||
icon: PropTypes.string.isRequired, | ||
onClick: PropTypes.func.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
import React, { Component } from 'preact-compat'; | ||
import PropTypes from 'prop-types'; | ||
import PlaybackButton from './PlaybackButton'; | ||
import { uniqueId } from '../helpers'; | ||
|
||
export default class PlaybackControls extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
dialogOpen: false, | ||
}; | ||
} | ||
|
||
componentWillMount() { | ||
this.idPrefix = `input${ uniqueId() }-`; | ||
} | ||
|
||
componentDidMount() { | ||
this.updateDialogState(); | ||
this.dialog.addEventListener( 'cancel', ( event ) => { | ||
event.preventDefault(); | ||
this.setState( { dialogOpen: false } ); | ||
} ); | ||
} | ||
|
||
componentDidUpdate() { | ||
this.updateDialogState(); | ||
} | ||
|
||
updateDialogState() { | ||
if ( ! this.state.dialogOpen && this.dialog.open ) { | ||
this.dialog.close(); | ||
if ( this.previousActiveElement ) { | ||
this.previousActiveElement.focus(); | ||
} | ||
} else if ( this.state.dialogOpen && ! this.dialog.open ) { | ||
this.previousActiveElement = document.activeElement; | ||
this.dialog.showModal(); | ||
} | ||
} | ||
|
||
render() { | ||
const showDialog = () => { | ||
this.setState( { dialogOpen: true } ); | ||
}; | ||
const hideDialog = () => { | ||
this.setState( { dialogOpen: false } ); | ||
}; | ||
const saveDialogRef = ( dialog ) => { | ||
this.dialog = dialog; | ||
}; | ||
|
||
return ( | ||
<fieldset> | ||
<legend>Playback</legend> | ||
<PlaybackButton icon="▶" label="Play" onClick={ this.props.play } /> | ||
<PlaybackButton icon="⏹" label="Stop" onClick={ this.props.stop } /> | ||
<PlaybackButton icon="⏪" label="Previous" onClick={ this.props.previous } /> | ||
<PlaybackButton icon="⏩" label="Forward" onClick={ this.props.next } /> | ||
<PlaybackButton icon="⚙" label="Settings" onClick={ showDialog } /> | ||
|
||
<dialog ref={ saveDialogRef }> | ||
<p> | ||
<label htmlFor={ this.idPrefix + 'rate' }>Rate:</label> | ||
<input id={ this.idPrefix + 'rate' } type="number" defaultValue={1.0} /> | ||
</p> | ||
<p> | ||
<label htmlFor={ this.idPrefix + 'pitch' }>Pitch:</label> | ||
<input id={ this.idPrefix + 'pitch' } type="number" defaultValue={1.0} /> | ||
</p> | ||
<p> | ||
<label htmlFor={ this.idPrefix + 'voice[en]' }>English Voice:</label> | ||
<select id={ this.idPrefix + 'voice[en]' }> | ||
<option>Alex</option> | ||
</select> | ||
</p> | ||
<button onClick={ hideDialog }>Close</button> | ||
</dialog> | ||
</fieldset> | ||
); | ||
} | ||
} | ||
|
||
PlaybackControls.propTypes = { | ||
play: PropTypes.func.isRequired, | ||
stop: PropTypes.func.isRequired, | ||
previous: PropTypes.func.isRequired, | ||
next: PropTypes.func.isRequired, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters