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

Separate input and select styles using Aphrodite #6689

Merged
merged 3 commits into from
Jan 23, 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
1 change: 1 addition & 0 deletions app/extensions/brave/img/caret_down_grey.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions app/renderer/components/dropdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

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

const caretDownGrey = require('../../extensions/brave/img/caret_down_grey.svg')

class Dropdown extends ImmutableComponent {
render () {
const className = css(
this.props['data-isFormControl'] && commonStyles.formControl,
styles.dropdown,
this.props['data-isSettings'] && styles.settings
)

return <select className={className} {...this.props}>
{this.props.children}
</select>
}
}

class FormDropdown extends ImmutableComponent {
render () {
return <Dropdown data-isFormControl='true' {...this.props} />
}
}

class SettingDropdown extends ImmutableComponent {
render () {
return <FormDropdown data-isSettings='true' {...this.props} />
}
}

const selectPadding = '0.4em'

const styles = StyleSheet.create({
'dropdown': {
background: `url(${caretDownGrey}) calc(100% - ${selectPadding}) 50% / contain no-repeat`,
backgroundColor: '#fefefe',
backgroundSize: '12px 12px',
boxShadow: `-1px 1px 3px -1px ${globalStyles.color.mediumGray}`,
height: '2rem',
outline: 'none',
// right padding is larger, to account for the down arrow SVG
padding: `${selectPadding} 1.5em ${selectPadding} ${selectPadding}`,
'-webkit-appearance': 'none',
width: 'auto'
},
'outlineable': {
':focus': {
outlineColor: globalStyles.color.statsBlue,
outlineOffset: '-4px',
outlineStyle: 'solid',
outlineWidth: '1px'
}
},
'settings': {
width: '280px'
}
})

module.exports = {
Dropdown,
FormDropdown,
SettingDropdown
}
39 changes: 39 additions & 0 deletions app/renderer/components/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const React = require('react')
const ImmutableComponent = require('../../../js/components/immutableComponent')

class SettingsList extends ImmutableComponent {
render () {
return <div className='settingsListContainer'>
{
this.props.dataL10nId
? <div className='settingsListTitle' data-l10n-id={this.props.dataL10nId} />
: null
}
<div className='settingsList'>
{this.props.children}
</div>
</div>
}
}

class SettingItem extends ImmutableComponent {
render () {
return <div className='settingItem'>
{
this.props.dataL10nId
? <span data-l10n-id={this.props.dataL10nId} />
: null
}
{this.props.children}
</div>
}
}

module.exports = {
SettingsList,
SettingItem
}
25 changes: 25 additions & 0 deletions app/renderer/components/styles/commonStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const {StyleSheet} = require('aphrodite')
const globalStyles = require('./global')

const styles = StyleSheet.create({
Copy link
Contributor

@luixxiul luixxiul Jan 17, 2017

Choose a reason for hiding this comment

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

How about adding these under this line for reference? Is it too much?

/*
app/renderer/components/dropdown.js
app/renderer/components/textbox.js
*/

'formControl': {
Copy link
Contributor

@luixxiul luixxiul Jan 17, 2017

Choose a reason for hiding this comment

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

.form-control {
display: block;
background: white;
border: solid 1px @lightGray;
border-radius: @borderRadius;
box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
box-sizing: border-box;
color: @darkGray;
font-size: 14.5px;
height: 2.25em;
outline: none;
padding: 0.4em;
width: 100%;
}

background: 'white',
border: `solid 1px ${globalStyles.color.black20}`,
borderRadius: globalStyles.radius.borderRadius,
boxShadow: `inset 0 1px 1px ${globalStyles.color.black10}`,
boxSizing: 'border-box',
display: 'block',
color: globalStyles.color.darkGray,
fontSize: '14.5px',
height: '2.25em',
outline: 'none',
padding: '0.4em',
width: '100%'
}
})

module.exports = styles
1 change: 1 addition & 0 deletions app/renderer/components/styles/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const globalStyles = {
gray25: 'rgba(116, 116, 130, 0.25)',
gray50: 'rgba(116, 116, 130, 0.5)',
black10: 'rgba(0, 0, 0, 0.1)',
black20: 'rgba(0, 0, 0, 0.2)',
black25: 'rgba(0, 0, 0, 0.25)',
black50: 'rgba(0, 0, 0, 0.5)',
black75: 'rgba(0, 0, 0, 0.75)',
Expand Down
74 changes: 74 additions & 0 deletions app/renderer/components/textbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

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

class Textbox extends ImmutableComponent {
render () {
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-isRecoveryKeyTextbox'] && styles.recoveryKeys
)

return <input type='text' className={className} {...this.props} />
}
}

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

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

class RecoveryKeyTextbox extends ImmutableComponent {
render () {
return <SettingTextbox data-isRecoveryKey='true' {...this.props} />
}
}

const styles = StyleSheet.create({
'textbox': {
boxSizing: 'border-box',
width: 'auto'
},
'outlineable': {
':focus': {
outlineColor: globalStyles.color.statsBlue,
outlineOffset: '-4px',
outlineStyle: 'solid',
outlineWidth: '1px'
}
},
'isSettings': {
width: '280px'
Copy link
Contributor

Choose a reason for hiding this comment

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

},
'readOnly': {
background: globalStyles.color.veryLightGray,
boxShadow: 'none',
outline: 'none'
},
'recoveryKeys': {
Copy link
Contributor

Choose a reason for hiding this comment

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

.firstRecoveryKey,
.secondRecoveryKey {
margin-bottom: 20px;
}

marginBottom: '20px'
}
})

module.exports = {
Textbox,
FormTextbox,
SettingTextbox,
RecoveryKeyTextbox
}
Loading