Skip to content

Commit

Permalink
theme switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
vladkens committed Jan 22, 2024
1 parent 9472c46 commit 4d74cb2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 11 deletions.
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<script>
const isDark = localStorage.getItem("dark") === "true"
document.body.classList.toggle("dark", isDark)
</script>
</body>
</html>
18 changes: 17 additions & 1 deletion src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@ import { Timeline } from "./components/Timeline"
import { TzListState } from "./state"
import { getPlaceByTzName } from "./utils/places"

const ChangeTheme: FC = () => {
const change = () => {
const isDark = !document.body.classList.contains("dark")
document.body.classList.toggle("dark", isDark)
localStorage.setItem("dark", isDark.toString())
}

return <button onClick={change}>ChangeTheme</button>
}

const Index: FC = () => {
const [tzs, setTzs] = useAtom(TzListState)
const places = tzs.map((tz) => getPlaceByTzName(tz))

return (
<div className="flex flex-col gap-2.5 py-2.5">
<SelectPlace values={places} onChange={(place) => setTzs((old) => [...old, place.tzName])} />
<div className="flex flex-row gap-2.5">
<SelectPlace
values={places}
onChange={(place) => setTzs((old) => [...old, place.tzName])}
/>
<ChangeTheme />
</div>

<div className="flex flex-col gap-2">
{places.map((x, idx) => (
Expand Down
3 changes: 2 additions & 1 deletion src/components/Timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ export const Timeline: FC<{ place: Place }> = ({ place }) => {
isHome && "border-orange-500",
)}
onClick={() => setTzHome(place.tzName)}
disabled={isHome}
>
{isHome ? "><" : withSign((place.tzOffset - refPlace.tzOffset) / 60)}
{isHome ? "🏠" : withSign((place.tzOffset - refPlace.tzOffset) / 60)}
</button>

<TzInfo place={place} />
Expand Down
32 changes: 30 additions & 2 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
@tailwind components;
@tailwind utilities;

body {
@apply bg-gray-100;
/*
- https://ui.shadcn.com/themes
- https://daisyui.com/docs/colors/
- https://github.com/saadeghi/daisyui/blob/master/src/theming/themes.js
*/

@layer base {
:root {
--base-100: #f1f1f1;
--base-200: #dbdbdb;
--base-300: #c6c6c6;
--base-txt: #141414;
}

.dark {
--base-100: #0a0a0b;
--base-200: #171718;
--base-300: #2f2d30;
--base-txt: #dca54d;
}
}

@layer base {
* {
/* @apply border-border; */
}

body {
@apply bg-base text-base-txt;
}
}
15 changes: 8 additions & 7 deletions tailwind.config.cjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
darkMode: "class",
theme: {
extend: {},
extend: {
colors: {
base: { DEFAULT: "var(--base-100)", txt: "var(--base-txt)" },
},
},
},
plugins: [],
}
}

0 comments on commit 4d74cb2

Please sign in to comment.