From 14d50f116774bb134f628a86f72a9663c65cbc22 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Mon, 13 Mar 2023 03:06:21 +0800 Subject: [PATCH] feat: add dark theme support --- .../{button.module.css => button.module.scss} | 14 +- app/components/button.tsx | 4 +- .../{home.module.css => home.module.scss} | 12 +- app/components/home.tsx | 142 +++++++++++++++--- .../{ui-lib.module.css => ui-lib.module.scss} | 2 + app/components/ui-lib.tsx | 2 +- app/globals.css | 49 ------ app/globals.scss | 141 +++++++++++++++++ app/icons/reload.svg | 24 +++ app/layout.tsx | 2 +- app/store.ts | 11 +- next.config.js | 7 +- package.json | 1 + yarn.lock | 76 +++++++++- 14 files changed, 395 insertions(+), 92 deletions(-) rename app/components/{button.module.css => button.module.scss} (70%) rename app/components/{home.module.css => home.module.scss} (95%) rename app/components/{ui-lib.module.css => ui-lib.module.scss} (92%) delete mode 100644 app/globals.css create mode 100644 app/globals.scss create mode 100644 app/icons/reload.svg diff --git a/app/components/button.module.css b/app/components/button.module.scss similarity index 70% rename from app/components/button.module.css rename to app/components/button.module.scss index 6f04a0b3..1f2a4d29 100644 --- a/app/components/button.module.css +++ b/app/components/button.module.scss @@ -8,7 +8,7 @@ box-shadow: var(--card-shadow); cursor: pointer; - transition: all .3s ease; + transition: all 0.3s ease; overflow: hidden; user-select: none; } @@ -29,7 +29,17 @@ align-items: center; } +@media (prefers-color-scheme: dark) { + div:not(:global(.no-dark)) > .icon-button-icon { + filter: invert(0.5); + } + + .icon-button:hover { + filter: brightness(1.2) hue-rotate(0.01turn); + } +} + .icon-button-text { margin-left: 5px; font-size: 12px; -} \ No newline at end of file +} diff --git a/app/components/button.tsx b/app/components/button.tsx index 8aea3ea2..43b699b6 100644 --- a/app/components/button.tsx +++ b/app/components/button.tsx @@ -1,6 +1,6 @@ import * as React from "react"; -import styles from "./button.module.css"; +import styles from "./button.module.scss"; export function IconButton(props: { onClick?: () => void; @@ -8,6 +8,7 @@ export function IconButton(props: { text?: string; bordered?: boolean; className?: string; + title?: string; }) { return (
{props.icon}
{props.text && ( diff --git a/app/components/home.module.css b/app/components/home.module.scss similarity index 95% rename from app/components/home.module.css rename to app/components/home.module.scss index f5decd52..0c3c07da 100644 --- a/app/components/home.module.css +++ b/app/components/home.module.scss @@ -8,6 +8,8 @@ border: var(--border-in-light); border-radius: 20px; box-shadow: var(--shadow); + color: var(--black); + background-color: var(--white); display: flex; overflow: hidden; @@ -177,11 +179,11 @@ margin-top: 5px; } -.chat-actions { +.window-actions { display: inline-flex; } -.chat-action-button { +.window-action-button { margin-left: 10px; } @@ -237,13 +239,14 @@ } .chat-message-item { - margin-top: 5px; + margin-top: 10px; border-radius: 10px; background-color: rgba(0, 0, 0, 0.05); padding: 10px; font-size: 14px; user-select: text; word-break: break-all; + border: var(--border-in-light); } .chat-message-user > .chat-message-container > .chat-message-item { @@ -289,11 +292,12 @@ border-radius: 10px; border: var(--border-in-light); box-shadow: var(--card-shadow); + background-color: var(--white); + color: var(--black); font-family: inherit; padding: 10px 14px; resize: none; outline: none; - color: #333; } .chat-input:focus { diff --git a/app/components/home.tsx b/app/components/home.tsx index 4efdefc4..4916dca0 100644 --- a/app/components/home.tsx +++ b/app/components/home.tsx @@ -6,10 +6,10 @@ import "katex/dist/katex.min.css"; import RemarkMath from "remark-math"; import RehypeKatex from "rehype-katex"; -import EmojiPicker, { Emoji, EmojiClickData } from "emoji-picker-react"; +import EmojiPicker, { Emoji, Theme as EmojiTheme } from "emoji-picker-react"; import { IconButton } from "./button"; -import styles from "./home.module.css"; +import styles from "./home.module.scss"; import SettingsIcon from "../icons/settings.svg"; import GithubIcon from "../icons/github.svg"; @@ -21,8 +21,9 @@ import BotIcon from "../icons/bot.svg"; import AddIcon from "../icons/add.svg"; import DeleteIcon from "../icons/delete.svg"; import LoadingIcon from "../icons/three-dots.svg"; +import ResetIcon from "../icons/reload.svg"; -import { Message, SubmitKey, useChatStore } from "../store"; +import { Message, SubmitKey, useChatStore, Theme } from "../store"; import { Card, List, ListItem, Popover } from "./ui-lib"; export function Markdown(props: { content: string }) { @@ -101,12 +102,34 @@ export function ChatList() { ); } +function useSubmitHandler() { + const config = useChatStore((state) => state.config); + const submitKey = config.submitKey; + + const shouldSubmit = (e: KeyboardEvent) => { + if (e.key !== "Enter") return false; + + return ( + (config.submitKey === SubmitKey.AltEnter && e.altKey) || + (config.submitKey === SubmitKey.CtrlEnter && e.ctrlKey) || + (config.submitKey === SubmitKey.ShiftEnter && e.shiftKey) || + config.submitKey === SubmitKey.Enter + ); + }; + + return { + submitKey, + shouldSubmit, + }; +} + export function Chat() { type RenderMessage = Message & { preview?: boolean }; const session = useChatStore((state) => state.currentSession()); const [userInput, setUserInput] = useState(""); const [isLoading, setIsLoading] = useState(false); + const { submitKey, shouldSubmit } = useSubmitHandler(); const onUserInput = useChatStore((state) => state.onUserInput); const onUserSubmit = () => { @@ -116,7 +139,7 @@ export function Chat() { setUserInput(""); }; const onInputKeyDown = (e: KeyboardEvent) => { - if (e.key === "Enter" && (e.shiftKey || e.ctrlKey || e.metaKey)) { + if (shouldSubmit(e)) { onUserSubmit(); e.preventDefault(); } @@ -165,12 +188,20 @@ export function Chat() { 与 ChatGPT 的 {session.messages.length} 条对话
-
-
- } bordered /> +
+
+ } + bordered + title="查看压缩后的历史 Prompt(开发中)" + />
-
- } bordered /> +
+ } + bordered + title="导出聊天记录为 Markdown(开发中)" + />
@@ -223,7 +254,7 @@ export function Chat() {