Skip to content

Commit

Permalink
migrate oprions to react [in progress] nsand#16 nsand#38
Browse files Browse the repository at this point in the history
  • Loading branch information
Yury Shapkarin committed Jan 28, 2020
1 parent c1bedd9 commit 69e07bc
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 53 deletions.
33 changes: 6 additions & 27 deletions pages/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,15 @@
margin-left: 33px;
color: #9e9e9e;
}
.theme-json {
width: 320px;
height: 100px;
}
</style>
<title>Tab Glutton Settings</title>
</head>
<body>
<nav class="navigation">
<img src="../img/tab_glutton_48.png" class="brand"><h1>Tab Glutton</h1>
</nav>
<main class="main">
<section>
<header class="heading">
<h2 class="headingText">Display</h2>
</header>
<ul class="options">
<li>
<div><input type="checkbox" id="showURL"><label class="label" for="showURL">Show tab URL</label></div>
<div class="optionTip">Shows the URL of the tab in addition to its title</div>
</li>
<li>
<div><input type="checkbox" id="collapse"><label class="label" for="collapse">Dense tab list</label></div>
<div class="optionTip">List tabs without a lot of space in between them</div>
<ul class="options">
<li>
<div><input type="checkbox" id="separate"><label class="label" for="separate">Show separators</label></div>
<div class="optionTip">Shows separators between each tab in the list</div>
</li>
</ul>
</li>
</ul>
</section>
</main>
<script src="../lib/options.js"></script>
<div id="options"></div>
<script src="../bundles/options.js"></script>
</body>
</html>
28 changes: 3 additions & 25 deletions src/components/popup/popup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,16 @@ import {
Title,
TabList
} from './style.js';
import themes from '../../themes';

export default class Popup extends React.Component {
constructor(props) {
super(props);
this.state = {
windows: [],
filter: '',
mru: {},
theme: 'dark'
mru: {}
};
// todo: move to preferences, user can select or create and input
this.themes = {
light: {
navigation: '#009688',
placeholder: 'rgba(255, 255, 255, 0.8)',
main: '#ffffff',
tab: {
title: '#212121',
link: '#9e9e9e'
}
},
dark: {
navigation: '#1e1e1e',
placeholder: 'rgba(255, 255, 255, 0.4)',
main: '#1c1c1c',
tab: {
title: '#e1e1e1',
link: '#a5a5a5'
}
}
}
}
componentDidMount() {
chrome.runtime.sendMessage({action: 'mru'}, (mru) => {
Expand Down Expand Up @@ -76,7 +55,7 @@ export default class Popup extends React.Component {
}
render() {
const {filter, windows, mru } = this.state;
const theme = this.themes[this.state.theme] || this.themes.light;
const theme = themes[window.localStorage.getItem('theme')] || themes.light;
return (
<ThemeProvider theme={theme}>
<Navigation>
Expand All @@ -86,7 +65,6 @@ export default class Popup extends React.Component {
placeholder="Search"
onChange={this.filter.bind(this)}
/>
<button onClick={() => this.setState({theme: this.state.theme === 'light' ? 'dark' : 'light' })}>Change Theme</button>
</Navigation>
<Main>
{
Expand Down
83 changes: 83 additions & 0 deletions src/options/components/options.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React from 'react';

import themes from '../../themes';

export default class Options extends React.Component {
constructor(props) {
super(props);
this.state = {
showUrl: window.localStorage.showURL,
isSeparated: window.localStorage.getItem('isSeparated'),
isCollapsed: window.localStorage.getItem('isCollapsed') || 'true',
theme: window.localStorage.getItem('theme') || 'light'
};
}
changeTheme(event) {
this.setState({theme: event.target.value});
window.localStorage.setItem('theme', event.target.value);
}
componentDidMount() {}
render() {
return (
<div>
<nav className="navigation">
<img src="../img/tab_glutton_48.png" className="brand" />
<h1>Tab Glutton</h1>
</nav>
<main className="main">
<section>
<header className="heading">
<h2 className="headingText">Display</h2>
</header>
<ul className="options">
<li>
<div>
<input type="checkbox" id="showURL" />
<label className="label" for="showURL">
Show tab URL
</label>
</div>
<div className="optionTip">
Shows the URL of the tab in addition to its title
</div>
</li>
<li>
<div>
<input type="checkbox" id="collapse" />
<label className="label" for="collapse">
Dense tab list
</label>
</div>
<div className="optionTip">
List tabs without a lot of space in between them
</div>
<ul className="options">
<li>
<div>
<input type="checkbox" id="separate" />
<label className="label" for="separate">
Show separators
</label>
</div>
<div className="optionTip">
Shows separators between each tab in the list
</div>
</li>
</ul>
</li>
<li>
<select value={this.state.theme} name="select" onChange={this.changeTheme}>
{Object.keys(themes).map(theme => (
<option value={theme} selected={this.state.theme === theme}>
{theme}
</option>
))}
</select>
</li>
</ul>
</section>
</main>
</div>
);
}
}
6 changes: 6 additions & 0 deletions src/options/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';

import Options from './components/options.jsx';

ReactDOM.render(<Options/>, document.getElementById('options'));
24 changes: 24 additions & 0 deletions src/themes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default {
light: {
navigation: '#009688',
placeholder: 'rgba(255, 255, 255, 0.8)',
main: '#ffffff',
tab: {
title: '#212121',
link: '#9e9e9e'
}
},
dark: {
navigation: '#1e1e1e',
placeholder: 'rgba(255, 255, 255, 0.4)',
main: '#1c1c1c',
tab: {
title: '#e1e1e1',
link: '#a5a5a5'
},
options: {
header: '',
main: ''
}
}
};
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const plugins = [];

module.exports = {
entry: {
index: './src/index.jsx'
index: './src/index.jsx',
options: './src/options/index.jsx'
},
output: {
path: path.join(__dirname, 'bundles'),
Expand Down

0 comments on commit 69e07bc

Please sign in to comment.