A call to action that writes the project brief

Build a closing CTA section in React where visitors pick chips to build a one-line brief, and the button turns into exactly that project with real kick-off and launch dates.

6 min read

The real component. Click the picture to open it live and try it before you read how it was built.

"Get started" says nothing. This call to action lets the visitor say what they want: a few chips build a one-line brief, and the button becomes that project, such as "Start a 4-week marketing site".

Picks become a sentence

Each question is a row of chips with an ink fill that slides from the old pick to the new. The picks read as one sentence with the choices in the accent colour, and the button's label rises in each time it changes.

src/registry/cta/project-brief/brief-text.ts

// What a visitor can pick, and how their picks read as one sentence and one button label.

export interface BriefOption {
  id: string;
  // The chip's text.
  label: string;
  // How it reads inside the brief sentence. Defaults to the label.
  phrase?: string;
  // How it reads inside the button label (a "4-week" for "a month"). Defaults to the phrase.
  token?: string;
  // How long the project runs, so the brief can show a launch date.
  weeks?: number;
}

export interface BriefField {
  id: string;
  // The question above the chips ("I need a", "Live in").
  label: string;
  // The words before the pick inside the sentence ("I need a", "live in", "for").
  lead: string;
  options: BriefOption[];
  // Optional fields start empty, and clicking the picked chip again clears them.
  isOptional?: boolean;
  defaultOptionId?: string;
}

// Field id → picked option id.
export type BriefPicks = Record<string, string | undefined>;

export interface BriefPart {
  fieldId: string;
  lead: string;
  phrase: string;
}

const PLACEHOLDER = /\{(\w+)\}/g;

export function getDefaultPicks(fields: BriefField[]): BriefPicks {
  return Object.fromEntries(
    fields.map((field) => [
      field.id,
      field.isOptional ? field.defaultOptionId : (field.defaultOptionId ?? field.options[0]?.id),
    ]),
  );
}

function getPickedOption(field: BriefField, picks: BriefPicks): BriefOption | undefined {
  return field.options.find((option) => option.id === picks[field.id]);
}

// The picked fields in order, each as its lead and the words of its pick.
export function getBriefParts(fields: BriefField[], picks: BriefPicks): BriefPart[] {
  return fields.flatMap((field) => {
    const option = getPickedOption(field, picks);
    return option ? [{ fieldId: field.id, lead: field.lead, phrase: option.phrase ?? option.label }] : [];
  });
}

export function joinBriefParts(parts: BriefPart[]): string {
  return `${parts.map((part) => `${part.lead} ${part.phrase}`).join(", ")}.`;
}

// Fills "{fieldId}" placeholders with each pick's token; a placeholder with no pick is dropped.
export function fillTemplate(template: string, fields: BriefField[], picks: BriefPicks): string {
  return template
    .replace(PLACEHOLDER, (_, fieldId: string) => {
      const field = fields.find((candidate) => candidate.id === fieldId);
      const option = field && getPickedOption(field, picks);
      return option ? (option.token ?? option.phrase ?? option.label) : "";
    })
    .replace(/\s+/g, " ")
    .trim();
}

// The project's length in weeks, from the first pick that has one.
export function getPickedWeeks(fields: BriefField[], picks: BriefPicks): number | undefined {
  return fields.map((field) => getPickedOption(field, picks)?.weeks).find((weeks) => weeks !== undefined);
}

// Carries the brief to wherever the button goes: the subject of a mailto, or a field of a contact form.
export function withBriefParam(href: string, param: string | undefined, brief: string): string {
  if (!param) return href;
  return `${href}${href.includes("?") ? "&" : "?"}${param}=${encodeURIComponent(brief)}`;
}
How picks read as a sentence and a button label

Dates from today

The next kick-off and the launch it leads to are worked out from today once the page has loaded, with a quiet placeholder until then so server and browser agree. An hourly refresh keeps a page left open overnight honest.

src/registry/cta/project-brief/brief-dates.tsx

"use client";

import { useNow } from "@/hooks/use-now";
import { addWeeks, formatShortDate, getNextKickoff, toIsoDay, type KickoffSchedule } from "./kickoff-dates";

// Today changes rarely; an hourly read keeps a page left open overnight honest.
const DATE_REFRESH_MS = 60 * 60 * 1000;

interface BriefDatesProps {
  schedule: KickoffSchedule;
  weeks: number | undefined;
  locale: string;
}

// The next kick-off and the launch it leads to, worked out from today once the page has loaded.
export function BriefDates({ schedule, weeks, locale }: BriefDatesProps) {
  const now = useNow(DATE_REFRESH_MS);
  const kickoff = now && getNextKickoff(now, schedule);
  const launch = kickoff && weeks !== undefined ? addWeeks(kickoff, weeks) : null;

  return (
    <dl className="mt-5 flex flex-wrap gap-x-8 gap-y-3 border-t border-dashed border-border-strong pt-4 text-sm">
      <div className="flex items-center gap-2">
        <span aria-hidden className="relative flex size-2">
          <span className="absolute inset-0 animate-ping rounded-full bg-primary/60 motion-reduce:animate-none" />
          <span className="relative size-2 rounded-full bg-primary" />
        </span>
        <dt className="text-muted-foreground">{schedule.label}</dt>
        <DateValue date={kickoff} locale={locale} />
      </div>
      {weeks !== undefined && (
        <div className="flex items-center gap-2">
          <dt className="text-muted-foreground">{schedule.launchLabel}</dt>
          <DateValue date={launch} locale={locale} />
        </div>
      )}
    </dl>
  );
}

// A date, or a quiet bar of the same size until the browser knows what day it is.
function DateValue({ date, locale }: { date: Date | null; locale: string }) {
  if (!date) return <dd aria-hidden className="h-4 w-20 rounded-sm bg-muted" />;
  return (
    <dd className="font-medium text-foreground tabular-nums">
      <time dateTime={toIsoDay(date)}>{formatShortDate(date, locale)}</time>
    </dd>
  );
}
Kick-off and launch dates

More articles