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

Commit

Permalink
Add NormalizedButton to browserButton.js
Browse files Browse the repository at this point in the history
Addresses #9283

- Replace stopButton, homeButton, publisherButton, and braveMenuButton
  • Loading branch information
Suguru Hirahara committed Jul 19, 2017
1 parent 9318cd5 commit a37b77a
Show file tree
Hide file tree
Showing 30 changed files with 105 additions and 81 deletions.
2 changes: 1 addition & 1 deletion app/renderer/components/bookmarks/addEditBookmarkForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Immutable = require('immutable')
const {StyleSheet, css} = require('aphrodite/no-important')

// Components
const BrowserButton = require('../common/browserButton')
const {BrowserButton} = require('../common/browserButton')
const {
CommonFormSection,
CommonFormDropdown,
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/bookmarks/bookmarksToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Immutable = require('immutable')

// Components
const ReduxComponent = require('../reduxComponent')
const BrowserButton = require('../common/browserButton')
const {BrowserButton} = require('../common/browserButton')
const BookmarkToolbarButton = require('./bookmarkToolbarButton')

// Actions
Expand Down
39 changes: 38 additions & 1 deletion app/renderer/components/common/browserButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ class BrowserButton extends ImmutableComponent {
}
}

class NormalizedButton extends ImmutableComponent {
render () {
return <button
disabled={this.props.disabled}
data-l10n-id={this.props.l10nId}
data-test-id={this.props.testId}
data-test2-id={this.props.test2Id}
data-l10n-args={JSON.stringify(this.props.l10nArgs || {})}
data-button-value={this.props.dataButtonValue}
onClick={this.props.onClick}
className={css(styles.normalizedButton, this.props.custom)}

// for publisherToggle.js
data-test-authorized={this.props.testAuthorized}
data-test-verified={this.props.testVerified}>
{
this.props.iconClass || this.props.label
? <span className={this.props.iconClass}>{this.props.label}</span>
: null
}
</button>
}
}

const buttonSize = '25px'

const styles = StyleSheet.create({
Expand Down Expand Up @@ -251,7 +275,20 @@ const styles = StyleSheet.create({
pointerEvents: 'none',
animation: 'none',
opacity: 0.25
},

// ref: https://github.com/brave/browser-laptop/blob/548e11b1c889332fadb379237555625ad2a3c845/less/button.less#L12-L18
normalizedButton: {
background: 'none',
outline: 'none',
border: 'none',
margin: 0,
userSelect: 'none',
whiteSpace: 'nowrap'
}
})

module.exports = BrowserButton
module.exports = {
BrowserButton,
NormalizedButton
}
2 changes: 1 addition & 1 deletion app/renderer/components/common/messageBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {StyleSheet, css} = require('aphrodite')
// Components
const ReduxComponent = require('../reduxComponent')
const Dialog = require('./dialog')
const BrowserButton = require('../common/browserButton')
const {BrowserButton} = require('../common/browserButton')
const SwitchControl = require('./switchControl')

// Actions
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/download/downloadsBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Immutable = require('immutable')
// Components
const ReduxComponent = require('../reduxComponent')
const Button = require('../common/button')
const BrowserButton = require('../common/browserButton')
const {BrowserButton} = require('../common/browserButton')
const DownloadItem = require('./downloadItem')

// Actions
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/main/braveryPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {StyleSheet, css} = require('aphrodite/no-important')
// Components
const ReduxComponent = require('../reduxComponent')
const Dialog = require('../common/dialog')
const BrowserButton = require('../common/browserButton')
const {BrowserButton} = require('../common/browserButton')
const SwitchControl = require('../common/switchControl')
const {BraveryPanelDropdown} = require('../common/dropdown')

Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/main/checkDefaultBrowserDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {StyleSheet, css} = require('aphrodite/no-important')
// Components
const ReduxComponent = require('../reduxComponent')
const Dialog = require('../common/dialog')
const BrowserButton = require('../common/browserButton')
const {BrowserButton} = require('../common/browserButton')
const SwitchControl = require('../common/switchControl')
const {
CommonFormMedium,
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/main/findbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Immutable = require('immutable')

// Components
const ReduxComponent = require('../reduxComponent')
const BrowserButton = require('../common/browserButton')
const {BrowserButton} = require('../common/browserButton')
const SwitchControl = require('../common/switchControl')

// Constants
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/main/noScriptInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const urlParse = require('../../../common/urlParse')
const ReduxComponent = require('../reduxComponent')
const ImmutableComponent = require('../immutableComponent')
const Dialog = require('../common/dialog')
const BrowserButton = require('../common/browserButton')
const {BrowserButton} = require('../common/browserButton')

// Actions
const appActions = require('../../../../js/actions/appActions')
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/main/notificationItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {StyleSheet, css} = require('aphrodite/no-important')

// Components
const ReduxComponent = require('../reduxComponent')
const BrowserButton = require('../common/browserButton')
const {BrowserButton} = require('../common/browserButton')

// Constants
const messages = require('../../../../js/constants/messages')
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/main/updateBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {StyleSheet, css} = require('aphrodite/no-important')
// Components
const ImmutableComponent = require('../immutableComponent')
const ReduxComponent = require('../reduxComponent')
const BrowserButton = require('../common/browserButton')
const {BrowserButton} = require('../common/browserButton')

// Actions
const appActions = require('../../../../js/actions/appActions')
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/navigation/browserAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Immutable = require('immutable')

// Components
const ReduxComponent = require('../reduxComponent')
const BrowserButton = require('../common/browserButton')
const {BrowserButton} = require('../common/browserButton')
const BrowserActionBadge = require('./browserActionBadge')

// State
Expand Down
19 changes: 5 additions & 14 deletions app/renderer/components/navigation/homeButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const React = require('react')

// Components
const ImmutableComponent = require('../immutableComponent')
const {NormalizedButton} = require('../common/browserButton')

// Actions
const appActions = require('../../../../js/actions/appActions')
Expand All @@ -29,14 +30,6 @@ class HomeButton extends ImmutableComponent {
this.onHome = this.onHome.bind(this)
}

componentDidMount () {
this.homeButton.addEventListener('auxclick', this.onHome)
}

componentWillUnmount () {
this.homeButton.removeEventListener('auxclick', this.onHome)
}

onHome (e) {
if (e.button === 2) {
return
Expand All @@ -57,10 +50,10 @@ class HomeButton extends ImmutableComponent {

// BEM Level: navigationBar__buttonContainer
render () {
return <button className={cx({
normalizeButton: true,
[css(styles.navigationButton, styles.navigationButton_home)]: true
})}
return <NormalizedButton custom={[
styles.navigationButton,
styles.navigationButton_home
]}
data-test-id='homeButton'
data-l10n-id='homeButton'
ref={(node) => { this.homeButton = node }}
Expand All @@ -71,8 +64,6 @@ class HomeButton extends ImmutableComponent {

const styles = StyleSheet.create({
navigationButton: {
// cf: https://github.com/brave/browser-laptop/blob/b161b37cf5e9f59be64855ebbc5d04816bfc537b/less/navigationBar.less#L550-L553
backgroundColor: globalStyles.color.buttonColor,
display: 'inline-block',
width: '100%',
height: '100%',
Expand Down
25 changes: 12 additions & 13 deletions app/renderer/components/navigation/navigationBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const AddEditBookmarkHanger = require('../bookmarks/addEditBookmarkHanger')
const PublisherToggle = require('./publisherToggle')
const LongPressButton = require('../common/longPressButton')
const HomeButton = require('./homeButton')
const {NormalizedButton} = require('../common/browserButton')

// Actions
const windowActions = require('../../../../js/actions/windowActions')
Expand Down Expand Up @@ -88,17 +89,6 @@ class NavigationBar extends React.Component {
this.props.bookmarked
}

// BEM Level: navigationBar__buttonContainer
get stopButton () {
return <button className={cx({
normalizeButton: true,
[css(styles.navigationButton, styles.navigationButton_stop)]: true
})}
data-l10n-id='stopButton'
onClick={this.onStop}
/>
}

// BEM Level: navigationBar__buttonContainer
get reloadButton () {
return <LongPressButton className={cx({
Expand All @@ -112,6 +102,17 @@ class NavigationBar extends React.Component {
/>
}

// BEM Level: navigationBar__buttonContainer
get stopButton () {
return <NormalizedButton custom={[
styles.navigationButton,
styles.navigationButton_stop
]}
l10nid='stopButton'
onClick={this.onStop}
/>
}

// BEM Level: navigationBar
get bookmarkButtonContainer () {
return <span className={css(
Expand Down Expand Up @@ -283,8 +284,6 @@ const styles = StyleSheet.create({
},

navigationButton: {
// cf: https://github.com/brave/browser-laptop/blob/b161b37cf5e9f59be64855ebbc5d04816bfc537b/less/navigationBar.less#L550-L553
backgroundColor: globalStyles.color.buttonColor,
display: 'inline-block',
width: '100%',
height: '100%',
Expand Down
13 changes: 5 additions & 8 deletions app/renderer/components/navigation/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const NavigationBar = require('./navigationBar')
const LongPressButton = require('../common/longPressButton')
const MenuBar = require('./menuBar')
const WindowCaptionButtons = require('./windowCaptionButtons')
const BrowserButton = require('../common/button')
const {NormalizedButton} = require('../common/browserButton')
const BrowserAction = require('./browserAction')

// State
Expand Down Expand Up @@ -286,12 +286,12 @@ class Navigator extends React.Component {

// BEM Level: navigator__menuBarAndNavigationBar__navigationBarWrapper__topLevelEndButtons__braveMenuButton
get braveMenuButton () {
return <BrowserButton className={css(
return <NormalizedButton custom={[
styles.braveMenuButton,
!this.props.shieldsEnabled && styles.braveMenuButton_shieldsDisabled,
this.props.shieldsDown && styles.braveMenuButton_shieldsDown,
this.props.isCaptionButton && styles.braveMenuButton_leftOfCaptionButton
)}
]}
l10nId='braveMenu'
testId={!this.props.shieldsEnabled ? 'braveMenuDisabled' : 'braveMenu'}
test2Id={`shield-down-${this.props.shieldsDown}`}
Expand Down Expand Up @@ -506,17 +506,14 @@ const styles = StyleSheet.create({
},

braveMenuButton: {
backgroundImage: `-webkit-image-set(url(${braveButton1x}) 1x, url(${braveButton2x}) 2x, url(${braveButton3x}) 3x)`,
backgroundRepeat: 'no-repeat',
background: `-webkit-image-set(url(${braveButton1x}) 1x, url(${braveButton2x}) 2x, url(${braveButton3x}) 3x) no-repeat`,
height: globalStyles.navigationBar.urlbarForm.height,
width: globalStyles.spacing.navbarBraveButtonWidth,
marginRight: globalStyles.spacing.navbarButtonSpacing,
userSelect: 'none',
position: 'relative',
WebkitAppRegion: 'no-drag',

':hover': {
backgroundImage: `-webkit-image-set(url(${braveButtonHover1x}) 1x, url(${braveButtonHover2x}) 2x, url(${braveButtonHover3x}) 3x)`
background: `-webkit-image-set(url(${braveButtonHover1x}) 1x, url(${braveButtonHover2x}) 2x, url(${braveButtonHover3x}) 3x) no-repeat`
}
},

Expand Down
34 changes: 17 additions & 17 deletions app/renderer/components/navigation/publisherToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {StyleSheet, css} = require('aphrodite/no-important')

// Components
const ReduxComponent = require('../reduxComponent')
const {NormalizedButton} = require('../common/browserButton')

// Actions
const appActions = require('../../../../js/actions/appActions')
Expand All @@ -16,7 +17,6 @@ const appActions = require('../../../../js/actions/appActions')
const publisherState = require('../../../common/lib/publisherUtil')

// Utils
const cx = require('../../../../js/lib/classSet')
const {getHostPattern} = require('../../../../js/lib/urlutil')
const {getBaseUrl} = require('../../../../js/lib/appUrlUtil')
const frameStateUtil = require('../../../../js/state/frameStateUtil')
Expand Down Expand Up @@ -68,23 +68,23 @@ class PublisherToggle extends React.Component {
return props
}

// TODO (Suguru): NormalizeButton
// ref: navigationBar__buttonContainer_bookmarkButtonContainer on navigationBar.js
render () {
return <span
data-test-id='publisherButton'
data-test-authorized={this.props.isEnabledForPaymentsPublisher}
data-test-verified={this.props.isVerifiedPublisher}
className={css(
commonStyles.rectangleContainer,
commonStyles.rectangleContainer_outsideOfurlbarForm,
styles.publisherButtonContainer
)}>
<button className={cx({
normalizeButton: true,
[css((!this.props.isEnabledForPaymentsPublisher && this.props.isVerifiedPublisher) && styles.publisherButtonContainer__button_noFundVerified, (this.props.isEnabledForPaymentsPublisher && this.props.isVerifiedPublisher) && styles.publisherButtonContainer__button_fundVerified, (!this.props.isEnabledForPaymentsPublisher && !this.props.isVerifiedPublisher) && styles.publisherButtonContainer__button_noFundUnverified, (this.props.isEnabledForPaymentsPublisher && !this.props.isVerifiedPublisher) && styles.publisherButtonContainer__button_fundUnverified, styles.publisherButtonContainer__button)]: true
})}
data-l10n-id={this.l10nString}
return <span className={css(
commonStyles.rectangleContainer,
commonStyles.rectangleContainer_outsideOfurlbarForm,
styles.publisherButtonContainer
)}>
<NormalizedButton custom={[
(!this.props.isEnabledForPaymentsPublisher && this.props.isVerifiedPublisher) && styles.publisherButtonContainer__button_noFundVerified,
(this.props.isEnabledForPaymentsPublisher && this.props.isVerifiedPublisher) && styles.publisherButtonContainer__button_fundVerified,
(!this.props.isEnabledForPaymentsPublisher && !this.props.isVerifiedPublisher) && styles.publisherButtonContainer__button_noFundUnverified,
(this.props.isEnabledForPaymentsPublisher && !this.props.isVerifiedPublisher) && styles.publisherButtonContainer__button_fundUnverified,
styles.publisherButtonContainer__button
]}
l10nId={this.l10nString}
testId='publisherButton'
testAuthorized={this.props.isEnabledForPaymentsPublisher}
testVerified={this.props.isVerifiedPublisher}
onClick={this.onAuthorizePublisher}
/>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {changeSetting} = require('../../../lib/settingsUtil')
const appConfig = require('../../../../../js/constants/appConfig')

// components
const BrowserButton = require('../../common/browserButton')
const {BrowserButton} = require('../../common/browserButton')
const {SettingsList, SettingItem, SettingCheckbox} = require('../../common/settings')
const {SettingDropdown} = require('../../common/dropdown')
const ImmutableComponent = require('../../immutableComponent')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const React = require('react')
const {StyleSheet, css} = require('aphrodite/no-important')

// components
const BrowserButton = require('../../common/browserButton')
const {BrowserButton} = require('../../common/browserButton')
const cx = require('../../../../../js/lib/classSet')
const ModalOverlay = require('../../common/modalOverlay')
const ImmutableComponent = require('../../immutableComponent')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {changeSetting} = require('../../../lib/settingsUtil')

// components
const ImmutableComponent = require('../../immutableComponent')
const BrowserButton = require('../../common/browserButton')
const {BrowserButton} = require('../../common/browserButton')
const {FormTextbox} = require('../../common/textbox')
const {FormDropdown} = require('../../common/dropdown')
const {SettingsList, SettingItem} = require('../../common/settings')
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/components/preferences/payment/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {formattedTimeFromNow, formattedDateFromTimestamp} = require('../../../../
const appUrlUtil = require('../../../../../js/lib/appUrlUtil')

// components
const BrowserButton = require('../../common/browserButton')
const {BrowserButton} = require('../../common/browserButton')
const ImmutableComponent = require('../../immutableComponent')

// style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {StyleSheet, css} = require('aphrodite/no-important')

// components
const ImmutableComponent = require('../../immutableComponent')
const BrowserButton = require('../../common/browserButton')
const {BrowserButton} = require('../../common/browserButton')

// style
const globalStyles = require('../../styles/global')
Expand Down
Loading

0 comments on commit a37b77a

Please sign in to comment.