1
1
import React from 'react' ;
2
+ import { ThemeProvider } from 'styled-components' ;
3
+
2
4
import TabItem from '../tab-item/tab-item.jsx' ;
3
- import styles from './popup.scss' ;
4
- import { Navigation , Filter } from './style.js' ;
5
+ import {
6
+ Navigation ,
7
+ Filter ,
8
+ Main ,
9
+ Section ,
10
+ Header ,
11
+ Title ,
12
+ TabList
13
+ } from './style.js' ;
5
14
6
15
export default class Popup extends React . Component {
7
16
constructor ( props ) {
8
17
super ( props ) ;
9
18
this . state = {
10
19
windows : [ ] ,
11
20
filter : '' ,
12
- mru : { }
21
+ mru : { } ,
22
+ theme : 'light'
13
23
} ;
24
+ this . themes = {
25
+ light : {
26
+ navigation : '#009688'
27
+ } ,
28
+ dark : {
29
+ navigation : '#000000'
30
+ }
31
+ }
14
32
}
15
33
componentDidMount ( ) {
16
34
chrome . runtime . sendMessage ( { action : 'mru' } , ( mru ) => {
@@ -44,16 +62,20 @@ export default class Popup extends React.Component {
44
62
} ) ;
45
63
}
46
64
render ( ) {
47
- const { filter, windows, mru} = this . state ;
48
- const cls = this . state . isSeparated ? '' : styles . window ;
65
+ const { filter, windows, mru } = this . state ;
66
+ const theme = this . themes [ this . state . theme ] || this . themes . light ;
49
67
return (
50
- < div >
68
+ < ThemeProvider theme = { theme } >
51
69
< Navigation >
52
- < div >
53
- < Filter ref = "filter" type = "text" placeholder = "Search" onChange = { this . filter . bind ( this ) } />
54
- </ div >
70
+ < Filter
71
+ ref = "filter"
72
+ type = "text"
73
+ placeholder = "Search"
74
+ onChange = { this . filter . bind ( this ) }
75
+ />
76
+ < button onClick = { ( ) => this . setState ( { theme : this . state . theme === 'light' ? 'dark' : 'light' } ) } > Change Theme</ button >
55
77
</ Navigation >
56
- < main className = { styles . main } >
78
+ < Main >
57
79
{
58
80
windows . sort ( ( left , right ) => {
59
81
// Compare the timestamps, if they exist, from the mru state
@@ -64,22 +86,25 @@ export default class Popup extends React.Component {
64
86
}
65
87
return comp ;
66
88
} ) . map ( $window =>
67
- < section className = { cls } key = { $window . id } >
68
- < header className = { styles . heading } >
69
- < h2 className = { styles . headingText } > { $window . tabs . length } tabs</ h2 >
70
- </ header >
71
- < ul className = { styles . tabList } >
89
+ < Section
90
+ className = { this . state . isSeparated ? '' : 'window' }
91
+ key = { $window . id }
92
+ >
93
+ < Header >
94
+ < Title > { $window . tabs . length } tabs</ Title >
95
+ </ Header >
96
+ < TabList >
72
97
{
73
98
$window . tabs
74
99
. filter ( tab => filter . length === 0 || tab . title . toLocaleLowerCase ( ) . indexOf ( filter ) >= 0 || tab . url . toLocaleLowerCase ( ) . indexOf ( filter ) >= 0 )
75
- . map ( tab => < TabItem key = { tab . id } tab = { tab } onClose = { this . closeTab . bind ( this ) } > </ TabItem > )
100
+ . map ( tab => < TabItem key = { tab . id } tab = { tab } onClose = { this . closeTab . bind ( this ) } / >)
76
101
}
77
- </ ul >
78
- </ section >
102
+ </ TabList >
103
+ </ Section >
79
104
)
80
105
}
81
- </ main >
82
- </ div >
106
+ </ Main >
107
+ </ ThemeProvider >
83
108
) ;
84
109
}
85
110
}
0 commit comments