1
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
4
4
5
5
const React = require ( 'react' )
6
6
const { StyleSheet, css} = require ( 'aphrodite/no-important' )
7
- const Immutable = require ( 'immutable' )
8
7
9
8
// Components
10
9
const ReduxComponent = require ( '../../reduxComponent' )
11
10
const TabIcon = require ( './tabIcon' )
12
11
13
12
// State
13
+ const partitionState = require ( '../../../../common/state/tabContentState/partitionState' )
14
14
const tabUIState = require ( '../../../../common/state/tabUIState' )
15
-
16
- // Constants
17
- const { tabs} = require ( '../../../../../js/constants/config' )
18
-
19
- // Utils
15
+ const tabState = require ( '../../../../common/state/tabState' )
20
16
const frameStateUtil = require ( '../../../../../js/state/frameStateUtil' )
21
17
22
18
// Styles
@@ -26,44 +22,39 @@ const newSessionSvg = require('../../../../extensions/brave/img/tabs/new_session
26
22
class NewSessionIcon extends React . Component {
27
23
mergeProps ( state , ownProps ) {
28
24
const currentWindow = state . get ( 'currentWindow' )
29
- const frameKey = ownProps . frameKey
30
- const frame = frameStateUtil . getFrameByKey ( currentWindow , frameKey ) || Immutable . Map ( )
31
- const partition = frame . get ( 'partitionNumber' )
32
- const hasSeconardImage = tabUIState . hasVisibleSecondaryIcon ( currentWindow , ownProps . frameKey )
25
+ const tabId = ownProps . tabId
26
+ const frameKey = frameStateUtil . getFrameKeyByTabId ( currentWindow , tabId )
33
27
34
28
const props = { }
35
- // used in renderer
36
- props . showSessionIcon = ! ! partition && hasSeconardImage
29
+ props . isPinned = tabState . isTabPinned ( state , tabId )
30
+ props . showPartitionIcon = partitionState . showPartitionIcon ( currentWindow , frameKey )
37
31
props . isActive = frameStateUtil . isFrameKeyActive ( currentWindow , frameKey )
38
- props . iconColor = tabUIState . getTabIconColor ( currentWindow , frameKey )
39
- props . partitionNumber = typeof partition === 'string'
40
- ? partition . replace ( / ^ p a r t i t i o n - / i, '' )
41
- : partition
42
- props . partitionIndicator = props . partitionNumber > tabs . maxAllowedNewSessions
43
- ? tabs . maxAllowedNewSessions
44
- : props . partitionNumber
45
-
46
- // used in functions
47
- props . frameKey = frameKey
32
+ props . textIsWhite = tabUIState . checkIfTextColor ( currentWindow , frameKey , 'white' )
33
+ props . partitionNumber = partitionState . getMaxAllowedPartitionNumber ( currentWindow , frameKey )
34
+ props . tabId = tabId
48
35
49
36
return props
50
37
}
51
38
52
39
render ( ) {
53
- if ( ! this . props . showSessionIcon ) {
40
+ if (
41
+ this . props . isPinned ||
42
+ ! this . props . showPartitionIcon ||
43
+ this . props . partitionNumber === 0
44
+ ) {
54
45
return null
55
46
}
56
- const newSession = StyleSheet . create ( {
57
- indicator : {
58
- // Based on getTextColorForBackground() icons can be only black or white.
59
- filter : this . props . isActive && this . props . iconColor === 'white' ? 'invert(100%)' : 'none'
47
+
48
+ const newSessionProps = StyleSheet . create ( {
49
+ newSession__indicator : {
50
+ filter : this . props . isActive && this . props . textIsWhite ? 'invert(100%)' : 'none'
60
51
}
61
52
} )
62
53
63
54
return < TabIcon symbol
64
55
data-test-id = 'newSessionIcon'
65
- className = { css ( styles . icon , styles . newSession , newSession . indicator ) }
66
- symbolContent = { this . props . partitionIndicator }
56
+ className = { css ( styles . newSession__icon , newSessionProps . newSession__indicator ) }
57
+ symbolContent = { this . props . partitionNumber }
67
58
l10nArgs = { this . props . partitionNumber }
68
59
l10nId = 'sessionInfoTab'
69
60
/>
@@ -73,21 +64,17 @@ class NewSessionIcon extends React.Component {
73
64
module . exports = ReduxComponent . connect ( NewSessionIcon )
74
65
75
66
const styles = StyleSheet . create ( {
76
- icon : {
67
+ newSession__icon : {
68
+ zIndex : 99 ,
69
+ boxSizing : 'border-box' ,
70
+ display : 'flex' ,
71
+ alignItems : 'center' ,
72
+ backgroundImage : `url(${ newSessionSvg } )` ,
73
+ backgroundPosition : 'center left' ,
74
+ backgroundRepeat : 'no-repeat' ,
75
+ backgroundSize : '13px' ,
77
76
width : globalStyles . spacing . iconSize ,
78
- minWidth : globalStyles . spacing . iconSize ,
79
77
height : globalStyles . spacing . iconSize ,
80
- backgroundSize : globalStyles . spacing . iconSize ,
81
- fontSize : globalStyles . fontSize . tabIcon ,
82
- backgroundPosition : 'center' ,
83
- backgroundRepeat : 'no-repeat' ,
84
- paddingLeft : globalStyles . spacing . defaultIconPadding ,
85
- paddingRight : globalStyles . spacing . defaultIconPadding
86
- } ,
87
-
88
- newSession : {
89
- position : 'relative' ,
90
- backgroundImage : `url(${ newSessionSvg } )` ,
91
- backgroundPosition : 'left'
78
+ marginRight : globalStyles . spacing . defaultTabMargin
92
79
}
93
80
} )
0 commit comments