feat(ui): login rebuilt on shadcn card/label/input, theme toggle available pre-auth

This commit is contained in:
2026-09-08 17:47:17 +08:00
parent 52e95a48d8
commit d9e9e95ece
+34 -50
View File
@@ -1,20 +1,13 @@
import { useState, type FormEvent, type ReactNode } from "react"; import { useState, type FormEvent } from "react";
import { Navigate, useLocation } from "react-router-dom"; import { Navigate, useLocation } from "react-router-dom";
import { useAuth } from "../auth/AuthContext"; import { BookMarked } from "lucide-react";
import { IconBooks, IconLock, IconUser } from "../components/icons"; import { useAuth } from "@/auth/AuthContext";
import { toast } from "../components/Toaster"; import { Button } from "@/components/ui/button";
import { btnPrimary, card, input } from "../components/ui"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
function Field({ icon, children }: { icon: ReactNode; children: ReactNode }) { import { Label } from "@/components/ui/label";
return ( import { ThemeToggle } from "@/components/theme-toggle";
<label className="block"> import { toast } from "@/components/Toaster";
<span className="relative block">
<span className="pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-stone-500">{icon}</span>
{children}
</span>
</label>
);
}
export default function Login() { export default function Login() {
const { login, user } = useAuth(); const { login, user } = useAuth();
@@ -38,42 +31,33 @@ export default function Login() {
} }
return ( return (
<div className="grid h-full place-items-center p-4"> <div className="relative grid h-full place-items-center p-4">
<form onSubmit={submit} className={`${card} fx-rise w-full max-w-sm space-y-4 p-8 shadow-2xl shadow-black/40`}> <div className="absolute right-3 top-3">
<div className="flex flex-col items-center pb-2 text-center"> <ThemeToggle />
<span className="grid size-12 place-items-center rounded-2xl bg-linear-to-br from-amber-500 to-orange-600 text-stone-950 shadow-lg shadow-amber-500/25">
<IconBooks className="size-7" />
</span>
<h1 className="mt-4 font-serif text-2xl font-semibold tracking-wide">
Book<span className="text-amber-400">Lib</span>
</h1>
<p className="mt-1 text-sm text-stone-500">你的漫画与书籍藏书馆</p>
</div> </div>
<Field icon={<IconUser className="size-4" />}> <form onSubmit={submit} className="fx-rise w-full max-w-sm">
<input <Card>
className={input + " w-full pl-9"} <CardHeader className="items-center text-center">
value={u} <span className="mb-2 grid size-10 place-items-center rounded-lg bg-accent text-accent-foreground">
onChange={(e) => setU(e.target.value)} <BookMarked className="size-5" />
aria-label="用户名" </span>
placeholder="用户名" <CardTitle className="text-xl tracking-tight">BookLib</CardTitle>
autoFocus <CardDescription>你的漫画与书籍藏书馆</CardDescription>
autoComplete="username" </CardHeader>
/> <CardContent className="space-y-4">
</Field> <div className="space-y-1.5">
<Field icon={<IconLock className="size-4" />}> <Label htmlFor="login-user">用户名</Label>
<input <Input id="login-user" value={u} onChange={(e) => setU(e.target.value)} autoFocus autoComplete="username" />
className={input + " w-full pl-9"} </div>
type="password" <div className="space-y-1.5">
value={p} <Label htmlFor="login-pass">密码</Label>
onChange={(e) => setP(e.target.value)} <Input id="login-pass" type="password" value={p} onChange={(e) => setP(e.target.value)} autoComplete="current-password" />
aria-label="密码" </div>
placeholder="密码" <Button type="submit" className="w-full" disabled={busy || !u || !p}>
autoComplete="current-password"
/>
</Field>
<button className={btnPrimary + " w-full justify-center py-2"} disabled={busy || !u || !p}>
{busy ? "登录中…" : "登录"} {busy ? "登录中…" : "登录"}
</button> </Button>
</CardContent>
</Card>
</form> </form>
</div> </div>
); );