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

Commit 758fa8c

Browse files
author
Suguru Hirahara
committed
Refactor navigationBar (part 1)
Full changelog: b76f995 Test Plan: available on #9299 (comment)
1 parent 669eb37 commit 758fa8c

File tree

9 files changed

+347
-297
lines changed

9 files changed

+347
-297
lines changed

app/renderer/components/navigation/homeButton.js

+29-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ const appActions = require('../../../../js/actions/appActions')
1414
const settings = require('../../../../js/constants/settings')
1515

1616
// Utils
17+
const cx = require('../../../../js/lib/classSet')
1718
const {getSetting} = require('../../../../js/settings')
1819
const eventUtil = require('../../../../js/lib/eventUtil')
1920

21+
const {StyleSheet, css} = require('aphrodite/no-important')
22+
const globalStyles = require('../styles/global')
23+
24+
const homeButton = require('../../../../img/toolbar/home_btn.svg')
25+
2026
class HomeButton extends ImmutableComponent {
2127
constructor (props) {
2228
super(props)
@@ -51,15 +57,36 @@ class HomeButton extends ImmutableComponent {
5157

5258
render () {
5359
return <span className='navigationButtonContainer'>
54-
<button
60+
<button className={cx({
61+
normalizeButton: true,
62+
[css(styles.navigator__navigationButtonContainer__navigationButton, styles.navigator__navigationButtonContainer__navigationButton_homeButton)]: true
63+
})}
5564
data-test-id='homeButton'
5665
data-l10n-id='homeButton'
57-
className='normalizeButton navigationButton homeButton'
5866
ref={(node) => { this.homeButton = node }}
5967
onClick={this.onHome}
6068
/>
6169
</span>
6270
}
6371
}
6472

73+
const styles = StyleSheet.create({
74+
navigator__navigationButtonContainer__navigationButton: {
75+
// cf: https://github.com/brave/browser-laptop/blob/b161b37cf5e9f59be64855ebbc5d04816bfc537b/less/navigationBar.less#L550-L553
76+
backgroundColor: globalStyles.color.buttonColor,
77+
display: 'inline-block',
78+
width: '100%',
79+
height: '100%',
80+
81+
// cf: https://github.com/brave/browser-laptop/blob/b161b37cf5e9f59be64855ebbc5d04816bfc537b/less/navigationBar.less#L584-L585
82+
margin: 0,
83+
padding: 0
84+
},
85+
86+
navigator__navigationButtonContainer__navigationButton_homeButton: {
87+
background: `url(${homeButton}) center no-repeat`,
88+
backgroundSize: `16px 16px`
89+
}
90+
})
91+
6592
module.exports = HomeButton

app/renderer/components/navigation/navigationBar.js

+111-27
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ const {getSetting} = require('../../../../js/settings')
3636
const contextMenus = require('../../../../js/contextMenus')
3737

3838
const {StyleSheet, css} = require('aphrodite/no-important')
39+
const globalStyles = require('../styles/global')
40+
const commonStyles = require('../styles/commonStyles')
41+
42+
const stopLoadingButton = require('../../../../img/toolbar/stoploading_btn.svg')
43+
const reloadButton = require('../../../../img/toolbar/reload_btn.svg')
44+
const bookmarkButton = require('../../../../img/toolbar/bookmark_btn.svg')
45+
const bookmarkedButton = require('../../../../img/toolbar/bookmark_marked.svg')
3946

4047
class NavigationBar extends React.Component {
4148
constructor (props) {
@@ -141,7 +148,7 @@ class NavigationBar extends React.Component {
141148
data-frame-key={this.props.activeFrameKey}
142149
className={cx({
143150
titleMode: this.props.titleMode,
144-
[css(styles.navigator_wide)]: this.props.isWideUrlBarEnabled
151+
[css(styles.navigator, this.props.isWideUrlBarEnabled && styles.navigator_wide)]: true
145152
})}>
146153
{
147154
this.props.showBookmarkHanger
@@ -153,14 +160,22 @@ class NavigationBar extends React.Component {
153160
? null
154161
: this.props.isLoading
155162
? <span className='navigationButtonContainer'>
156-
<button data-l10n-id='stopButton'
157-
className='normalizeButton navigationButton stopButton'
158-
onClick={this.onStop} />
163+
<button className={cx({
164+
normalizeButton: true,
165+
[css(styles.navigator__navigationButtonContainer__navigationButton, styles.navigator__navigationButtonContainer__navigationButton_stopButton)]: true
166+
})}
167+
data-l10n-id='stopButton'
168+
onClick={this.onStop}
169+
/>
159170
</span>
160171
: <span className='navigationButtonContainer'>
161172
<LongPressButton
162173
l10nId='reloadButton'
163-
className='normalizeButton navigationButton reloadButton'
174+
testId='reloadButton'
175+
className={cx({
176+
normalizeButton: true,
177+
[css(styles.navigator__navigationButtonContainer__navigationButton, styles.navigator__navigationButtonContainer__navigationButton_reloadButton)]: true
178+
})}
164179
onClick={this.onReload}
165180
onLongPress={this.onReloadLongPress} />
166181
</span>
@@ -170,27 +185,31 @@ class NavigationBar extends React.Component {
170185
? <HomeButton activeTabId={this.props.activeTabId} />
171186
: null
172187
}
173-
<div className='startButtons'>
174-
{
175-
!this.props.titleMode
176-
? <span className='bookmarkButtonContainer'>
177-
<button data-l10n-id={this.props.isBookmarked ? 'removeBookmarkButton' : 'addBookmarkButton'}
178-
className={cx({
179-
navigationButton: true,
180-
bookmarkButton: true,
181-
removeBookmarkButton: this.props.isBookmarked,
182-
withHomeButton: getSetting(settings.SHOW_HOME_BUTTON),
183-
normalizeButton: true
184-
})}
185-
onClick={this.onToggleBookmark} />
186-
</span>
187-
: null
188-
}
189-
</div>
188+
{
189+
!this.props.titleMode
190+
? <span className={cx({
191+
bookmarkButtonContainer: true,
192+
[css(commonStyles.navigator__buttonContainer, styles.navigator__buttonContainer_bookmarkButtonContainer)]: true
193+
})}>
194+
<button className={cx({
195+
normalizeButton: true,
196+
withHomeButton: getSetting(settings.SHOW_HOME_BUTTON),
197+
[css(styles.navigator__buttonContainer_bookmarkButtonContainer__bookmarkButton, this.bookmarked && styles.navigator__buttonContainer_bookmarkButtonContainer__bookmarkButton_removeBookmarkButton)]: true
198+
})}
199+
data-l10n-id={this.bookmarked ? 'removeBookmarkButton' : 'addBookmarkButton'}
200+
data-test-id={this.bookmarked ? 'bookmarked' : 'notBookmarked'}
201+
onClick={this.onToggleBookmark}
202+
/>
203+
</span>
204+
: null
205+
}
190206
<UrlBar titleMode={this.props.titleMode} />
191207
{
192208
this.props.showPublisherToggle
193-
? <div className='endButtons'>
209+
? <div className={css(
210+
this.props.titleMode && styles.navigator__endButtons_titleMode,
211+
!this.props.titleMode && styles.navigator__endButtons_notTitleMode
212+
)}>
194213
<PublisherToggle />
195214
</div>
196215
: null
@@ -199,13 +218,78 @@ class NavigationBar extends React.Component {
199218
}
200219
}
201220

221+
const rightMargin = `calc(${globalStyles.spacing.navbarLeftMarginDarwin} / 2)`
222+
202223
const styles = StyleSheet.create({
224+
225+
navigator: {
226+
boxSizing: 'border-box',
227+
display: 'flex',
228+
flexGrow: 1,
229+
alignItems: 'center',
230+
justifyContent: 'center',
231+
fontSize: '20px',
232+
minWidth: '0%', // allow the navigator to shrink
233+
maxWidth: '900px',
234+
marginRight: rightMargin,
235+
padding: 0,
236+
position: 'relative',
237+
userSelect: 'none',
238+
zIndex: globalStyles.zindex.zindexNavigationBar
239+
},
240+
203241
navigator_wide: {
242+
maxWidth: '100%',
243+
marginRight: '0',
244+
justifyContent: 'initial'
245+
},
246+
247+
navigator__navigationButtonContainer__navigationButton: {
248+
// cf: https://github.com/brave/browser-laptop/blob/b161b37cf5e9f59be64855ebbc5d04816bfc537b/less/navigationBar.less#L550-L553
249+
backgroundColor: globalStyles.color.buttonColor,
250+
display: 'inline-block',
251+
width: '100%',
252+
height: '100%',
253+
254+
// cf: https://github.com/brave/browser-laptop/blob/b161b37cf5e9f59be64855ebbc5d04816bfc537b/less/navigationBar.less#L584-L585
255+
margin: 0,
256+
padding: 0
257+
},
258+
259+
navigator__navigationButtonContainer__navigationButton_stopButton: {
260+
background: `url(${stopLoadingButton}) center no-repeat`,
261+
backgroundSize: '11px 11px'
262+
},
263+
264+
navigator__navigationButtonContainer__navigationButton_reloadButton: {
265+
background: `url(${reloadButton}) center no-repeat`,
266+
backgroundSize: '13px 13px'
267+
},
268+
269+
// cf: navigator__buttonContainer_addPublisherButtonContainer on publisherToggle.js
270+
navigator__buttonContainer_bookmarkButtonContainer: {
271+
borderRight: 'none',
272+
borderTopRightRadius: 0,
273+
borderBottomRightRadius: 0
274+
},
275+
276+
navigator__buttonContainer_bookmarkButtonContainer__bookmarkButton: {
277+
background: `url(${bookmarkButton}) center no-repeat`,
278+
backgroundSize: '14px 14px',
279+
width: globalStyles.navigationBar.urlbarForm.height, // #6704
280+
height: globalStyles.navigationBar.urlbarForm.height // #6704
281+
},
282+
283+
navigator__buttonContainer_bookmarkButtonContainer__bookmarkButton_removeBookmarkButton: {
284+
background: `url(${bookmarkedButton}) center no-repeat`
285+
},
286+
287+
navigator__endButtons_titleMode: {
288+
display: 'none'
289+
},
204290

205-
// TODO: Refactor navigationBar.js to remove !important
206-
maxWidth: '100% !important',
207-
marginRight: '0 !important',
208-
justifyContent: 'initial !important'
291+
navigator__endButtons_notTitleMode: {
292+
display: 'flex'
209293
}
210294
})
211295

0 commit comments

Comments
 (0)