feat(ui): login rebuilt on shadcn card/label/input, theme toggle available pre-auth
This commit is contained in:
@@ -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">
|
</div>
|
||||||
<IconBooks className="size-7" />
|
<form onSubmit={submit} className="fx-rise w-full max-w-sm">
|
||||||
</span>
|
<Card>
|
||||||
<h1 className="mt-4 font-serif text-2xl font-semibold tracking-wide">
|
<CardHeader className="items-center text-center">
|
||||||
Book<span className="text-amber-400">Lib</span>
|
<span className="mb-2 grid size-10 place-items-center rounded-lg bg-accent text-accent-foreground">
|
||||||
</h1>
|
<BookMarked className="size-5" />
|
||||||
<p className="mt-1 text-sm text-stone-500">你的漫画与书籍藏书馆</p>
|
</span>
|
||||||
</div>
|
<CardTitle className="text-xl tracking-tight">BookLib</CardTitle>
|
||||||
<Field icon={<IconUser className="size-4" />}>
|
<CardDescription>你的漫画与书籍藏书馆</CardDescription>
|
||||||
<input
|
</CardHeader>
|
||||||
className={input + " w-full pl-9"}
|
<CardContent className="space-y-4">
|
||||||
value={u}
|
<div className="space-y-1.5">
|
||||||
onChange={(e) => setU(e.target.value)}
|
<Label htmlFor="login-user">用户名</Label>
|
||||||
aria-label="用户名"
|
<Input id="login-user" value={u} onChange={(e) => setU(e.target.value)} autoFocus autoComplete="username" />
|
||||||
placeholder="用户名"
|
</div>
|
||||||
autoFocus
|
<div className="space-y-1.5">
|
||||||
autoComplete="username"
|
<Label htmlFor="login-pass">密码</Label>
|
||||||
/>
|
<Input id="login-pass" type="password" value={p} onChange={(e) => setP(e.target.value)} autoComplete="current-password" />
|
||||||
</Field>
|
</div>
|
||||||
<Field icon={<IconLock className="size-4" />}>
|
<Button type="submit" className="w-full" disabled={busy || !u || !p}>
|
||||||
<input
|
{busy ? "登录中…" : "登录"}
|
||||||
className={input + " w-full pl-9"}
|
</Button>
|
||||||
type="password"
|
</CardContent>
|
||||||
value={p}
|
</Card>
|
||||||
onChange={(e) => setP(e.target.value)}
|
|
||||||
aria-label="密码"
|
|
||||||
placeholder="密码"
|
|
||||||
autoComplete="current-password"
|
|
||||||
/>
|
|
||||||
</Field>
|
|
||||||
<button className={btnPrimary + " w-full justify-center py-2"} disabled={busy || !u || !p}>
|
|
||||||
{busy ? "登录中…" : "登录"}
|
|
||||||
</button>
|
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user