Newsletter Signup
A complete newsletter signup section, ready to adapt to your product.
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/newsletter-signup.jsonUse it
Scroll horizontally for long lines
"use client";
import { NewsletterSignup } from "@/components/jez-ui/blocks/newsletter-signup";
export default function Example() {
return (
<>
<NewsletterSignup />
</>
);
}
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 {
NewsletterSignup,
NewsletterSignupEyebrow,
NewsletterSignupHeading,
NewsletterSignupLead,
NewsletterSignupFields,
NewsletterSignupPrivacy,
NewsletterSignupStatus,
} from "@/components/jez-ui/blocks/newsletter-signup";
export default function Example() {
return (
<NewsletterSignup>
<NewsletterSignupEyebrow />
<NewsletterSignupHeading />
<NewsletterSignupLead />
<NewsletterSignupFields />
<NewsletterSignupPrivacy />
<NewsletterSignupStatus />
</NewsletterSignup>
);
}
Scroll horizontally for long lines
import { NewsletterSignup, NewsletterSignupContent, NewsletterSignupTitle, NewsletterSignupDescription, NewsletterSignupEyebrow, NewsletterSignupHeading, NewsletterSignupLead, NewsletterSignupFields, NewsletterSignupPrivacy, NewsletterSignupStatus } from "@/components/jez-ui/blocks/newsletter-signup";Props & types
Scroll horizontally for long lines
export type NewsletterSignupOptions = {
className?: string;
onSubmit?: (email: string) => Promise<void>;
heading?: React.ReactNode;
description?: React.ReactNode;
};
export type NewsletterSignupProps = Omit<
React.ComponentProps<"form">,
keyof NewsletterSignupOptions
> &
NewsletterSignupOptions;
NewsletterSignupPropsSource
View 4 source files
registry/blocks/newsletter-signup.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "../ui/utils";
import { ArrowUpRight, Mail } from "lucide-react";
import { Input } from "../ui/input";
import { Button } from "../ui/button";
export type NewsletterSignupOptions = {
className?: string;
onSubmit?: (email: string) => Promise<void>;
heading?: React.ReactNode;
description?: React.ReactNode;
};
export type NewsletterSignupProps = Omit<
React.ComponentProps<"form">,
keyof NewsletterSignupOptions
> &
NewsletterSignupOptions;
function useNewsletterSignupModel({
heading = (
<>
Good work starts
<br />
with a good read.
</>
),
description = "A monthly edit of design discoveries, work in progress, and things worth keeping. Written by people who make things.",
className,
onSubmit,
children,
...rootProps
}: NewsletterSignupProps) {
const [status, setStatus] = React.useState("");
const [busy, setBusy] = React.useState(false);
return {
heading,
description,
className,
onSubmit,
children,
rootProps,
status,
setStatus,
busy,
setBusy,
};
}
const NewsletterSignupCompositionContext = React.createContext<ReturnType<
typeof useNewsletterSignupModel
> | null>(null);
function useNewsletterSignupComposition() {
const context = React.useContext(NewsletterSignupCompositionContext);
if (!context)
throw new Error("NewsletterSignup parts must be inside NewsletterSignup.");
return context;
}
export function NewsletterSignup(props: NewsletterSignupProps) {
const model = useNewsletterSignupModel(props);
const { className, onSubmit, rootProps, setStatus, setBusy, children } =
model;
return (
<NewsletterSignupCompositionContext.Provider value={model}>
<form
{...rootProps}
className={cn(
"relative grid gap-5 overflow-hidden rounded-2xl border border-border bg-muted/30 p-7 sm:p-10",
className,
)}
onSubmit={async (e) => {
e.preventDefault();
setBusy(true);
const email = String(new FormData(e.currentTarget).get("email"));
try {
await onSubmit?.(email);
setStatus(
onSubmit
? "You’re on the list."
: "Demo complete. No email was sent.",
);
} catch {
setStatus("Unable to subscribe. Please try again.");
} finally {
setBusy(false);
}
}}
>
{children !== undefined ? (
children
) : (
<>
<NewsletterSignupEyebrow />
<NewsletterSignupHeading />
<NewsletterSignupLead />
<NewsletterSignupFields />
<NewsletterSignupPrivacy />
<NewsletterSignupStatus />
</>
)}
</form>
</NewsletterSignupCompositionContext.Provider>
);
}
export function NewsletterSignupContent({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="newsletter-signup-content"
className={cn(
"flex items-center gap-2 text-xs font-medium uppercase tracking-widest text-muted-foreground",
className,
)}
{...props}
/>
);
}
export function NewsletterSignupTitle({
className,
...props
}: React.ComponentProps<"h2">) {
return (
<h2
data-slot="newsletter-signup-title"
className={cn(
"max-w-lg font-display text-3xl leading-tight sm:text-4xl",
className,
)}
{...props}
/>
);
}
export function NewsletterSignupDescription({
className,
...props
}: React.ComponentProps<"p">) {
return (
<p
data-slot="newsletter-signup-description"
className={cn(
"max-w-md text-sm leading-relaxed text-muted-foreground",
className,
)}
{...props}
/>
);
}
export function NewsletterSignupEyebrow({
children,
...props
}: Partial<React.ComponentProps<typeof NewsletterSignupContent>> & {
children?: React.ReactNode;
}) {
const {} = useNewsletterSignupComposition();
return (
<NewsletterSignupContent {...props}>
{children === undefined ? (
<>
<Mail size={15} />
The studio dispatch
</>
) : (
children
)}
</NewsletterSignupContent>
);
}
export function NewsletterSignupHeading({
children,
...props
}: Partial<React.ComponentProps<typeof NewsletterSignupTitle>> & {
children?: React.ReactNode;
}) {
const { heading } = useNewsletterSignupComposition();
return (
<NewsletterSignupTitle {...props}>
{children === undefined ? heading : children}
</NewsletterSignupTitle>
);
}
export function NewsletterSignupLead({
children,
...props
}: Partial<React.ComponentProps<typeof NewsletterSignupDescription>> & {
children?: React.ReactNode;
}) {
const { description } = useNewsletterSignupComposition();
return (
<NewsletterSignupDescription {...props}>
{children === undefined ? description : children}
</NewsletterSignupDescription>
);
}
export function NewsletterSignupFields({
children,
...props
}: Partial<React.ComponentProps<"div">> & { children?: React.ReactNode }) {
const { busy } = useNewsletterSignupComposition();
return (
<div
{...props}
className={cn(
"mt-2 flex max-w-lg flex-col gap-2 sm:flex-row",
props.className,
)}
>
{children === undefined ? (
<>
<Input
type="email"
name="email"
required
aria-label="Email address"
placeholder="you@example.com"
/>
<Button type="submit" loading={busy}>
Subscribe <ArrowUpRight size={16} />
</Button>
</>
) : (
children
)}
</div>
);
}
export function NewsletterSignupPrivacy({
children,
...props
}: Partial<React.ComponentProps<"p">> & { children?: React.ReactNode }) {
return (
<p
{...props}
className={cn("text-xs text-muted-foreground", props.className)}
>
{children === undefined
? "One email a month. Unsubscribe whenever you like."
: children}
</p>
);
}
export function NewsletterSignupStatus({ children }: React.PropsWithChildren) {
const { status } = useNewsletterSignupComposition();
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/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/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 · 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 →