|
| 1 | +import { getIcon } from "@/components/IconRenderer" |
| 2 | +import { StaggerContainer, StaggerItem } from "@/components/animations/Stagger" |
| 3 | +import { Card } from "@/components/ui/Card" |
| 4 | +import { Section } from "@/components/ui/Section" |
| 5 | +import type { FlowExampleLayoutBlock } from "@/lib/cms" |
| 6 | +import { cn } from "@/lib/utils" |
| 7 | +import { FlowExampleDiagram, type FlowDiagramNode } from "./client/FlowExampleDiagram" |
| 8 | + |
| 9 | +interface FlowExampleSectionProps { |
| 10 | + content?: FlowExampleLayoutBlock | null |
| 11 | +} |
| 12 | + |
| 13 | +export function FlowExampleSection({ content }: FlowExampleSectionProps) { |
| 14 | + const trigger = content?.flow?.trigger |
| 15 | + if (!content || !trigger?.name) return null |
| 16 | + |
| 17 | + const triggerNode: FlowDiagramNode = { |
| 18 | + id: "trigger", |
| 19 | + icon: getIcon(trigger.icon, 20), |
| 20 | + text: trigger.name, |
| 21 | + } |
| 22 | + const items: FlowDiagramNode[] = |
| 23 | + content.flow?.items?.map((item, index) => ({ |
| 24 | + id: String(item.id ?? index), |
| 25 | + icon: getIcon(item.icon, 20, item.id ?? index), |
| 26 | + text: item.text, |
| 27 | + })) ?? [] |
| 28 | + const isCenter = content.sectionLayout === "flowCenter" |
| 29 | + const isRight = content.sectionLayout === "flowRight" |
| 30 | + const flow = ( |
| 31 | + <div |
| 32 | + className={cn( |
| 33 | + "relative m-2 min-w-0 overflow-hidden rounded-2xl border border-white/10 bg-primary/40", |
| 34 | + isCenter ? "min-h-72" : "min-h-72 lg:min-h-96", |
| 35 | + isRight && "lg:order-2" |
| 36 | + )} |
| 37 | + > |
| 38 | + <FlowExampleDiagram trigger={triggerNode} items={items} /> |
| 39 | + </div> |
| 40 | + ) |
| 41 | + const body = ( |
| 42 | + <StaggerContainer className={cn("flex flex-col justify-center p-8 md:p-10", isRight && "lg:order-1")} delayChildren={0.06} staggerChildren={0.08}> |
| 43 | + {content.contentHeading && ( |
| 44 | + <StaggerItem as="h2" y={14} duration={0.38} className="text-3xl font-semibold leading-tight tracking-tight text-white md:text-4xl"> |
| 45 | + {content.contentHeading} |
| 46 | + </StaggerItem> |
| 47 | + )} |
| 48 | + {content.contentDescription && ( |
| 49 | + <StaggerItem as="p" y={14} duration={0.38} className="mt-4 max-w-2xl text-base leading-7 text-secondary md:text-lg"> |
| 50 | + {content.contentDescription} |
| 51 | + </StaggerItem> |
| 52 | + )} |
| 53 | + </StaggerContainer> |
| 54 | + ) |
| 55 | + |
| 56 | + const example = <article className={cn("relative z-10 overflow-hidden", isCenter ? "flex flex-col" : "grid lg:grid-cols-2")}>{isCenter ? <>{flow}{(content.contentHeading || content.contentDescription) && body}</> : <>{flow}{body}</>}</article> |
| 57 | + |
| 58 | + return ( |
| 59 | + <Section |
| 60 | + heading={content.sectionHeading} |
| 61 | + description={content.sectionDescription} |
| 62 | + linkButton={content.sectionLinkButton} |
| 63 | + funnelType="center" |
| 64 | + animation={{ preset: "none" }} |
| 65 | + > |
| 66 | + <div className={cn("mx-auto w-full", isCenter && "max-w-5xl")}> |
| 67 | + {content.showBorder ? <Card size="lg" variant="light" className="p-2!">{example}</Card> : example} |
| 68 | + </div> |
| 69 | + </Section> |
| 70 | + ) |
| 71 | +} |
0 commit comments