diff --git a/bun.lock b/bun.lock index 838a47c..1775e5d 100644 --- a/bun.lock +++ b/bun.lock @@ -1,5 +1,6 @@ { "lockfileVersion": 1, + "configVersion": 0, "workspaces": { "": { "name": "calmhn", diff --git a/src/App.tsx b/src/App.tsx index 77b045d..7b506cd 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,16 @@ import { useEffect, useState } from 'react' import { ArrowSquareOut, ChatCircle, ArrowUp, Clock } from '@phosphor-icons/react' +type Theme = 'orange' | 'purple' | 'green' | 'blue' | 'teal' + +const themes: { id: Theme; swatch: string }[] = [ + { id: 'orange', swatch: 'bg-orange-300' }, + { id: 'purple', swatch: 'bg-purple-300' }, + { id: 'green', swatch: 'bg-green-300' }, + { id: 'blue', swatch: 'bg-blue-300' }, + { id: 'teal', swatch: 'bg-teal-300' }, +] + interface AlgoliaStory { objectID: string title: string @@ -25,6 +35,14 @@ function App() { const [stories, setStories] = useState([]) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) + const [theme, setTheme] = useState( + () => (localStorage.getItem('hn-theme') as Theme) || 'orange' + ) + + useEffect(() => { + document.documentElement.setAttribute('data-theme', theme) + localStorage.setItem('hn-theme', theme) + }, [theme]) useEffect(() => { const fetchTopStories = async () => { @@ -110,15 +128,29 @@ function App() { return (
-
+
-
-

- Calm HN -

-

- Top stories from the last three months -

+
+
+

+ Calm HN +

+

+ Top stories from the last three months +

+
+
+ {themes.map(t => ( +
@@ -132,7 +164,7 @@ function App() { aria-label={story.title} />
- + {index + 1}

diff --git a/src/index.css b/src/index.css index b329b2a..f47df35 100644 --- a/src/index.css +++ b/src/index.css @@ -10,4 +10,14 @@ body { font-family: "InterVariable", sans-serif; -} \ No newline at end of file +} + +:root { + --accent: var(--color-orange-200); +} + +[data-theme="orange"] { --accent: var(--color-orange-200); } +[data-theme="purple"] { --accent: var(--color-purple-200); } +[data-theme="green"] { --accent: var(--color-green-200); } +[data-theme="blue"] { --accent: var(--color-blue-200); } +[data-theme="teal"] { --accent: var(--color-teal-200); } \ No newline at end of file