From 1c7167bcf95af18d0c6db03ef6e5e31ad3aeed43 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Sat, 3 Sep 2022 12:19:13 +0800 Subject: [PATCH] feat: add theme editor. --- package.json | 2 +- src/App.tsx | 2 ++ src/assets/color.svg | 7 +++++ src/{pages/home => commands}/copy.tsx | 0 src/commands/css.tsx | 27 ++++++++++++++++++ src/{pages/home => commands}/theme.tsx | 13 ++++++--- src/commands/title.tsx | 25 +++++++++++++++++ src/components/Layout.tsx | 24 ++++++++++++++-- src/pages/home/Preview.tsx | 4 +-- src/pages/home/index.tsx | 18 ++++++------ src/pages/theme/Preview.tsx | 19 +++++++++++++ src/pages/theme/editor.tsx | 38 ++++++++++++++++++++++++++ src/store/context.tsx | 24 +++++++++++++--- src/themes/default.md.css | 6 ++-- src/themes/simple.md.css | 6 ++-- src/themes/underscore.md.css | 6 ++-- 16 files changed, 190 insertions(+), 31 deletions(-) create mode 100644 src/assets/color.svg rename src/{pages/home => commands}/copy.tsx (100%) create mode 100644 src/commands/css.tsx rename src/{pages/home => commands}/theme.tsx (84%) create mode 100644 src/commands/title.tsx create mode 100644 src/pages/theme/Preview.tsx create mode 100644 src/pages/theme/editor.tsx diff --git a/package.json b/package.json index d1e31ed..bf9ba94 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@uiw/codemirror-theme-xcode": "^4.11.6", "@uiw/react-back-to-top": "^1.2.0", "@uiw/react-github-corners": "^1.5.15", - "@uiw/react-markdown-editor": "^5.5.1", + "@uiw/react-markdown-editor": "^5.6.0", "@wcj/dark-mode": "^1.0.15", "css-tree": "^2.2.1", "react": "^18.2.0", diff --git a/src/App.tsx b/src/App.tsx index 3d65adc..6a1063b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,12 +1,14 @@ import { Routes, Route } from 'react-router-dom'; import { Layout } from './components/Layout'; import { HomePage } from './pages/home'; +import { EditorPage } from './pages/theme/editor'; export default function App() { return ( }> } /> + } /> ); diff --git a/src/assets/color.svg b/src/assets/color.svg new file mode 100644 index 0000000..6f800d2 --- /dev/null +++ b/src/assets/color.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/pages/home/copy.tsx b/src/commands/copy.tsx similarity index 100% rename from src/pages/home/copy.tsx rename to src/commands/copy.tsx diff --git a/src/commands/css.tsx b/src/commands/css.tsx new file mode 100644 index 0000000..88aa919 --- /dev/null +++ b/src/commands/css.tsx @@ -0,0 +1,27 @@ +import { NavLink } from 'react-router-dom'; +import { ICommand } from '@uiw/react-markdown-editor'; +import styled from 'styled-components'; + +const Link = styled(NavLink)` + font-size: 0.8rem; + line-height: 0.8rem; + text-decoration: none; + padding: 0.18rem 0.3rem; + &:hover { + color: var(--color-accent-fg); + background-color: var(--color-neutral-muted); + border-radius: 0.2rem; + } +`; + +export const cssCommand: ICommand = { + name: 'previewTtheme', + keyCommand: 'previewTtheme', + button: () => 编辑主题, +}; + +export const previousCommand: ICommand = { + name: 'previous', + keyCommand: 'previous', + button: () => 返回, +}; diff --git a/src/pages/home/theme.tsx b/src/commands/theme.tsx similarity index 84% rename from src/pages/home/theme.tsx rename to src/commands/theme.tsx index 99f935f..60482fd 100644 --- a/src/pages/home/theme.tsx +++ b/src/commands/theme.tsx @@ -1,7 +1,7 @@ import React, { useContext } from 'react'; import { ICommand, IMarkdownEditor, ToolBarProps } from '@uiw/react-markdown-editor'; import styled from 'styled-components'; -import { Context, previewThemes, PreviewThemeValue, themes as editorThemes, ThemeValue } from '../../store/context'; +import { Context, previewThemes, PreviewThemeValue, themes as editorThemes, ThemeValue } from '../store/context'; const Select = styled.select` max-width: 4rem; @@ -46,10 +46,15 @@ export const theme: ICommand = { }; const ThemePreviewView: React.FC<{}> = () => { - const { css, setCss } = useContext(Context); - const handleChange = (ev: React.ChangeEvent) => setCss(ev.target.value as any); + const { setCss, previewTheme, setPreviewTheme } = useContext(Context); + const handleChange = (ev: React.ChangeEvent) => { + const value = ev.target.value as PreviewThemeValue; + console.log('vvvv'); + setPreviewTheme(value); + setCss(previewThemes[value].value); + }; return ( - {(Object.keys(previewThemes) as Array).map((name, key) => { return (