Skip to content

Commit bba2227

Browse files
authored
[cookbook] Add Modular theme colors (#93)
* Add Modular theme colors, add sass, update gitignore, simplify themetoggle component * rerun pnpm install after rebase
1 parent 6b9c432 commit bba2227

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+238
-373
lines changed

genai-cookbook/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

33
# dependencies
4-
node_modules/
4+
**/node_modules/
55
.pnp
66
.pnp.js
77
.yarn/install-state.gz

genai-cookbook/apps/cookbook/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import '@mantine/core/styles.css'
2-
import '@/styles/globals.css'
2+
import '@/styles/globals.scss'
33

44
import type { Metadata } from 'next'
55
import { MantineProvider } from '@mantine/core'

genai-cookbook/apps/cookbook/components/ThemeToggle.tsx

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,24 @@
22

33
import { ActionIcon, Tooltip, useMantineColorScheme } from '@mantine/core'
44
import { IconMoon, IconSun } from '@tabler/icons-react'
5-
import { useEffect, useState } from 'react'
6-
7-
const STORAGE_KEY = 'color-scheme'
85

96
export function ThemeToggle({ stroke }: { stroke: number }): JSX.Element {
10-
const { colorScheme, setColorScheme } = useMantineColorScheme()
11-
const [mounted, setMounted] = useState(false)
12-
13-
useEffect(() => {
14-
setMounted(true)
15-
}, [])
16-
17-
useEffect(() => {
18-
const root = document.documentElement
19-
if (colorScheme === 'dark') {
20-
root.classList.add('dark')
21-
} else {
22-
root.classList.remove('dark')
23-
}
24-
25-
try {
26-
localStorage.setItem(STORAGE_KEY, colorScheme)
27-
} catch {}
28-
}, [colorScheme])
7+
const { setColorScheme, colorScheme } = useMantineColorScheme()
298

30-
const toggle = (): void => {
31-
setColorScheme(colorScheme === 'dark' ? 'light' : 'dark')
9+
function toggleColorScheme() {
10+
const result = colorScheme === 'dark' ? 'light' : 'dark'
11+
return setColorScheme(result)
3212
}
3313

3414
const label = colorScheme === 'dark' ? 'Switch to light' : 'Switch to dark'
3515

36-
if (!mounted) {
37-
return (
38-
<ActionIcon aria-label="Toggle theme">
39-
<span style={{ opacity: 0 }}>&nbsp;</span>
40-
</ActionIcon>
41-
)
42-
}
43-
4416
return (
4517
<Tooltip label={label}>
46-
<ActionIcon onClick={toggle} aria-label={label} variant="transparent">
18+
<ActionIcon
19+
onClick={toggleColorScheme}
20+
aria-label={label}
21+
variant="transparent"
22+
>
4723
{colorScheme === 'dark' ? (
4824
<IconMoon stroke={stroke} />
4925
) : (

genai-cookbook/apps/cookbook/node_modules/.bin/acorn

Lines changed: 0 additions & 21 deletions
This file was deleted.

genai-cookbook/apps/cookbook/node_modules/.bin/eslint

Lines changed: 0 additions & 21 deletions
This file was deleted.

genai-cookbook/apps/cookbook/node_modules/.bin/jiti

Lines changed: 0 additions & 21 deletions
This file was deleted.

genai-cookbook/apps/cookbook/node_modules/.bin/nanoid

Lines changed: 0 additions & 21 deletions
This file was deleted.

genai-cookbook/apps/cookbook/node_modules/.bin/next

Lines changed: 0 additions & 21 deletions
This file was deleted.

genai-cookbook/apps/cookbook/node_modules/.bin/openai

Lines changed: 0 additions & 21 deletions
This file was deleted.

genai-cookbook/apps/cookbook/node_modules/.bin/tailwind

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)