Sign In Form
A working sign in form with illustrative data and frontend interactions.
Make it yours.
Install the editable source and its dependencies into your React + Tailwind project.
Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/sign-in-form.jsonUse it
Scroll horizontally for long lines
"use client";
import { SignInForm } from "@/components/jez-ui/blocks/sign-in-form";
export default function Example() {
return (
<>
<SignInForm />
</>
);
}
Compose your own
These styled parts are included in the same install. Use children to build your layout; add className only when you want an override.
Scroll horizontally for long lines
"use client";
import {
SignInForm,
SignInFormIntro,
SignInFormEmailField,
SignInFormPasswordField,
SignInFormSubmit,
SignInFormStatus,
} from "@/components/jez-ui/blocks/sign-in-form";
export default function Example() {
return (
<SignInForm>
<SignInFormIntro />
<SignInFormEmailField />
<SignInFormPasswordField />
<SignInFormSubmit />
<SignInFormStatus />
</SignInForm>
);
}
Scroll horizontally for long lines
import { SignInForm, SignInFormContent, SignInFormTitle, SignInFormIntro, SignInFormEmailField, SignInFormPasswordField, SignInFormSubmit, SignInFormStatus } from "@/components/jez-ui/blocks/sign-in-form";Props & types
Scroll horizontally for long lines
export type SignInFormOptions = {
className?: string;
onSubmit?: (data: Record<string, string>) => Promise<void>;
heading?: React.ReactNode;
};
export type SignInFormProps = Omit<
React.ComponentProps<"form">,
keyof SignInFormOptions
> &
SignInFormOptions;
SignInFormPropsSource
View 6 source files
registry/blocks/sign-in-form.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "../ui/utils";
import { LockKeyhole } from "lucide-react";
import { PasswordInput } from "../ui/password-input";
import { Input } from "../ui/input";
import { FormField } from "../ui/form-field";
import { Button } from "../ui/button";
export type SignInFormOptions = {
className?: string;
onSubmit?: (data: Record<string, string>) => Promise<void>;
heading?: React.ReactNode;
};
export type SignInFormProps = Omit<
React.ComponentProps<"form">,
keyof SignInFormOptions
> &
SignInFormOptions;
function useSignInFormModel({
heading = "Welcome back.",
className,
onSubmit,
children,
...rootProps
}: SignInFormProps) {
const [status, setStatus] = React.useState("");
const [busy, setBusy] = React.useState(false);
return {
heading,
className,
onSubmit,
children,
rootProps,
status,
setStatus,
busy,
setBusy,
};
}
const SignInFormCompositionContext = React.createContext<ReturnType<
typeof useSignInFormModel
> | null>(null);
function useSignInFormComposition() {
const context = React.useContext(SignInFormCompositionContext);
if (!context) throw new Error("SignInForm parts must be inside SignInForm.");
return context;
}
export function SignInForm(props: SignInFormProps) {
const model = useSignInFormModel(props);
const { className, onSubmit, rootProps, setStatus, setBusy, children } =
model;
return (
<SignInFormCompositionContext.Provider value={model}>
<form
{...rootProps}
className={cn(
"grid w-full max-w-md gap-5 rounded-2xl border border-border bg-background p-7 sm:p-9",
className,
)}
onSubmit={async (e) => {
e.preventDefault();
const data = Object.fromEntries(
new FormData(e.currentTarget),
) as Record<string, string>;
setBusy(true);
try {
await onSubmit?.(data);
setStatus(
onSubmit
? "Request complete."
: "Demo complete. No account or email was created.",
);
} catch {
setStatus("Unable to continue. Check your details and try again.");
} finally {
setBusy(false);
}
}}
>
{children !== undefined ? (
children
) : (
<>
<SignInFormIntro />
<SignInFormEmailField />
<SignInFormPasswordField />
<SignInFormSubmit />
<SignInFormStatus />
</>
)}
</form>
</SignInFormCompositionContext.Provider>
);
}
export function SignInFormContent({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="sign-in-form-content"
className={cn("mb-2", className)}
{...props}
/>
);
}
export function SignInFormTitle({
className,
...props
}: React.ComponentProps<"h2">) {
return (
<h2
data-slot="sign-in-form-title"
className={cn("font-display text-2xl", className)}
{...props}
/>
);
}
export function SignInFormIntro({
children,
...props
}: Partial<React.ComponentProps<typeof SignInFormContent>> & {
children?: React.ReactNode;
}) {
const { heading } = useSignInFormComposition();
return (
<SignInFormContent {...props}>
{children === undefined ? (
<>
<span className="mb-5 grid size-10 place-items-center rounded-xl border border-border bg-muted/30">
<LockKeyhole size={18} />
</span>
<SignInFormTitle>{heading}</SignInFormTitle>
<p className="mt-2 text-sm leading-relaxed text-muted-foreground">
Sign in to pick up where you left off.
</p>
</>
) : (
children
)}
</SignInFormContent>
);
}
export function SignInFormEmailField({
children,
...props
}: Partial<React.ComponentProps<typeof FormField>> & {
children?: React.ReactNode;
}) {
const {} = useSignInFormComposition();
return (
<FormField label="Email" {...props}>
{children === undefined ? (
<Input
name="email"
type="email"
required
autoComplete="email"
placeholder="you@company.com"
/>
) : (
children
)}
</FormField>
);
}
export function SignInFormPasswordField({
children,
...props
}: Partial<React.ComponentProps<typeof FormField>> & {
children?: React.ReactNode;
}) {
const {} = useSignInFormComposition();
return (
<FormField label="Password" {...props}>
{children === undefined ? (
<PasswordInput
name="password"
required
minLength={8}
autoComplete="current-password"
/>
) : (
children
)}
</FormField>
);
}
export function SignInFormSubmit({
children,
...props
}: Partial<React.ComponentProps<typeof Button>> & {
children?: React.ReactNode;
}) {
const { busy } = useSignInFormComposition();
return (
<Button type="submit" loading={busy} {...props}>
{children === undefined ? "Sign in" : children}
</Button>
);
}
export function SignInFormStatus({ children }: React.PropsWithChildren) {
const { status } = useSignInFormComposition();
return children === undefined
? status && (
<p role="status" className="text-sm">
{status}
</p>
)
: children;
}
registry/ui/utils.ts
Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
return twMerge(clsx(values));
}
registry/ui/password-input.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { Eye, EyeOff, LockKeyhole } from "lucide-react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { Input } from "./input";
import { cn } from "./utils";
export function PasswordInput({
className,
inputClassName,
...props
}: Omit<React.ComponentProps<typeof Input>, "type"> & {
inputClassName?: string;
}) {
const [visible, setVisible] = React.useState(false);
const reduce = useReducedMotion();
return (
<div className={cn("group relative w-full", className)}>
<LockKeyhole
size={15}
className="pointer-events-none absolute left-3 top-1/2 z-10 -translate-y-1/2 text-muted-foreground transition-colors group-focus-within:text-primary"
/>
<Input
aria-label="Password"
autoComplete="current-password"
{...props}
type={visible ? "text" : "password"}
className={cn("px-10", inputClassName)}
/>
<button
type="button"
disabled={props.disabled}
aria-label={visible ? "Hide password" : "Show password"}
aria-pressed={visible}
onMouseDown={(e) => e.preventDefault()}
onClick={() => setVisible((v) => !v)}
className="absolute right-1 top-1 grid size-8 place-items-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground"
>
<AnimatePresence mode="wait" initial={false}>
<motion.span
key={String(visible)}
initial={{
opacity: 0,
rotate: reduce ? 0 : -35,
scale: reduce ? 1 : 0.7,
}}
animate={{ opacity: 1, rotate: 0, scale: 1 }}
exit={{
opacity: 0,
rotate: reduce ? 0 : 35,
scale: reduce ? 1 : 0.7,
}}
transition={{ duration: reduce ? 0 : 0.12 }}
>
{visible ? <EyeOff size={16} /> : <Eye size={16} />}
</motion.span>
</AnimatePresence>
</button>
</div>
);
}
registry/ui/input.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
export function Input({ className, ...props }: React.ComponentProps<"input">) {
return (
<input
className={cn(
"block h-10 w-full min-w-0 rounded-lg border border-border bg-background px-3 text-sm leading-normal shadow-[0_1px_2px_#00000004] transition-[border-color,box-shadow] placeholder:text-muted-foreground/75 hover:border-foreground/25 focus:border-primary focus:outline-none focus:ring-3 focus:ring-primary/10 aria-invalid:border-danger aria-invalid:ring-danger/10 disabled:cursor-not-allowed disabled:bg-muted/50 disabled:opacity-50",
className,
)}
{...props}
/>
);
}
registry/ui/form-field.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
export function FormField({
label,
hint,
error,
children,
className,
...rootProps
}: Omit<
React.ComponentProps<"div">,
keyof {
label: string;
hint?: string;
error?: string;
children: React.ReactElement<{
id?: string;
"aria-describedby"?: string;
"aria-invalid"?: boolean;
}>;
className?: string;
}
> & {
label: string;
hint?: string;
error?: string;
children: React.ReactElement<{
id?: string;
"aria-describedby"?: string;
"aria-invalid"?: boolean;
}>;
className?: string;
}) {
const generatedId = React.useId();
const id = children.props.id ?? generatedId;
return (
<div {...rootProps} className={cn("grid gap-2", className)}>
<label htmlFor={id} className="text-sm font-medium">
{label}
</label>
{React.cloneElement(children, {
id,
"aria-describedby":
[
children.props["aria-describedby"],
hint || error ? id + "-help" : undefined,
]
.filter(Boolean)
.join(" ") || undefined,
"aria-invalid": error ? true : children.props["aria-invalid"],
})}
{(hint || error) && (
<p
id={id + "-help"}
role={error ? "alert" : undefined}
className={cn(
"text-xs",
error ? "text-danger" : "text-muted-foreground",
)}
>
{error || hint}
</p>
)}
</div>
);
}
export function Field({ className, ...props }: React.ComponentProps<"div">) {
return <div className={cn("grid gap-2", className)} {...props} />;
}
export function FieldGroup({
className,
...props
}: React.ComponentProps<"div">) {
return <div className={cn("grid gap-6", className)} {...props} />;
}
export function FieldSet({
className,
...props
}: React.ComponentProps<"fieldset">) {
return (
<fieldset className={cn("grid min-w-0 gap-5", className)} {...props} />
);
}
export function FieldLegend({
className,
...props
}: React.ComponentProps<"legend">) {
return <legend className={cn("mb-3 font-medium", className)} {...props} />;
}
export function FieldLabel({
className,
...props
}: React.ComponentProps<"label">) {
return <label className={cn("text-sm font-medium", className)} {...props} />;
}
export function FieldDescription({
className,
...props
}: React.ComponentProps<"p">) {
return (
<p
className={cn("text-xs leading-relaxed text-muted-foreground", className)}
{...props}
/>
);
}
export function FieldError({ className, ...props }: React.ComponentProps<"p">) {
return (
<p
role="alert"
className={cn("text-xs leading-relaxed text-danger", className)}
{...props}
/>
);
}
export function FieldContent({
className,
...props
}: React.ComponentProps<"div">) {
return <div className={cn("grid min-w-0 gap-1", className)} {...props} />;
}
export function FieldRow({
className,
...props
}: React.ComponentProps<"label">) {
return (
<label
className={cn("flex items-center gap-3 text-sm font-medium", className)}
{...props}
/>
);
}
registry/ui/button.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { Slot } from "radix-ui";
import { LoaderCircle } from "lucide-react";
import { cn } from "./utils";
export type ButtonProps = React.ComponentProps<"button"> & {
variant?: "primary" | "secondary" | "outline" | "ghost" | "danger";
size?: "sm" | "md" | "lg";
loading?: boolean;
asChild?: boolean;
};
export function Button({
variant = "primary",
size = "md",
loading,
asChild,
className,
children,
disabled,
...props
}: ButtonProps) {
const Comp = asChild ? Slot.Root : "button";
return (
<Comp
type={asChild ? undefined : "button"}
disabled={asChild ? undefined : disabled || loading}
aria-disabled={disabled || loading || undefined}
aria-busy={loading || undefined}
className={cn(
"relative inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-transparent text-sm font-medium leading-none transition-[background-color,border-color,box-shadow,transform] duration-150 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary active:scale-[.98] disabled:pointer-events-none disabled:opacity-45 aria-disabled:pointer-events-none [&_svg]:shrink-0",
{
"bg-primary text-primary-foreground shadow-[inset_0_1px_0_#ffffff26,0_1px_2px_#00000012] hover:bg-primary/90":
variant === "primary",
"border-border/60 bg-muted text-foreground hover:bg-muted/70":
variant === "secondary",
"border-border bg-background text-foreground shadow-sm hover:bg-muted/60":
variant === "outline",
"text-muted-foreground hover:bg-muted hover:text-foreground":
variant === "ghost",
"bg-danger text-danger-foreground hover:bg-danger/90":
variant === "danger",
},
{
"h-8 px-3 text-xs": size === "sm",
"h-10 px-4": size === "md",
"h-12 px-6": size === "lg",
},
className,
)}
{...props}
>
{asChild ? (
children
) : (
<>
<span
className={cn(
"inline-flex min-w-0 flex-1 items-center justify-center gap-2",
loading && "invisible",
)}
>
{children}
</span>
{loading && (
<LoaderCircle
aria-hidden="true"
className="absolute size-4 animate-spin motion-reduce:animate-none"
/>
)}
</>
)}
</Comp>
);
}
Dependencies
lucide-react@0.577.0 · clsx@2.1.1 · tailwind-merge@3.5.0 · motion@13.2.0 · radix-ui@1.6.7
Accessibility & behaviour
Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.
Read the accessibility and performance guide →