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

Commit b0460f4

Browse files
committed
Use switchControl text properties instead of sibling label elements
closes #8243 as this ensures all remaining uses of switchControl gain the built-in label click handler. covers the case-sensitivity toggle in findbar, as well as all the switches on the preferences page.
1 parent f7778d7 commit b0460f4

File tree

6 files changed

+42
-131
lines changed

6 files changed

+42
-131
lines changed

app/renderer/components/common/settings.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ class SettingCheckbox extends ImmutableComponent {
9090

9191
const labelClass = cx({
9292
[css(settingCheckboxStyles.label)]: this.props.small,
93-
[this.props.labelClassName]: !!this.props.labelClassName
94-
93+
[this.props.labelClassName]: !!this.props.labelClassName,
94+
[css(settingCheckboxStyles.expansiveRightText)]: !this.props.compact
9595
})
9696

9797
return <div {...props} data-test-id={this.props.dataTestId}>
@@ -101,11 +101,9 @@ class SettingCheckbox extends ImmutableComponent {
101101
onClick={this.onClick}
102102
checkedOn={this.props.checked !== undefined ? this.props.checked : getSetting(this.props.prefKey, this.props.settings)}
103103
className={this.props.switchClassName}
104-
/>
105-
<label className={labelClass}
106-
data-l10n-id={this.props.dataL10nId}
107-
data-l10n-args={this.props.dataL10nArgs}
108-
htmlFor={this.props.prefKey}
104+
customRightTextClassName={labelClass}
105+
rightl10nId={this.props.dataL10nId}
106+
rightl10nArgs={this.props.dataL10nArgs}
109107
/>
110108
{this.props.options}
111109
</div>
@@ -115,6 +113,9 @@ class SettingCheckbox extends ImmutableComponent {
115113
const settingCheckboxStyles = StyleSheet.create({
116114
label: {
117115
fontSize: 'smaller'
116+
},
117+
expansiveRightText: {
118+
paddingLeft: '9px'
118119
}
119120
})
120121

app/renderer/components/main/findbar.js

+14-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
const React = require('react')
66
const Immutable = require('immutable')
7+
const {StyleSheet, css} = require('aphrodite')
78

89
// Components
910
const ReduxComponent = require('../reduxComponent')
@@ -24,6 +25,7 @@ const {getTextColorForBackground} = require('../../../../js/lib/color')
2425
const frameStateUtil = require('../../../../js/state/frameStateUtil')
2526
const {getSetting} = require('../../../../js/settings')
2627
const debounce = require('../../../../js/lib/debounce')
28+
const cx = require('../../../../js/lib/classSet')
2729

2830
// Styles
2931
const globalStyles = require('../styles/global')
@@ -224,16 +226,18 @@ class FindBar extends React.Component {
224226

225227
render () {
226228
let findBarStyle = {}
227-
let findBarTextStyle = {}
229+
let findBarTextStyles = {}
228230

229231
if (this.props.backgroundColor) {
232+
findBarTextStyles = StyleSheet.create({
233+
matchingTextColor: {
234+
color: this.props.textColor
235+
}
236+
})
230237
findBarStyle = {
231238
background: this.props.backgroundColor,
232239
color: this.props.textColor
233240
}
234-
findBarTextStyle = {
235-
color: this.props.textColor
236-
}
237241
}
238242

239243
return <div className='findBar' style={findBarStyle} onBlur={this.onBlur}>
@@ -275,16 +279,15 @@ class FindBar extends React.Component {
275279
id='caseSensitivityCheckbox'
276280
checkedOn={this.props.isCaseSensitive}
277281
onClick={this.onCaseSensitivityChange}
278-
/>
279-
<label
280-
htmlFor='caseSensitivityCheckbox'
281-
data-l10n-id='caseSensitivity'
282-
style={findBarTextStyle}
282+
customRightTextClassName={css(findBarTextStyles.matchingTextColor)}
283+
rightl10nId='caseSensitivity'
283284
/>
284285
</div>
285286
<span
286-
className='closeButton'
287-
style={findBarTextStyle}
287+
className={cx({
288+
closeButton: true,
289+
[css(findBarTextStyles.matchingTextColor)]: true
290+
})}
288291
onClick={this.onFindHide}
289292
>+</span>
290293
</div>

app/renderer/components/preferences/payment/ledgerTable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class LedgerTable extends ImmutableComponent {
264264
<div className={css(styles.hideExcludedSites)}>
265265
<div className={css(styles.columnOffset)} />
266266
<div className={css(styles.rightColumn)}>
267-
<SettingCheckbox small
267+
<SettingCheckbox small compact
268268
dataL10nId='hideExcluded'
269269
prefKey={settings.PAYMENTS_SITES_HIDE_EXCLUDED}
270270
settings={this.props.settings}

app/renderer/components/preferences/paymentsTab.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,11 @@ class PaymentsTab extends ImmutableComponent {
196196
styles.flexAlignCenter,
197197
styles.paymentsSwitches
198198
)}>
199-
<div className={css(styles.flexAlignEnd, styles.switchWrap)} data-test-id='enablePaymentsSwitch'>
199+
<div className={css(styles.flexAlignCenter, styles.switchWrap)} data-test-id='enablePaymentsSwitch'>
200200
<span className={css(styles.switchWrap__switchSpan)} data-l10n-id='off' />
201-
<SettingCheckbox dataL10nId='on'
201+
<SettingCheckbox
202+
dataL10nId='on'
203+
compact
202204
prefKey={settings.PAYMENTS_ENABLED}
203205
settings={this.props.settings}
204206
onChangeSetting={this.props.onChangeSetting}
@@ -226,6 +228,7 @@ class PaymentsTab extends ImmutableComponent {
226228
<div className={css(styles.switchWrap__autoSuggestSwitch)}>
227229
<div className={css(styles.flexAlignCenter, styles.autoSuggestSwitch__subtext)}>
228230
<SettingCheckbox dataL10nId='autoSuggestSites'
231+
compact
229232
prefKey={settings.PAYMENTS_SITES_AUTO_SUGGEST}
230233
settings={this.props.settings}
231234
disabled={!enabled}
@@ -280,10 +283,6 @@ const styles = StyleSheet.create({
280283
display: 'flex',
281284
alignItems: 'center'
282285
},
283-
flexAlignEnd: {
284-
display: 'flex',
285-
alignItems: 'flex-end'
286-
},
287286

288287
paymentsContainer: {
289288
position: 'relative',
@@ -307,11 +306,6 @@ const styles = StyleSheet.create({
307306
switchWrap: {
308307
width: paymentStyles.width.tableCell
309308
},
310-
switchWrap__switchControl: {
311-
// TODO: Refactor switchControls.less
312-
paddingTop: '0 !important',
313-
paddingBottom: '0 !important'
314-
},
315309
switchWrap__switchSpan: {
316310
color: '#999',
317311
fontWeight: 'bold'
@@ -340,8 +334,7 @@ const styles = StyleSheet.create({
340334
},
341335
autoSuggestSwitch__moreInfoBtnSuggest: {
342336
position: 'relative',
343-
top: '-1px',
344-
left: '8px',
337+
left: '3px',
345338
cursor: 'pointer',
346339

347340
// TODO: refactor preferences.less to remove !important

less/about/preferences.less

-99
Original file line numberDiff line numberDiff line change
@@ -272,105 +272,6 @@ table.sortableTable {
272272
color: @braveOrange;
273273
}
274274

275-
.prefTabContainer .switchControl {
276-
display: inline-block;
277-
vertical-align: middle;
278-
align-items: center;
279-
padding: 5px;
280-
cursor: pointer;
281-
282-
&.disabled {
283-
.switchBackground {
284-
opacity: 0.3;
285-
}
286-
.switchControlRightText, .switchControlLeftText {
287-
opacity: 0.3;
288-
}
289-
cursor: default;
290-
}
291-
292-
&:not(.disabled) {
293-
.switchBackground.switchedOn {
294-
background-color: @switchBG_on;
295-
.switchIndicator {
296-
right: 2px;
297-
}
298-
}
299-
}
300-
301-
&.large {
302-
.switchBackground {
303-
height: 26px;
304-
width: 60px;
305-
.switchIndicator {
306-
height: 22px;
307-
width: 22px;
308-
}
309-
}
310-
}
311-
312-
&.small {
313-
.switchBackground {
314-
height: @smallSwitchHeight;
315-
width: @smallSwitchWidth;
316-
.switchIndicator {
317-
height: @smallSwitchNubDiameter;
318-
width: @smallSwitchNubDiameter;
319-
top: 1px;
320-
right: calc(@smallSwitchWidth - @smallSwitchNubDiameter - @switchNubRightMargin);
321-
}
322-
}
323-
}
324-
325-
> label {
326-
vertical-align: middle;
327-
}
328-
329-
.switchControlText {
330-
margin: auto 0;
331-
}
332-
333-
.switchControlLeftText {
334-
margin: auto 5px auto 0;
335-
}
336-
337-
.switchControlRightText {
338-
margin: auto 0 auto 5px;
339-
}
340-
341-
.switchControlTopText {
342-
margin: 0 auto 5px auto;
343-
}
344-
345-
.switchControlRight {
346-
display: flex;
347-
}
348-
349-
.switchMiddle {
350-
display: flex;
351-
flex-direction: column;
352-
}
353-
354-
.switchBackground {
355-
background-color: @switchBG_off;
356-
border-radius: 12px;
357-
height: @switchHeight;
358-
position: relative;
359-
width: @switchWidth;
360-
box-shadow: @switchShadow;
361-
362-
.switchIndicator {
363-
background-color: white;
364-
border-radius: 100%;
365-
height: @switchNubDiameter;
366-
position: absolute;
367-
top: @switchNubTopMargin;
368-
width: @switchNubDiameter;
369-
box-shadow: @switchNubShadow;
370-
}
371-
}
372-
}
373-
374275
.widevineInfo {
375276
line-height: 1.3em;
376277

less/switchControls.less

+13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@
3636
}
3737
}
3838
}
39+
40+
&.small {
41+
.switchBackground {
42+
height: @smallSwitchHeight;
43+
width: @smallSwitchWidth;
44+
.switchIndicator {
45+
height: @smallSwitchNubDiameter;
46+
width: @smallSwitchNubDiameter;
47+
top: 1px;
48+
right: calc(@smallSwitchWidth - @smallSwitchNubDiameter - @switchNubRightMargin);
49+
}
50+
}
51+
}
3952

4053
.switchControlText {
4154
margin: auto 0;

0 commit comments

Comments
 (0)