Skip to content

Commit db304bc

Browse files
author
Yury Shapkarin
committed
basic theme switch nsand#38
1 parent 86a7811 commit db304bc

File tree

4 files changed

+83
-85
lines changed

4 files changed

+83
-85
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/popup/popup.jsx

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,34 @@
11
import React from 'react';
2+
import { ThemeProvider } from 'styled-components';
3+
24
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';
514

615
export default class Popup extends React.Component {
716
constructor(props) {
817
super(props);
918
this.state = {
1019
windows: [],
1120
filter: '',
12-
mru: {}
21+
mru: {},
22+
theme: 'light'
1323
};
24+
this.themes = {
25+
light: {
26+
navigation: '#009688'
27+
},
28+
dark: {
29+
navigation: '#000000'
30+
}
31+
}
1432
}
1533
componentDidMount() {
1634
chrome.runtime.sendMessage({action: 'mru'}, (mru) => {
@@ -44,16 +62,20 @@ export default class Popup extends React.Component {
4462
});
4563
}
4664
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;
4967
return (
50-
<div>
68+
<ThemeProvider theme={theme}>
5169
<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>
5577
</Navigation>
56-
<main className={styles.main}>
78+
<Main>
5779
{
5880
windows.sort((left, right) => {
5981
// Compare the timestamps, if they exist, from the mru state
@@ -64,22 +86,25 @@ export default class Popup extends React.Component {
6486
}
6587
return comp;
6688
}).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>
7297
{
7398
$window.tabs
7499
.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)}/>)
76101
}
77-
</ul>
78-
</section>
102+
</TabList>
103+
</Section>
79104
)
80105
}
81-
</main>
82-
</div>
106+
</Main>
107+
</ThemeProvider>
83108
);
84109
}
85110
}

src/components/popup/popup.scss

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/components/popup/style.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import styled from "styled-components";
1+
import styled from 'styled-components';
22

33
export const Navigation = styled.nav`
44
position: fixed;
@@ -8,7 +8,7 @@ export const Navigation = styled.nav`
88
justify-content: center;
99
align-items: center;
1010
top: 0;
11-
background-color: #009688;
11+
background-color: ${({ theme: { navigation } }) => navigation};
1212
height: 56px;
1313
box-shadow: rgba(0, 0, 0, 0.137255) 0px 0px 4px 0px,
1414
rgba(0, 0, 0, 0.278431) 0px 4px 8px 0px;
@@ -30,3 +30,38 @@ export const Filter = styled.input`
3030
color: rgba(255, 255, 255, 0.8);
3131
}
3232
`;
33+
34+
export const Main = styled.main`
35+
margin-top: 56px;
36+
`;
37+
38+
export const Section = styled.section`
39+
&.window {
40+
&:not(:first-child) {
41+
&:before {
42+
content: '';
43+
display: block;
44+
border-top: 1px solid #ddd;
45+
margin: 0 16px;
46+
}
47+
}
48+
}
49+
`;
50+
51+
export const Header = styled.header`
52+
display: flex;
53+
align-items: center;
54+
height: 48px;
55+
`;
56+
57+
export const Title = styled.h2`
58+
font-size: 14px;
59+
margin: 0;
60+
padding: 0 16px;
61+
font-weight: normal;
62+
`;
63+
64+
export const TabList = styled.ul`
65+
margin: 0;
66+
padding: 0;
67+
`;

0 commit comments

Comments
 (0)