---
title: "Basic Login · UI SDK — StyleX Blocks"
description: "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."
url: "https://stylexblocks.com/block/ui-sdk/basic-login/"
agent:
  instructions: "Use this search API to find relevant components and blocks across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://stylexblocks.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Basic Login block

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.

- Behavior engine: UI SDK
- Category: [Auth](https://stylexblocks.com/blocks/auth.md)
- Built with: [Alert](https://stylexblocks.com/components/ui-sdk/alert.md), [Button](https://stylexblocks.com/components/ui-sdk/button.md), [Center](https://stylexblocks.com/components/ui-sdk/center.md), [Checkbox](https://stylexblocks.com/components/ui-sdk/checkbox.md), [Field](https://stylexblocks.com/components/ui-sdk/field.md), [Heading](https://stylexblocks.com/components/ui-sdk/heading.md), [Icon](https://stylexblocks.com/components/ui-sdk/icon.md), [Icon Button](https://stylexblocks.com/components/ui-sdk/icon-button.md), [Input](https://stylexblocks.com/components/ui-sdk/input.md), [Link](https://stylexblocks.com/components/ui-sdk/link.md), [Password Input](https://stylexblocks.com/components/ui-sdk/password-input.md), [Spinner](https://stylexblocks.com/components/ui-sdk/spinner.md), [Stack](https://stylexblocks.com/components/ui-sdk/stack.md), [Text](https://stylexblocks.com/components/ui-sdk/text.md), [Toast](https://stylexblocks.com/components/ui-sdk/toast.md)
- HTML page: https://stylexblocks.com/block/ui-sdk/basic-login/

## Install

Configure the project once (sets the behavior engine and import aliases):

```sh
npx stylexblocks init --style ui-sdk
```

Then add the item as source you own:

```sh
npx stylexblocks add basic-login
```

Equivalent: `npx shadcn add @stylexblocks/basic-login`. Registry item JSON: https://stylexblocks.com/r/ui-sdk/basic-login.json

## Usage

```tsx
import { BasicLogin } from "#components/blocks/ui-sdk/basic-login.tsx";

export function Example() {
  return (
    <div style={{ minHeight: "100dvh" }}>
      <BasicLogin />
    </div>
  );
}
```

## Source

`components/blocks/ui-sdk/basic-login.tsx`

```tsx
import * 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>
  );
}
```

Credit: Inspired by [Basic Login](https://astryx.atmeta.com/playground?template=login) from Astryx (MIT License · Copyright (c) 2026 Meta Platforms, Inc.)
