This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 973
/
Copy pathsettings.js
222 lines (200 loc) · 5.76 KB
/
settings.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/* 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('../immutableComponent')
const {StyleSheet, css} = require('aphrodite')
const aboutActions = require('../../../../js/about/aboutActions')
const getSetting = require('../../../../js/settings').getSetting
const {changeSetting} = require('../../lib/settingsUtil')
const SwitchControl = require('./switchControl')
const cx = require('../../../../js/lib/classSet')
const settings = require('../../../../js/constants/settings')
class SettingsList extends ImmutableComponent {
render () {
return <div className={cx({
settingsListContainer: true,
[this.props.className]: !!this.props.className
})}>
{
this.props.dataL10nId
? <div className={cx({
settingsListTitle: true,
[this.props.titleClassName]: !!this.props.titleClassName
})} data-l10n-id={this.props.dataL10nId} />
: null
}
<div className={cx({
settingsList: true,
[this.props.listClassName]: !!this.props.listClassName
})}>
{this.props.children}
</div>
</div>
}
}
class SettingItem extends ImmutableComponent {
render () {
return <div className={cx({
settingItem: true,
[this.props.itemClassName]: !!this.props.itemClassName
})}>
{
this.props.dataL10nId
? <span data-l10n-id={this.props.dataL10nId} />
: null
}
{this.props.children}
</div>
}
}
class SettingCheckbox extends ImmutableComponent {
constructor () {
super()
this.onClick = this.onClick.bind(this)
}
onClick (e) {
if (this.props.forPassword) {
// You can only have one active password manager
// if user decide to disable all,
// switch back password to unmanaged (null)
e.target.value
? aboutActions.changeSetting(settings.ACTIVE_PASSWORD_MANAGER, this.props.prefKey)
: aboutActions.changeSetting(settings.ACTIVE_PASSWORD_MANAGER, void (0))
}
if (this.props.disabled) {
return
}
return this.props.onChange
? this.props.onChange(e)
: changeSetting(this.props.onChangeSetting, this.props.prefKey, e)
}
render () {
const props = {
style: this.props.style,
className: cx({
settingItem: true,
[this.props.className]: !!this.props.className
})
}
if (this.props.id) {
props.id = this.props.id
}
const labelClass = cx({
[css(settingCheckboxStyles.label)]: this.props.small,
[this.props.labelClassName]: !!this.props.labelClassName
})
return <div {...props} data-test-id={this.props.dataTestId}>
<SwitchControl id={this.props.prefKey}
small={this.props.small}
disabled={this.props.disabled}
onClick={this.onClick}
checkedOn={this.props.checked !== undefined ? this.props.checked : getSetting(this.props.prefKey, this.props.settings)}
className={this.props.switchClassName}
/>
<label className={labelClass}
data-l10n-id={this.props.dataL10nId}
data-l10n-args={this.props.dataL10nArgs}
htmlFor={this.props.prefKey}
/>
{this.props.options}
</div>
}
}
const settingCheckboxStyles = StyleSheet.create({
label: {
fontSize: 'smaller'
}
})
class SiteSettingCheckbox extends ImmutableComponent {
constructor () {
super()
this.onClick = this.onClick.bind(this)
}
onClick (e) {
if (!this.props.disabled || this.props.hostPattern) {
const value = !!e.target.value
value === this.props.defaultValue
? aboutActions.removeSiteSetting(this.props.hostPattern,
this.props.prefKey)
: aboutActions.changeSiteSetting(this.props.hostPattern,
this.props.prefKey, value)
}
}
render () {
return <div style={this.props.style} className={cx({
settingItem: true,
siteSettingItem: true,
[this.props.className]: !!this.props.className
})}>
<SwitchControl
small={this.props.small}
disabled={this.props.disabled}
onClick={this.onClick}
checkedOn={this.props.checked}
className={this.props.switchClassName}
/>
</div>
}
}
class SettingItemIcon extends ImmutableComponent {
render () {
const bg = StyleSheet.create({
Icon: {
'-webkit-mask-image': `url(${this.props.icon})`
}
})
return <div className='settingItem'>
{
this.props.dataL10nId
? <span data-l10n-id={this.props.dataL10nId} />
: null
}
<div>
{
this.props.position === 'left'
? <span className={css(bg.Icon, styles.icon, styles.iconLeft)} data-icon-position='left' onClick={this.props.clickAction} />
: null
}
<div className={css(styles.child)}>
{this.props.children}
</div>
{
this.props.position === 'right'
? <span className={css(bg.Icon, styles.icon, styles.iconRight)} data-icon-position='right' onClick={this.props.clickAction} />
: null
}
</div>
</div>
}
}
const styles = StyleSheet.create({
icon: {
backgroundColor: '#5a5a5a',
height: '16px',
width: '16px',
display: 'inline-block',
verticalAlign: 'top',
padding: '0px',
'-webkit-mask-repeat': 'no-repeat',
':hover': {
backgroundColor: '#000'
}
},
iconLeft: {
margin: '8px 10px 0 0'
},
iconRight: {
margin: '8px 0 0 10px'
},
child: {
display: 'inline-block'
}
})
module.exports = {
SettingsList,
SettingItem,
SettingCheckbox,
SiteSettingCheckbox,
SettingItemIcon
}