Skip to documentation

Design system / Sources & standards

Current repository source

contentShowcase.tsx

src/components/showcase/contentShowcase.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.

"use client";

import { useId, type MouseEvent, type ReactNode } from "react";
import { Maximize2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Card, CardAction, CardContent, CardHeader } from "@/components/ui/card";
import { Dialog } from "@/components/ui/dialog";
import { Text } from "@/components/ui/text";
import { cn } from "@/lib/utils";
import { ContentCarousel } from "@/components/carousel/contentCarousel";
import { ContentCarouselDialog } from "@/components/carousel/contentCarouselDialog";
import { ShowcaseGrid } from "./showcaseGrid";
import { useContentShowcase } from "./useContentShowcase";

export type ContentShowcaseItem = {
  id: string;
  label: string;
  content: ReactNode;
  footer?: ReactNode;
  cardFooter?: ReactNode;
  featuredContent?: ReactNode;
  expandedContent: ReactNode;
  expandedFooter?: ReactNode;
};
export type ContentShowcaseProps = {
  title: string;
  showTitle?: boolean;
  items: readonly ContentShowcaseItem[];
  variant?: "carousel" | "cards";
  emptyMessage?: string;
  companion?: ReactNode;
};

/** Extend the native expand button's hit area without intercepting media or file controls. */
function activateCard(event: MouseEvent<HTMLDivElement>) {
  if (event.defaultPrevented || event.button !== 0 || !(event.target instanceof Element)) return;
  if (!event.currentTarget.contains(event.target) || event.target.closest("button, a, video, audio, input, select, textarea, summary, [role='button'], [role='link'], [contenteditable='true']")) return;
  if (window.getSelection()?.toString()) return;
  event.currentTarget.querySelector<HTMLButtonElement>('[data-slot="showcase-expand"]')?.click();
}

/** Shared collection organism: inline carousel or cards, one expanded viewer. */
export function ContentShowcase({ title, showTitle = true, items, variant = "carousel", emptyMessage = "No items to display.", companion }: ContentShowcaseProps) {
  const id = useId();
  const viewer = useContentShowcase();
  const grid = companion != null;
  const cards = items.map((item, index) => {
    const featured = grid && index === 0;
    return <Card key={item.id} data-slot="showcase-item-card" onClick={activateCard} className={cn("min-w-0 max-w-full cursor-pointer gap-3 py-4 transition-colors hover:border-primary/50 has-focus-visible:border-ring", grid ? "min-h-0" : "w-full sm:w-64")}>
      <CardHeader className="shrink-0 px-4">
        <Text variant="supporting" className="text-muted-foreground">{index + 1} of {items.length}</Text>
        <CardAction><Button data-slot="showcase-expand" type="button" variant="ghost" size="icon-sm" aria-haspopup="dialog" aria-label={`Expand ${item.label}`} onClick={(event) => viewer.expand(event.currentTarget, index)}><Maximize2 aria-hidden="true" /></Button></CardAction>
      </CardHeader>
      <CardContent className="flex min-h-0 flex-1 flex-col gap-3 px-0">
        <div className="min-w-0 flex-1">{featured ? item.featuredContent ?? item.content : item.content}</div>
        {item.cardFooter ? <div className="px-3">{item.cardFooter}</div> : null}
      </CardContent>
    </Card>;
  });
  const empty = <Text variant="supporting" className="text-muted-foreground">{emptyMessage}</Text>;
  return <Dialog open={viewer.open} onOpenChange={viewer.onOpenChange}>
    <div ref={viewer.inlineRef} data-slot="content-showcase" data-variant={variant} className={cn("min-w-0", variant === "carousel" && grid && "space-y-6")}>
      {variant === "carousel" ? <><ContentCarousel title={title} showTitle={showTitle} items={items} variant="card" emptyMessage={emptyMessage} setApi={viewer.setInlineApi}
        headerAction={items.length ? <Button type="button" variant="ghost" size="sm" aria-haspopup="dialog" aria-label={`Expand ${title}`} onClick={(event) => viewer.expand(event.currentTarget)}><Maximize2 aria-hidden="true" />Expand</Button> : null} />{companion}</> :
        <section aria-labelledby={showTitle ? `${id}-title` : undefined} aria-label={showTitle ? undefined : `${title} (${items.length})`} className="space-y-4">
          {showTitle ? <h2 id={`${id}-title`} className="text-label font-semibold">{title} <span className="font-normal text-muted-foreground">({items.length})</span></h2> : null}
          {grid && items.length ? <ShowcaseGrid featured={cards[0]} companion={companion}>{cards.slice(1)}</ShowcaseGrid> : <>{items.length ? <div data-slot="showcase-tiles" className="flex flex-wrap items-start gap-4">{cards}</div> : empty}{grid ? companion : null}</>}
        </section>}
    </div>
    <ContentCarouselDialog ref={viewer.dialogRef} title={title} items={items.map((item) => ({ id: item.id, content: item.expandedContent, footer: item.expandedFooter }))}
      startIndex={viewer.startIndex} setApi={viewer.setExpandedApi} onOpenAutoFocus={viewer.focusCarousel} onCloseAutoFocus={viewer.restoreFocus} />
  </Dialog>;
}
All sources and standards
Current components and theme tokens. Fictional example data. Source views refresh on deployment; authors maintain contract notes.