diff --git a/src/app.postcss b/src/app.postcss index d213f1d3..1b5c3824 100644 --- a/src/app.postcss +++ b/src/app.postcss @@ -1,18 +1,10 @@ @tailwind base; @tailwind components; @tailwind utilities; -/* -.nav-btn { - @apply lg:p-2 py-3 px-0 block border-b-2 border-transparent hover:border-white; -} - -.btn { - @apply bg-indigo-500 hover:bg-indigo-700 rounded px-4 shadow; -} -.action-btn { - @apply rounded p-2 bg-indigo-400 shadow flex-auto text-white hover:bg-indigo-500; -} .input { - @apply flex-1 border-indigo-400 border-solid border-2 rounded; -} */ + @apply flex-1 border-primary border-solid border-2 rounded; +} +.action-btn { + @apply btn btn-primary; +} diff --git a/src/lib/components/actions.svelte b/src/lib/components/actions.svelte index 110fd2b3..7f72f1e2 100644 --- a/src/lib/components/actions.svelte +++ b/src/lib/components/actions.svelte @@ -179,7 +179,9 @@
@@ -191,7 +193,7 @@ bind:value={gistURL} placeholder="Enter Gist URL" /> diff --git a/src/lib/components/card/card.svelte b/src/lib/components/card/card.svelte index a7974a51..eb72643a 100644 --- a/src/lib/components/card/card.svelte +++ b/src/lib/components/card/card.svelte @@ -10,7 +10,9 @@
-
(isOpen = !isOpen)}> +
(isOpen = !isOpen)}>
diff --git a/src/lib/components/editor/editor.svelte b/src/lib/components/editor/editor.svelte index 07ecbe3e..d2986ddb 100644 --- a/src/lib/components/editor/editor.svelte +++ b/src/lib/components/editor/editor.svelte @@ -1,6 +1,7 @@ - setTheme(selectedTheme)}> {#each themes as theme} {/each} diff --git a/src/lib/util/state.ts b/src/lib/util/state.ts index 864d3183..f2143b16 100644 --- a/src/lib/util/state.ts +++ b/src/lib/util/state.ts @@ -24,7 +24,6 @@ export const defaultState: State = { updateDiagram: true }; -export const themeStore = persist(writable(''), localStorage(), 'themeStore'); export const codeStore = persist(writable(defaultState), localStorage(), 'codeStore'); export const base64State = derived([codeStore], ([code], set) => { set(toBase64(JSON.stringify(code), true)); @@ -93,6 +92,17 @@ export const updateConfig = (config: string, updateEditor: boolean): void => { }); }; +export const toggleDarkTheme = (dark: boolean): void => { + codeStore.update((state) => { + const config = JSON.parse(state.mermaid); + if (!config.theme || ['dark', 'default'].includes(config.theme)) { + config.theme = dark ? 'dark' : 'default'; + } + + return { ...state, mermaid: JSON.stringify(config), updateEditor: true }; + }); +}; + export const initURLSubscription = (): void => { base64State.subscribe((state: string) => { history.replaceState(undefined, undefined, `#${state}`); diff --git a/src/lib/util/theme.ts b/src/lib/util/theme.ts new file mode 100644 index 00000000..f8f3c389 --- /dev/null +++ b/src/lib/util/theme.ts @@ -0,0 +1,20 @@ +import { writable } from 'svelte/store'; +import { persist, localStorage } from '@macfja/svelte-persistent-store'; +import { toggleDarkTheme } from './state'; + +export const themeStore = persist( + writable({ + isDark: false, + theme: 'light' + }), + localStorage(), + 'themeStore' +); + +const darkThemes = ['dark', 'synthwave', 'halloween', 'forest', 'luxury', 'black', 'dracula']; + +export const setTheme = (theme: string): void => { + const isDark = darkThemes.includes(theme); + console.log('Setting theme', theme); + themeStore.set({ theme, isDark }); +}; diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index 1bef1e14..7e16bcbf 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -3,7 +3,7 @@ import { base } from '$app/paths'; import { onMount } from 'svelte'; import { loadingStateStore } from '$lib/util/loading'; - import { themeStore } from '$lib/util/state'; + import { themeStore } from '$lib/util/theme'; import Theme from '$lib/components/theme.svelte'; // This can be removed once https://github.com/sveltejs/kit/issues/1612 is fixed. diff --git a/src/routes/edit.svelte b/src/routes/edit.svelte index 7e63f127..f56d5217 100644 --- a/src/routes/edit.svelte +++ b/src/routes/edit.svelte @@ -159,7 +159,7 @@ @@ -167,7 +167,7 @@
-
+
Code editing not supported on mobile. Please use a desktop browser.
diff --git a/tailwind.config.cjs b/tailwind.config.cjs index 8747d7f9..cefc1a3f 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -1,8 +1,5 @@ -const { tailwindExtractor } = require('tailwindcss/lib/lib/purgeUnusedStyles'); - module.exports = { mode: 'jit', - darkMode: 'media', plugins: [require('daisyui')], purge: ['./src/**/*.{html,js,svelte,ts}'], theme: {