forked from fahrPool/fahrPool
feat: add UI primitives (Button, Card, Alert, FormField) and restyle login page
This commit is contained in:
parent
83cbba1635
commit
11c893e1b9
|
|
@ -1,4 +1,8 @@
|
|||
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({
|
||||
searchParams,
|
||||
|
|
@ -8,20 +12,24 @@ export default async function LoginPage({
|
|||
const { error } = await searchParams;
|
||||
|
||||
return (
|
||||
<main>
|
||||
<h1>Anmelden</h1>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
<main className="flex flex-1 items-center justify-center px-4 py-8">
|
||||
<Card className="w-full max-w-sm">
|
||||
<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}>
|
||||
<div>
|
||||
<label htmlFor="email">E-Mail</label>
|
||||
<input id="email" name="email" type="email" required />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="password">Passwort</label>
|
||||
<input id="password" name="password" type="password" required />
|
||||
</div>
|
||||
<button type="submit">Anmelden</button>
|
||||
<FormField label="E-Mail" htmlFor="email">
|
||||
<input id="email" name="email" type="email" required className={FIELD_CLASSES} />
|
||||
</FormField>
|
||||
<FormField label="Passwort" htmlFor="password">
|
||||
<input id="password" name="password" type="password" required className={FIELD_CLASSES} />
|
||||
</FormField>
|
||||
<Button type="submit">Anmelden</Button>
|
||||
</form>
|
||||
</Card>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
|
@ -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} />;
|
||||
}
|
||||
|
|
@ -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} />;
|
||||
}
|
||||
|
|
@ -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>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue