This repository was archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 971
/
Copy pathbrowserButton.js
184 lines (160 loc) · 6.27 KB
/
browserButton.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
/* 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 {StyleSheet, css} = require('aphrodite/no-important')
const ImmutableComponent = require('../immutableComponent')
const globalStyles = require('../styles/global')
class BrowserButton extends ImmutableComponent {
get classNames () {
return [
styles.browserButton,
this.props.primaryColor && [styles.browserButton_default, styles.browserButton_primaryColor],
this.props.secondaryColor && [styles.browserButton_default, styles.browserButton_secondaryColor],
this.props.subtleItem && [styles.browserButton_default, styles.browserButton_subtleItem],
this.props.extensionItem && styles.browserButton_extensionItem,
this.props.groupedItem && styles.browserButton_groupedItem,
this.props.notificationItem && styles.browserButton_notificationItem
// TODO: These are other button styles app-wise
// that needs to be refactored and included in this file
// .............................................
// this.props.smallItem && styles.browserButton_smallItem,
// this.props.actionItem && styles.browserButton_actionItem,
// this.props.navItem && styles.browserButton_navItem,
// this.props.panelItem && styles.browserButton_panelItem,
]
}
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 || {})}
style={this.props.inlineStyles}
data-button-value={this.props.dataButtonValue}
onClick={this.props.onClick}
className={css(this.classNames, this.props.custom)}>
{
this.props.iconClass || this.props.label
? <span className={this.props.iconClass}>{this.props.label}</span>
: null
}
</button>
}
}
const buttonSize = '25px'
const styles = StyleSheet.create({
browserButton: {
margin: '0 3px',
whiteSpace: 'nowrap',
outline: 'none',
cursor: 'default',
display: 'inline-block',
lineHeight: buttonSize,
height: buttonSize,
width: buttonSize,
fontSize: '13px',
borderRadius: '2px',
textAlign: 'center',
transition: '.1s opacity, .1s background',
userSelect: 'none',
backgroundSize: '16px',
backgroundPosition: 'center center',
backgroundRepeat: 'no-repeat',
backgroundImage: 'none',
backgroundColor: globalStyles.button.default.backgroundColor,
border: 'none',
// cf: https://github.com/brave/browser-laptop/blob/548e11b1c889332fadb379237555625ad2a3c845/less/button.less#L49
color: globalStyles.button.color,
':hover': {
color: globalStyles.button.default.hoverColor
}
},
// applies for primary and white buttons
browserButton_default: {
// cf: https://github.com/brave/browser-laptop/blob/548e11b1c889332fadb379237555625ad2a3c845/less/button.less#L92
color: globalStyles.button.default.color,
position: 'relative',
boxShadow: globalStyles.button.default.boxShadow,
cursor: 'pointer',
lineHeight: 1.25,
width: 'auto',
height: 'auto',
fontSize: globalStyles.spacing.defaultFontSize,
// cf: https://github.com/brave/browser-laptop/blob/548e11b1c889332fadb379237555625ad2a3c845/less/button.less#L94-L95
paddingTop: '5px',
paddingBottom: '5px',
// cf: https://github.com/brave/browser-laptop/blob/548e11b1c889332fadb379237555625ad2a3c845/less/button.less#L105-L106
paddingRight: '16px',
paddingLeft: '16px',
// cf: https://github.com/brave/browser-laptop/blob/548e11b1c889332fadb379237555625ad2a3c845/less/button.less#L98
minWidth: `calc(${globalStyles.spacing.defaultFontSize} * 6)`, // issue #6384
':active': {
// push the button down when active
bottom: '-1px'
}
},
browserButton_primaryColor: {
background: globalStyles.button.primary.background,
borderLeft: '2px solid transparent',
borderRight: '2px solid transparent',
borderTop: `2px solid ${globalStyles.button.primary.gradientColor1}`,
borderBottom: `2px solid ${globalStyles.button.primary.gradientColor2}`,
cursor: 'pointer',
':hover': {
border: `2px solid ${globalStyles.button.primary.borderHoverColor}`,
color: globalStyles.button.primary.hoverColor
}
},
browserButton_secondaryColor: {
background: globalStyles.button.secondary.background,
border: '1px solid white',
color: globalStyles.button.secondary.color,
cursor: 'pointer',
':hover': {
border: `1px solid ${globalStyles.button.secondary.borderHoverColor}`,
color: globalStyles.button.secondary.hoverColor
}
},
browserButton_extensionItem: {
WebkitAppRegion: 'no-drag',
backgroundSize: 'contain',
height: '17px',
margin: '4px 0 0 0',
opacity: '0.85',
backgroundRepeat: 'no-repeat'
},
browserButton_groupedItem: {
// Legacy LESS inside ledger is too nested
// and this style won't have effect without using !important
//
// TODO: remove !important and check advancedSettings.js
// once preferences is fully refactored
marginRight: '4px !important',
marginLeft: '4px !important'
},
browserButton_notificationItem: {
fontSize: '13px',
marginRight: '10px',
padding: '2px 15px',
textTransform: 'capitalize',
width: 'auto'
},
browserButton_subtleItem: {
background: globalStyles.button.subtle.backgroundColor,
// cf: https://github.com/brave/browser-laptop/blob/548e11b1c889332fadb379237555625ad2a3c845/less/button.less#L152
fontSize: '14px',
// Adding box-shadow:none to cancel the box-shadow specified on browserButton_default
// On button.less, box-shadow is only speficied to .primaryButton and .whiteButton
// cf:
// https://github.com/brave/browser-laptop/blob/548e11b1c889332fadb379237555625ad2a3c845/less/button.less#L114
// https://github.com/brave/browser-laptop/blob/548e11b1c889332fadb379237555625ad2a3c845/less/button.less#L137
boxShadow: 'none',
// Cancel pushing down the button to make the button subtle
':active': {
bottom: 0
}
}
})
module.exports = BrowserButton