Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Refactor loginRequired.js with Aphrodite and commonForm #8011

Merged
merged 2 commits into from
Apr 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/extensions/brave/locales/en-US/app.properties
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ moreBookmarks=More bookmarks…
fullScreenModeWarning={{host}} entered full screen mode, press ESC to exit.
braveMenuTotalReplacements=Total Replacements: {{count}}
basicAuthRequired=Authentication Required
basicAuthUsernameLabel=Username:
basicAuthPasswordLabel=Password:
basicAuthUsernameLabel=Username
basicAuthPasswordLabel=Password
basicAuthMessage={{host}} requires a username and password.
crashScreenHeader=Something went wrong =(
crashScreenText=An error occurred while displaying this webpage. To continue, reload or navigate to another page.
Expand Down
39 changes: 38 additions & 1 deletion app/renderer/components/commonForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const globalStyles = require('./styles/global')
const commonStyles = require('./styles/commonStyles')

const {FormDropdown} = require('./dropdown')
const {FormTextbox} = require('./textbox')

class CommonForm extends ImmutableComponent {
render () {
Expand All @@ -23,6 +24,12 @@ class CommonFormDropdown extends ImmutableComponent {
}
}

class CommonFormTextbox extends ImmutableComponent {
render () {
return <FormTextbox data-isCommonForm='true' {...this.props} />
}
}

class CommonFormClickable extends ImmutableComponent {
render () {
return <div className={css(styles.CommonFormClickable)} {...this.props} />
Expand Down Expand Up @@ -71,6 +78,7 @@ const styles = StyleSheet.create({
padding: 0,
top: '40px',
cursor: 'default',
width: '100%',
maxWidth: '422px',
WebkitUserSelect: 'none'

Expand Down Expand Up @@ -109,13 +117,42 @@ const styles = StyleSheet.create({
}
})

const commonFormStyles = StyleSheet.create({
sectionWrapper: {
display: 'flex',
justifyContent: 'space-between'
},
inputWrapper: {
display: 'flex',
flexFlow: 'column',
justifyContent: 'space-around'
},
inputWrapper__label: {
marginRight: `calc(${globalStyles.spacing.dialogInsideMargin} / 2)`
},
inputWrapper__input: {
flexGrow: 1
},
input__bottomRow: {
marginTop: `calc(${globalStyles.spacing.dialogInsideMargin} / 3)`
},
input__marginRow: {
marginTop: `calc(${globalStyles.spacing.dialogInsideMargin} / 3)`
},
input__box: {
fontSize: globalStyles.fontSize.flyoutDialog
}
})

module.exports = {
CommonForm,
CommonFormDropdown,
CommonFormTextbox,
CommonFormClickable,
CommonFormSection,
CommonFormTitle,
CommonFormSubSection,
CommonFormButtonWrapper,
CommonFormBottomWrapper
CommonFormBottomWrapper,
commonFormStyles
}
16 changes: 16 additions & 0 deletions app/renderer/components/styles/commonStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ const styles = StyleSheet.create({
padding: '0.4em',
width: '100%'
},

// Textbox -- copied from textbox.js
textbox: {
boxSizing: 'border-box',
width: 'auto'
},
textbox__outlineable: {
':focus': {
outlineColor: globalStyles.color.statsBlue,
outlineOffset: '-4px',
outlineStyle: 'solid',
outlineWidth: '1px'
}
},

// Dialogs
flyoutDialog: {
background: globalStyles.color.toolbarBackground,
borderRadius: globalStyles.radius.borderRadius,
Expand Down
9 changes: 7 additions & 2 deletions app/renderer/components/textbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

const React = require('react')
const ImmutableComponent = require('../../../js/components/immutableComponent')
const {StyleSheet, css} = require('aphrodite')
const {StyleSheet, css} = require('aphrodite/no-important')
const globalStyles = require('./styles/global')
const commonStyles = require('./styles/commonStyles')

Expand All @@ -14,8 +14,9 @@ class Textbox extends ImmutableComponent {
const className = css(
this.props['data-isFormControl'] && commonStyles.formControl,
styles.textbox,
this.props['data-isSettings'] && styles.isSettings,
(this.props.readonly || this.props.readOnly) ? styles.readOnly : styles.outlineable,
this.props['data-isCommonForm'] && styles.isCommonForm,
this.props['data-isSettings'] && styles.isSettings,
this.props['data-isRecoveryKeyTextbox'] && styles.recoveryKeys
)

Expand Down Expand Up @@ -73,6 +74,10 @@ const styles = StyleSheet.create({
outlineWidth: '1px'
}
},
isCommonForm: {
fontSize: globalStyles.fontSize.flyoutDialog,
width: '100%'
},
isSettings: {
width: '280px'
},
Expand Down
87 changes: 67 additions & 20 deletions js/components/loginRequired.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ const appActions = require('../actions/appActions')
const KeyCodes = require('../../app/common/constants/keyCodes')
const urlResolve = require('url').resolve

const {StyleSheet, css} = require('aphrodite/no-important')
const commonStyles = require('../../app/renderer/components/styles/commonStyles')

const {
CommonForm,
CommonFormSection,
CommonFormTitle,
CommonFormTextbox,
CommonFormButtonWrapper,
commonFormStyles
} = require('../../app/renderer/components/commonForm')

class LoginRequired extends React.Component {
constructor () {
super()
Expand Down Expand Up @@ -73,31 +85,66 @@ class LoginRequired extends React.Component {
host: urlResolve(this.detail.getIn(['request', 'url']), '/')
}
return <Dialog onHide={this.onClose} isClickDismiss>
<div className='genericForm' onClick={this.onClick.bind(this)}>
<h2 data-l10n-id='basicAuthRequired' />
<div className='genericFormSubtitle' data-l10n-id='basicAuthMessage' data-l10n-args={JSON.stringify(l10nArgs)} />
<div className='genericFormTable'>
<div id='loginUsername' className='formRow'>
<label data-l10n-id='basicAuthUsernameLabel' htmlFor='loginUsername' />
<input spellCheck='false' onKeyDown={this.onKeyDown} onChange={this.onUsernameChange} value={this.state.username} ref={(loginUsername) => { this.loginUsername = loginUsername }} />
</div>
{
!this.isFolder
? <div id='loginPassword' className='formRow'>
<label data-l10n-id='basicAuthPasswordLabel' htmlFor='loginPassword' />
<input spellCheck='false' type='password' onKeyDown={this.onKeyDown} onChange={this.onPasswordChange} value={this.state.password} />
<CommonForm onClick={this.onClick.bind(this)}>
<CommonFormTitle data-l10n-id='basicAuthRequired' />
<CommonFormSection data-l10n-id='basicAuthMessage' data-l10n-args={JSON.stringify(l10nArgs)} />
<CommonFormSection>
<div className={css(styles.sectionWrapper)}>
<div data-test-id='loginLabel'
className={css(commonFormStyles.inputWrapper,
commonFormStyles.inputWrapper__label
)}>
<label data-l10n-id='basicAuthUsernameLabel' htmlFor='loginUsername' />
<label className={css(commonFormStyles.input__bottomRow)} data-l10n-id='basicAuthPasswordLabel' htmlFor='loginPassword' />
</div>
: null
}
<div className='formRow'>
<Button l10nId='cancel' className='whiteButton' onClick={this.onClose} />
<Button l10nId='ok' className='primaryButton' onClick={this.onSave.bind(this)} />
{
!this.isFolder
? <div id='loginInput' className={css(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure. We could remove them later if we would.

commonFormStyles.inputWrapper,
commonFormStyles.inputWrapper__input
)}>
<input className={css(
commonStyles.formControl,
commonStyles.textbox,
commonStyles.textbox__outlineable,
commonFormStyles.input__box
)}
spellCheck='false'
onKeyDown={this.onKeyDown}
onChange={this.onUsernameChange}
value={this.state.username}
ref={(loginUsername) => { this.loginUsername = loginUsername }}
/>
<div className={css(commonFormStyles.input__marginRow)}>
<CommonFormTextbox
spellCheck='false'
type='password'
onKeyDown={this.onKeyDown}
onChange={this.onPasswordChange}
value={this.state.password}
/>
</div>
</div>
: null
}
</div>
</div>
</div>
</CommonFormSection>
<CommonFormButtonWrapper>
<Button l10nId='cancel' className='whiteButton' onClick={this.onClose} />
<Button l10nId='ok' className='primaryButton' onClick={this.onSave.bind(this)} />
</CommonFormButtonWrapper>
</CommonForm>
</Dialog>
}
}

LoginRequired.propTypes = { frameProps: React.PropTypes.object }

const styles = StyleSheet.create({
sectionWrapper: {
display: 'flex',
justifyContent: 'space-between'
}
})

module.exports = LoginRequired