doo-boilerplate 0.1.12 → 0.1.13
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/package.json +1 -1
- package/templates/template-nextjs/src/components/common/theme-toggle.tsx +18 -6
- package/templates/template-nextjs/src/components/layout/header.tsx +26 -19
- package/templates/template-nextjs/src/styles/globals.css +21 -0
- package/templates/template-vite/src/components/common/theme-toggle.tsx +18 -6
- package/templates/template-vite/src/components/layout/header.tsx +33 -19
- package/templates/template-vite/src/styles/globals.css +21 -0
package/package.json
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
+
import { useCallback } from 'react'
|
|
3
4
|
import { useTheme } from 'next-themes'
|
|
4
5
|
import { Moon, Sun } from 'lucide-react'
|
|
5
6
|
|
|
6
7
|
import { Button } from '@/components/ui/button'
|
|
7
8
|
|
|
8
9
|
export function ThemeToggle() {
|
|
9
|
-
const {
|
|
10
|
+
const { resolvedTheme, setTheme } = useTheme()
|
|
11
|
+
|
|
12
|
+
const toggle = useCallback((e: React.MouseEvent) => {
|
|
13
|
+
const next = resolvedTheme === 'dark' ? 'light' : 'dark'
|
|
14
|
+
const root = document.documentElement
|
|
15
|
+
|
|
16
|
+
if (!document.startViewTransition) {
|
|
17
|
+
setTheme(next)
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
root.style.setProperty('--x', `${e.clientX}px`)
|
|
22
|
+
root.style.setProperty('--y', `${e.clientY}px`)
|
|
23
|
+
document.startViewTransition(() => setTheme(next))
|
|
24
|
+
}, [resolvedTheme, setTheme])
|
|
25
|
+
|
|
10
26
|
return (
|
|
11
|
-
<Button
|
|
12
|
-
variant='ghost'
|
|
13
|
-
size='icon'
|
|
14
|
-
onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
|
|
15
|
-
>
|
|
27
|
+
<Button variant='ghost' size='icon' onClick={toggle} aria-label='Toggle theme'>
|
|
16
28
|
<Sun className='h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0' />
|
|
17
29
|
<Moon className='absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100' />
|
|
18
30
|
<span className='sr-only'>Toggle theme</span>
|
|
@@ -8,6 +8,13 @@ import { useRouter } from 'next/navigation'
|
|
|
8
8
|
import { useSignOut } from '@/features/auth/hooks/use-auth'
|
|
9
9
|
import { useAuthStore } from '@/stores/auth-store'
|
|
10
10
|
import { ThemeToggle } from '@/components/common/theme-toggle'
|
|
11
|
+
import {
|
|
12
|
+
Select,
|
|
13
|
+
SelectContent,
|
|
14
|
+
SelectItem,
|
|
15
|
+
SelectTrigger,
|
|
16
|
+
SelectValue,
|
|
17
|
+
} from '@/components/ui/select'
|
|
11
18
|
|
|
12
19
|
import { Avatar, AvatarFallback } from '../ui/avatar'
|
|
13
20
|
import { Button } from '../ui/button'
|
|
@@ -22,8 +29,8 @@ import {
|
|
|
22
29
|
import { useSidebarStore } from './sidebar'
|
|
23
30
|
|
|
24
31
|
const LANGUAGES = [
|
|
25
|
-
{ code: 'en',
|
|
26
|
-
{ code: 'vi',
|
|
32
|
+
{ code: 'en', name: 'English', flag: '🇬🇧' },
|
|
33
|
+
{ code: 'vi', name: 'Tiếng Việt', flag: '🇻🇳' },
|
|
27
34
|
]
|
|
28
35
|
|
|
29
36
|
function getLangFromCookie(): string {
|
|
@@ -35,6 +42,7 @@ function getLangFromCookie(): string {
|
|
|
35
42
|
function LangSwitcher() {
|
|
36
43
|
const [locale, setLocale] = useState(getLangFromCookie)
|
|
37
44
|
const router = useRouter()
|
|
45
|
+
const current = LANGUAGES.find((l) => l.code === locale) ?? LANGUAGES[0]
|
|
38
46
|
|
|
39
47
|
function switchLocale(code: string) {
|
|
40
48
|
document.cookie = `NEXT_LOCALE=${code}; path=/; max-age=${365 * 24 * 60 * 60}`
|
|
@@ -43,24 +51,23 @@ function LangSwitcher() {
|
|
|
43
51
|
}
|
|
44
52
|
|
|
45
53
|
return (
|
|
46
|
-
<
|
|
47
|
-
<
|
|
48
|
-
<
|
|
49
|
-
{
|
|
50
|
-
</
|
|
51
|
-
</
|
|
52
|
-
<
|
|
53
|
-
{LANGUAGES.map(({ code,
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</DropdownMenuItem>
|
|
54
|
+
<Select value={current.code} onValueChange={switchLocale}>
|
|
55
|
+
<SelectTrigger className='h-8 w-auto gap-1 border-0 bg-transparent px-2 shadow-none focus:ring-0'>
|
|
56
|
+
<SelectValue>
|
|
57
|
+
<span>{current.flag}</span>
|
|
58
|
+
</SelectValue>
|
|
59
|
+
</SelectTrigger>
|
|
60
|
+
<SelectContent align='end'>
|
|
61
|
+
{LANGUAGES.map(({ code, name, flag }) => (
|
|
62
|
+
<SelectItem key={code} value={code}>
|
|
63
|
+
<div className='flex items-center gap-2'>
|
|
64
|
+
<span>{flag}</span>
|
|
65
|
+
<span>{name}</span>
|
|
66
|
+
</div>
|
|
67
|
+
</SelectItem>
|
|
61
68
|
))}
|
|
62
|
-
</
|
|
63
|
-
</
|
|
69
|
+
</SelectContent>
|
|
70
|
+
</Select>
|
|
64
71
|
)
|
|
65
72
|
}
|
|
66
73
|
|
|
@@ -63,3 +63,24 @@ body {
|
|
|
63
63
|
color: var(--color-foreground);
|
|
64
64
|
font-family: var(--font-sans);
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
/* View transition: circular reveal for theme toggle */
|
|
68
|
+
::view-transition-old(root),
|
|
69
|
+
::view-transition-new(root) {
|
|
70
|
+
animation: none;
|
|
71
|
+
mix-blend-mode: normal;
|
|
72
|
+
}
|
|
73
|
+
.dark::view-transition-old(root) {
|
|
74
|
+
z-index: 1;
|
|
75
|
+
}
|
|
76
|
+
.dark::view-transition-new(root) {
|
|
77
|
+
z-index: 999;
|
|
78
|
+
}
|
|
79
|
+
::view-transition-new(root) {
|
|
80
|
+
clip-path: circle(0% at var(--x, 50%) var(--y, 50%));
|
|
81
|
+
animation: theme-reveal 0.45s ease-in-out;
|
|
82
|
+
}
|
|
83
|
+
@keyframes theme-reveal {
|
|
84
|
+
from { clip-path: circle(0% at var(--x, 50%) var(--y, 50%)); }
|
|
85
|
+
to { clip-path: circle(150% at var(--x, 50%) var(--y, 50%)); }
|
|
86
|
+
}
|
|
@@ -1,16 +1,28 @@
|
|
|
1
|
+
import { useCallback } from 'react'
|
|
1
2
|
import { useTheme } from 'next-themes'
|
|
2
3
|
import { Moon, Sun } from 'lucide-react'
|
|
3
4
|
|
|
4
5
|
import { Button } from '@/components/ui/button'
|
|
5
6
|
|
|
6
7
|
export function ThemeToggle() {
|
|
7
|
-
const {
|
|
8
|
+
const { resolvedTheme, setTheme } = useTheme()
|
|
9
|
+
|
|
10
|
+
const toggle = useCallback((e: React.MouseEvent) => {
|
|
11
|
+
const next = resolvedTheme === 'dark' ? 'light' : 'dark'
|
|
12
|
+
const root = document.documentElement
|
|
13
|
+
|
|
14
|
+
if (!document.startViewTransition) {
|
|
15
|
+
setTheme(next)
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
root.style.setProperty('--x', `${e.clientX}px`)
|
|
20
|
+
root.style.setProperty('--y', `${e.clientY}px`)
|
|
21
|
+
document.startViewTransition(() => setTheme(next))
|
|
22
|
+
}, [resolvedTheme, setTheme])
|
|
23
|
+
|
|
8
24
|
return (
|
|
9
|
-
<Button
|
|
10
|
-
variant='ghost'
|
|
11
|
-
size='icon'
|
|
12
|
-
onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
|
|
13
|
-
>
|
|
25
|
+
<Button variant='ghost' size='icon' onClick={toggle} aria-label='Toggle theme'>
|
|
14
26
|
<Sun className='h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0' />
|
|
15
27
|
<Moon className='absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100' />
|
|
16
28
|
<span className='sr-only'>Toggle theme</span>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useTransition } from 'react'
|
|
1
2
|
import { LogOut, User } from 'lucide-react'
|
|
2
3
|
import { useTranslation } from 'react-i18next'
|
|
3
4
|
|
|
@@ -14,33 +15,46 @@ import {
|
|
|
14
15
|
DropdownMenuSeparator,
|
|
15
16
|
DropdownMenuTrigger,
|
|
16
17
|
} from '@/components/ui/dropdown-menu'
|
|
18
|
+
import {
|
|
19
|
+
Select,
|
|
20
|
+
SelectContent,
|
|
21
|
+
SelectItem,
|
|
22
|
+
SelectTrigger,
|
|
23
|
+
SelectValue,
|
|
24
|
+
} from '@/components/ui/select'
|
|
17
25
|
|
|
18
26
|
const LANGUAGES = [
|
|
19
|
-
{ code: 'en',
|
|
20
|
-
{ code: 'vi',
|
|
27
|
+
{ code: 'en', name: 'English', flag: '🇬🇧' },
|
|
28
|
+
{ code: 'vi', name: 'Tiếng Việt', flag: '🇻🇳' },
|
|
21
29
|
]
|
|
22
30
|
|
|
23
31
|
function LangSwitcher() {
|
|
24
32
|
const { i18n } = useTranslation()
|
|
33
|
+
const [isPending, startTransition] = useTransition()
|
|
34
|
+
const current = LANGUAGES.find((l) => l.code === i18n.language) ?? LANGUAGES[0]
|
|
35
|
+
|
|
25
36
|
return (
|
|
26
|
-
<
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
>
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
<Select
|
|
38
|
+
value={current.code}
|
|
39
|
+
onValueChange={(v) => startTransition(() => i18n.changeLanguage(v))}
|
|
40
|
+
disabled={isPending}
|
|
41
|
+
>
|
|
42
|
+
<SelectTrigger className='h-8 w-auto gap-1 border-0 bg-transparent px-2 shadow-none focus:ring-0'>
|
|
43
|
+
<SelectValue>
|
|
44
|
+
<span>{current.flag}</span>
|
|
45
|
+
</SelectValue>
|
|
46
|
+
</SelectTrigger>
|
|
47
|
+
<SelectContent align='end'>
|
|
48
|
+
{LANGUAGES.map(({ code, name, flag }) => (
|
|
49
|
+
<SelectItem key={code} value={code}>
|
|
50
|
+
<div className='flex items-center gap-2'>
|
|
51
|
+
<span>{flag}</span>
|
|
52
|
+
<span>{name}</span>
|
|
53
|
+
</div>
|
|
54
|
+
</SelectItem>
|
|
41
55
|
))}
|
|
42
|
-
</
|
|
43
|
-
</
|
|
56
|
+
</SelectContent>
|
|
57
|
+
</Select>
|
|
44
58
|
)
|
|
45
59
|
}
|
|
46
60
|
|
|
@@ -79,3 +79,24 @@
|
|
|
79
79
|
@apply bg-background text-foreground;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
+
|
|
83
|
+
/* View transition: circular reveal for theme toggle */
|
|
84
|
+
::view-transition-old(root),
|
|
85
|
+
::view-transition-new(root) {
|
|
86
|
+
animation: none;
|
|
87
|
+
mix-blend-mode: normal;
|
|
88
|
+
}
|
|
89
|
+
.dark::view-transition-old(root) {
|
|
90
|
+
z-index: 1;
|
|
91
|
+
}
|
|
92
|
+
.dark::view-transition-new(root) {
|
|
93
|
+
z-index: 999;
|
|
94
|
+
}
|
|
95
|
+
::view-transition-new(root) {
|
|
96
|
+
clip-path: circle(0% at var(--x, 50%) var(--y, 50%));
|
|
97
|
+
animation: theme-reveal 0.45s ease-in-out;
|
|
98
|
+
}
|
|
99
|
+
@keyframes theme-reveal {
|
|
100
|
+
from { clip-path: circle(0% at var(--x, 50%) var(--y, 50%)); }
|
|
101
|
+
to { clip-path: circle(150% at var(--x, 50%) var(--y, 50%)); }
|
|
102
|
+
}
|