Files
collabry-components/src/components/Auth/Auth.tsx
T
2026-11-14 08:49:19 +01:00

144 lines
4.5 KiB
TypeScript

import type { ComponentProps } from 'react';
import { Check } from 'lucide-react';
import { cn } from '../../lib/cn';
/**
* Left half of the login and register screens.
*
* <AuthBrandPanel>
* <Logo variant="stacked" />
* <AuthBrandContent>
* <AuthHeadline>Gruppenarbeit, die einfach funktioniert!</AuthHeadline>
* <FeatureList><FeatureItem><FeatureIcon><Users /></FeatureIcon><FeatureContent>…</FeatureContent></FeatureItem></FeatureList>
* </AuthBrandContent>
* </AuthBrandPanel>
*/
export function AuthBrandPanel({ className, ...props }: ComponentProps<'div'>) {
return (
<div
data-slot="auth-brand-panel"
className={cn(
'box-border flex min-w-0 flex-[1_1_520px] flex-col items-center justify-center gap-9 border-r border-line-shell bg-brand px-[clamp(24px,5vw,72px)] py-12',
className,
)}
{...props}
/>
);
}
export function AuthBrandContent({ className, ...props }: ComponentProps<'div'>) {
return (
<div
data-slot="auth-brand-content"
className={cn('flex w-full max-w-[420px] flex-col gap-7', className)}
{...props}
/>
);
}
export function AuthHeadline({ className, ...props }: ComponentProps<'p'>) {
return (
<p
data-slot="auth-headline"
className={cn('m-0 text-center text-[30px] leading-tight font-black tracking-[-0.01em] text-balance', className)}
{...props}
/>
);
}
export function FeatureList({ className, ...props }: ComponentProps<'ul'>) {
return <ul data-slot="feature-list" className={cn('m-0 flex flex-col gap-[18px] p-0', className)} {...props} />;
}
export function FeatureItem({ className, ...props }: ComponentProps<'li'>) {
return <li data-slot="feature-item" className={cn('flex list-none items-start gap-3.5', className)} {...props} />;
}
export function FeatureIcon({ className, ...props }: ComponentProps<'span'>) {
return (
<span
data-slot="feature-icon"
className={cn(
'flex h-9 w-9 flex-none items-center justify-center rounded-[10px] border border-line-divider bg-feature text-accent-fg',
className,
)}
{...props}
/>
);
}
export function FeatureContent(props: ComponentProps<'div'>) {
return <div data-slot="feature-content" {...props} />;
}
export function FeatureTitle({ className, ...props }: ComponentProps<'div'>) {
return <div data-slot="feature-title" className={cn('leading-tight font-bold', className)} {...props} />;
}
export function FeatureDescription({ className, ...props }: ComponentProps<'div'>) {
return (
<div data-slot="feature-description" className={cn('mt-0.5 leading-snug text-fg-muted', className)} {...props} />
);
}
export interface PasswordRuleCheck {
label: string;
met: boolean;
}
/** Checks a password against the design's three rules. */
export function passwordRules(pw: string): PasswordRuleCheck[] {
return [
{ label: 'Mindestens 8 Zeichen', met: pw.length >= 8 },
{ label: 'Groß- und Kleinbuchstaben', met: /[a-zäöü]/.test(pw) && /[A-ZÄÖÜ]/.test(pw) },
{ label: 'Mindestens eine Zahl', met: /\d/.test(pw) },
];
}
/** Live checklist under a password field: `PasswordRule`s. Link it with `aria-describedby`. */
export function PasswordRules({ className, ...props }: ComponentProps<'ul'>) {
return (
<ul
aria-label="Passwort-Anforderungen"
data-slot="password-rules"
className={cn('m-0 mt-1 flex flex-col gap-1.5 p-0', className)}
{...props}
/>
);
}
export interface PasswordRuleProps extends ComponentProps<'li'> {
met: boolean;
/** Show it in red while unmet (after a submit attempt). */
showError?: boolean;
}
export function PasswordRule({ met, showError, className, children, ...props }: PasswordRuleProps) {
return (
<li
data-slot="password-rule"
className={cn(
'flex list-none items-center gap-2 text-xs',
met ? 'text-fg-muted' : showError ? 'text-danger-fg' : 'text-fg-subtle',
className,
)}
{...props}
>
{met ? (
<span className="flex h-4 w-4 flex-none items-center justify-center rounded-full bg-success text-on-color">
<Check size={10} strokeWidth={4} aria-hidden="true" />
</span>
) : (
<span
className={cn(
'box-border h-4 w-4 flex-none rounded-full border-[1.5px]',
showError ? 'border-danger-fg' : 'border-line-control',
)}
/>
)}
{children}
<span className="sr-only">{met ? 'erfüllt' : 'nicht erfüllt'}</span>
</li>
);
}