Newsletter signup
An email field and button that morph into one pill: the button travels, the envelope flies off, and a confirmation slides in.
"use client";
import { useState, type FormEvent } from "react";
import "./newsletter-signup.css";
/**
* NewsletterSignup
* - idle → sending → done. The "send" is faked with a timeout; call your email provider there.
* - The whole pill changes shape per state with CSS only (data-state on the form).
*/
export function NewsletterSignup({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const [email, setEmail] = useState("");
const [state, setState] = useState<"idle" | "sending" | "done" | "error">(
"idle",
);
const submit = (e: FormEvent) => {
e.preventDefault();
if (!/^\S+@\S+\.\S{2,}$/.test(email)) return setState("error");
setState("sending");
setTimeout(() => setState("done"), 1100); // replace with your request
};
return (
<div className="gu-news" data-theme={theme}>
<h3>One good email a month.</h3>
<p>
Free design resources, new pieces and nothing else. Unsubscribe in one
click.
</p>
<form
className="gu-news__pill"
data-state={state}
onSubmit={submit}
noValidate
>
<label htmlFor="gu-news-email" className="gu-sr">
Email address
</label>
<input
id="gu-news-email"
type="email"
inputMode="email"
autoComplete="email"
placeholder="you@studio.com"
value={email}
disabled={state === "sending" || state === "done"}
aria-invalid={state === "error"}
aria-describedby="gu-news-msg"
onChange={(e) => {
setEmail(e.target.value);
if (state === "error") setState("idle");
}}
/>
<button
type="submit"
disabled={state === "sending" || state === "done"}
>
<span className="gu-news__label">Subscribe</span>
<svg className="gu-news__env" viewBox="0 0 24 24" aria-hidden="true">
<rect x="3" y="5.5" width="18" height="13" rx="2" />
<path d="m4 7 8 6 8-6" />
</svg>
</button>
<span className="gu-news__done" aria-hidden={state !== "done"}>
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="m5 10.5 3.2 3.2L15 6.5" />
</svg>
You're in. Check {email.split("@")[1] ?? "your inbox"} to
confirm.
</span>
</form>
<p id="gu-news-msg" className="gu-news__msg" role="status">
{state === "error"
? "That email is missing something. Try name@example.com."
: state === "done"
? "Subscribed. A confirmation email is on its way."
: ""}
</p>
</div>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Newsletter signup
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A newsletter signup where the email field and button share one pill. Submitting shrinks the button to a circle and an envelope flies off; then the pill turns lime and a confirmation slides up in place.
## Layout and look
- Title "One good email a month." (clamp 26–35px, weight 900, tight), a muted line, then the pill.
- Pill: 60px tall, 1.5px border, background #fbf8f2 (dark #18181b), 5px inner padding. Input fills the space; a 140px Ink button ("Subscribe") sits inside on the right and turns orange on hover.
- Done: lime #d7ff3a pill with dark text: check icon + "You're in. Check {domain} to confirm."
## Behavior and motion
1. Invalid email: border goes orange-red, the pill shakes ±5px, a helpful message appears.
2. Sending: button width animates 140px → 48px (500ms cubic-bezier(0.16, 1, 0.3, 1)), the label slides up and out, an envelope slides in, then flies to the top-right while shrinking and fading.
3. Done: input and button slide up and fade; the confirmation slides up from below.
## Touch
56px+ height; type="email" keyboard.
## Accessibility
- Visually hidden label; aria-invalid and aria-describedby link to a role="status" message.
- prefers-reduced-motion: instant state changes, no shake or flight.
## Props
theme. Replace the timeout with your provider's request.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### NewsletterSignup.tsx
```tsx
"use client";
import { useState, type FormEvent } from "react";
import "./newsletter-signup.css";
/**
* NewsletterSignup
* - idle → sending → done. The "send" is faked with a timeout; call your email provider there.
* - The whole pill changes shape per state with CSS only (data-state on the form).
*/
export function NewsletterSignup({
theme = "light",
}: {
theme?: "light" | "dark";
}) {
const [email, setEmail] = useState("");
const [state, setState] = useState<"idle" | "sending" | "done" | "error">(
"idle",
);
const submit = (e: FormEvent) => {
e.preventDefault();
if (!/^\S+@\S+\.\S{2,}$/.test(email)) return setState("error");
setState("sending");
setTimeout(() => setState("done"), 1100); // replace with your request
};
return (
<div className="gu-news" data-theme={theme}>
<h3>One good email a month.</h3>
<p>
Free design resources, new pieces and nothing else. Unsubscribe in one
click.
</p>
<form
className="gu-news__pill"
data-state={state}
onSubmit={submit}
noValidate
>
<label htmlFor="gu-news-email" className="gu-sr">
Email address
</label>
<input
id="gu-news-email"
type="email"
inputMode="email"
autoComplete="email"
placeholder="you@studio.com"
value={email}
disabled={state === "sending" || state === "done"}
aria-invalid={state === "error"}
aria-describedby="gu-news-msg"
onChange={(e) => {
setEmail(e.target.value);
if (state === "error") setState("idle");
}}
/>
<button
type="submit"
disabled={state === "sending" || state === "done"}
>
<span className="gu-news__label">Subscribe</span>
<svg className="gu-news__env" viewBox="0 0 24 24" aria-hidden="true">
<rect x="3" y="5.5" width="18" height="13" rx="2" />
<path d="m4 7 8 6 8-6" />
</svg>
</button>
<span className="gu-news__done" aria-hidden={state !== "done"}>
<svg viewBox="0 0 20 20" aria-hidden="true">
<path d="m5 10.5 3.2 3.2L15 6.5" />
</svg>
You're in. Check {email.split("@")[1] ?? "your inbox"} to
confirm.
</span>
</form>
<p id="gu-news-msg" className="gu-news__msg" role="status">
{state === "error"
? "That email is missing something. Try name@example.com."
: state === "done"
? "Subscribed. A confirmation email is on its way."
: ""}
</p>
</div>
);
}
```
### newsletter-signup.css
```css
/* NewsletterSignup: change these colors to match your brand. */
.gu-news {
--text: #0e0e10;
--muted: #57534b;
--pill: #fbf8f2;
--line: rgb(14 14 16 / 0.18);
--btn: #0e0e10;
--btn-text: #f3eee3;
--accent: #ff5a1f;
--ok: #d7ff3a;
--error: #c2410c;
--focus: #2b35ff;
--ease: cubic-bezier(0.16, 1, 0.3, 1);
display: grid;
gap: 10px;
width: min(100%, 480px);
color: var(--text);
font-family: system-ui, sans-serif;
}
.gu-news[data-theme="dark"] {
--text: #f3eee3;
--muted: #aea89c;
--pill: #18181b;
--line: rgb(243 238 227 / 0.18);
--btn: #f3eee3;
--btn-text: #0e0e10;
--error: #fb923c;
--focus: #d7ff3a;
}
.gu-news h3 {
margin: 0;
font-size: clamp(1.6rem, 6cqi, 2.2rem);
font-weight: 900;
letter-spacing: -0.04em;
line-height: 1;
}
.gu-news > p {
margin: 0 0 6px;
color: var(--muted);
}
.gu-news__pill {
position: relative;
display: flex;
height: 60px;
padding: 5px;
overflow: hidden;
border: 1.5px solid var(--line);
border-radius: 999px;
background: var(--pill);
transition:
border-color 0.3s,
background-color 0.4s var(--ease);
}
.gu-news__pill:focus-within {
border-color: var(--focus);
box-shadow: 0 0 0 4px color-mix(in srgb, var(--focus) 18%, transparent);
}
.gu-news__pill[data-state="error"] {
border-color: var(--error);
animation: gu-news-shake 0.4s;
}
@keyframes gu-news-shake {
25%,
75% {
transform: translateX(-5px);
}
50% {
transform: translateX(5px);
}
}
.gu-news input {
flex: 1;
min-width: 0;
padding: 0 16px;
border: 0;
outline: none;
background: none;
color: inherit;
font: inherit;
font-size: 1rem;
transition:
opacity 0.3s,
transform 0.4s var(--ease);
}
.gu-news button {
position: relative;
display: grid;
place-items: center;
width: 140px;
border: 0;
border-radius: 999px;
background: var(--btn);
color: var(--btn-text);
font: inherit;
font-weight: 800;
cursor: pointer;
transition:
width 0.5s var(--ease),
background-color 0.3s;
}
.gu-news button:hover {
background: var(--accent);
color: #0e0e10;
}
.gu-news button:focus-visible {
outline: 3px solid var(--focus);
outline-offset: 2px;
}
.gu-news__label,
.gu-news__env {
grid-area: 1 / 1;
transition:
opacity 0.25s,
transform 0.5s var(--ease);
}
.gu-news__env {
width: 22px;
fill: none;
stroke: currentColor;
stroke-width: 2;
stroke-linejoin: round;
opacity: 0;
transform: translateY(14px);
}
/* Sending: the button shrinks to a circle and the envelope flies out to the right */
.gu-news__pill[data-state="sending"] input {
opacity: 0.4;
}
.gu-news__pill[data-state="sending"] button {
width: 48px;
background: var(--accent);
color: #0e0e10;
}
.gu-news__pill[data-state="sending"] .gu-news__label {
opacity: 0;
transform: translateY(-14px);
}
.gu-news__pill[data-state="sending"] .gu-news__env {
opacity: 1;
transform: none;
animation: gu-news-fly 0.7s 0.4s var(--ease) forwards;
}
@keyframes gu-news-fly {
to {
transform: translate(60px, -40px) rotate(-20deg) scale(0.6);
opacity: 0;
}
}
/* Done: the pill turns lime and the confirmation slides up */
.gu-news__pill[data-state="done"] {
border-color: transparent;
background: var(--ok);
color: #0e0e10;
}
.gu-news__pill[data-state="done"] input,
.gu-news__pill[data-state="done"] button {
opacity: 0;
transform: translateY(-30px);
transition:
opacity 0.2s,
transform 0.4s var(--ease);
}
.gu-news__done {
position: absolute;
inset: 0;
display: flex;
align-items: center;
gap: 10px;
padding: 0 22px;
font-weight: 800;
opacity: 0;
transform: translateY(30px);
pointer-events: none;
transition:
opacity 0.3s 0.1s,
transform 0.5s 0.1s var(--ease);
}
.gu-news__pill[data-state="done"] .gu-news__done {
opacity: 1;
transform: none;
}
.gu-news__done svg {
flex: none;
width: 22px;
fill: none;
stroke: currentColor;
stroke-width: 2.6;
stroke-linecap: round;
stroke-linejoin: round;
}
.gu-news__msg {
min-height: 1.3em;
margin: 0;
padding-left: 18px;
font-size: 0.85rem;
font-weight: 600;
color: var(--muted);
}
.gu-news:has([data-state="error"]) .gu-news__msg {
color: var(--error);
}
.gu-sr {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
}
@container (max-width: 380px) {
.gu-news button {
width: 112px;
}
}
@media (prefers-reduced-motion: reduce) {
.gu-news *,
.gu-news__pill {
transition-duration: 0.01s !important;
animation: none !important;
}
}
```
You might also want
Next piece: Notification bellCopy field
Components, beginner
Date range picker
Components, advanced
Floating label form
Components, beginner