From 60d86898bc42dfe9e15cb22b0de1402da39e84ab Mon Sep 17 00:00:00 2001 From: Saurabh Chaturvedi <56601821+saurabhchaturvedy@users.noreply.github.com> Date: Wed, 14 Apr 2021 09:14:19 +0530 Subject: [PATCH] Add light/dark theme toggle to editor #29 (#38) --- components/EditorColumn.js | 24 ++++++++++++++++++++++-- public/toggle_moon.svg | 1 + public/toggle_sun.svg | 1 + styles/globals.css | 4 ++++ 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 public/toggle_moon.svg create mode 100644 public/toggle_sun.svg diff --git a/components/EditorColumn.js b/components/EditorColumn.js index c16f6c5..9525a80 100644 --- a/components/EditorColumn.js +++ b/components/EditorColumn.js @@ -7,6 +7,7 @@ export const EditorColumn = ({ focusedSectionSlug, templates, setTemplates }) => return section ? section.markdown : '' } const [markdown, setMarkdown] = useState(getMarkdown()) + const [toggleState, setToggleState] = useState({ theme: 'vs-dark', img: 'toggle_sun.svg' }) useEffect(() => { const markdown = getMarkdown() @@ -25,14 +26,27 @@ export const EditorColumn = ({ focusedSectionSlug, templates, setTemplates }) => }) } + const toggleTheme = () => { + toggleDarkMode(toggleState, setToggleState) + } + return (
-

Editor

+

+ Editor + +

{focusedSectionSlug ? (
) } + +const toggleDarkMode = (toggleState, setToggleState) => { + toggleState.theme == 'vs-dark' + ? setToggleState({ theme: 'light', img: 'toggle_moon.svg' }) + : setToggleState({ theme: 'vs-dark', img: 'toggle_sun.svg' }) +} diff --git a/public/toggle_moon.svg b/public/toggle_moon.svg new file mode 100644 index 0000000..1df3109 --- /dev/null +++ b/public/toggle_moon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/public/toggle_sun.svg b/public/toggle_sun.svg new file mode 100644 index 0000000..8a7a6f9 --- /dev/null +++ b/public/toggle_sun.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/styles/globals.css b/styles/globals.css index 87f907a..8772cc9 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -6,6 +6,10 @@ max-height: calc(100vh - 160px); } +.toggle-dark-mode { + float: right; +} + @layer base { html { @apply bg-gray-50;