Material UI: consistent JSX style

This commit is contained in:
DC
2016-08-31 12:57:56 -07:00
parent b98f8476f5
commit e0af554caa
6 changed files with 59 additions and 71 deletions

View File

@@ -17,15 +17,14 @@ class Heading extends React.Component {
render () { render () {
const HeadingTag = 'h' + this.props.level const HeadingTag = 'h' + this.props.level
return ( const style = {
<HeadingTag
style={{
color: colors.grey100, color: colors.grey100,
fontSize: 20, fontSize: 20,
marginBottom: 15, marginBottom: 15,
marginTop: 30 marginTop: 30
}} }
> return (
<HeadingTag style={style}>
{this.props.children} {this.props.children}
</HeadingTag> </HeadingTag>
) )

View File

@@ -7,6 +7,9 @@ const remote = electron.remote
const RaisedButton = require('material-ui/RaisedButton').default const RaisedButton = require('material-ui/RaisedButton').default
const TextField = require('material-ui/TextField').default const TextField = require('material-ui/TextField').default
// Lets you pick a file or directory.
// Uses the system Open File dialog.
// You can't edit the text field directly.
class PathSelector extends React.Component { class PathSelector extends React.Component {
static get propTypes () { static get propTypes () {
return { return {
@@ -43,48 +46,39 @@ class PathSelector extends React.Component {
render () { render () {
const id = this.props.title.replace(' ', '-').toLowerCase() const id = this.props.title.replace(' ', '-').toLowerCase()
return ( const wrapperStyle = {
<div
className={this.props.className}
style={{
alignItems: 'center', alignItems: 'center',
display: 'flex', display: 'flex',
width: '100%' width: '100%'
}} }
> const labelStyle = {
<div
className='label'
style={{
flex: '0 auto', flex: '0 auto',
marginRight: 10, marginRight: 10,
overflow: 'hidden', overflow: 'hidden',
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
whiteSpace: 'nowrap' whiteSpace: 'nowrap'
}} }
> const textareaStyle = {
{this.props.title}:
</div>
<TextField
className='control'
disabled
id={id}
inputStyle={{
color: colors.grey50 color: colors.grey50
}} }
style={{ const textFieldStyle = {
flex: '1', flex: '1',
fontSize: 14 fontSize: 14
}} }
value={this.props.displayValue || this.props.value} const text = this.props.displayValue || this.props.value
/> const buttonStyle = {
<RaisedButton
className='control'
label='Change'
onClick={this.handleClick}
style={{
marginLeft: 10 marginLeft: 10
}} }
/>
return (
<div className={this.props.className} style={wrapperStyle}>
<div className='label' style={labelStyle}>
{this.props.title}:
</div>
<TextField className='control' disabled id={id} value={text}
inputStyle={textareaStyle} style={textFieldStyle} />
<RaisedButton className='control' label='Change' onClick={this.handleClick}
style={buttonStyle} />
</div> </div>
) )
} }

View File

@@ -14,6 +14,8 @@ const CreateTorrentErrorPage = require('../components/create-torrent-error-page'
const Heading = require('../components/heading') const Heading = require('../components/heading')
const ShowMore = require('../components/show-more') const ShowMore = require('../components/show-more')
// Shows a basic UI to create a torrent, from an already-selected file or folder.
// Includes a "Show Advanced..." button and more advanced UI.
class CreateTorrentPage extends React.Component { class CreateTorrentPage extends React.Component {
constructor (props) { constructor (props) {
super(props) super(props)
@@ -92,7 +94,7 @@ class CreateTorrentPage extends React.Component {
marginBottom: 10 marginBottom: 10
}} }}
hideLabel='Hide advanced settings...' hideLabel='Hide advanced settings...'
showLabel='Show advanced settings...' > showLabel='Show advanced settings...'>
{this.renderAdvanced()} {this.renderAdvanced()}
</ShowMore> </ShowMore>
<div className='float-right'> <div className='float-right'>
@@ -101,18 +103,20 @@ class CreateTorrentPage extends React.Component {
style={{ style={{
marginRight: 10 marginRight: 10
}} }}
onClick={dispatcher('cancel')} onClick={dispatcher('cancel')} />
/>
<RaisedButton <RaisedButton
label='Create Torrent' label='Create Torrent'
primary primary
onClick={this.handleSubmit} onClick={this.handleSubmit} />
/>
</div> </div>
</div> </div>
) )
} }
// Renders everything after clicking Show Advanced...:
// * Is Private? (private torrents, not announced to DHT)
// * Announce list (trackers)
// * Comment
renderAdvanced () { renderAdvanced () {
// Create file list // Create file list
var maxFileElems = 100 var maxFileElems = 100

View File

@@ -392,16 +392,14 @@ function renderPlayerControls (state) {
<div <div
key='cursor' key='cursor'
className='playback-cursor' className='playback-cursor'
style={playbackCursorStyle} style={playbackCursorStyle} />
/>
<div <div
key='scrub-bar' key='scrub-bar'
className='scrub-bar' className='scrub-bar'
draggable='true' draggable='true'
onDragStart={handleDragStart} onDragStart={handleDragStart}
onClick={handleScrub} onClick={handleScrub}
onDrag={handleScrub} onDrag={handleScrub} />
/>
</div>, </div>,
<i <i
@@ -516,8 +514,7 @@ function renderPlayerControls (state) {
type='range' min='0' max='1' step='0.05' type='range' min='0' max='1' step='0.05'
value={volume} value={volume}
onChange={handleVolumeScrub} onChange={handleVolumeScrub}
style={volumeStyle} style={volumeStyle} />
/>
</div> </div>
)) ))

View File

@@ -33,8 +33,7 @@ class PreferencesPage extends React.Component {
}} }}
onChange={this.handleDownloadPathChange} onChange={this.handleDownloadPathChange}
title='Download location' title='Download location'
value={this.props.state.unsaved.prefs.downloadPath} value={this.props.state.unsaved.prefs.downloadPath} />
/>
</Preference> </Preference>
) )
} }
@@ -50,8 +49,7 @@ class PreferencesPage extends React.Component {
className='control' className='control'
checked={!this.props.state.unsaved.prefs.openExternalPlayer} checked={!this.props.state.unsaved.prefs.openExternalPlayer}
label={'Play torrent media files using WebTorrent'} label={'Play torrent media files using WebTorrent'}
onCheck={this.handleOpenExternalPlayerChange} onCheck={this.handleOpenExternalPlayerChange} />
/>
</Preference> </Preference>
) )
} }
@@ -81,8 +79,7 @@ class PreferencesPage extends React.Component {
displayValue={playerName} displayValue={playerName}
onChange={this.handleExternalPlayerPathChange} onChange={this.handleExternalPlayerPathChange}
title='External player' title='External player'
value={this.props.state.unsaved.prefs.externalPlayerPath} value={this.props.state.unsaved.prefs.externalPlayerPath} />
/>
</Preference> </Preference>
) )
} }
@@ -110,8 +107,7 @@ class PreferencesPage extends React.Component {
<RaisedButton <RaisedButton
className='control' className='control'
onClick={this.handleSetDefaultApp} onClick={this.handleSetDefaultApp}
label='Make WebTorrent the default' label='Make WebTorrent the default' />
/>
</Preference> </Preference>
) )
} }
@@ -127,7 +123,7 @@ class PreferencesPage extends React.Component {
marginRight: 25 marginRight: 25
} }
return ( return (
<div style={style} > <div style={style}>
<PreferencesSection title='Downloads'> <PreferencesSection title='Downloads'>
{this.downloadPathSelector()} {this.downloadPathSelector()}
</PreferencesSection> </PreferencesSection>

View File

@@ -198,8 +198,7 @@ module.exports = class TorrentList extends React.Component {
key='download-button' key='download-button'
className={'button-round icon download ' + torrentSummary.status} className={'button-round icon download ' + torrentSummary.status}
title={downloadTooltip} title={downloadTooltip}
onClick={dispatcher('toggleTorrent', infoHash)} onClick={dispatcher('toggleTorrent', infoHash)}>
>
{downloadIcon} {downloadIcon}
</i> </i>
) )
@@ -221,8 +220,7 @@ module.exports = class TorrentList extends React.Component {
key='play-button' key='play-button'
title={playTooltip} title={playTooltip}
className={'button-round icon play ' + playClass} className={'button-round icon play ' + playClass}
onClick={dispatcher('playFile', infoHash)} onClick={dispatcher('playFile', infoHash)}>
>
{playIcon} {playIcon}
</i> </i>
) )