'use client' import type { ContentListingGroup, ContentListingItem } from '~/lib/content-listings.schema' import { filterContentListingItems, getContentListingById, getContentListingGroupLabel, isExternalContentListingHref, } from '~/lib/content-listings.utils' import { useSendTelemetryEvent } from '~/lib/telemetry' import { ChevronDown, ChevronRight } from 'lucide-react' import Link from 'next/link' import { useCallback, useMemo } from 'react' import ReactMarkdown from 'react-markdown' import { Badge, cn, Heading } from 'ui' import { GlassPanel } from 'ui-patterns/GlassPanel' import { resolveContentListingIcon } from './iconChip' const GRID_ITEM_CLASS = { // Stay 2-up until xl (~1280px) so cards aren't cramped beside the docs sidebar. 2: 'col-span-12 md:col-span-6', 3: 'col-span-12 md:col-span-6 xl:col-span-4', 4: 'col-span-12 md:col-span-6 xl:col-span-3', } as const function useContentListingClickHandler(group: ContentListingGroup) { const sendTelemetryEvent = useSendTelemetryEvent() const groupLabel = getContentListingGroupLabel(group) const trackClick = useCallback( (item: ContentListingItem) => { if (!item.href) return sendTelemetryEvent({ action: 'docs_content_listing_clicked', properties: { targetPath: item.href, linkTitle: item.title, ...(groupLabel ? { groupTitle: groupLabel } : {}), listingId: group.id, }, }) }, [sendTelemetryEvent, group.id, groupLabel] ) return { trackClick } } const PROGRESSION_COLUMNS = 2 type FlowDirection = 'right' | 'wrap' | 'none' function progressionDirection(index: number, count: number): FlowDirection { if (index >= count - 1) return 'none' if (index % PROGRESSION_COLUMNS === PROGRESSION_COLUMNS - 1) return 'wrap' return 'right' } function FlowArrow({ icon: Icon }: { icon: typeof ChevronDown }) { return ( ) } function ProgressionConnector({ direction }: { direction: Exclude }) { return ( {direction === 'right' && ( )} {direction === 'wrap' && ( )} ) } function ContentListingProgression({ group }: { group: ContentListingGroup }) { const { trackClick } = useContentListingClickHandler(group) const items = filterContentListingItems(group.items).filter( (item): item is ContentListingItem & { href: string } => Boolean(item.href) ) return (
    {items.map((item, index) => { const direction = progressionDirection(index, items.length) const panel = ( {item.subtitle && ( {item.subtitle} )} ) return (
  1. trackClick(item)} > {panel} {direction !== 'none' && }
  2. ) })}
) } function ContentListingGroupHeading({ group }: { group: ContentListingGroup }) { if (!group.heading) return null return ( {group.heading} ) } function ContentListingsGroup({ group }: { group: ContentListingGroup }) { const { trackClick } = useContentListingClickHandler(group) const items = useMemo(() => filterContentListingItems(group.items), [group.items]) const isGrid = group.type === 'grid' const listClassName = isGrid ? 'grid md:grid-cols-12 gap-4' : 'list-disc pl-6 space-y-2' const gridItemClassName = isGrid ? GRID_ITEM_CLASS[group.columns ?? 3] : undefined if (!items.length) return null // Heading stays outside `not-prose` so it inherits the surrounding MDX prose // typography. The list itself opts out so its explicit Tailwind layout wins. return (
{group.description && (
{group.description}
)}
    {items.map((item) => { const key = `${group.id}-${item.href ?? item.title}` const panel = ( {item.badge} ) : undefined } > {item.badge && item.badgePosition === 'below' && ( {item.badge} )} {item.subtitle && ( {item.subtitle} )} {item.description} ) const listContent = ( <> {item.title}: {item.description} ) if (!item.href) { return (
  • {isGrid ? panel : listContent}
  • ) } const external = isExternalContentListingHref(item.href) if (isGrid) { return (
  • trackClick(item)} target={external ? '_blank' : undefined} rel={external ? 'noopener noreferrer' : undefined} > {panel}
  • ) } return (
  • trackClick(item)} target={external ? '_blank' : undefined} rel={external ? 'noopener noreferrer' : undefined} > {listContent}
  • ) })}
) } export function ContentListings({ id }: { id: string }) { const group = getContentListingById(id) if (!group || !filterContentListingItems(group.items).length) return null if (group.type === 'progression') { return (
) } return (
) }