Skip to documentation

Design system / Sources & standards

Current repository source

submissionCard.tsx

src/components/submissions/submissionCard.tsx

This view contains the escaped source read during the deployment build. Code and policy text are unchanged. Markdown is shown as source, not rendered as a document. A new deployment refreshes the content.

import { useId, type ReactNode } from "react";
import Link from "next/link";
import { Badge } from "@/components/ui/badge";

export type SubmissionCardMetadataField = "brand" | "agency" | "country" | "zone" | "category";

export interface SubmissionCardDisplay {
  /** Select and order inline facts. An empty list hides all metadata. */
  metadata?: readonly SubmissionCardMetadataField[];
  status?: boolean;
  score?: boolean;
  /** Context and attribution are opt-in to keep collection cards compact. */
  edition?: boolean;
  submitter?: boolean;
  date?: boolean;
}

const defaultMetadata: readonly SubmissionCardMetadataField[] = ["brand", "zone", "country", "agency", "category"];

export interface SubmissionCardProps {
  title: string;
  status?: string;
  brand?: string | null;
  agency?: string | null;
  country?: string | null;
  zone?: string | null;
  submittedByName?: string | null;
  updatedAt?: string;
  dateLabel?: string;
  editionTitle?: string;
  year?: number;
  categoryName?: string | null;
  posterImageUrl?: string | null;
  /** Media collections retain a poster placeholder for title-only drafts. */
  media?: boolean;
  score?: string | null;
  href: string | null;
  headingLevel?: 3 | 4;
  display?: SubmissionCardDisplay;
  /** Static summary facts inside the link. Never put controls here. */
  children?: ReactNode;
  /** Controls and expandable details stay outside the summary link. */
  action?: ReactNode;
  /** Thumbnail-corner controls outside the summary link. Implies a media frame. */
  mediaAction?: ReactNode;
}

/** Shared summary molecule. Callers own authorized data, destinations and actions. */
export function SubmissionCard({
  title, status, brand, agency, country, zone, submittedByName, updatedAt,
  dateLabel = "Updated", editionTitle, year, categoryName, posterImageUrl,
  media = false, score, href, headingLevel = 3, display = {}, children, action, mediaAction,
}: SubmissionCardProps) {
  const titleId = useId();
  const Heading = `h${headingLevel}` as "h3" | "h4";
  const metadata = { brand: ["Brand", brand], agency: ["Agency", agency], country: ["Country", country], zone: ["Zone", zone], category: ["Category", categoryName] };
  const facts = (display.metadata ?? defaultMetadata).map(field => ({ field, label: metadata[field][0], value: metadata[field][1] })).filter(fact => fact.value);
  const hasMedia = media || Boolean(posterImageUrl) || Boolean(mediaAction);
  const statusBadge = display.status !== false && status ? <Badge variant={status === "draft" ? "secondary" : "outline"} className={`max-w-full whitespace-normal break-words capitalize${hasMedia && status !== "draft" ? " bg-card text-card-foreground" : ""}`}>{status === "draft" ? "Draft" : status === "submitted" ? "Submitted" : status}</Badge> : null;
  const showSubmitter = display.submitter === true && submittedByName !== undefined;
  const showDate = display.date === true && Boolean(updatedAt);
  const content = <>
    {hasMedia ? <div className="relative aspect-[16/9] overflow-hidden bg-muted" data-submission-media>
      {posterImageUrl ? (
        // eslint-disable-next-line @next/next/no-img-element
        <img src={posterImageUrl} alt="" className="size-full object-cover transition duration-300 group-hover:scale-105" />
      ) : <div className="size-full bg-gradient-to-br from-muted to-accent" />}
      {statusBadge ? <div className="absolute inset-x-3 top-3 flex justify-end">{statusBadge}</div> : null}
    </div> : null}
    <div className="flex min-w-0 flex-1 flex-col gap-2 p-4">
      {display.edition && editionTitle ? <p className="break-words text-eyebrow uppercase text-muted-foreground">{editionTitle}{year !== undefined ? ` · ${year}` : ""}</p> : null}
      {!hasMedia ? statusBadge : null}
      <div className="flex items-start justify-between gap-2">
        <Heading id={titleId} className="min-w-0 break-words text-label font-semibold group-hover:underline">{title}</Heading>
        {display.score !== false && score ? <span className="shrink-0 rounded-full bg-primary/10 px-2 py-0.5 text-supporting font-semibold text-primary">{score}</span> : null}
      </div>
      {facts.length ? <dl className="flex flex-wrap gap-x-2 gap-y-1 text-supporting text-muted-foreground">
        {facts.map(({ field, label, value }, index) => <div key={field} className="min-w-0 max-w-full">
          <dt className="sr-only">{label}</dt>
          <dd className="break-words">{index > 0 ? <span aria-hidden="true" className="mr-2">·</span> : null}{value}</dd>
        </div>)}
      </dl> : null}
      {children}
      {showSubmitter || showDate ? <div className="mt-auto flex flex-wrap gap-x-3 gap-y-1 pt-2 text-supporting text-muted-foreground">
        {showSubmitter ? <span className="min-w-0 max-w-full break-words">{submittedByName ?? "Unknown submitter"}</span> : null}
        {showDate && updatedAt ? <span>{dateLabel} {new Intl.DateTimeFormat("en-US", { day: "numeric", month: "short", year: "numeric" }).format(new Date(updatedAt))}</span> : null}
      </div> : null}
    </div>
  </>;
  const contentClass = "flex min-w-0 flex-1 flex-col";
  return <article aria-labelledby={titleId} data-submission-card className="group relative flex h-full min-w-0 flex-col overflow-hidden rounded-xl border bg-card text-card-foreground transition hover:-translate-y-0.5 hover:border-primary/50 hover:shadow-md">
    {href ? <Link href={href} aria-labelledby={titleId} className={`${contentClass} focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring`}>{content}</Link> : <div className={contentClass}>{content}</div>}
    {mediaAction ? <div data-submission-media-action className="pointer-events-none absolute inset-x-3 top-3 flex justify-start"><div className="pointer-events-auto min-w-0 max-w-full">{mediaAction}</div></div> : null}
    {action ? <div className="space-y-3 border-t p-4">{action}</div> : null}
  </article>;
}
All sources and standards
Current components and theme tokens. Fictional example data. Source views refresh on deployment; authors maintain contract notes.