All blocks
Basic Login
Minimal, zero-chrome centered credential sign-in form resting directly on the canvas with inline validation, password visibility toggle, inline forgot-password feedback, remember-me persistence, and toast confirmation.
Built withAlertButtonCenterCheckboxFieldHeadingIconIcon ButtonInputLinkPassword InputSpinnerStackTextToast
Sign in to Alder Notes
Enter your email and password to continue.
New to Alder Notes? Create an account
Install
1npx stylexblocks add basic-loginSource
components/blocks/ui-sdk/basic-login.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493import * as stylex from "@stylexjs/stylex";import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { Alert } from "#components/ui/ui-sdk/alert.tsx";import { Button } from "#components/ui/ui-sdk/button.tsx";import { Square } from "#components/ui/ui-sdk/center.tsx";import { Checkbox } from "#components/ui/ui-sdk/checkbox.tsx";import { Field } from "#components/ui/ui-sdk/field.tsx";import { Heading } from "#components/ui/ui-sdk/heading.tsx";import { Icon } from "#components/ui/ui-sdk/icon.tsx";import { IconButton } from "#components/ui/ui-sdk/icon-button.tsx";import { Input } from "#components/ui/ui-sdk/input.tsx";import { Link } from "#components/ui/ui-sdk/link.tsx";import { PasswordInput } from "#components/ui/ui-sdk/password-input.tsx";import { Spinner } from "#components/ui/ui-sdk/spinner.tsx";import { HStack, VStack } from "#components/ui/ui-sdk/stack.tsx";import { Text } from "#components/ui/ui-sdk/text.tsx";import { Toast, Toaster } from "#components/ui/ui-sdk/toast.tsx";import { semanticColors } from "@stylexblocks/ui/semantic-tokens/colors.stylex.ts";import { semanticRadii } from "@stylexblocks/ui/semantic-tokens/radii.stylex.ts";import { accentPalette } from "@stylexblocks/ui/themes/palettes.ts";import { fontSizes } from "@stylexblocks/ui/tokens/font-sizes.stylex.ts";import { fontWeights } from "@stylexblocks/ui/tokens/font-weights.stylex.ts";import { fonts } from "@stylexblocks/ui/tokens/fonts.stylex.ts";import { letterSpacings } from "@stylexblocks/ui/tokens/letter-spacings.stylex.ts";import { lineHeights } from "@stylexblocks/ui/tokens/line-heights.stylex.ts";import { spacing } from "@stylexblocks/ui/tokens/spacing.stylex.ts";import type { StyleOverrideProps } from "#lib/recipe-props.ts";
// ── Types ─────────────────────────────────────────────────────────────────────
export interface BasicLoginCredentials { email: string; password: string; rememberMe: boolean;}
export interface BasicLoginProps extends StyleOverrideProps { /** Product or workspace name displayed in headings and feedback copy. */ brandName?: string; /** Primary heading displayed above the form. */ title?: string; /** Concise supporting line beneath the heading. */ description?: string; /** Initial email address value. */ defaultEmail?: string; /** Initial checked state for the remember-me checkbox. */ defaultRememberMe?: boolean; /** Called after client-side validation succeeds on sign-in. */ onSignIn?: (credentials: BasicLoginCredentials) => void; /** Called when the user activates the forgot-password link. */ onForgotPassword?: (email: string) => void; /** Called when the user activates the create-account link. */ onCreateAccount?: () => void;}
interface BasicLoginErrors { email?: string; password?: string;}
type RecoveryNotice = | { kind: "sent"; email: string } | { kind: "missing-email" } | null;
// ── Inline SVG Icons ──────────────────────────────────────────────────────────
function AlderMark() { return ( <Icon size="md" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" > <path d="M5.5 4.5h9l4 4v11a1.5 1.5 0 0 1-1.5 1.5H7a1.5 1.5 0 0 1-1.5-1.5v-15Z" /> <path d="M14.5 4.5V9h4" /> <path d="M9 13h6" /> <path d="M9 16.5h4" /> </Icon> );}
function MailNoticeIcon() { return ( <Icon size="sm" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" > <rect x="2.5" y="4.5" width="15" height="11" rx="2" /> <path d="M3.5 6l6.5 4.5L16.5 6" /> </Icon> );}
function CloseIcon() { return ( <Icon size="xs" viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" aria-hidden="true" > <path d="M4 4l8 8" /> <path d="M12 4l-8 8" /> </Icon> );}
// ── Validation ────────────────────────────────────────────────────────────────
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
function validateCredentials(email: string, password: string): BasicLoginErrors { const nextErrors: BasicLoginErrors = {}; const trimmedEmail = email.trim();
if (!trimmedEmail) { nextErrors.email = "Enter your email address."; } else if (!EMAIL_PATTERN.test(trimmedEmail)) { nextErrors.email = "Enter a valid email address (for example, hello@aldernotes.app)."; }
if (!password) { nextErrors.password = "Enter your password."; } else if (password.length < 8) { nextErrors.password = "Password must be at least 8 characters."; }
return nextErrors;}
// ── Styles ────────────────────────────────────────────────────────────────────
const COMPACT = "@container basic-login (max-width: 480px)";
const styles = stylex.create({ root: { backgroundColor: semanticColors.bg, color: semanticColors.fg, containerName: "basic-login", containerType: "inline-size", fontFamily: fonts.body, minHeight: "100%", overflowY: "auto", paddingBlock: { default: spacing._10, [COMPACT]: spacing._6, }, paddingInline: spacing._4, width: "100%", }, column: { gap: { default: spacing._7, [COMPACT]: spacing._6, }, marginBlock: "auto", maxWidth: "22rem", width: "100%", }, header: { gap: spacing._3_5, textAlign: "center", }, emblem: { backgroundColor: semanticColors.bgSubtle, borderColor: semanticColors.borderSubtle, borderRadius: semanticRadii.panel, borderStyle: "solid", borderWidth: "1px", color: semanticColors.fg, }, title: { color: semanticColors.fg, letterSpacing: letterSpacings.tight, marginBlock: 0, textAlign: "center", }, notice: { alignItems: "flex-start", }, noticeIndicator: { marginBlockStart: spacing._0_5, }, noticeDismiss: { marginBlockStart: `calc(${spacing._1} * -1)`, marginInlineEnd: `calc(${spacing._1} * -1)`, }, fullWidth: { width: "100%", }, passwordLabel: { fontSize: fontSizes.sm, lineHeight: lineHeights.sm, }, inlineLink: { fontSize: fontSizes.xs, fontWeight: fontWeights.medium, lineHeight: lineHeights.xs, }, checkboxLabel: { color: semanticColors.fgMuted, fontWeight: fontWeights.normal, },});
// ── Component ─────────────────────────────────────────────────────────────────
/** * BasicLogin — minimal, zero-chrome centered credential sign-in surface resting * directly on the canvas with inline validation, password visibility toggle, * inline forgot-password feedback, remember-me persistence, and toast * confirmation. */export function BasicLogin({ brandName = "Alder Notes", title = "Sign in to Alder Notes", description = "Enter your email and password to continue.", defaultEmail = "", defaultRememberMe = true, onSignIn, onForgotPassword, onCreateAccount, palette, style,}: BasicLoginProps) { const [email, setEmail] = useState(defaultEmail); const [password, setPassword] = useState(""); const [rememberMe, setRememberMe] = useState(defaultRememberMe); const [errors, setErrors] = useState<BasicLoginErrors>({}); const [recoveryNotice, setRecoveryNotice] = useState<RecoveryNotice>(null); const [isSubmitting, setIsSubmitting] = useState(false);
const emailInputRef = useRef<HTMLInputElement>(null); const submitTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null); const queue = useMemo(() => Toast.createToaster(), []);
useEffect(() => { return () => { if (submitTimerRef.current !== null) { clearTimeout(submitTimerRef.current); } }; }, []);
const handleEmailChange = useCallback((nextValue: string) => { setEmail(nextValue); setErrors((prev) => (prev.email ? { ...prev, email: undefined } : prev)); setRecoveryNotice((prev) => (prev?.kind === "missing-email" ? null : prev)); }, []);
const handlePasswordChange = useCallback((nextValue: string) => { setPassword(nextValue); setErrors((prev) => (prev.password ? { ...prev, password: undefined } : prev)); }, []);
const handleSubmit = useCallback( (event: React.FormEvent<HTMLFormElement>) => { event.preventDefault(); if (isSubmitting) return;
const nextErrors = validateCredentials(email, password); if (nextErrors.email || nextErrors.password) { setErrors(nextErrors); if (nextErrors.email) { emailInputRef.current?.focus(); } return; }
setErrors({}); setRecoveryNotice(null); setIsSubmitting(true);
const trimmedEmail = email.trim(); submitTimerRef.current = setTimeout(() => { submitTimerRef.current = null; setIsSubmitting(false); onSignIn?.({ email: trimmedEmail, password, rememberMe, }); queue.success(`Signed in to ${brandName}`, { description: rememberMe ? `Active session for ${trimmedEmail} — remembered for 30 days.` : `Active session for ${trimmedEmail} for this browser session.`, }); }, 600); }, [brandName, email, isSubmitting, onSignIn, password, queue, rememberMe], );
const handleForgotPassword = useCallback( (event: React.MouseEvent<HTMLAnchorElement>) => { event.preventDefault(); const trimmedEmail = email.trim(); onForgotPassword?.(trimmedEmail);
if (trimmedEmail && EMAIL_PATTERN.test(trimmedEmail)) { setErrors((prev) => (prev.email ? { ...prev, email: undefined } : prev)); setRecoveryNotice({ kind: "sent", email: trimmedEmail }); } else { setRecoveryNotice({ kind: "missing-email" }); emailInputRef.current?.focus(); } }, [email, onForgotPassword], );
const handleCreateAccount = useCallback( (event: React.MouseEvent<HTMLAnchorElement>) => { event.preventDefault(); onCreateAccount?.(); queue.info(`Create a ${brandName} account`, { description: "New account registration is ready to connect to your sign-up flow.", }); }, [brandName, onCreateAccount, queue], );
return ( <VStack align="center" gap="0" palette={palette} style={[styles.root, style]}> <VStack render={<main />} style={styles.column}> <VStack render={<header />} align="center" style={styles.header}> <Square size="md" style={styles.emblem} aria-hidden="true"> <AlderMark /> </Square> <VStack align="center" gap="1"> <Heading render={<h1 />} size="2xl" style={styles.title}> {title} </Heading> <Text variant="muted" size="sm" align="center"> {description} </Text> </VStack> </VStack>
{recoveryNotice ? ( <Alert.Root status="info" variant="subtle" size="sm" palette={accentPalette} role="status" aria-live="polite" style={styles.notice} > <Alert.Indicator style={styles.noticeIndicator}> <MailNoticeIcon /> </Alert.Indicator> <Alert.Content> <Alert.Title> {recoveryNotice.kind === "sent" ? "Password reset link sent" : "Enter your email first"} </Alert.Title> <Alert.Description> {recoveryNotice.kind === "sent" ? `Check ${recoveryNotice.email} for instructions to reset your password.` : `Type your ${brandName} email below, then select Forgot password? again.`} </Alert.Description> </Alert.Content> <IconButton type="button" variant="ghost" size="xs" palette={accentPalette} aria-label="Dismiss password recovery notice" onClick={() => setRecoveryNotice(null)} style={styles.noticeDismiss} > <CloseIcon /> </IconButton> </Alert.Root> ) : null}
<VStack render={<form noValidate onSubmit={handleSubmit} />} gap="5" style={styles.fullWidth} > <VStack gap="4" style={styles.fullWidth}> <Field.Root invalid={Boolean(errors.email)}> <Field.Label>Email</Field.Label> <Input ref={emailInputRef} type="email" name="email" size="lg" autoComplete="email" placeholder="hello@aldernotes.app" value={email} onValueChange={handleEmailChange} disabled={isSubmitting} /> {errors.email ? <Field.Error match>{errors.email}</Field.Error> : null} </Field.Root>
<PasswordInput.Root size="lg" name="password" autoComplete="current-password" invalid={Boolean(errors.password)} disabled={isSubmitting} value={password} onValueChange={handlePasswordChange} > <HStack gap="2" justify="between" style={styles.fullWidth}> <PasswordInput.Label style={styles.passwordLabel}> Password </PasswordInput.Label> <Link href="#forgot-password" palette={accentPalette} style={styles.inlineLink} onClick={handleForgotPassword} > Forgot password? </Link> </HStack> <PasswordInput.Control> <PasswordInput.Input placeholder="Enter your password" /> <PasswordInput.VisibilityTrigger /> </PasswordInput.Control> {errors.password ? ( <Field.Error match>{errors.password}</Field.Error> ) : null} </PasswordInput.Root>
<Checkbox.Root size="sm" palette={accentPalette}> <Checkbox.Control checked={rememberMe} disabled={isSubmitting} onCheckedChange={(next) => setRememberMe(next === true)} /> <Checkbox.Label style={styles.checkboxLabel}> Remember me for 30 days </Checkbox.Label> </Checkbox.Root> </VStack>
<Button type="submit" variant="solid" size="lg" palette={accentPalette} disabled={isSubmitting} style={styles.fullWidth} > {isSubmitting ? ( <> <Spinner size="xs" aria-hidden="true" /> Signing in… </> ) : ( "Sign in" )} </Button> </VStack>
<Text variant="caption" align="center"> New to {brandName}?{" "} <Link href="#create-account" palette={accentPalette} style={styles.inlineLink} onClick={handleCreateAccount} > Create an account </Link> </Text> </VStack>
<Toaster toaster={queue} /> </VStack> );}
Inspired by the Basic Login template from Astryx (MIT License · Copyright (c) 2026 Meta Platforms, Inc.).