Files
webb/src/components/sections/SectionRenderer.tsx
T

243 lines
7.2 KiB
TypeScript
Raw Normal View History

import React from 'react';
import { SectionConfig, ToolItem, AppItem, CategoryItem, VariantSpec } from '@/types';
import { resolveBindings, isSectionVisible } from '@/lib/config/bindings';
import { HeroSection } from './HeroSection';
import { ToolGridSection } from './ToolGridSection';
import { TryItWidget } from './TryItWidget';
import { BeforeAfterSection } from './BeforeAfterSection';
import { AppCardsSection } from './AppCardsSection';
import { AppHandoffSection } from './AppHandoffSection';
import { AvailabilitySection } from './AvailabilitySection';
import { AppPickerSection } from './AppPickerSection';
import { StepsSection } from './StepsSection';
import { FeatureListSection } from './FeatureListSection';
import { FaqSection } from './FaqSection';
import { StatsSection } from './StatsSection';
import { PricingExplainerSection } from './PricingExplainerSection';
import { RelatedToolsSection } from './RelatedToolsSection';
import { RichTextSection } from './RichTextSection';
import { CtaBannerSection } from './CtaBannerSection';
import { NoticeSection } from './NoticeSection';
import { TransformationReelSection } from './TransformationReelSection';
import { MediaShowcaseSection } from './MediaShowcaseSection';
import { VisualUseCasesSection } from './VisualUseCasesSection';
import { WorkflowVisualizerSection } from './WorkflowVisualizerSection';
import { VerticalToolStackSection } from './VerticalToolStackSection';
import { MajorToolBannersSection } from './MajorToolBannersSection';
import { CinematicHorizontalScrollSection } from './CinematicHorizontalScrollSection';
import { ShiftableToolsGridSection } from './ShiftableToolsGridSection';
import { TrendyBentoSection } from './TrendyBentoSection';
import { RecommendedAppsSection } from './RecommendedAppsSection';
import { HowItWorks3DSection } from './HowItWorks3DSection';
import { ReviewsMarqueeSection } from './ReviewsMarqueeSection';
import { SectionEntrance } from '@/components/ui/SectionEntrance';
interface SectionRendererProps {
section: SectionConfig;
context: {
site?: any;
page?: any;
tool?: ToolItem | null;
app?: AppItem | null;
homeApp?: AppItem | null;
tools?: ToolItem[];
apps?: AppItem[];
categories?: CategoryItem[];
variants?: VariantSpec[];
relatedTools?: ToolItem[];
locale?: string;
device?: 'mobile' | 'desktop';
};
}
export function SectionRenderer(props: SectionRendererProps) {
// Sticky scroll-linked sections must not have parent transforms or content-visibility containment
if (props.section.type === 'majorToolBanners' || props.section.type === 'cinematicHorizontal') {
return <SectionContent {...props} />;
}
return (
<SectionEntrance id={props.section.id}>
<SectionContent {...props} />
</SectionEntrance>
);
}
function SectionContent({ section, context }: SectionRendererProps) {
const locale = context.locale || 'en';
// Visibility Check (PRD §5.2, §5.3 CFG-09)
if (!isSectionVisible(section, { device: context.device, locale })) {
return null;
}
// Resolve bindings on section props (PRD §5.2)
const resolvedProps = resolveBindings(section.props || {}, context, locale);
switch (section.type) {
case 'hero':
return (
<HeroSection
{...resolvedProps}
variant={section.variant}
tool={context.tool}
homeApp={context.homeApp}
variants={context.variants}
locale={locale}
/>
);
case 'shiftableToolsGrid':
case 'toolsGridShiftable':
case 'ourTools':
return (
<ShiftableToolsGridSection
{...resolvedProps}
tools={context.tools}
locale={locale}
/>
);
case 'trendyBento':
case 'bentoGrid':
return <TrendyBentoSection {...resolvedProps} />;
case 'recommendedApps':
return (
<RecommendedAppsSection
{...resolvedProps}
apps={context.apps}
locale={locale}
/>
);
case 'howItWorks':
case 'howSection':
return <HowItWorks3DSection {...resolvedProps} />;
case 'reviewsMarquee':
case 'reviews':
return <ReviewsMarqueeSection {...resolvedProps} />;
case 'transformationReel':
case 'mediaShowcase':
case 'mediaReel':
return <MediaShowcaseSection {...resolvedProps} />;
case 'majorToolBanners':
case 'cinematicHorizontal':
return <CinematicHorizontalScrollSection {...resolvedProps} />;
case 'visualUseCases':
return <VisualUseCasesSection />;
case 'workflowVisualizer':
return <WorkflowVisualizerSection />;
case 'verticalToolStack':
return (
<VerticalToolStackSection
context={{
tools: context.tools || [],
categories: context.categories || [],
apps: context.apps || [],
locale,
}}
/>
);
case 'toolGrid':
return (
<ToolGridSection
{...resolvedProps}
tools={context.tools}
categories={context.categories}
apps={context.apps}
locale={locale}
/>
);
case 'tryItWidget':
if (!context.tool) return null;
return (
<div id="tool-tryit" className="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8 py-10 sm:py-14">
<TryItWidget
tool={context.tool}
homeApp={context.homeApp}
variants={context.variants}
locale={locale}
/>
</div>
);
case 'beforeAfter':
return <BeforeAfterSection {...resolvedProps} locale={locale} />;
case 'appCards':
return (
<AppCardsSection
{...resolvedProps}
apps={context.apps}
layout={section.variant as any}
locale={locale}
/>
);
case 'appHandoff':
if (!context.app && !context.homeApp) return null;
return (
<AppHandoffSection
{...resolvedProps}
app={(context.app || context.homeApp)!}
tool={context.tool}
locale={locale}
/>
);
case 'availability':
if (!context.tool) return null;
return (
<AvailabilitySection
tool={context.tool}
homeApp={context.homeApp}
locale={locale}
/>
);
case 'appPicker':
return <AppPickerSection {...resolvedProps} apps={context.apps} locale={locale} />;
case 'steps':
return <StepsSection {...resolvedProps} locale={locale} />;
case 'featureList':
return <FeatureListSection {...resolvedProps} locale={locale} />;
case 'faq':
return <FaqSection {...resolvedProps} locale={locale} />;
case 'stats':
return <StatsSection {...resolvedProps} />;
case 'pricingExplainer':
return <PricingExplainerSection {...resolvedProps} locale={locale} />;
case 'relatedTools':
return <RelatedToolsSection tools={context.relatedTools} locale={locale} />;
case 'richText':
return <RichTextSection {...resolvedProps} />;
case 'ctaBanner':
return <CtaBannerSection {...resolvedProps} locale={locale} />;
case 'notice':
return <NoticeSection {...resolvedProps} locale={locale} />;
default:
console.warn(`[SectionRenderer] Unknown section type: ${section.type}`);
return null;
}
}