create-mohit-next 0.0.0-stage → 2.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/README.md +139 -2
- package/index.js +399 -0
- package/lib/features.js +358 -0
- package/lib/scaffold.js +471 -0
- package/package.json +40 -4
- package/templates/common/_editorconfig +12 -0
- package/templates/common/_gitattributes +5 -0
- package/templates/common/_github/dependabot.yml +14 -0
- package/templates/common/_github/workflows/ci.yml +66 -0
- package/templates/common/_husky/commit-msg +1 -0
- package/templates/common/_husky/pre-commit +1 -0
- package/templates/common/_nvmrc +1 -0
- package/templates/common/_prettierignore +15 -0
- package/templates/common/commitlint.config.mjs +10 -0
- package/templates/next/AGENTS.md +9 -0
- package/templates/next/Dockerfile +48 -0
- package/templates/next/README.md +328 -0
- package/templates/next/_dockerignore +13 -0
- package/templates/next/_env.example +20 -0
- package/templates/next/_gitignore +50 -0
- package/templates/next/docker-compose.yml +33 -0
- package/templates/next/e2e/rbac.spec.ts +69 -0
- package/templates/next/e2e/server.mjs +35 -0
- package/templates/next/eslint.config.mjs +33 -0
- package/templates/next/next.config.ts +47 -0
- package/templates/next/package.json +68 -0
- package/templates/next/playwright.config.ts +30 -0
- package/templates/next/public/robots.txt +6 -0
- package/templates/next/scripts/seed.ts +111 -0
- package/templates/next/src/app/(app)/admin/audit/page.tsx +99 -0
- package/templates/next/src/app/(app)/admin/page.tsx +92 -0
- package/templates/next/src/app/(app)/dashboard/page.tsx +120 -0
- package/templates/next/src/app/(app)/error.tsx +28 -0
- package/templates/next/src/app/(app)/layout.tsx +58 -0
- package/templates/next/src/app/(app)/loading.tsx +5 -0
- package/templates/next/src/app/(app)/reports/page.tsx +128 -0
- package/templates/next/src/app/(app)/settings/page.tsx +66 -0
- package/templates/next/src/app/(auth)/forgot-password/page.tsx +17 -0
- package/templates/next/src/app/(auth)/layout.tsx +18 -0
- package/templates/next/src/app/(auth)/login/page.tsx +18 -0
- package/templates/next/src/app/(auth)/register/page.tsx +18 -0
- package/templates/next/src/app/(auth)/reset-password/page.tsx +18 -0
- package/templates/next/src/app/api/account/password/route.ts +45 -0
- package/templates/next/src/app/api/account/route.ts +25 -0
- package/templates/next/src/app/api/account/sessions/route.ts +12 -0
- package/templates/next/src/app/api/admin/audit/route.ts +13 -0
- package/templates/next/src/app/api/admin/users/[id]/route.ts +61 -0
- package/templates/next/src/app/api/admin/users/route.ts +18 -0
- package/templates/next/src/app/api/auth/forgot-password/route.ts +47 -0
- package/templates/next/src/app/api/auth/login/route.ts +43 -0
- package/templates/next/src/app/api/auth/logout/route.ts +21 -0
- package/templates/next/src/app/api/auth/me/route.ts +21 -0
- package/templates/next/src/app/api/auth/register/route.ts +74 -0
- package/templates/next/src/app/api/auth/resend-verification/route.ts +25 -0
- package/templates/next/src/app/api/auth/reset-password/route.ts +43 -0
- package/templates/next/src/app/api/auth/verify-email/route.ts +29 -0
- package/templates/next/src/app/api/health/route.ts +27 -0
- package/templates/next/src/app/favicon.ico +0 -0
- package/templates/next/src/app/forbidden/page.tsx +47 -0
- package/templates/next/src/app/layout.tsx +55 -0
- package/templates/next/src/app/not-found.tsx +20 -0
- package/templates/next/src/app/opengraph-image.tsx +49 -0
- package/templates/next/src/app/page.tsx +165 -0
- package/templates/next/src/app/robots.ts +15 -0
- package/templates/next/src/app/sitemap.ts +13 -0
- package/templates/next/src/app/verify-email/page.tsx +23 -0
- package/templates/next/src/components/admin/user-actions.tsx +124 -0
- package/templates/next/src/components/admin/users-data-table.tsx +221 -0
- package/templates/next/src/components/admin/users-table.tsx +67 -0
- package/templates/next/src/components/auth/auth-card.tsx +41 -0
- package/templates/next/src/components/auth/can.tsx +34 -0
- package/templates/next/src/components/auth/forgot-password-form.tsx +76 -0
- package/templates/next/src/components/auth/form-field.tsx +40 -0
- package/templates/next/src/components/auth/login-form.tsx +87 -0
- package/templates/next/src/components/auth/password-input.tsx +43 -0
- package/templates/next/src/components/auth/register-form.tsx +117 -0
- package/templates/next/src/components/auth/reset-password-form.tsx +80 -0
- package/templates/next/src/components/auth/session-refresher.tsx +44 -0
- package/templates/next/src/components/auth/verify-email-banner.tsx +43 -0
- package/templates/next/src/components/auth/verify-email-status.tsx +44 -0
- package/templates/next/src/components/layout/nav-links.tsx +37 -0
- package/templates/next/src/components/layout/navbar.tsx +27 -0
- package/templates/next/src/components/layout/page-header.tsx +21 -0
- package/templates/next/src/components/layout/sidebar.tsx +83 -0
- package/templates/next/src/components/layout/skeletons.tsx +57 -0
- package/templates/next/src/components/layout/user-menu.tsx +118 -0
- package/templates/next/src/components/logo.tsx +16 -0
- package/templates/next/src/components/motion/fade-in.tsx +19 -0
- package/templates/next/src/components/providers/user-provider.tsx +60 -0
- package/templates/next/src/components/reports/animated-bar.tsx +24 -0
- package/templates/next/src/components/reports/role-chart.tsx +61 -0
- package/templates/next/src/components/reports/signups-chart.tsx +64 -0
- package/templates/next/src/components/role-badge.tsx +11 -0
- package/templates/next/src/components/settings/password-form.tsx +80 -0
- package/templates/next/src/components/settings/profile-form.tsx +63 -0
- package/templates/next/src/components/settings/sessions-card.tsx +70 -0
- package/templates/next/src/components/theme-toggle.tsx +61 -0
- package/templates/next/src/config/rbac.test.ts +89 -0
- package/templates/next/src/config/rbac.ts +170 -0
- package/templates/next/src/config/site.ts +4 -0
- package/templates/next/src/lib/api.ts +179 -0
- package/templates/next/src/lib/audit.ts +66 -0
- package/templates/next/src/lib/auth.ts +50 -0
- package/templates/next/src/lib/dal.ts +63 -0
- package/templates/next/src/lib/db.ts +35 -0
- package/templates/next/src/lib/email-templates.ts +55 -0
- package/templates/next/src/lib/email.ts +53 -0
- package/templates/next/src/lib/env.ts +90 -0
- package/templates/next/src/lib/http.ts +57 -0
- package/templates/next/src/lib/password-strength.test.ts +20 -0
- package/templates/next/src/lib/password-strength.ts +24 -0
- package/templates/next/src/lib/rate-limit.test.ts +47 -0
- package/templates/next/src/lib/rate-limit.ts +70 -0
- package/templates/next/src/lib/redirect.test.ts +23 -0
- package/templates/next/src/lib/redirect.ts +21 -0
- package/templates/next/src/lib/session.ts +71 -0
- package/templates/next/src/lib/theme.ts +32 -0
- package/templates/next/src/lib/tokens.ts +63 -0
- package/templates/next/src/lib/users.ts +196 -0
- package/templates/next/src/lib/validations/account.ts +20 -0
- package/templates/next/src/lib/validations/auth.test.ts +39 -0
- package/templates/next/src/lib/validations/auth.ts +66 -0
- package/templates/next/src/lib/validations/user.ts +13 -0
- package/templates/next/src/models/audit-log.ts +33 -0
- package/templates/next/src/models/auth-token.ts +26 -0
- package/templates/next/src/models/user.ts +35 -0
- package/templates/next/src/proxy.ts +57 -0
- package/templates/next/src/styles/app.css +1092 -0
- package/templates/next/src/types/user.ts +13 -0
- package/templates/next/tsconfig.json +34 -0
- package/templates/next/vitest.config.mts +13 -0
- package/templates/styles/css.css +580 -0
- package/templates/styles/shadcn.css +142 -0
- package/templates/styles/tailwind.css +140 -0
- package/templates/ui/css/components/alert-dialog.tsx +172 -0
- package/templates/ui/css/components/avatar.tsx +17 -0
- package/templates/ui/css/components/badge.tsx +18 -0
- package/templates/ui/css/components/button.tsx +41 -0
- package/templates/ui/css/components/card.tsx +33 -0
- package/templates/ui/css/components/dropdown-menu.tsx +230 -0
- package/templates/ui/css/components/input.tsx +7 -0
- package/templates/ui/css/components/label.tsx +7 -0
- package/templates/ui/css/components/native-select.tsx +23 -0
- package/templates/ui/css/components/skeleton.tsx +7 -0
- package/templates/ui/css/components/slot.tsx +30 -0
- package/templates/ui/css/components/table.tsx +31 -0
- package/templates/ui/css/utils.ts +16 -0
- package/templates/ui/shadcn/components/alert-dialog.tsx +199 -0
- package/templates/ui/shadcn/components/avatar.tsx +111 -0
- package/templates/ui/shadcn/components/badge.tsx +44 -0
- package/templates/ui/shadcn/components/button.tsx +66 -0
- package/templates/ui/shadcn/components/card.tsx +87 -0
- package/templates/ui/shadcn/components/dropdown-menu.tsx +268 -0
- package/templates/ui/shadcn/components/input.tsx +18 -0
- package/templates/ui/shadcn/components/label.tsx +20 -0
- package/templates/ui/shadcn/components/native-select.tsx +54 -0
- package/templates/ui/shadcn/components/skeleton.tsx +13 -0
- package/templates/ui/shadcn/components/table.tsx +115 -0
- package/templates/ui/shadcn/utils.ts +1 -0
- package/templates/ui/tailwind/components/alert-dialog.tsx +177 -0
- package/templates/ui/tailwind/components/avatar.tsx +36 -0
- package/templates/ui/tailwind/components/badge.tsx +29 -0
- package/templates/ui/tailwind/components/button.tsx +65 -0
- package/templates/ui/tailwind/components/card.tsx +70 -0
- package/templates/ui/tailwind/components/dropdown-menu.tsx +236 -0
- package/templates/ui/tailwind/components/input.tsx +17 -0
- package/templates/ui/tailwind/components/label.tsx +16 -0
- package/templates/ui/tailwind/components/native-select.tsx +32 -0
- package/templates/ui/tailwind/components/skeleton.tsx +13 -0
- package/templates/ui/tailwind/components/slot.tsx +34 -0
- package/templates/ui/tailwind/components/table.tsx +56 -0
- package/templates/ui/tailwind/utils.ts +1 -0
- package/templates/vite/Dockerfile +29 -0
- package/templates/vite/README.md +142 -0
- package/templates/vite/_dockerignore +14 -0
- package/templates/vite/_env.example +8 -0
- package/templates/vite/_gitignore +37 -0
- package/templates/vite/e2e/app.spec.ts +41 -0
- package/templates/vite/index.html +32 -0
- package/templates/vite/nginx.conf +26 -0
- package/templates/vite/package.json +61 -0
- package/templates/vite/playwright.config.ts +27 -0
- package/templates/vite/public/favicon.svg +1 -0
- package/templates/vite/src/App.test.tsx +28 -0
- package/templates/vite/src/App.tsx +26 -0
- package/templates/vite/src/components/home.tsx +121 -0
- package/templates/vite/src/components/layout/root-layout.tsx +18 -0
- package/templates/vite/src/components/layout/site-footer.tsx +10 -0
- package/templates/vite/src/components/layout/site-header.tsx +49 -0
- package/templates/vite/src/components/theme-toggle.tsx +90 -0
- package/templates/vite/src/env.ts +36 -0
- package/templates/vite/src/lib/theme.ts +26 -0
- package/templates/vite/src/main.tsx +13 -0
- package/templates/vite/src/pages/about.tsx +52 -0
- package/templates/vite/src/pages/not-found.tsx +33 -0
- package/templates/vite/src/router.ts +24 -0
- package/templates/vite/src/styles/app.css +281 -0
- package/templates/vite/src/test/setup.ts +21 -0
- package/templates/vite/tsconfig.app.json +31 -0
- package/templates/vite/tsconfig.json +7 -0
- package/templates/vite/tsconfig.node.json +23 -0
- package/templates/vite/vite.config.ts +30 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Blocks, Gauge, Minus, Palette, Plus, ShieldCheck } from "lucide-react";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
|
|
4
|
+
// @feature ui
|
|
5
|
+
import { Badge } from "@/components/ui/badge";
|
|
6
|
+
import { Button } from "@/components/ui/button";
|
|
7
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
|
8
|
+
// @end ui
|
|
9
|
+
|
|
10
|
+
const FEATURES = [
|
|
11
|
+
{
|
|
12
|
+
icon: Gauge,
|
|
13
|
+
title: "Instant dev server",
|
|
14
|
+
description: "Vite with hot module replacement and fast production builds.",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
icon: Palette,
|
|
18
|
+
title: "Light, dark & system themes",
|
|
19
|
+
description: "CSS variables for every color, applied before the first paint.",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
icon: Blocks,
|
|
23
|
+
title: "Ready-made building blocks",
|
|
24
|
+
description: "Components, routing and env validation you can delete or extend.",
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
icon: ShieldCheck,
|
|
28
|
+
title: "Quality checks built in",
|
|
29
|
+
description: "Linting, formatting, tests and CI, depending on what you picked.",
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
export function Home() {
|
|
34
|
+
const [count, setCount] = useState(0);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div className="page">
|
|
38
|
+
<section className="hero">
|
|
39
|
+
{/* @feature ui */}
|
|
40
|
+
<Badge variant="outline">Vite + React 19</Badge>
|
|
41
|
+
{/* @end ui */}
|
|
42
|
+
{/* @feature !ui */}
|
|
43
|
+
<span className="pill">Vite + React 19</span>
|
|
44
|
+
{/* @end !ui */}
|
|
45
|
+
<h1 className="hero-title">Start building something great</h1>
|
|
46
|
+
<p className="hero-lead">
|
|
47
|
+
Edit <code className="code">src/components/home.tsx</code> and save to see your changes
|
|
48
|
+
instantly.
|
|
49
|
+
</p>
|
|
50
|
+
</section>
|
|
51
|
+
|
|
52
|
+
<section className="feature-grid">
|
|
53
|
+
{FEATURES.map(({ icon: Icon, title, description }) => (
|
|
54
|
+
// @feature ui
|
|
55
|
+
<Card key={title}>
|
|
56
|
+
<CardHeader>
|
|
57
|
+
<div className="feature-icon">
|
|
58
|
+
<Icon size={16} />
|
|
59
|
+
</div>
|
|
60
|
+
<CardTitle>{title}</CardTitle>
|
|
61
|
+
<CardDescription>{description}</CardDescription>
|
|
62
|
+
</CardHeader>
|
|
63
|
+
</Card>
|
|
64
|
+
// @end ui
|
|
65
|
+
// @feature !ui
|
|
66
|
+
<article key={title} className="panel">
|
|
67
|
+
<div className="feature-icon">
|
|
68
|
+
<Icon size={16} />
|
|
69
|
+
</div>
|
|
70
|
+
<h2 className="panel-title">{title}</h2>
|
|
71
|
+
<p className="muted">{description}</p>
|
|
72
|
+
</article>
|
|
73
|
+
// @end !ui
|
|
74
|
+
))}
|
|
75
|
+
</section>
|
|
76
|
+
|
|
77
|
+
{/* @feature ui */}
|
|
78
|
+
<Card className="counter-card">
|
|
79
|
+
<CardHeader>
|
|
80
|
+
<CardTitle>Counter</CardTitle>
|
|
81
|
+
<CardDescription>State, events and re-rendering in one tiny example.</CardDescription>
|
|
82
|
+
</CardHeader>
|
|
83
|
+
<CardContent className="counter">
|
|
84
|
+
<Button variant="outline" size="icon" onClick={() => setCount((c) => c - 1)} aria-label="Decrement">
|
|
85
|
+
<Minus />
|
|
86
|
+
</Button>
|
|
87
|
+
<output className="counter-value" aria-live="polite" aria-label="Count">
|
|
88
|
+
{count}
|
|
89
|
+
</output>
|
|
90
|
+
<Button variant="outline" size="icon" onClick={() => setCount((c) => c + 1)} aria-label="Increment">
|
|
91
|
+
<Plus />
|
|
92
|
+
</Button>
|
|
93
|
+
<Button variant="ghost" onClick={() => setCount(0)} disabled={count === 0}>
|
|
94
|
+
Reset
|
|
95
|
+
</Button>
|
|
96
|
+
</CardContent>
|
|
97
|
+
</Card>
|
|
98
|
+
{/* @end ui */}
|
|
99
|
+
{/* @feature !ui */}
|
|
100
|
+
<section className="panel counter-card">
|
|
101
|
+
<h2 className="panel-title">Counter</h2>
|
|
102
|
+
<p className="muted">State, events and re-rendering in one tiny example.</p>
|
|
103
|
+
<div className="counter">
|
|
104
|
+
<button type="button" className="plain-button" onClick={() => setCount((c) => c - 1)} aria-label="Decrement">
|
|
105
|
+
<Minus size={16} />
|
|
106
|
+
</button>
|
|
107
|
+
<output className="counter-value" aria-live="polite" aria-label="Count">
|
|
108
|
+
{count}
|
|
109
|
+
</output>
|
|
110
|
+
<button type="button" className="plain-button" onClick={() => setCount((c) => c + 1)} aria-label="Increment">
|
|
111
|
+
<Plus size={16} />
|
|
112
|
+
</button>
|
|
113
|
+
<button type="button" className="plain-button" onClick={() => setCount(0)} disabled={count === 0}>
|
|
114
|
+
Reset
|
|
115
|
+
</button>
|
|
116
|
+
</div>
|
|
117
|
+
</section>
|
|
118
|
+
{/* @end !ui */}
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Outlet, ScrollRestoration } from "react-router";
|
|
2
|
+
|
|
3
|
+
import { SiteHeader } from "@/components/layout/site-header";
|
|
4
|
+
import { SiteFooter } from "@/components/layout/site-footer";
|
|
5
|
+
|
|
6
|
+
/** Shared shell for every route: header, page content, footer. */
|
|
7
|
+
export function RootLayout() {
|
|
8
|
+
return (
|
|
9
|
+
<div className="app">
|
|
10
|
+
<SiteHeader />
|
|
11
|
+
<main className="main">
|
|
12
|
+
<Outlet />
|
|
13
|
+
</main>
|
|
14
|
+
<SiteFooter />
|
|
15
|
+
<ScrollRestoration />
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Zap } from "lucide-react";
|
|
2
|
+
// @feature router
|
|
3
|
+
import { Link, NavLink } from "react-router";
|
|
4
|
+
// @end router
|
|
5
|
+
|
|
6
|
+
import { ThemeToggle } from "@/components/theme-toggle";
|
|
7
|
+
import { env } from "@/env";
|
|
8
|
+
|
|
9
|
+
// @feature router
|
|
10
|
+
const NAV = [
|
|
11
|
+
{ to: "/", label: "Home" },
|
|
12
|
+
{ to: "/about", label: "About" },
|
|
13
|
+
];
|
|
14
|
+
// @end router
|
|
15
|
+
|
|
16
|
+
export function SiteHeader() {
|
|
17
|
+
return (
|
|
18
|
+
<header className="site-header">
|
|
19
|
+
<div className="site-header-inner">
|
|
20
|
+
{/* @feature router */}
|
|
21
|
+
<Link to="/" className="logo">
|
|
22
|
+
<span className="logo-mark" aria-hidden>
|
|
23
|
+
<Zap size={16} />
|
|
24
|
+
</span>
|
|
25
|
+
{env.VITE_APP_NAME}
|
|
26
|
+
</Link>
|
|
27
|
+
<nav className="site-nav" aria-label="Main">
|
|
28
|
+
{NAV.map((item) => (
|
|
29
|
+
<NavLink key={item.to} to={item.to} end className="nav-link">
|
|
30
|
+
{item.label}
|
|
31
|
+
</NavLink>
|
|
32
|
+
))}
|
|
33
|
+
</nav>
|
|
34
|
+
{/* @end router */}
|
|
35
|
+
{/* @feature !router */}
|
|
36
|
+
<a href="/" className="logo">
|
|
37
|
+
<span className="logo-mark" aria-hidden>
|
|
38
|
+
<Zap size={16} />
|
|
39
|
+
</span>
|
|
40
|
+
{env.VITE_APP_NAME}
|
|
41
|
+
</a>
|
|
42
|
+
{/* @end !router */}
|
|
43
|
+
<div className="site-header-actions">
|
|
44
|
+
<ThemeToggle />
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
</header>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// @feature ui
|
|
2
|
+
import { Check, Monitor, Moon, Sun } from "lucide-react";
|
|
3
|
+
// @end ui
|
|
4
|
+
// @feature !ui
|
|
5
|
+
import { Monitor, Moon, Sun } from "lucide-react";
|
|
6
|
+
// @end !ui
|
|
7
|
+
import { useSyncExternalStore } from "react";
|
|
8
|
+
|
|
9
|
+
// @feature ui
|
|
10
|
+
import { Button } from "@/components/ui/button";
|
|
11
|
+
import {
|
|
12
|
+
DropdownMenu,
|
|
13
|
+
DropdownMenuContent,
|
|
14
|
+
DropdownMenuItem,
|
|
15
|
+
DropdownMenuTrigger,
|
|
16
|
+
} from "@/components/ui/dropdown-menu";
|
|
17
|
+
// @end ui
|
|
18
|
+
import { applyTheme, readTheme, THEME_STORAGE_KEY, type Theme } from "@/lib/theme";
|
|
19
|
+
|
|
20
|
+
const OPTIONS: { value: Theme; label: string; icon: typeof Sun }[] = [
|
|
21
|
+
{ value: "light", label: "Light", icon: Sun },
|
|
22
|
+
{ value: "dark", label: "Dark", icon: Moon },
|
|
23
|
+
{ value: "system", label: "System", icon: Monitor },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
// Tiny external store over localStorage so every toggle stays in sync.
|
|
27
|
+
const listeners = new Set<() => void>();
|
|
28
|
+
function subscribe(listener: () => void) {
|
|
29
|
+
listeners.add(listener);
|
|
30
|
+
const onStorage = (e: StorageEvent) => e.key === THEME_STORAGE_KEY && listener();
|
|
31
|
+
window.addEventListener("storage", onStorage);
|
|
32
|
+
return () => {
|
|
33
|
+
listeners.delete(listener);
|
|
34
|
+
window.removeEventListener("storage", onStorage);
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function choose(value: Theme) {
|
|
39
|
+
applyTheme(value);
|
|
40
|
+
listeners.forEach((listener) => listener());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// @feature ui
|
|
44
|
+
/** Light / Dark / System switcher. */
|
|
45
|
+
export function ThemeToggle() {
|
|
46
|
+
const theme = useSyncExternalStore(subscribe, readTheme, () => "system" as Theme);
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<DropdownMenu>
|
|
50
|
+
<DropdownMenuTrigger asChild>
|
|
51
|
+
<Button variant="ghost" size="icon" aria-label="Change theme">
|
|
52
|
+
<Sun className="theme-icon-light" />
|
|
53
|
+
<Moon className="theme-icon-dark" />
|
|
54
|
+
</Button>
|
|
55
|
+
</DropdownMenuTrigger>
|
|
56
|
+
<DropdownMenuContent align="end">
|
|
57
|
+
{OPTIONS.map(({ value, label, icon: Icon }) => (
|
|
58
|
+
<DropdownMenuItem key={value} onSelect={() => choose(value)}>
|
|
59
|
+
<Icon />
|
|
60
|
+
<span className="menu-grow">{label}</span>
|
|
61
|
+
{theme === value && <Check aria-label="selected" />}
|
|
62
|
+
</DropdownMenuItem>
|
|
63
|
+
))}
|
|
64
|
+
</DropdownMenuContent>
|
|
65
|
+
</DropdownMenu>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
// @end ui
|
|
69
|
+
// @feature !ui
|
|
70
|
+
/** Cycles Light -> Dark -> System. */
|
|
71
|
+
export function ThemeToggle() {
|
|
72
|
+
const theme = useSyncExternalStore(subscribe, readTheme, () => "system" as Theme);
|
|
73
|
+
const index = OPTIONS.findIndex((o) => o.value === theme);
|
|
74
|
+
const current = OPTIONS[index];
|
|
75
|
+
const next = OPTIONS[(index + 1) % OPTIONS.length];
|
|
76
|
+
const Icon = current.icon;
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<button
|
|
80
|
+
type="button"
|
|
81
|
+
className="icon-button"
|
|
82
|
+
onClick={() => choose(next.value)}
|
|
83
|
+
aria-label={`Theme: ${current.label}. Switch to ${next.label}`}
|
|
84
|
+
title={`Theme: ${current.label}`}
|
|
85
|
+
>
|
|
86
|
+
<Icon size={18} />
|
|
87
|
+
</button>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
// @end !ui
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @feature env
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Client environment variables, validated once at startup.
|
|
6
|
+
*
|
|
7
|
+
* Only variables prefixed with VITE_ are exposed to the browser, and they are
|
|
8
|
+
* baked in at build time: never put secrets here. Define them in .env.local.
|
|
9
|
+
*/
|
|
10
|
+
const envSchema = z.object({
|
|
11
|
+
VITE_APP_NAME: z.string().min(1).default("{{PROJECT_TITLE}}"),
|
|
12
|
+
/** Base URL of your backend API (optional). */
|
|
13
|
+
VITE_API_URL: z.preprocess(
|
|
14
|
+
(value) => (value === "" ? undefined : value), // an empty `VITE_API_URL=` means "not set"
|
|
15
|
+
z.url("VITE_API_URL must be a full URL like https://api.example.com").optional(),
|
|
16
|
+
),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const parsed = envSchema.safeParse(import.meta.env);
|
|
20
|
+
if (!parsed.success) {
|
|
21
|
+
throw new Error(`Invalid environment variables (check .env.local):\n${z.prettifyError(parsed.error)}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const env = parsed.data;
|
|
25
|
+
// @end env
|
|
26
|
+
// @feature !env
|
|
27
|
+
/**
|
|
28
|
+
* Client environment variables. Only variables prefixed with VITE_ are
|
|
29
|
+
* exposed to the browser, and they are baked in at build time: never put
|
|
30
|
+
* secrets here. Define them in .env.local.
|
|
31
|
+
*/
|
|
32
|
+
export const env = {
|
|
33
|
+
VITE_APP_NAME: (import.meta.env.VITE_APP_NAME as string | undefined) || "{{PROJECT_TITLE}}",
|
|
34
|
+
VITE_API_URL: import.meta.env.VITE_API_URL as string | undefined,
|
|
35
|
+
};
|
|
36
|
+
// @end !env
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Must match the key used by the inline script in index.html. */
|
|
2
|
+
export const THEME_STORAGE_KEY = "theme";
|
|
3
|
+
export const THEMES = ["light", "dark", "system"] as const;
|
|
4
|
+
export type Theme = (typeof THEMES)[number];
|
|
5
|
+
|
|
6
|
+
export function readTheme(): Theme {
|
|
7
|
+
try {
|
|
8
|
+
const value = localStorage.getItem(THEME_STORAGE_KEY);
|
|
9
|
+
return value === "light" || value === "dark" ? value : "system";
|
|
10
|
+
} catch {
|
|
11
|
+
return "system";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Saves the preference and applies it immediately. */
|
|
16
|
+
export function applyTheme(theme: Theme) {
|
|
17
|
+
try {
|
|
18
|
+
localStorage.setItem(THEME_STORAGE_KEY, theme);
|
|
19
|
+
} catch {
|
|
20
|
+
// Storage unavailable (private mode): the choice just won't persist.
|
|
21
|
+
}
|
|
22
|
+
const dark =
|
|
23
|
+
theme === "dark" ||
|
|
24
|
+
(theme === "system" && window.matchMedia("(prefers-color-scheme: dark)").matches);
|
|
25
|
+
document.documentElement.classList.toggle("dark", dark);
|
|
26
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { StrictMode } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
|
|
4
|
+
import App from "@/App";
|
|
5
|
+
|
|
6
|
+
import "./index.css";
|
|
7
|
+
import "./styles/app.css";
|
|
8
|
+
|
|
9
|
+
createRoot(document.getElementById("root")!).render(
|
|
10
|
+
<StrictMode>
|
|
11
|
+
<App />
|
|
12
|
+
</StrictMode>,
|
|
13
|
+
);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// @feature ui
|
|
2
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
|
3
|
+
// @end ui
|
|
4
|
+
import { env } from "@/env";
|
|
5
|
+
|
|
6
|
+
const STACK = [
|
|
7
|
+
["React 19", "UI library"],
|
|
8
|
+
["Vite", "Dev server and bundler"],
|
|
9
|
+
["React Router", "Client-side routing (src/router.tsx)"],
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
export function About() {
|
|
13
|
+
const rows = (
|
|
14
|
+
<dl className="definition-list">
|
|
15
|
+
{STACK.map(([term, description]) => (
|
|
16
|
+
<div key={term}>
|
|
17
|
+
<dt>{term}</dt>
|
|
18
|
+
<dd className="muted">{description}</dd>
|
|
19
|
+
</div>
|
|
20
|
+
))}
|
|
21
|
+
<div>
|
|
22
|
+
<dt>VITE_API_URL</dt>
|
|
23
|
+
<dd className="muted">{env.VITE_API_URL ?? "not set (add it to .env.local)"}</dd>
|
|
24
|
+
</div>
|
|
25
|
+
</dl>
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div className="page">
|
|
30
|
+
<h1 className="page-title">About</h1>
|
|
31
|
+
<p className="muted">
|
|
32
|
+
This page lives in <code className="code">src/pages/about.tsx</code>. Add routes in{" "}
|
|
33
|
+
<code className="code">src/router.tsx</code>.
|
|
34
|
+
</p>
|
|
35
|
+
{/* @feature ui */}
|
|
36
|
+
<Card>
|
|
37
|
+
<CardHeader>
|
|
38
|
+
<CardTitle>The stack</CardTitle>
|
|
39
|
+
<CardDescription>What this project is built with.</CardDescription>
|
|
40
|
+
</CardHeader>
|
|
41
|
+
<CardContent>{rows}</CardContent>
|
|
42
|
+
</Card>
|
|
43
|
+
{/* @end ui */}
|
|
44
|
+
{/* @feature !ui */}
|
|
45
|
+
<section className="panel">
|
|
46
|
+
<h2 className="panel-title">The stack</h2>
|
|
47
|
+
{rows}
|
|
48
|
+
</section>
|
|
49
|
+
{/* @end !ui */}
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isRouteErrorResponse, Link, useRouteError } from "react-router";
|
|
2
|
+
|
|
3
|
+
// @feature ui
|
|
4
|
+
import { Button } from "@/components/ui/button";
|
|
5
|
+
// @end ui
|
|
6
|
+
|
|
7
|
+
/** Shown for unknown URLs and for errors thrown while rendering a route. */
|
|
8
|
+
export function NotFound() {
|
|
9
|
+
const error = useRouteError();
|
|
10
|
+
const isError = error != null && !(isRouteErrorResponse(error) && error.status === 404);
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<div className="status">
|
|
14
|
+
<p className="status-code">{isError ? "Error" : "404"}</p>
|
|
15
|
+
<h1 className="page-title">{isError ? "Something went wrong" : "Page not found"}</h1>
|
|
16
|
+
<p className="muted">
|
|
17
|
+
{isError
|
|
18
|
+
? "An unexpected error occurred while loading this page."
|
|
19
|
+
: "The page you're looking for doesn't exist or has been moved."}
|
|
20
|
+
</p>
|
|
21
|
+
{/* @feature ui */}
|
|
22
|
+
<Button asChild>
|
|
23
|
+
<Link to="/">Back home</Link>
|
|
24
|
+
</Button>
|
|
25
|
+
{/* @end ui */}
|
|
26
|
+
{/* @feature !ui */}
|
|
27
|
+
<Link to="/" className="plain-button">
|
|
28
|
+
Back home
|
|
29
|
+
</Link>
|
|
30
|
+
{/* @end !ui */}
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { createBrowserRouter } from "react-router";
|
|
2
|
+
|
|
3
|
+
import { Home } from "@/components/home";
|
|
4
|
+
import { RootLayout } from "@/components/layout/root-layout";
|
|
5
|
+
import { About } from "@/pages/about";
|
|
6
|
+
import { NotFound } from "@/pages/not-found";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* App routes (React Router, data mode). Add a page:
|
|
10
|
+
* 1. create src/pages/my-page.tsx
|
|
11
|
+
* 2. add { path: "my-page", Component: MyPage } to `children`
|
|
12
|
+
*/
|
|
13
|
+
export const router = createBrowserRouter([
|
|
14
|
+
{
|
|
15
|
+
path: "/",
|
|
16
|
+
Component: RootLayout,
|
|
17
|
+
ErrorBoundary: NotFound,
|
|
18
|
+
children: [
|
|
19
|
+
{ index: true, Component: Home },
|
|
20
|
+
{ path: "about", Component: About },
|
|
21
|
+
{ path: "*", Component: NotFound },
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
]);
|