Add theme option

This commit is contained in:
sienori 2021-01-07 21:55:56 +09:00
parent 56f85ef661
commit f5d6b8617a
10 changed files with 93 additions and 11 deletions

View file

@ -158,6 +158,18 @@
"styleLabel": { "styleLabel": {
"message": "Style" "message": "Style"
}, },
"themeLabel": {
"message": "Theme"
},
"themeCaptionLabel": {
"message": "Specify the color scheme."
},
"lightLabel": {
"message": "Light"
},
"darkLabel": {
"message": "Dark"
},
"buttonStyleLabel": { "buttonStyleLabel": {
"message": "Translation button" "message": "Translation button"
}, },

View file

@ -1,11 +1,24 @@
import React from "react"; import React from "react";
import browser from "webextension-polyfill";
import { HashRouter } from "react-router-dom"; import { HashRouter } from "react-router-dom";
import { initSettings, getSettings } from "../../settings/settings";
import SideBar from "./SideBar"; import SideBar from "./SideBar";
import ContentsArea from "./ContentsArea"; import ContentsArea from "./ContentsArea";
import ScrollToTop from "./ScrollToTop"; import ScrollToTop from "./ScrollToTop";
import "../styles/OptionsPage.scss"; import "../styles/OptionsPage.scss";
const setupTheme = async () => {
await initSettings();
document.body.dataset.theme = getSettings("theme");
browser.storage.onChanged.addListener((changes) => {
if (changes.Settings.newValue.theme === changes.Settings.oldValue.theme) return;
document.body.dataset.theme = changes.Settings.newValue.theme;
});
};
export default () => { export default () => {
setupTheme();
return ( return (
<HashRouter hashType="noslash"> <HashRouter hashType="noslash">
<ScrollToTop> <ScrollToTop>

View file

@ -83,6 +83,8 @@ input,
textarea { textarea {
font-family: inherit; font-family: inherit;
font-size: 14px; font-size: 14px;
background-color: var(--sub-bg);
color: var(--main-text);
} }
textarea { textarea {
@ -224,6 +226,8 @@ input[type="color"] {
/*select*/ /*select*/
select { select {
background-color: var(--sub-bg);
color: var(--main-text);
-moz-appearance: none; -moz-appearance: none;
-webkit-appearance: none; -webkit-appearance: none;
text-overflow: ellipsis; text-overflow: ellipsis;
@ -233,6 +237,7 @@ select {
padding-right: 20px; padding-right: 20px;
width: 100%; width: 100%;
height: 30px; height: 30px;
scrollbar-color: var(--button) var(--line);
&:hover, &:hover,
&:focus { &:focus {
border: var(--highlight) solid 1px; border: var(--highlight) solid 1px;
@ -278,12 +283,12 @@ input[type="button"],
color: var(--main-text); color: var(--main-text);
border: 1px solid var(--button); border: 1px solid var(--button);
border-radius: 2px; border-radius: 2px;
background-color: #fbfbfb; background-color: var(--line);
cursor: pointer; cursor: pointer;
white-space: nowrap; white-space: nowrap;
&:hover, &:hover,
&:focus { &:focus {
background: #f5f5f5; background-color: var(--button);
border-color: var(--highlight); border-color: var(--highlight);
} }
&.includeSpan { &.includeSpan {
@ -302,7 +307,7 @@ input[type="button"],
justify-content: center; justify-content: center;
align-items: center; align-items: center;
&:focus-within { &:focus-within {
background: #f5f5f5; background-color: var(--button);
border-color: var(--highlight); border-color: var(--highlight);
} }
} }

View file

@ -1,11 +1,25 @@
:root { body {
background-color: var(--main-bg);
--main-text: #0c0c0d; --main-text: #0c0c0d;
--sub-text: #737373; --sub-text: #737373;
--line: #ededf0; --line: #ededf0;
--button: #d7d7db; --button: #d7d7db;
--highlight: #5595ff; --highlight: #5595ff;
--main-bg: #ffffff; --main-bg: #ffffff;
--sub-bg: #ffffff;
--new: #ff4f4f; --new: #ff4f4f;
&[data-theme="dark"] {
--main-text: #e6e6e6;
--sub-text: #aaaaaa;
--line: #373737;
--button: #929292;
--highlight: #5595ff;
--main-bg: #181818;
--sub-bg: #101010;
--new: #ed5f5f;
}
} }
.optionsPage { .optionsPage {
@ -14,7 +28,6 @@
font-size: 15px; font-size: 15px;
font-weight: 400; font-weight: 400;
color: var(--main-text); color: var(--main-text);
background-color: var(--main-bg);
line-height: 1.5; line-height: 1.5;
margin: 20px 40px; margin: 20px 40px;
} }

View file

@ -54,6 +54,7 @@ export default class PopupPage extends Component {
overWriteLogLevel(); overWriteLogLevel();
updateLogLevel(); updateLogLevel();
document.body.dataset.theme = getSettings("theme");
const targetLang = getSettings("targetLang"); const targetLang = getSettings("targetLang");
this.setState({ this.setState({
targetLang: targetLang targetLang: targetLang

View file

@ -47,12 +47,14 @@
-webkit-appearance: none; -webkit-appearance: none;
text-overflow: ellipsis; text-overflow: ellipsis;
background-color: var(--main-bg); background-color: var(--main-bg);
color: var(--main-text);
border: var(--button) solid 1px; border: var(--button) solid 1px;
border-radius: 2px; border-radius: 2px;
padding: 3px 5px; padding: 3px 5px;
padding-right: 20px; padding-right: 20px;
width: 100%; width: 100%;
transition: border-color 100ms ease-out; transition: border-color 100ms ease-out;
scrollbar-color: var(--button) var(--line);
&:hover { &:hover {
border-color: var(--highlight); border-color: var(--highlight);
} }

View file

@ -12,7 +12,7 @@
.title { .title {
font-size: 15px; font-size: 15px;
font-weight: 400; font-weight: 400;
color: #666; color: var(--sub-text);
cursor: default; cursor: default;
flex-shrink: 0; flex-shrink: 0;
} }

View file

@ -6,6 +6,7 @@
font: inherit; font: inherit;
resize: none; resize: none;
overflow: auto; overflow: auto;
color: var(--main-text);
background-color: var(--main-bg); background-color: var(--main-bg);
box-sizing: border-box; box-sizing: border-box;
@ -18,6 +19,7 @@
padding: 10px; padding: 10px;
border: solid 1px var(--button); border: solid 1px var(--button);
border-radius: 2px; border-radius: 2px;
outline: none;
transition: border-color 100ms ease-out; transition: border-color 100ms ease-out;
} }

View file

@ -21,9 +21,7 @@ body {
::-moz-selection { ::-moz-selection {
background: var(--line); background: var(--line);
} }
}
:root {
--main-text: #0c0c0d; --main-text: #0c0c0d;
--sub-text: #737373; --sub-text: #737373;
--line: #ededf0; --line: #ededf0;
@ -35,4 +33,19 @@ body {
--warn: #ff8f00; --warn: #ff8f00;
--success: #058b00; --success: #058b00;
--info: #0a84ff; --info: #0a84ff;
&[data-theme="dark"] {
--main-text: #e6e6e6;
--sub-text: #aaaaaa;
--line: #373737;
--button: #929292;
--highlight: #5595ff;
--main-bg: #181818;
--highlight-bg: #2e4343;
--confirm: #ed5f5f;
--error: #ca1532;
--warn: #ee8e12;
--success: #2a9c26;
--info: #1471d0;
}
} }

View file

@ -14,6 +14,8 @@ const getDefaultLangs = () => {
const langListOptions = generateLangOptions(); const langListOptions = generateLangOptions();
const defaultLangs = getDefaultLangs(); const defaultLangs = getDefaultLangs();
const getTheme = () =>
window.matchMedia('(prefers-color-scheme: dark)').matches ? "dark" : "light";
export default [ export default [
{ {
@ -91,6 +93,7 @@ export default [
title: "modifierKeyLabel", title: "modifierKeyLabel",
captions: [], captions: [],
type: "none", type: "none",
new: true,
childElements: [ childElements: [
{ {
id: "ifOnlyTranslateWhenModifierKeyPressed", id: "ifOnlyTranslateWhenModifierKeyPressed",
@ -185,6 +188,24 @@ export default [
{ {
category: "styleLabel", category: "styleLabel",
elements: [ elements: [
{
id: "theme",
title: "themeLabel",
captions: ["themeCaptionLabel"],
type: "select",
default: getTheme(),
options: [
{
name: "lightLabel",
value: "light"
},
{
name: "darkLabel",
value: "dark"
}
],
new: true
},
{ {
title: "buttonStyleLabel", title: "buttonStyleLabel",
captions: ["buttonStyleCaptionLabel"], captions: ["buttonStyleCaptionLabel"],
@ -357,21 +378,21 @@ export default [
title: "resultFontColorLabel", title: "resultFontColorLabel",
captions: [], captions: [],
type: "color", type: "color",
default: "#000000" default: getTheme() === "light" ? "#000000" : "#e6e6e6"
}, },
{ {
id: "candidateFontColor", id: "candidateFontColor",
title: "candidateFontColorLabel", title: "candidateFontColorLabel",
captions: [], captions: [],
type: "color", type: "color",
default: "#737373" default: getTheme() === "light" ? "#737373" : "#aaaaaa"
}, },
{ {
id: "bgColor", id: "bgColor",
title: "bgColorLabel", title: "bgColorLabel",
captions: [], captions: [],
type: "color", type: "color",
default: "#ffffff" default: getTheme() === "light" ? "#ffffff" : "#181818"
} }
] ]
} }