Skip to content

Commit d69eaa5

Browse files
committed
Use switchControl text properties instead of sibling label element
closes brave#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 settings page.
1 parent f7778d7 commit d69eaa5

File tree

5 files changed

+34
-129
lines changed

5 files changed

+34
-129
lines changed

app/renderer/components/common/settings.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ class SettingCheckbox extends ImmutableComponent {
9191
const labelClass = cx({
9292
[css(settingCheckboxStyles.label)]: this.props.small,
9393
[this.props.labelClassName]: !!this.props.labelClassName
94-
9594
})
9695

9796
return <div {...props} data-test-id={this.props.dataTestId}>
@@ -101,11 +100,9 @@ class SettingCheckbox extends ImmutableComponent {
101100
onClick={this.onClick}
102101
checkedOn={this.props.checked !== undefined ? this.props.checked : getSetting(this.props.prefKey, this.props.settings)}
103102
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}
103+
customRightTextClassName={labelClass}
104+
rightl10nId={this.props.dataL10nId}
105+
rightl10nArgs={this.props.dataL10nArgs}
109106
/>
110107
{this.props.options}
111108
</div>

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/paymentsTab.js

+4-13
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ 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'
202203
prefKey={settings.PAYMENTS_ENABLED}
203204
settings={this.props.settings}
204205
onChangeSetting={this.props.onChangeSetting}
@@ -280,10 +281,6 @@ const styles = StyleSheet.create({
280281
display: 'flex',
281282
alignItems: 'center'
282283
},
283-
flexAlignEnd: {
284-
display: 'flex',
285-
alignItems: 'flex-end'
286-
},
287284

288285
paymentsContainer: {
289286
position: 'relative',
@@ -307,11 +304,6 @@ const styles = StyleSheet.create({
307304
switchWrap: {
308305
width: paymentStyles.width.tableCell
309306
},
310-
switchWrap__switchControl: {
311-
// TODO: Refactor switchControls.less
312-
paddingTop: '0 !important',
313-
paddingBottom: '0 !important'
314-
},
315307
switchWrap__switchSpan: {
316308
color: '#999',
317309
fontWeight: 'bold'
@@ -340,8 +332,7 @@ const styles = StyleSheet.create({
340332
},
341333
autoSuggestSwitch__moreInfoBtnSuggest: {
342334
position: 'relative',
343-
top: '-1px',
344-
left: '8px',
335+
left: '3px',
345336
cursor: 'pointer',
346337

347338
// 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)