electron-vite-react-template 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +15 -0
- package/.github/workflows/ci.yml +77 -0
- package/CONTRIBUTING.md +58 -0
- package/LICENSE +21 -0
- package/README.md +157 -0
- package/SECURITY.md +29 -0
- package/docs/PROJECT.md +249 -0
- package/electron.vite.config.ts +46 -0
- package/eslint.config.js +28 -0
- package/package.json +57 -0
- package/postcss.config.js +6 -0
- package/src/main/index.ts +110 -0
- package/src/preload/index.ts +33 -0
- package/src/renderer/env.d.ts +16 -0
- package/src/renderer/index.html +16 -0
- package/src/renderer/src/components/mode-toggle.tsx +31 -0
- package/src/renderer/src/components/theme-provider.tsx +140 -0
- package/src/renderer/src/components/ui/button.tsx +50 -0
- package/src/renderer/src/components/ui/dropdown-menu.tsx +188 -0
- package/src/renderer/src/components/use-theme.ts +12 -0
- package/src/renderer/src/hooks/use-sample.ts +7 -0
- package/src/renderer/src/i18n/index.ts +27 -0
- package/src/renderer/src/i18n/locales/en.json +8 -0
- package/src/renderer/src/i18n/locales/fr.json +8 -0
- package/src/renderer/src/index.css +59 -0
- package/src/renderer/src/lib/utils.ts +6 -0
- package/src/renderer/src/main.tsx +66 -0
- package/src/renderer/src/stores/app-store.ts +20 -0
- package/tailwind.config.js +53 -0
- package/template/.github/workflows/ci.yml +77 -0
- package/template/electron.vite.config.ts +46 -0
- package/template/eslint.config.js +28 -0
- package/template/package.json +31 -0
- package/template/postcss.config.js +6 -0
- package/template/src/main/index.ts +110 -0
- package/template/src/preload/index.ts +33 -0
- package/template/src/renderer/env.d.ts +16 -0
- package/template/src/renderer/index.html +16 -0
- package/template/src/renderer/src/components/mode-toggle.tsx +31 -0
- package/template/src/renderer/src/components/theme-provider.tsx +140 -0
- package/template/src/renderer/src/components/ui/button.tsx +50 -0
- package/template/src/renderer/src/components/ui/dropdown-menu.tsx +188 -0
- package/template/src/renderer/src/components/use-theme.ts +12 -0
- package/template/src/renderer/src/hooks/use-sample.ts +7 -0
- package/template/src/renderer/src/i18n/index.ts +27 -0
- package/template/src/renderer/src/i18n/locales/en.json +8 -0
- package/template/src/renderer/src/i18n/locales/fr.json +8 -0
- package/template/src/renderer/src/index.css +59 -0
- package/template/src/renderer/src/lib/utils.ts +6 -0
- package/template/src/renderer/src/main.tsx +66 -0
- package/template/src/renderer/src/stores/app-store.ts +20 -0
- package/template/tailwind.config.js +53 -0
- package/template/template-package.json +57 -0
- package/template/tsconfig.json +7 -0
- package/template/tsconfig.node.json +20 -0
- package/template/tsconfig.web.json +25 -0
- package/template/vitest.config.ts +17 -0
- package/tests/renderer/sample.test.ts +7 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +20 -0
- package/tsconfig.web.json +25 -0
- package/vitest.config.ts +17 -0
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "electron-vite-react-template",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Electron + Vite + React template with TypeScript",
|
|
5
|
+
"main": "./out/main/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"author": "Nesalia",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"dev": "electron-vite dev",
|
|
11
|
+
"build": "electron-vite build",
|
|
12
|
+
"preview": "electron-vite preview",
|
|
13
|
+
"lint": "eslint .",
|
|
14
|
+
"typecheck": "tsc --noEmit",
|
|
15
|
+
"test": "vitest run",
|
|
16
|
+
"test:ui": "vitest"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@electron-toolkit/preload": "^3.0.1",
|
|
20
|
+
"@electron-toolkit/utils": "^3.0.0",
|
|
21
|
+
"@radix-ui/react-dropdown-menu": "^2.1.2",
|
|
22
|
+
"@radix-ui/react-slot": "^1.1.0",
|
|
23
|
+
"@tanstack/react-query": "^5.59.0",
|
|
24
|
+
"@tanstack/react-router": "^1.44.0",
|
|
25
|
+
"class-variance-authority": "^0.7.0",
|
|
26
|
+
"clsx": "^2.1.1",
|
|
27
|
+
"electron-log": "^5.2.4",
|
|
28
|
+
"i18next": "^23.15.1",
|
|
29
|
+
"lucide-react": "^0.447.0",
|
|
30
|
+
"react": "^18.3.1",
|
|
31
|
+
"react-dom": "^18.3.1",
|
|
32
|
+
"react-i18next": "^15.0.2",
|
|
33
|
+
"tailwind-merge": "^2.5.4",
|
|
34
|
+
"zustand": "^4.5.5"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@eslint/js": "^9.12.0",
|
|
38
|
+
"@types/node": "^22.7.4",
|
|
39
|
+
"@types/react": "^18.3.11",
|
|
40
|
+
"@types/react-dom": "^18.3.0",
|
|
41
|
+
"@vitejs/plugin-react": "^4.3.2",
|
|
42
|
+
"autoprefixer": "^10.4.20",
|
|
43
|
+
"electron": "^32.1.2",
|
|
44
|
+
"electron-vite": "^2.3.0",
|
|
45
|
+
"eslint": "^9.12.0",
|
|
46
|
+
"eslint-plugin-react-hooks": "^5.0.0",
|
|
47
|
+
"eslint-plugin-react-refresh": "^0.4.13",
|
|
48
|
+
"globals": "^15.10.0",
|
|
49
|
+
"jsdom": "^28.1.0",
|
|
50
|
+
"postcss": "^8.4.47",
|
|
51
|
+
"tailwindcss": "^3.4.13",
|
|
52
|
+
"typescript": "^5.6.2",
|
|
53
|
+
"typescript-eslint": "^8.8.0",
|
|
54
|
+
"vite": "^5.4.8",
|
|
55
|
+
"vitest": "^2.1.2"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { app, shell, BrowserWindow, nativeTheme, ipcMain } from 'electron'
|
|
2
|
+
import { join } from 'path'
|
|
3
|
+
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
|
|
4
|
+
import log from 'electron-log/main.js'
|
|
5
|
+
|
|
6
|
+
// Initialize logging
|
|
7
|
+
log.initialize()
|
|
8
|
+
log.transports.file.level = 'info'
|
|
9
|
+
log.transports.console.level = 'debug'
|
|
10
|
+
|
|
11
|
+
// Log app start
|
|
12
|
+
log.info('Application starting...')
|
|
13
|
+
log.info(`Electron version: ${process.versions.electron}`)
|
|
14
|
+
log.info(`Chrome version: ${process.versions.chrome}`)
|
|
15
|
+
log.info(`Node version: ${process.versions.node}`)
|
|
16
|
+
|
|
17
|
+
function createWindow(): void {
|
|
18
|
+
log.info('Creating main window...')
|
|
19
|
+
|
|
20
|
+
const mainWindow = new BrowserWindow({
|
|
21
|
+
width: 1200,
|
|
22
|
+
height: 800,
|
|
23
|
+
minWidth: 800,
|
|
24
|
+
minHeight: 600,
|
|
25
|
+
show: false,
|
|
26
|
+
autoHideMenuBar: false,
|
|
27
|
+
webPreferences: {
|
|
28
|
+
preload: join(__dirname, '../preload/index.js'),
|
|
29
|
+
sandbox: false,
|
|
30
|
+
contextIsolation: true,
|
|
31
|
+
nodeIntegration: false
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
mainWindow.on('ready-to-show', () => {
|
|
36
|
+
log.info('Window ready to show')
|
|
37
|
+
mainWindow.show()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
mainWindow.webContents.setWindowOpenHandler((details) => {
|
|
41
|
+
shell.openExternal(details.url)
|
|
42
|
+
return { action: 'deny' }
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// Load the app
|
|
46
|
+
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
|
|
47
|
+
log.info(`Loading dev URL: ${process.env['ELECTRON_RENDERER_URL']}`)
|
|
48
|
+
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
|
|
49
|
+
} else {
|
|
50
|
+
log.info('Loading production build')
|
|
51
|
+
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Listen for system theme changes
|
|
56
|
+
nativeTheme.on('updated', () => {
|
|
57
|
+
const theme = nativeTheme.shouldUseDarkColors ? 'dark' : 'light'
|
|
58
|
+
log.info(`System theme changed to: ${theme}`)
|
|
59
|
+
// Broadcast to all windows
|
|
60
|
+
BrowserWindow.getAllWindows().forEach((window) => {
|
|
61
|
+
window.webContents.send('theme-changed', theme)
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
// Handle uncaught exceptions
|
|
66
|
+
process.on('uncaughtException', (error) => {
|
|
67
|
+
log.error('Uncaught exception:', error)
|
|
68
|
+
app.quit()
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
process.on('unhandledRejection', (reason) => {
|
|
72
|
+
log.error('Unhandled rejection:', reason)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
// App lifecycle
|
|
76
|
+
app.whenReady().then(() => {
|
|
77
|
+
log.info('App ready')
|
|
78
|
+
|
|
79
|
+
// Set app user model id for windows
|
|
80
|
+
electronApp.setAppUserModelId('com.nesalia.electron-vite-react-template')
|
|
81
|
+
|
|
82
|
+
// Default open or close DevTools by F12 in development
|
|
83
|
+
// and ignore CommandOrControl + R in production
|
|
84
|
+
app.on('browser-window-created', (_, window) => {
|
|
85
|
+
optimizer.watchWindowShortcuts(window)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
createWindow()
|
|
89
|
+
|
|
90
|
+
app.on('activate', () => {
|
|
91
|
+
// On macOS it's common to re-create a window in the app
|
|
92
|
+
// when the dock icon is clicked and there are no other windows open
|
|
93
|
+
if (BrowserWindow.getAllWindows().length === 0) {
|
|
94
|
+
createWindow()
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// Quit when all windows are closed, except on macOS
|
|
100
|
+
app.on('window-all-closed', () => {
|
|
101
|
+
log.info('All windows closed')
|
|
102
|
+
if (process.platform !== 'darwin') {
|
|
103
|
+
app.quit()
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
// IPC handlers for theme
|
|
108
|
+
ipcMain.handle('get-system-theme', () => {
|
|
109
|
+
return nativeTheme.shouldUseDarkColors ? 'dark' : 'light'
|
|
110
|
+
})
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { contextBridge, ipcRenderer } from 'electron'
|
|
2
|
+
import { electronAPI } from '@electron-toolkit/preload'
|
|
3
|
+
|
|
4
|
+
// Custom APIs for renderer
|
|
5
|
+
const api = {
|
|
6
|
+
// Theme
|
|
7
|
+
getSystemTheme: (): Promise<'dark' | 'light'> => ipcRenderer.invoke('get-system-theme'),
|
|
8
|
+
onThemeChange: (callback: (theme: 'dark' | 'light') => void): (() => void) => {
|
|
9
|
+
const handler = (_event: Electron.IpcRendererEvent, theme: 'dark' | 'light'): void => {
|
|
10
|
+
callback(theme)
|
|
11
|
+
}
|
|
12
|
+
ipcRenderer.on('theme-changed', handler)
|
|
13
|
+
return () => {
|
|
14
|
+
ipcRenderer.removeListener('theme-changed', handler)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Use `contextBridge` APIs to expose Electron APIs to
|
|
20
|
+
// renderer only if context isolation is enabled
|
|
21
|
+
if (process.contextIsolated) {
|
|
22
|
+
try {
|
|
23
|
+
contextBridge.exposeInMainWorld('electron', electronAPI)
|
|
24
|
+
contextBridge.exposeInMainWorld('api', api)
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(error)
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
// @ts-expect-error (define in dts)
|
|
30
|
+
window.electron = electronAPI
|
|
31
|
+
// @ts-expect-error (define in dts)
|
|
32
|
+
window.api = api
|
|
33
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
interface Window {
|
|
4
|
+
electron: {
|
|
5
|
+
ipcRenderer: {
|
|
6
|
+
send: (channel: string, ...args: unknown[]) => void
|
|
7
|
+
on: (channel: string, func: (...args: unknown[]) => void) => void
|
|
8
|
+
removeListener: (channel: string, func: (...args: unknown[]) => void) => void
|
|
9
|
+
invoke: <T = unknown>(channel: string, ...args: unknown[]) => Promise<T>
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
api: {
|
|
13
|
+
getSystemTheme: () => Promise<'dark' | 'light'>
|
|
14
|
+
onThemeChange: (callback: (theme: 'dark' | 'light') => void) => () => void
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<meta
|
|
7
|
+
http-equiv="Content-Security-Policy"
|
|
8
|
+
content="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'"
|
|
9
|
+
/>
|
|
10
|
+
<title>Electron Vite React Template</title>
|
|
11
|
+
</head>
|
|
12
|
+
<body>
|
|
13
|
+
<div id="root"></div>
|
|
14
|
+
<script type="module" src="./src/main.tsx"></script>
|
|
15
|
+
</body>
|
|
16
|
+
</html>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Moon, Sun } from 'lucide-react'
|
|
2
|
+
|
|
3
|
+
import { Button } from './ui/button'
|
|
4
|
+
import {
|
|
5
|
+
DropdownMenu,
|
|
6
|
+
DropdownMenuContent,
|
|
7
|
+
DropdownMenuItem,
|
|
8
|
+
DropdownMenuTrigger
|
|
9
|
+
} from './ui/dropdown-menu'
|
|
10
|
+
import { useTheme } from './use-theme'
|
|
11
|
+
|
|
12
|
+
export function ModeToggle(): JSX.Element {
|
|
13
|
+
const { setTheme } = useTheme()
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<DropdownMenu>
|
|
17
|
+
<DropdownMenuTrigger asChild>
|
|
18
|
+
<Button variant="outline" size="icon" className="relative">
|
|
19
|
+
<Sun className="h-[1.2rem] w-[1.2rem] scale-100 rotate-0 transition-all dark:scale-0 dark:-rotate-90" />
|
|
20
|
+
<Moon className="absolute h-[1.2rem] w-[1.2rem] scale-0 rotate-90 transition-all dark:scale-100 dark:rotate-0" />
|
|
21
|
+
<span className="sr-only">Toggle theme</span>
|
|
22
|
+
</Button>
|
|
23
|
+
</DropdownMenuTrigger>
|
|
24
|
+
<DropdownMenuContent align="end">
|
|
25
|
+
<DropdownMenuItem onClick={() => setTheme('light')}>Light</DropdownMenuItem>
|
|
26
|
+
<DropdownMenuItem onClick={() => setTheme('dark')}>Dark</DropdownMenuItem>
|
|
27
|
+
<DropdownMenuItem onClick={() => setTheme('system')}>System</DropdownMenuItem>
|
|
28
|
+
</DropdownMenuContent>
|
|
29
|
+
</DropdownMenu>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createContext, useEffect, useState, type ReactNode } from 'react'
|
|
2
|
+
|
|
3
|
+
export type Theme = 'dark' | 'light' | 'system'
|
|
4
|
+
|
|
5
|
+
export type ThemeProviderProps = {
|
|
6
|
+
children: ReactNode
|
|
7
|
+
defaultTheme?: Theme
|
|
8
|
+
storageKey?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type ThemeProviderState = {
|
|
12
|
+
theme: Theme
|
|
13
|
+
setTheme: (theme: Theme) => void
|
|
14
|
+
actualTheme: 'dark' | 'light'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const initialState: ThemeProviderState = {
|
|
18
|
+
theme: 'system',
|
|
19
|
+
setTheme: () => null,
|
|
20
|
+
actualTheme: 'light'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const ThemeProviderContext = createContext<ThemeProviderState>(initialState)
|
|
24
|
+
|
|
25
|
+
export function ThemeProvider({
|
|
26
|
+
children,
|
|
27
|
+
defaultTheme = 'system',
|
|
28
|
+
storageKey = 'vite-ui-theme'
|
|
29
|
+
}: ThemeProviderProps): JSX.Element {
|
|
30
|
+
const [theme, setThemeState] = useState<Theme>(() => {
|
|
31
|
+
const stored = localStorage.getItem(storageKey)
|
|
32
|
+
return (stored as Theme) || defaultTheme
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const [actualTheme, setActualTheme] = useState<'dark' | 'light'>('light')
|
|
36
|
+
|
|
37
|
+
// Get initial system theme from Electron
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const getSystemTheme = async (): Promise<void> => {
|
|
40
|
+
try {
|
|
41
|
+
if (window.api?.getSystemTheme) {
|
|
42
|
+
const systemTheme = await window.api.getSystemTheme()
|
|
43
|
+
setActualTheme(systemTheme)
|
|
44
|
+
} else {
|
|
45
|
+
// Fallback for browser
|
|
46
|
+
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
47
|
+
setActualTheme(isDark ? 'dark' : 'light')
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
51
|
+
setActualTheme(isDark ? 'dark' : 'light')
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getSystemTheme()
|
|
56
|
+
}, [])
|
|
57
|
+
|
|
58
|
+
// Listen for system theme changes from Electron
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
let unsubscribe: (() => void) | undefined
|
|
61
|
+
|
|
62
|
+
const initThemeListener = async (): Promise<void> => {
|
|
63
|
+
if (window.api?.onThemeChange) {
|
|
64
|
+
unsubscribe = window.api.onThemeChange((newTheme) => {
|
|
65
|
+
if (theme === 'system') {
|
|
66
|
+
setActualTheme(newTheme)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
initThemeListener()
|
|
73
|
+
|
|
74
|
+
// Also listen to browser media query changes as fallback
|
|
75
|
+
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
|
76
|
+
const handleChange = (e: MediaQueryListEvent): void => {
|
|
77
|
+
if (theme === 'system') {
|
|
78
|
+
setActualTheme(e.matches ? 'dark' : 'light')
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
mediaQuery.addEventListener('change', handleChange)
|
|
82
|
+
|
|
83
|
+
return () => {
|
|
84
|
+
mediaQuery.removeEventListener('change', handleChange)
|
|
85
|
+
if (unsubscribe) {
|
|
86
|
+
unsubscribe()
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}, [theme])
|
|
90
|
+
|
|
91
|
+
// Apply theme to document
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
const root = window.document.documentElement
|
|
94
|
+
|
|
95
|
+
root.classList.remove('light', 'dark')
|
|
96
|
+
|
|
97
|
+
if (theme === 'system') {
|
|
98
|
+
root.classList.add(actualTheme)
|
|
99
|
+
return
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
root.classList.add(theme)
|
|
103
|
+
setActualTheme(theme === 'dark' ? 'dark' : 'light')
|
|
104
|
+
}, [theme, actualTheme])
|
|
105
|
+
|
|
106
|
+
const value = {
|
|
107
|
+
theme,
|
|
108
|
+
setTheme: (newTheme: Theme): void => {
|
|
109
|
+
localStorage.setItem(storageKey, newTheme)
|
|
110
|
+
setThemeState(newTheme)
|
|
111
|
+
|
|
112
|
+
// Update actualTheme immediately if not system
|
|
113
|
+
if (newTheme !== 'system') {
|
|
114
|
+
setActualTheme(newTheme === 'dark' ? 'dark' : 'light')
|
|
115
|
+
} else {
|
|
116
|
+
// Re-check system theme
|
|
117
|
+
const getSystemTheme = async (): Promise<void> => {
|
|
118
|
+
try {
|
|
119
|
+
if (window.api?.getSystemTheme) {
|
|
120
|
+
const systemTheme = await window.api.getSystemTheme()
|
|
121
|
+
setActualTheme(systemTheme)
|
|
122
|
+
} else {
|
|
123
|
+
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
124
|
+
setActualTheme(isDark ? 'dark' : 'light')
|
|
125
|
+
}
|
|
126
|
+
} catch {
|
|
127
|
+
const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
128
|
+
setActualTheme(isDark ? 'dark' : 'light')
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
getSystemTheme()
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
actualTheme
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<ThemeProviderContext.Provider value={value}>{children}</ThemeProviderContext.Provider>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import { Slot } from '@radix-ui/react-slot'
|
|
3
|
+
import { cva, type VariantProps } from 'class-variance-authority'
|
|
4
|
+
|
|
5
|
+
import { cn } from '@/lib/utils'
|
|
6
|
+
|
|
7
|
+
const buttonVariants = cva(
|
|
8
|
+
'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
|
|
13
|
+
destructive: 'bg-destructive text-destructive-foreground hover:bg-destructive/90',
|
|
14
|
+
outline:
|
|
15
|
+
'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
|
|
16
|
+
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
|
17
|
+
ghost: 'hover:bg-accent hover:text-accent-foreground',
|
|
18
|
+
link: 'text-primary underline-offset-4 hover:underline'
|
|
19
|
+
},
|
|
20
|
+
size: {
|
|
21
|
+
default: 'h-10 px-4 py-2',
|
|
22
|
+
sm: 'h-9 rounded-md px-3',
|
|
23
|
+
lg: 'h-11 rounded-md px-8',
|
|
24
|
+
icon: 'h-10 w-10'
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
defaultVariants: {
|
|
28
|
+
variant: 'default',
|
|
29
|
+
size: 'default'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
export interface ButtonProps
|
|
35
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
36
|
+
VariantProps<typeof buttonVariants> {
|
|
37
|
+
asChild?: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
|
|
41
|
+
({ className, variant, size, asChild = false, ...props }, ref) => {
|
|
42
|
+
const Comp = asChild ? Slot : 'button'
|
|
43
|
+
return (
|
|
44
|
+
<Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
Button.displayName = 'Button'
|
|
49
|
+
|
|
50
|
+
export { Button, buttonVariants }
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu'
|
|
3
|
+
import { Check, ChevronRight, Circle } from 'lucide-react'
|
|
4
|
+
|
|
5
|
+
import { cn } from '@/lib/utils'
|
|
6
|
+
|
|
7
|
+
const DropdownMenu = DropdownMenuPrimitive.Root
|
|
8
|
+
|
|
9
|
+
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger
|
|
10
|
+
|
|
11
|
+
const DropdownMenuGroup = DropdownMenuPrimitive.Group
|
|
12
|
+
|
|
13
|
+
const DropdownMenuPortal = DropdownMenuPrimitive.Portal
|
|
14
|
+
|
|
15
|
+
const DropdownMenuSub = DropdownMenuPrimitive.Sub
|
|
16
|
+
|
|
17
|
+
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup
|
|
18
|
+
|
|
19
|
+
const DropdownMenuSubTrigger = React.forwardRef<
|
|
20
|
+
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
|
|
21
|
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
|
|
22
|
+
inset?: boolean
|
|
23
|
+
}
|
|
24
|
+
>(({ className, inset, children, ...props }, ref) => (
|
|
25
|
+
<DropdownMenuPrimitive.SubTrigger
|
|
26
|
+
ref={ref}
|
|
27
|
+
className={cn(
|
|
28
|
+
'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent',
|
|
29
|
+
inset && 'pl-8',
|
|
30
|
+
className
|
|
31
|
+
)}
|
|
32
|
+
{...props}
|
|
33
|
+
>
|
|
34
|
+
{children}
|
|
35
|
+
<ChevronRight className="ml-auto h-4 w-4" />
|
|
36
|
+
</DropdownMenuPrimitive.SubTrigger>
|
|
37
|
+
))
|
|
38
|
+
DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName
|
|
39
|
+
|
|
40
|
+
const DropdownMenuSubContent = React.forwardRef<
|
|
41
|
+
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
|
|
42
|
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
|
|
43
|
+
>(({ className, ...props }, ref) => (
|
|
44
|
+
<DropdownMenuPrimitive.SubContent
|
|
45
|
+
ref={ref}
|
|
46
|
+
className={cn(
|
|
47
|
+
'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
|
48
|
+
className
|
|
49
|
+
)}
|
|
50
|
+
{...props}
|
|
51
|
+
/>
|
|
52
|
+
))
|
|
53
|
+
DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName
|
|
54
|
+
|
|
55
|
+
const DropdownMenuContent = React.forwardRef<
|
|
56
|
+
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
|
|
57
|
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
|
|
58
|
+
>(({ className, sideOffset = 4, ...props }, ref) => (
|
|
59
|
+
<DropdownMenuPrimitive.Portal>
|
|
60
|
+
<DropdownMenuPrimitive.Content
|
|
61
|
+
ref={ref}
|
|
62
|
+
sideOffset={sideOffset}
|
|
63
|
+
className={cn(
|
|
64
|
+
'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
|
65
|
+
className
|
|
66
|
+
)}
|
|
67
|
+
{...props}
|
|
68
|
+
/>
|
|
69
|
+
</DropdownMenuPrimitive.Portal>
|
|
70
|
+
))
|
|
71
|
+
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
|
|
72
|
+
|
|
73
|
+
const DropdownMenuItem = React.forwardRef<
|
|
74
|
+
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
|
|
75
|
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
|
|
76
|
+
inset?: boolean
|
|
77
|
+
}
|
|
78
|
+
>(({ className, inset, ...props }, ref) => (
|
|
79
|
+
<DropdownMenuPrimitive.Item
|
|
80
|
+
ref={ref}
|
|
81
|
+
className={cn(
|
|
82
|
+
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
83
|
+
inset && 'pl-8',
|
|
84
|
+
className
|
|
85
|
+
)}
|
|
86
|
+
{...props}
|
|
87
|
+
/>
|
|
88
|
+
))
|
|
89
|
+
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName
|
|
90
|
+
|
|
91
|
+
const DropdownMenuCheckboxItem = React.forwardRef<
|
|
92
|
+
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
|
|
93
|
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
|
|
94
|
+
>(({ className, children, checked, ...props }, ref) => (
|
|
95
|
+
<DropdownMenuPrimitive.CheckboxItem
|
|
96
|
+
ref={ref}
|
|
97
|
+
className={cn(
|
|
98
|
+
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
99
|
+
className
|
|
100
|
+
)}
|
|
101
|
+
checked={checked}
|
|
102
|
+
{...props}
|
|
103
|
+
>
|
|
104
|
+
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
105
|
+
<DropdownMenuPrimitive.ItemIndicator>
|
|
106
|
+
<Check className="h-4 w-4" />
|
|
107
|
+
</DropdownMenuPrimitive.ItemIndicator>
|
|
108
|
+
</span>
|
|
109
|
+
{children}
|
|
110
|
+
</DropdownMenuPrimitive.CheckboxItem>
|
|
111
|
+
))
|
|
112
|
+
DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName
|
|
113
|
+
|
|
114
|
+
const DropdownMenuRadioItem = React.forwardRef<
|
|
115
|
+
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
|
|
116
|
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
|
|
117
|
+
>(({ className, children, ...props }, ref) => (
|
|
118
|
+
<DropdownMenuPrimitive.RadioItem
|
|
119
|
+
ref={ref}
|
|
120
|
+
className={cn(
|
|
121
|
+
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
122
|
+
className
|
|
123
|
+
)}
|
|
124
|
+
{...props}
|
|
125
|
+
>
|
|
126
|
+
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
|
|
127
|
+
<DropdownMenuPrimitive.ItemIndicator>
|
|
128
|
+
<Circle className="h-2 w-2 fill-current" />
|
|
129
|
+
</DropdownMenuPrimitive.ItemIndicator>
|
|
130
|
+
</span>
|
|
131
|
+
{children}
|
|
132
|
+
</DropdownMenuPrimitive.RadioItem>
|
|
133
|
+
))
|
|
134
|
+
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName
|
|
135
|
+
|
|
136
|
+
const DropdownMenuLabel = React.forwardRef<
|
|
137
|
+
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
|
|
138
|
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
|
|
139
|
+
inset?: boolean
|
|
140
|
+
}
|
|
141
|
+
>(({ className, inset, ...props }, ref) => (
|
|
142
|
+
<DropdownMenuPrimitive.Label
|
|
143
|
+
ref={ref}
|
|
144
|
+
className={cn('px-2 py-1.5 text-sm font-semibold', inset && 'pl-8', className)}
|
|
145
|
+
{...props}
|
|
146
|
+
/>
|
|
147
|
+
))
|
|
148
|
+
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName
|
|
149
|
+
|
|
150
|
+
const DropdownMenuSeparator = React.forwardRef<
|
|
151
|
+
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
|
|
152
|
+
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
|
|
153
|
+
>(({ className, ...props }, ref) => (
|
|
154
|
+
<DropdownMenuPrimitive.Separator
|
|
155
|
+
ref={ref}
|
|
156
|
+
className={cn('-mx-1 my-1 h-px bg-muted', className)}
|
|
157
|
+
{...props}
|
|
158
|
+
/>
|
|
159
|
+
))
|
|
160
|
+
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName
|
|
161
|
+
|
|
162
|
+
const DropdownMenuShortcut = ({
|
|
163
|
+
className,
|
|
164
|
+
...props
|
|
165
|
+
}: React.HTMLAttributes<HTMLSpanElement>): JSX.Element => {
|
|
166
|
+
return (
|
|
167
|
+
<span className={cn('ml-auto text-xs tracking-widest opacity-60', className)} {...props} />
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
DropdownMenuShortcut.displayName = 'DropdownMenuShortcut'
|
|
171
|
+
|
|
172
|
+
export {
|
|
173
|
+
DropdownMenu,
|
|
174
|
+
DropdownMenuTrigger,
|
|
175
|
+
DropdownMenuContent,
|
|
176
|
+
DropdownMenuItem,
|
|
177
|
+
DropdownMenuCheckboxItem,
|
|
178
|
+
DropdownMenuRadioItem,
|
|
179
|
+
DropdownMenuLabel,
|
|
180
|
+
DropdownMenuSeparator,
|
|
181
|
+
DropdownMenuShortcut,
|
|
182
|
+
DropdownMenuGroup,
|
|
183
|
+
DropdownMenuPortal,
|
|
184
|
+
DropdownMenuSub,
|
|
185
|
+
DropdownMenuSubContent,
|
|
186
|
+
DropdownMenuSubTrigger,
|
|
187
|
+
DropdownMenuRadioGroup
|
|
188
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useContext } from 'react'
|
|
2
|
+
import { ThemeProviderContext, type ThemeProviderState } from './theme-provider'
|
|
3
|
+
|
|
4
|
+
export const useTheme = (): ThemeProviderState => {
|
|
5
|
+
const context = useContext(ThemeProviderContext)
|
|
6
|
+
|
|
7
|
+
if (context === undefined) {
|
|
8
|
+
throw new Error('useTheme must be used within a ThemeProvider')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return context
|
|
12
|
+
}
|