import React from 'react'; import { resolveStackableColor } from '../../utils'; import type { StackableColorValue, EditTags } from '../../types'; /** Native Contentstack link field: `{ title, href }`. */ export interface ProcessStepLink { title?: string; href?: string; } export interface ProcessStepItem { /** * The oversized glyph. Free text straight from the CMS — `01`, `A`, `IV`, * `§` all render. Never parsed as a number and never used for ordering, so * editors are free to label steps however the content calls for. */ label?: string; /** * Named `step_title` rather than `title`: a group subfield with the uid * `title` collides with the content type's mandatory Title field on import. * Props map 1:1 onto field uids, so the prop carries the same name. */ step_title?: string; description?: string; /** * Clipped inside the glyph rather than shown as a picture. Asset URL or a * Contentstack asset object — both are accepted. */ image?: string | { url?: string }; image_alt?: string; link?: ProcessStepLink; $?: EditTags; } export interface ProcessStepProps { heading?: string; subheading?: string; heading_alignment?: 'left' | 'center' | 'right' | string; steps?: ProcessStepItem[]; /** `Alternating` mirrors every second row, as in a zig-zag. */ layout?: 'Alternating' | 'Text Left' | 'Text Right' | string; /** Hairline rule between rows. */ show_dividers?: boolean; /** Short accent bar under each step title. */ show_accent_rule?: boolean; glyph_scale?: 'Small' | 'Medium' | 'Large' | string; background_color?: StackableColorValue; text_color?: StackableColorValue; /** Accent bar, and the glyph itself when a step has no image. */ accent_color?: StackableColorValue; className?: string; /** Contentstack Live Preview edit tags for this entry's own fields. See `EditTags`. */ $?: EditTags; } /** File fields arrive as a URL string from the catalog, as an asset object from the Delivery API. */ function resolveImage(image: ProcessStepItem['image']): string { if (!image) return ''; if (typeof image === 'string') return image.trim(); return typeof image.url === 'string' ? image.url.trim() : ''; } const ALIGNMENTS: Record = { left: 'text-left items-start', center: 'text-center items-center', right: 'text-right items-end', }; /** Section heading: Typography's Accent font when a project sets one, otherwise the page's own. */ const DISPLAY_FONT = 'var(--stackables-font-display, inherit)'; /** * The glyph needs a different face from the heading. Orbitron's zero carries a * diagonal slash and its `1` is angular — fine for a heading, wrong for a * numeral this size. A heavy grotesque has plain geometric figures and wide * strokes, which also show more of the clipped image. Deliberately not a * webfont: no new network request, and `--stackables-font-glyph` lets a host * swap in whatever their brand uses. */ const GLYPH_FONT = 'var(--stackables-font-glyph, "Arial Black", "Helvetica Neue", Helvetica, Arial, sans-serif)'; const GLYPH_SCALES: Record = { Small: 0.72, Medium: 1, Large: 1.32 }; /** * `[min-rem, preferred-vw, max-rem]` per label length. A three- or * four-character label has to start smaller or it outgrows its half of the row, * so the ramp is picked from the label itself rather than fixed. */ const GLYPH_RAMP: ReadonlyArray = [ [5, 19, 13.5], // 1–2 characters — the common case [4, 14.5, 10], // 3 [3, 10.5, 7], // 4 or more ]; function glyphFontSize(label: string, scale: number): string { const ramp = GLYPH_RAMP[Math.min(Math.max(label.length - 2, 0), GLYPH_RAMP.length - 1)]; const [min, vw, max] = ramp; return `clamp(${(min * scale).toFixed(2)}rem, ${(vw * scale).toFixed(1)}vw, ${(max * scale).toFixed(2)}rem)`; } export function ProcessStep({ heading = '', subheading = '', heading_alignment = 'center', steps = [], layout = 'Alternating', show_dividers = true, show_accent_rule = true, glyph_scale = 'Medium', background_color, text_color, accent_color, className = '', $, }: ProcessStepProps) { const resolvedBg = resolveStackableColor(background_color); const resolvedText = resolveStackableColor(text_color); const resolvedAccent = resolveStackableColor(accent_color); const sectionClasses = 'bg-white'; const headingClasses = 'text-gray-900'; const subheadingClasses = 'text-gray-600'; const titleClasses = headingClasses; // Body copy in the mock is deliberately light, but light grey on white fails // AA at this size — gray-500 measures 4.02. These land at 5.74 and 6.98. const bodyClasses = 'text-gray-600'; const dividerClasses = 'bg-gray-200'; // Only reached when a step has no image, so the glyph still has presence. const glyphFallbackClasses = 'text-gray-200'; const accentRuleClasses = 'bg-amber-400'; const alignClass = ALIGNMENTS[heading_alignment] ?? ALIGNMENTS.center; const scale = GLYPH_SCALES[glyph_scale] ?? GLYPH_SCALES.Medium; // Original index (into `steps`) travels alongside each // visible step, since filtering out empty steps would otherwise shift indices. const visibleSteps = (steps ?? []) .map((step, originalIndex) => ({ step, originalIndex })) .filter( ({ step: s }) => Boolean(s?.label?.trim()) || Boolean(s?.step_title?.trim()) || Boolean(s?.description?.trim()), ); return (
{/* ── Section heading ────────────────────────────────────────────── */} {(heading || subheading) && (
{heading && (

{heading}

)} {subheading && (

{subheading}

)}
)} {/* ── Steps ──────────────────────────────────────────────────────── */} {visibleSteps.length === 0 ? (

No steps added yet.

) : (
    {visibleSteps.map(({ step, originalIndex }, i) => { const stepTags = step.$; const src = resolveImage(step.image); const label = step.label?.trim() ?? ''; const href = step.link?.href?.trim(); // `Alternating` mirrors odd rows; the two fixed layouts don't. const glyphFirst = layout === 'Text Right' ? true : layout === 'Text Left' ? false : i % 2 === 1; const glyph = label && (
    {label}
    ); const copy = (
    {step.step_title && (

    {href ? ( {step.step_title} ) : ( step.step_title )}

    )} {show_accent_rule && step.step_title && ( )} {step.description && (

    {step.description}

    )}
    ); return (
  1. {show_dividers && i > 0 && } {/* flex-wrap keeps this responsive with no viewport breakpoints: the halves share the row until minWidth can no longer be met, then stack. Verified at 390px: because wrapping in `row-reverse` still fills top-to-bottom, every stacked row reads copy-then-glyph regardless of mirroring, so narrow screens stay consistent. */}
    {copy}
    {glyph}
  2. ); })}
)}
); } export default ProcessStep;