Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/components/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createClientOnlyFn, createIsomorphicFn } from '@tanstack/react-start'
import * as React from 'react'
import { createContext, ReactNode, useEffect, useState } from 'react'
import { z } from 'zod'
import { THEME_COLORS } from '~/utils/utils'

const themeModeSchema = z.enum(['light', 'dark', 'auto'])
const resolvedThemeSchema = z.enum(['light', 'dark'])
Expand Down Expand Up @@ -46,6 +47,14 @@ const updateThemeClass = createClientOnlyFn((themeMode: ThemeMode) => {
if (themeMode === 'auto') {
root.classList.add('auto')
}

const metaThemeColor = document.querySelector('meta[name="theme-color"]')
if (metaThemeColor) {
metaThemeColor.setAttribute(
'content',
newTheme === 'dark' ? THEME_COLORS.dark : THEME_COLORS.light
)
}
})

const setupPreferredListener = createClientOnlyFn(() => {
Expand Down
11 changes: 11 additions & 0 deletions src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { authClient } from '../utils/auth.client'

import { LibrariesLayout } from './_libraries/route'
import { TanStackUser } from 'convex/auth'
import { THEME_COLORS } from '~/utils/utils'

export const Route = createRootRouteWithContext<{
queryClient: QueryClient
Expand All @@ -49,6 +50,16 @@ export const Route = createRootRouteWithContext<{
name: 'viewport',
content: 'width=device-width, initial-scale=1',
},
{
name: 'theme-color',
content: THEME_COLORS.light,
media: '(prefers-color-scheme: light)',
},
{
name: 'theme-color',
content: THEME_COLORS.dark,
media: '(prefers-color-scheme: dark)',
},
...seo({
title:
'TanStack | High Quality Open-Source Software for Web Developers',
Expand Down
1 change: 1 addition & 0 deletions src/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ button {
html,
body {
@apply text-gray-900 bg-gray-50 dark:bg-gray-900 dark:text-gray-200;
overscroll-behavior: none;
}

.using-mouse * {
Expand Down
7 changes: 7 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,10 @@ export async function logTime<T>(
console.log(`${lable}: ${(end - start).toLocaleString()} ms`)
return result as any
}

export const THEME_COLORS = {
light: '#f9fafb', // Tailwind gray-50
dark: '#101828', // Tailwind gray-900
} as const

export type ThemeColor = keyof typeof THEME_COLORS