All blocks
Login Card
Centered workspace sign-in card with inline field validation, password visibility toggle, remember-device persistence, Google, GitHub, and passkey provider buttons, and toast feedback.
Built withButtonCardCheckboxFieldGridHeadingIconIcon BadgeInputLinkPassword InputSeparatorSpinnerStackTextToast
Meridian Cloud
Welcome back
Sign in to your Meridian Cloud workspace
By continuing, you agree to our Terms of Service and Privacy Policy.
Install
1npx stylexblocks add login-cardSource
components/blocks/ui-sdk/login-card.tsx
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604import * as stylex from "@stylexjs/stylex";import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { Button } from "#components/ui/ui-sdk/button.tsx";import { Card } from "#components/ui/ui-sdk/card.tsx";import { Checkbox } from "#components/ui/ui-sdk/checkbox.tsx";import { Field } from "#components/ui/ui-sdk/field.tsx";import { Grid } from "#components/ui/ui-sdk/grid.tsx";import { Heading } from "#components/ui/ui-sdk/heading.tsx";import { Icon } from "#components/ui/ui-sdk/icon.tsx";import { IconBadge } from "#components/ui/ui-sdk/icon-badge.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 { Separator } from "#components/ui/ui-sdk/separator.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 { 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 type LoginProviderId = "google" | "github" | "passkey";
export interface LoginCredentials { email: string; password: string; rememberDevice: boolean;}
export interface LoginCardProps extends StyleOverrideProps { /** Workspace or product name shown in the brand lockup and sign-up prompt. */ brandName?: string; /** Primary card heading. */ title?: string; /** Supporting subtitle beneath the heading. */ description?: string; /** Initial work email value. */ defaultEmail?: string; /** Initial state of the remember-device checkbox. */ defaultRememberDevice?: boolean; /** Called after client-side validation succeeds on sign-in. */ onSignIn?: (credentials: LoginCredentials) => void; /** Called when a social or passkey provider button is activated. */ onProviderSignIn?: (provider: LoginProviderId) => void; /** Called when the user activates the forgot-password link. */ onForgotPassword?: (email: string) => void; /** Called when the user activates the create-account link. */ onSignUp?: () => void;}
interface LoginErrors { email?: string; password?: string;}
// ── Inline SVG Marks ──────────────────────────────────────────────────────────
function MeridianMark() { return ( <Icon size="sm" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" > <circle cx="10" cy="10" r="7.5" /> <ellipse cx="10" cy="10" rx="3.4" ry="7.5" /> <path d="M2.8 10h14.4" /> </Icon> );}
function GoogleIcon() { return ( <Icon size="sm" viewBox="0 0 24 24" fill="none" aria-hidden="true"> <path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92a5.06 5.06 0 0 1-2.2 3.32v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.1Z" fill="#4285F4" /> <path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23Z" fill="#34A853" /> <path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62Z" fill="#FBBC05" /> <path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53Z" fill="#EA4335" /> </Icon> );}
function GitHubIcon() { return ( <Icon size="sm" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"> <path fillRule="evenodd" clipRule="evenodd" d="M12 2C6.48 2 2 6.59 2 12.25c0 4.53 2.87 8.37 6.84 9.73.5.09.68-.22.68-.49 0-.24-.01-.88-.01-1.73-2.78.62-3.37-1.37-3.37-1.37-.45-1.18-1.11-1.5-1.11-1.5-.91-.64.07-.63.07-.63 1 .07 1.53 1.06 1.53 1.06.89 1.56 2.34 1.11 2.91.85.09-.66.35-1.11.63-1.37-2.22-.26-4.56-1.14-4.56-5.07 0-1.12.39-2.03 1.03-2.75-.1-.26-.45-1.3.1-2.71 0 0 .84-.28 2.75 1.05A9.38 9.38 0 0 1 12 6.84c.85 0 1.71.12 2.51.35 1.91-1.33 2.75-1.05 2.75-1.05.55 1.41.2 2.45.1 2.71.64.72 1.03 1.63 1.03 2.75 0 3.94-2.34 4.81-4.57 5.06.36.32.68.94.68 1.9 0 1.37-.01 2.48-.01 2.81 0 .27.18.59.69.49A10.22 10.22 0 0 0 22 12.25C22 6.59 17.52 2 12 2Z" /> </Icon> );}
function PasskeyIcon() { return ( <Icon size="sm" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true" > <circle cx="7.5" cy="8.5" r="3.5" /> <path d="M10.4 10.6 17 17.2" /> <path d="M14 14.2 16.2 12" /> <path d="M15.8 16 17.5 14.3" /> </Icon> );}
// ── Validation & Provider Metadata ────────────────────────────────────────────
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const PROVIDER_META: Record< LoginProviderId, { title: string; description: string }> = { google: { title: "Continuing with Google", description: "Redirecting to Google Workspace SSO for Meridian Cloud.", }, github: { title: "Continuing with GitHub", description: "Authorizing your GitHub developer account with Meridian Cloud.", }, passkey: { title: "Passkey prompt ready", description: "Use Touch ID, Face ID, or a hardware security key to verify.", },};
function validateCredentials(email: string, password: string): LoginErrors { const nextErrors: LoginErrors = {}; const trimmedEmail = email.trim();
if (!trimmedEmail) { nextErrors.email = "Enter your work email address."; } else if (!EMAIL_PATTERN.test(trimmedEmail)) { nextErrors.email = "Enter a valid email address (for example, maya@meridian.dev)."; }
if (!password) { nextErrors.password = "Enter your password to continue."; } else if (password.length < 8) { nextErrors.password = "Password must be at least 8 characters."; }
return nextErrors;}
// ── Styles ────────────────────────────────────────────────────────────────────
const styles = stylex.create({ root: { backgroundColor: semanticColors.bg, color: semanticColors.fg, fontFamily: fonts.body, minHeight: "100%", overflowY: "auto", paddingBlock: { default: spacing._10, "@media (max-width: 640px)": spacing._6, }, paddingInline: spacing._4, width: "100%", }, column: { maxWidth: "25rem", width: "100%", }, brandName: { letterSpacing: letterSpacings.tight, }, fullWidth: { width: "100%", }, cardHeader: { alignItems: "center", gap: spacing._1, textAlign: "center", }, title: { marginBlock: 0, textAlign: "center", }, subtitle: { marginBlock: 0, textAlign: "center", }, cardBody: { gap: spacing._5, }, fields: { gap: spacing._3_5, 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, }, dividerLine: { flexBasis: 0, flexGrow: 1, flexShrink: 1, minWidth: 0, width: "auto", }, dividerText: { flexShrink: 0, whiteSpace: "nowrap", }, providerGrid: { gap: spacing._2_5, gridTemplateColumns: { default: "repeat(2, minmax(0, 1fr))", "@media (max-width: 360px)": "1fr", }, width: "100%", }, legal: { lineHeight: lineHeights.sm, maxWidth: "36ch", }, legalLink: { color: semanticColors.fgMuted, fontSize: fontSizes.xs, lineHeight: lineHeights.sm, },});
// ── Component ─────────────────────────────────────────────────────────────────
/** * LoginCard — centered authentication card for Meridian Cloud pairing work * email and password fields with inline validation, password visibility toggle, * remember-device persistence, social/passkey provider actions, and toast * feedback. */export function LoginCard({ brandName = "Meridian Cloud", title = "Welcome back", description = "Sign in to your Meridian Cloud workspace", defaultEmail = "", defaultRememberDevice = true, onSignIn, onProviderSignIn, onForgotPassword, onSignUp, palette, style,}: LoginCardProps) { const [email, setEmail] = useState(defaultEmail); const [password, setPassword] = useState(""); const [rememberDevice, setRememberDevice] = useState(defaultRememberDevice); const [errors, setErrors] = useState<LoginErrors>({}); const [isSubmitting, setIsSubmitting] = useState(false);
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)); }, []);
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); return; }
setErrors({}); setIsSubmitting(true);
const trimmedEmail = email.trim(); submitTimerRef.current = setTimeout(() => { submitTimerRef.current = null; setIsSubmitting(false); onSignIn?.({ email: trimmedEmail, password, rememberDevice, }); queue.success(`Signed in to ${brandName}`, { description: rememberDevice ? `Session active for ${trimmedEmail} — device remembered for 30 days.` : `Session active for ${trimmedEmail} for this browser session.`, }); }, 650); }, [brandName, email, isSubmitting, onSignIn, password, queue, rememberDevice], );
const handleProviderClick = useCallback( (provider: LoginProviderId) => { onProviderSignIn?.(provider); const copy = PROVIDER_META[provider]; queue.info(copy.title, { description: copy.description }); }, [onProviderSignIn, queue], );
const handleForgotPassword = useCallback( (event: React.MouseEvent<HTMLAnchorElement>) => { event.preventDefault(); const trimmedEmail = email.trim(); onForgotPassword?.(trimmedEmail); const target = trimmedEmail && EMAIL_PATTERN.test(trimmedEmail) ? trimmedEmail : "maya@meridian.dev"; queue.info("Password reset link sent", { description: `Check ${target} for workspace recovery instructions.`, }); }, [email, onForgotPassword, queue], );
const handleSignUpClick = useCallback( (event: React.MouseEvent<HTMLAnchorElement>) => { event.preventDefault(); onSignUp?.(); queue.info("Workspace registration", { description: `Create a new ${brandName} seat or request a team invite.`, }); }, [brandName, onSignUp, queue], );
const handleLegalClick = useCallback( (event: React.MouseEvent<HTMLAnchorElement>, docTitle: string) => { event.preventDefault(); queue.info(docTitle, { description: `Reviewing ${brandName} ${docTitle.toLowerCase()}.`, }); }, [brandName, queue], );
return ( <VStack align="center" justify="center" gap="0" palette={palette} style={[styles.root, style]} > <VStack render={<main />} align="center" gap="5" style={styles.column}> {/* Brand lockup */} <VStack align="center" gap="2"> <IconBadge variant="solid" size="md" palette={accentPalette} aria-hidden="true" > <MeridianMark /> </IconBadge> <Text render={<span />} size="md" weight="semibold" style={styles.brandName}> {brandName} </Text> </VStack>
{/* Sign-in card */} <Card.Root variant="elevated" size="lg" style={styles.fullWidth}> <Card.Header style={styles.cardHeader}> <Heading render={<h1 />} size="2xl" style={styles.title}> {title} </Heading> <Card.Description style={styles.subtitle}>{description}</Card.Description> </Card.Header>
<Card.Body style={styles.cardBody}> <VStack render={<form noValidate onSubmit={handleSubmit} />} gap="4" style={styles.fullWidth} > <VStack style={styles.fields}> <Field.Root invalid={Boolean(errors.email)}> <Field.Label>Work email</Field.Label> <Input type="email" name="email" size="lg" autoComplete="email" placeholder="maya@meridian.dev" 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={rememberDevice} disabled={isSubmitting} onCheckedChange={(next) => setRememberDevice(next === true)} /> <Checkbox.Label style={styles.checkboxLabel}> Remember this device 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>
<HStack gap="3" style={styles.fullWidth}> <Separator decorative style={styles.dividerLine} /> <Text render={<span />} variant="caption" style={styles.dividerText}> Or continue with </Text> <Separator decorative style={styles.dividerLine} /> </HStack>
<VStack gap="2.5" style={styles.fullWidth}> <Grid columns="2" style={styles.providerGrid}> <Button type="button" variant="surface" size="lg" disabled={isSubmitting} onClick={() => handleProviderClick("google")} style={styles.fullWidth} > <GoogleIcon /> Google </Button> <Button type="button" variant="surface" size="lg" disabled={isSubmitting} onClick={() => handleProviderClick("github")} style={styles.fullWidth} > <GitHubIcon /> GitHub </Button> </Grid>
<Button type="button" variant="surface" size="lg" disabled={isSubmitting} onClick={() => handleProviderClick("passkey")} style={styles.fullWidth} > <PasskeyIcon /> Sign in with passkey </Button> </VStack>
<Text variant="caption" align="center"> New to {brandName}?{" "} <Link href="#create-account" palette={accentPalette} style={styles.inlineLink} onClick={handleSignUpClick} > Create an account </Link> </Text> </Card.Body> </Card.Root>
{/* Legal terms */} <Text variant="caption" align="center" style={styles.legal}> By continuing, you agree to our{" "} <Link href="#terms" variant="underline" style={styles.legalLink} onClick={(event) => handleLegalClick(event, "Terms of Service")} > Terms of Service </Link>{" "} and{" "} <Link href="#privacy" variant="underline" style={styles.legalLink} onClick={(event) => handleLegalClick(event, "Privacy Policy")} > Privacy Policy </Link> . </Text> </VStack>
<Toaster toaster={queue} /> </VStack> );}
Inspired by the Login Card template from Astryx (MIT License · Copyright (c) 2026 Meta Platforms, Inc.).