aboutsummaryrefslogtreecommitdiff
path: root/src/console/components
diff options
context:
space:
mode:
Diffstat (limited to 'src/console/components')
-rw-r--r--src/console/components/ColorSchemeProvider.tsx76
-rw-r--r--src/console/components/Console.tsx40
-rw-r--r--src/console/components/ErrorMessage.tsx2
-rw-r--r--src/console/components/InfoMessage.tsx2
-rw-r--r--src/console/components/console/CompletionItem.tsx2
-rw-r--r--src/console/components/console/CompletionTitle.tsx2
-rw-r--r--src/console/components/console/Input.tsx2
7 files changed, 21 insertions, 105 deletions
diff --git a/src/console/components/ColorSchemeProvider.tsx b/src/console/components/ColorSchemeProvider.tsx
deleted file mode 100644
index bd63571..0000000
--- a/src/console/components/ColorSchemeProvider.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-import React from "react";
-import ColorScheme from "../../shared/ColorScheme";
-import { ThemeProvider } from "styled-components";
-import baseStyled, { ThemedStyledInterface } from "styled-components";
-
-type ThemeProperties = {
- completionTitleBackground: string;
- completionTitleForeground: string;
- completionItemBackground: string;
- completionItemForeground: string;
- completionItemDescriptionForeground: string;
- completionSelectedBackground: string;
- completionSelectedForeground: string;
- commandBackground: string;
- commandForeground: string;
- consoleErrorBackground: string;
- consoleErrorForeground: string;
- consoleInfoBackground: string;
- consoleInfoForeground: string;
-};
-
-export const LightTheme: ThemeProperties = {
- completionTitleBackground: "lightgray",
- completionTitleForeground: "#000000",
- completionItemBackground: "#ffffff",
- completionItemForeground: "#000000",
- completionItemDescriptionForeground: "#008000",
- completionSelectedBackground: "#ffff00",
- completionSelectedForeground: "#000000",
- commandBackground: "#ffffff",
- commandForeground: "#000000",
- consoleErrorBackground: "#ff0000",
- consoleErrorForeground: "#ffffff",
- consoleInfoBackground: "#ffffff",
- consoleInfoForeground: "#018786",
-};
-
-export const DarkTheme: ThemeProperties = {
- completionTitleBackground: "#052027",
- completionTitleForeground: "white",
- completionItemBackground: "#2f474f",
- completionItemForeground: "white",
- completionItemDescriptionForeground: "#86fab0",
- completionSelectedBackground: "#eeff41",
- completionSelectedForeground: "#000000",
- commandBackground: "#052027",
- commandForeground: "white",
- consoleErrorBackground: "red",
- consoleErrorForeground: "white",
- consoleInfoBackground: "#052027",
- consoleInfoForeground: "#ffffff",
-};
-
-interface Props extends React.HTMLAttributes<HTMLElement> {
- colorscheme: ColorScheme;
-}
-
-const ColorSchemeProvider: React.FC<Props> = ({ colorscheme, children }) => {
- let theme = LightTheme;
- if (colorscheme === ColorScheme.System) {
- if (
- window.matchMedia &&
- window.matchMedia("(prefers-color-scheme: dark)").matches
- ) {
- theme = DarkTheme;
- }
- } else if (colorscheme === ColorScheme.Dark) {
- theme = DarkTheme;
- }
-
- return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
-};
-
-export const styled = baseStyled as ThemedStyledInterface<ThemeProperties>;
-
-export default ColorSchemeProvider;
diff --git a/src/console/components/Console.tsx b/src/console/components/Console.tsx
index b97ed62..f6f4234 100644
--- a/src/console/components/Console.tsx
+++ b/src/console/components/Console.tsx
@@ -3,37 +3,29 @@ import FindPrompt from "./FindPrompt";
import CommandPrompt from "./CommandPrompt";
import InfoMessage from "./InfoMessage";
import ErrorMessage from "./ErrorMessage";
-import * as consoleActions from "../../console/actions/console";
-import ColorSchemeProvider from "./ColorSchemeProvider";
import AppContext from "./AppContext";
+import { useColorSchemeRefresh } from "../colorscheme/hooks";
const Console: React.FC = () => {
- const { state, dispatch } = React.useContext(AppContext);
+ const { state } = React.useContext(AppContext);
+ const refreshColorScheme = useColorSchemeRefresh();
React.useEffect(() => {
- dispatch(consoleActions.setColorScheme());
+ refreshColorScheme();
}, []);
- const ele = (() => {
- switch (state.mode) {
- case "command":
- return <CommandPrompt />;
- case "find":
- return <FindPrompt />;
- case "info":
- return <InfoMessage>{state.messageText}</InfoMessage>;
- case "error":
- return <ErrorMessage>{state.messageText}</ErrorMessage>;
- default:
- return null;
- }
- })();
-
- return (
- <ColorSchemeProvider colorscheme={state.colorscheme}>
- {ele}
- </ColorSchemeProvider>
- );
+ switch (state.mode) {
+ case "command":
+ return <CommandPrompt />;
+ case "find":
+ return <FindPrompt />;
+ case "info":
+ return <InfoMessage>{state.messageText}</InfoMessage>;
+ case "error":
+ return <ErrorMessage>{state.messageText}</ErrorMessage>;
+ default:
+ return null;
+ }
};
export default Console;
diff --git a/src/console/components/ErrorMessage.tsx b/src/console/components/ErrorMessage.tsx
index 93b049b..f8d5ae7 100644
--- a/src/console/components/ErrorMessage.tsx
+++ b/src/console/components/ErrorMessage.tsx
@@ -1,5 +1,5 @@
import React from "react";
-import { styled } from "./ColorSchemeProvider";
+import styled from "../colorscheme/styled";
const Wrapper = styled.p`
border-top: 1px solid gray;
diff --git a/src/console/components/InfoMessage.tsx b/src/console/components/InfoMessage.tsx
index 02ad27d..ccd9bcf 100644
--- a/src/console/components/InfoMessage.tsx
+++ b/src/console/components/InfoMessage.tsx
@@ -1,5 +1,5 @@
import React from "react";
-import { styled } from "./ColorSchemeProvider";
+import styled from "../colorscheme/styled";
const Wrapper = styled.p`
border-top: 1px solid gray;
diff --git a/src/console/components/console/CompletionItem.tsx b/src/console/components/console/CompletionItem.tsx
index 7313491..2de1375 100644
--- a/src/console/components/console/CompletionItem.tsx
+++ b/src/console/components/console/CompletionItem.tsx
@@ -1,5 +1,5 @@
import React from "react";
-import { styled } from "../ColorSchemeProvider";
+import styled from "../../colorscheme/styled";
const Container = styled.li<{
shown: boolean;
diff --git a/src/console/components/console/CompletionTitle.tsx b/src/console/components/console/CompletionTitle.tsx
index a8e8a54..4018b3f 100644
--- a/src/console/components/console/CompletionTitle.tsx
+++ b/src/console/components/console/CompletionTitle.tsx
@@ -1,5 +1,5 @@
import React from "react";
-import { styled } from "../ColorSchemeProvider";
+import styled from "../../colorscheme/styled";
const Li = styled.li<{ shown: boolean }>`
display: ${({ shown }) => (shown ? "display" : "none")};
diff --git a/src/console/components/console/Input.tsx b/src/console/components/console/Input.tsx
index 7850f43..442bd30 100644
--- a/src/console/components/console/Input.tsx
+++ b/src/console/components/console/Input.tsx
@@ -1,5 +1,5 @@
import React from "react";
-import { styled } from "../ColorSchemeProvider";
+import styled from "../../colorscheme/styled";
const Container = styled.div`
background-color: ${({ theme }) => theme.commandBackground};