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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import i18n from 'i18next'
|
|
2
|
+
import { initReactI18next } from 'react-i18next'
|
|
3
|
+
import en from './locales/en.json'
|
|
4
|
+
import fr from './locales/fr.json'
|
|
5
|
+
|
|
6
|
+
// Get system locale
|
|
7
|
+
const getSystemLocale = (): string => {
|
|
8
|
+
if (typeof navigator !== 'undefined') {
|
|
9
|
+
const lang = navigator.language || 'en'
|
|
10
|
+
return lang.split('-')[0]
|
|
11
|
+
}
|
|
12
|
+
return 'en'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
i18n.use(initReactI18next).init({
|
|
16
|
+
resources: {
|
|
17
|
+
en: { translation: en },
|
|
18
|
+
fr: { translation: fr }
|
|
19
|
+
},
|
|
20
|
+
lng: getSystemLocale(),
|
|
21
|
+
fallbackLng: 'en',
|
|
22
|
+
interpolation: {
|
|
23
|
+
escapeValue: false
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export default i18n
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
@tailwind base;
|
|
2
|
+
@tailwind components;
|
|
3
|
+
@tailwind utilities;
|
|
4
|
+
|
|
5
|
+
@layer base {
|
|
6
|
+
:root {
|
|
7
|
+
--background: 0 0% 100%;
|
|
8
|
+
--foreground: 222.2 84% 4.9%;
|
|
9
|
+
--card: 0 0% 100%;
|
|
10
|
+
--card-foreground: 222.2 84% 4.9%;
|
|
11
|
+
--popover: 0 0% 100%;
|
|
12
|
+
--popover-foreground: 222.2 84% 4.9%;
|
|
13
|
+
--primary: 222.2 47.4% 11.2%;
|
|
14
|
+
--primary-foreground: 210 40% 98%;
|
|
15
|
+
--secondary: 210 40% 96.1%;
|
|
16
|
+
--secondary-foreground: 222.2 47.4% 11.2%;
|
|
17
|
+
--muted: 210 40% 96.1%;
|
|
18
|
+
--muted-foreground: 215.4 16.3% 46.9%;
|
|
19
|
+
--accent: 210 40% 96.1%;
|
|
20
|
+
--accent-foreground: 222.2 47.4% 11.2%;
|
|
21
|
+
--destructive: 0 84.2% 60.2%;
|
|
22
|
+
--destructive-foreground: 210 40% 98%;
|
|
23
|
+
--border: 214.3 31.8% 91.4%;
|
|
24
|
+
--input: 214.3 31.8% 91.4%;
|
|
25
|
+
--ring: 222.2 84% 4.9%;
|
|
26
|
+
--radius: 0.5rem;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.dark {
|
|
30
|
+
--background: 222.2 84% 4.9%;
|
|
31
|
+
--foreground: 210 40% 98%;
|
|
32
|
+
--card: 222.2 84% 4.9%;
|
|
33
|
+
--card-foreground: 210 40% 98%;
|
|
34
|
+
--popover: 222.2 84% 4.9%;
|
|
35
|
+
--popover-foreground: 210 40% 98%;
|
|
36
|
+
--primary: 210 40% 98%;
|
|
37
|
+
--primary-foreground: 222.2 47.4% 11.2%;
|
|
38
|
+
--secondary: 217.2 32.6% 17.5%;
|
|
39
|
+
--secondary-foreground: 210 40% 98%;
|
|
40
|
+
--muted: 217.2 32.6% 17.5%;
|
|
41
|
+
--muted-foreground: 215 20.2% 65.1%;
|
|
42
|
+
--accent: 217.2 32.6% 17.5%;
|
|
43
|
+
--accent-foreground: 210 40% 98%;
|
|
44
|
+
--destructive: 0 62.8% 30.6%;
|
|
45
|
+
--destructive-foreground: 210 40% 98%;
|
|
46
|
+
--border: 217.2 32.6% 17.5%;
|
|
47
|
+
--input: 217.2 32.6% 17.5%;
|
|
48
|
+
--ring: 212.7 26.8% 83.9%;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@layer base {
|
|
53
|
+
* {
|
|
54
|
+
@apply border-border;
|
|
55
|
+
}
|
|
56
|
+
body {
|
|
57
|
+
@apply bg-background text-foreground;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import './index.css'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
import ReactDOM from 'react-dom/client'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import { ThemeProvider } from './components/theme-provider'
|
|
6
|
+
import { RouterProvider, createRouter, createRootRoute, createRoute, Outlet } from '@tanstack/react-router'
|
|
7
|
+
import './i18n'
|
|
8
|
+
|
|
9
|
+
const queryClient = new QueryClient({
|
|
10
|
+
defaultOptions: {
|
|
11
|
+
queries: {
|
|
12
|
+
staleTime: 5 * 60 * 1000
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// Define routes
|
|
18
|
+
const rootRoute = createRootRoute({
|
|
19
|
+
component: () => (
|
|
20
|
+
<div className="min-h-screen bg-background text-foreground">
|
|
21
|
+
<header className="border-b">
|
|
22
|
+
<div className="container mx-auto flex items-center justify-between p-4">
|
|
23
|
+
<h1 className="text-2xl font-bold">Electron Vite React Template</h1>
|
|
24
|
+
</div>
|
|
25
|
+
</header>
|
|
26
|
+
<main className="container mx-auto p-4">
|
|
27
|
+
<Outlet />
|
|
28
|
+
</main>
|
|
29
|
+
</div>
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const indexRoute = createRoute({
|
|
34
|
+
getParentRoute: () => rootRoute,
|
|
35
|
+
path: '/',
|
|
36
|
+
component: function Index() {
|
|
37
|
+
return <p>Welcome to your Electron app!</p>
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
const routeTree = rootRoute.addChildren([indexRoute])
|
|
42
|
+
|
|
43
|
+
const router = createRouter({
|
|
44
|
+
routeTree,
|
|
45
|
+
context: {
|
|
46
|
+
queryClient
|
|
47
|
+
},
|
|
48
|
+
defaultPreload: 'intent'
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// Declare router for type-safe routing
|
|
52
|
+
declare module '@tanstack/react-router' {
|
|
53
|
+
interface Register {
|
|
54
|
+
router: typeof router
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
59
|
+
<React.StrictMode>
|
|
60
|
+
<QueryClientProvider client={queryClient}>
|
|
61
|
+
<ThemeProvider defaultTheme="system" storageKey="vite-ui-theme">
|
|
62
|
+
<RouterProvider router={router} />
|
|
63
|
+
</ThemeProvider>
|
|
64
|
+
</QueryClientProvider>
|
|
65
|
+
</React.StrictMode>
|
|
66
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { create } from 'zustand'
|
|
2
|
+
import { persist } from 'zustand/middleware'
|
|
3
|
+
|
|
4
|
+
interface AppState {
|
|
5
|
+
// User preferences
|
|
6
|
+
language: string
|
|
7
|
+
setLanguage: (language: string) => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const useAppStore = create<AppState>()(
|
|
11
|
+
persist(
|
|
12
|
+
(set) => ({
|
|
13
|
+
language: 'en',
|
|
14
|
+
setLanguage: (language) => set({ language })
|
|
15
|
+
}),
|
|
16
|
+
{
|
|
17
|
+
name: 'app-storage'
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** @type {import('tailwindcss').Config} */
|
|
2
|
+
export default {
|
|
3
|
+
darkMode: ['class'],
|
|
4
|
+
content: [
|
|
5
|
+
'./src/renderer/index.html',
|
|
6
|
+
'./src/renderer/src/**/*.{js,ts,jsx,tsx}'
|
|
7
|
+
],
|
|
8
|
+
theme: {
|
|
9
|
+
extend: {
|
|
10
|
+
colors: {
|
|
11
|
+
border: 'hsl(var(--border))',
|
|
12
|
+
input: 'hsl(var(--input))',
|
|
13
|
+
ring: 'hsl(var(--ring))',
|
|
14
|
+
background: 'hsl(var(--background))',
|
|
15
|
+
foreground: 'hsl(var(--foreground))',
|
|
16
|
+
primary: {
|
|
17
|
+
DEFAULT: 'hsl(var(--primary))',
|
|
18
|
+
foreground: 'hsl(var(--primary-foreground))'
|
|
19
|
+
},
|
|
20
|
+
secondary: {
|
|
21
|
+
DEFAULT: 'hsl(var(--secondary))',
|
|
22
|
+
foreground: 'hsl(var(--secondary-foreground))'
|
|
23
|
+
},
|
|
24
|
+
destructive: {
|
|
25
|
+
DEFAULT: 'hsl(var(--destructive))',
|
|
26
|
+
foreground: 'hsl(var(--destructive-foreground))'
|
|
27
|
+
},
|
|
28
|
+
muted: {
|
|
29
|
+
DEFAULT: 'hsl(var(--muted))',
|
|
30
|
+
foreground: 'hsl(var(--muted-foreground))'
|
|
31
|
+
},
|
|
32
|
+
accent: {
|
|
33
|
+
DEFAULT: 'hsl(var(--accent))',
|
|
34
|
+
foreground: 'hsl(var(--accent-foreground))'
|
|
35
|
+
},
|
|
36
|
+
popover: {
|
|
37
|
+
DEFAULT: 'hsl(var(--popover))',
|
|
38
|
+
foreground: 'hsl(var(--popover-foreground))'
|
|
39
|
+
},
|
|
40
|
+
card: {
|
|
41
|
+
DEFAULT: 'hsl(var(--card))',
|
|
42
|
+
foreground: 'hsl(var(--card-foreground))'
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
borderRadius: {
|
|
46
|
+
lg: 'var(--radius)',
|
|
47
|
+
md: 'calc(var(--radius) - 2px)',
|
|
48
|
+
sm: 'calc(var(--radius) - 4px)'
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
plugins: []
|
|
53
|
+
}
|