From bacdd69e82d0a206a520cbfe7d038564bd83fa4a Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 28 Jan 2024 18:21:51 -0700 Subject: [PATCH] feat: font increase and decrease buttons --- src/components/Navbar.svelte | 2 +- src/components/Passage.svelte | 23 ++++++++------ src/components/StudyChapter.svelte | 29 +++++++++++++++++- src/components/Switch.svelte | 5 +-- src/components/icons/DecreaseFont.svelte | 8 +++++ src/components/icons/IncreaseFont.svelte | 13 ++++++++ src/routes/+layout.svelte | 39 ++++++++++++------------ src/routes/notes/+page.svelte | 4 +-- src/services/alert.js | 2 +- src/state/config.js | 14 +++++++++ src/state/dark.js | 3 -- 11 files changed, 99 insertions(+), 43 deletions(-) create mode 100644 src/components/icons/DecreaseFont.svelte create mode 100644 src/components/icons/IncreaseFont.svelte create mode 100644 src/state/config.js delete mode 100644 src/state/dark.js diff --git a/src/components/Navbar.svelte b/src/components/Navbar.svelte index eb33272..46712fc 100644 --- a/src/components/Navbar.svelte +++ b/src/components/Navbar.svelte @@ -8,7 +8,7 @@ import { signOut, updateUserInfo } from '@/services/api/auth' import Link from './Link.svelte' - import { darkTheme } from '@/state/dark' + import { darkTheme } from '@/state/config' import Logo from './Logo.svelte' import Switch from './Switch.svelte' import { diff --git a/src/components/Passage.svelte b/src/components/Passage.svelte index 2b9a83c..241ec19 100644 --- a/src/components/Passage.svelte +++ b/src/components/Passage.svelte @@ -1,4 +1,10 @@ @@ -410,6 +430,13 @@ > Nuevo Testamento + + + @@ -426,7 +453,7 @@
{#if !loading}
- +
{/if} diff --git a/src/components/Switch.svelte b/src/components/Switch.svelte index 0b24be6..cad9f81 100644 --- a/src/components/Switch.svelte +++ b/src/components/Switch.svelte @@ -1,5 +1,5 @@
diff --git a/src/components/icons/DecreaseFont.svelte b/src/components/icons/DecreaseFont.svelte new file mode 100644 index 0000000..4bea2c0 --- /dev/null +++ b/src/components/icons/DecreaseFont.svelte @@ -0,0 +1,8 @@ + + + \ No newline at end of file diff --git a/src/components/icons/IncreaseFont.svelte b/src/components/icons/IncreaseFont.svelte new file mode 100644 index 0000000..13ca75d --- /dev/null +++ b/src/components/icons/IncreaseFont.svelte @@ -0,0 +1,13 @@ + + + + + diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index b5fecf3..d5164e5 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -3,29 +3,27 @@ import { browser } from '$app/environment' import { onMount } from 'svelte' import '@/app.css' - import { darkTheme } from '@/state/dark' + import { darkTheme } from '@/state/config' export const checkMode = () => { - - if (browser) { - if ( - localStorage.theme === 'dark' || - (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches) - ) { - document.documentElement.classList.add('dark') - darkTheme.set(true) - } else { - document.documentElement.classList.remove('dark') - darkTheme.set(false) - } - - } + if (browser) { + if ( + localStorage.theme === 'dark' || + (!('theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches) + ) { + document.documentElement.classList.add('dark') + darkTheme.set(true) + } else { + document.documentElement.classList.remove('dark') + darkTheme.set(false) + } + } } onMount(() => checkMode()) -
+
@@ -34,7 +32,8 @@
\ No newline at end of file + .theme-transition { + transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, + border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; + } + diff --git a/src/routes/notes/+page.svelte b/src/routes/notes/+page.svelte index 51911f7..719f01c 100644 --- a/src/routes/notes/+page.svelte +++ b/src/routes/notes/+page.svelte @@ -2,14 +2,12 @@ import { onMount } from 'svelte' import Swal from 'sweetalert2' - import { user } from '@/state/user' import { notes } from '@/state/notes' - import { darkTheme } from '@/state/dark' + import { darkTheme } from '@/state/config' import { createAlert } from '@/services/alert' import Button from '@/components/Button.svelte' import { Stretch } from 'svelte-loading-spinners' import { API_BASE_URL } from '@/constants' - import { draft, studyMode } from '@/state/study' import { goto } from '$app/navigation' let loadingNotes = true diff --git a/src/services/alert.js b/src/services/alert.js index 0a1db77..6ecb61e 100644 --- a/src/services/alert.js +++ b/src/services/alert.js @@ -5,7 +5,7 @@ import { isDarkTheme } from '@/utils/darkTheme' * @param {'error'|'loading'|'success'|'normal'=} type * @param {number=} duration */ -export async function createAlert (message, type = 'normal', duration = 2000) { +export async function createAlert(message, type = 'normal', duration = 2000) { const { toast } = await import('wc-toast') const types = ['error', 'loading', 'success'] /** @type {{ type: 'dark'|'light'|'custom'|undefined }} */ diff --git a/src/state/config.js b/src/state/config.js new file mode 100644 index 0000000..5a02499 --- /dev/null +++ b/src/state/config.js @@ -0,0 +1,14 @@ +import { writable } from 'svelte/store' + +export const darkTheme = writable(false) + +export const fontSize = writable(16) + +/** + * + * @param {number} size + */ +export function setFontSize(size) { + fontSize.set(size) + localStorage.setItem('fontSize', JSON.stringify(size)) +} \ No newline at end of file diff --git a/src/state/dark.js b/src/state/dark.js deleted file mode 100644 index 5ec6f81..0000000 --- a/src/state/dark.js +++ /dev/null @@ -1,3 +0,0 @@ -import { writable } from 'svelte/store' - -export const darkTheme = writable(false)