1
0
Fork 0

feat: add UI primitives (Button, Card, Alert, FormField) and restyle login page

This commit is contained in:
Jonny 2026-07-06 11:37:15 +02:00
parent 83cbba1635
commit 11c893e1b9
5 changed files with 83 additions and 14 deletions

View File

@ -1,4 +1,8 @@
import { login } from "./actions"; import { login } from "./actions";
import { Button } from "@/components/ui/Button";
import { Card } from "@/components/ui/Card";
import { Alert } from "@/components/ui/Alert";
import { FormField, FIELD_CLASSES } from "@/components/ui/FormField";
export default async function LoginPage({ export default async function LoginPage({
searchParams, searchParams,
@ -8,20 +12,24 @@ export default async function LoginPage({
const { error } = await searchParams; const { error } = await searchParams;
return ( return (
<main> <main className="flex flex-1 items-center justify-center px-4 py-8">
<h1>Anmelden</h1> <Card className="w-full max-w-sm">
{error && <p role="alert">{error}</p>} <h1 className="mb-6 text-center text-xl font-semibold text-asphalt-grey">Anmelden</h1>
{error && (
<div className="mb-4">
<Alert>{error}</Alert>
</div>
)}
<form action={login}> <form action={login}>
<div> <FormField label="E-Mail" htmlFor="email">
<label htmlFor="email">E-Mail</label> <input id="email" name="email" type="email" required className={FIELD_CLASSES} />
<input id="email" name="email" type="email" required /> </FormField>
</div> <FormField label="Passwort" htmlFor="password">
<div> <input id="password" name="password" type="password" required className={FIELD_CLASSES} />
<label htmlFor="password">Passwort</label> </FormField>
<input id="password" name="password" type="password" required /> <Button type="submit">Anmelden</Button>
</div>
<button type="submit">Anmelden</button>
</form> </form>
</Card>
</main> </main>
); );
} }

View File

@ -0,0 +1,7 @@
export function Alert({ children }: { children: React.ReactNode }) {
return (
<p role="alert" className="rounded-md border border-status-danger bg-red-50 px-4 py-3 text-status-danger">
{children}
</p>
);
}

View File

@ -0,0 +1,28 @@
import type { ComponentProps } from "react";
export type ButtonVariant = "primary" | "secondary" | "destructive";
const VARIANT_CLASSES: Record<ButtonVariant, string> = {
primary: "bg-performance-blue text-white hover:bg-night-blue",
secondary: "bg-white text-asphalt-grey border border-asphalt-grey hover:bg-aluminium-grey",
destructive: "bg-status-danger text-white hover:bg-red-700",
};
export function buttonClasses(variant: ButtonVariant = "primary", fullWidth = true): string {
return [
"inline-flex min-h-11 items-center justify-center rounded-md px-4 py-2 text-center font-medium",
"transition-colors focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2",
"focus-visible:outline-performance-blue disabled:cursor-not-allowed disabled:opacity-50",
VARIANT_CLASSES[variant],
fullWidth ? "w-full" : "",
].join(" ");
}
export function Button({
variant = "primary",
fullWidth = true,
className = "",
...props
}: ComponentProps<"button"> & { variant?: ButtonVariant; fullWidth?: boolean }) {
return <button className={`${buttonClasses(variant, fullWidth)} ${className}`} {...props} />;
}

View File

@ -0,0 +1,5 @@
import type { ComponentProps } from "react";
export function Card({ className = "", ...props }: ComponentProps<"div">) {
return <div className={`rounded-lg border border-aluminium-grey bg-white p-4 shadow-sm ${className}`} {...props} />;
}

View File

@ -0,0 +1,21 @@
export const FIELD_CLASSES =
"min-h-11 w-full rounded-md border border-aluminium-grey px-3 py-2 text-base text-asphalt-grey focus:outline-none focus:ring-2 focus:ring-performance-blue";
export function FormField({
label,
htmlFor,
children,
}: {
label: string;
htmlFor: string;
children: React.ReactNode;
}) {
return (
<div className="mb-4 flex flex-col gap-1">
<label htmlFor={htmlFor} className="text-sm font-medium text-asphalt-grey">
{label}
</label>
{children}
</div>
);
}