diff --git a/src/App.jsx b/src/App.jsx index 4d66a78..10d3f20 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -523,17 +523,23 @@ function FlowRow({ return 'disabled'; }; const isRowClickable = Boolean(onLabelClick) && !isEditing; - const isWrappedStepLayout = steps.length > 5; - const isSingleStepLayout = steps.length === 1; - const stepRows = isWrappedStepLayout - ? steps.reduce((rows, step, index) => { - const rowIndex = Math.floor(index / 4); - rows[rowIndex] = [...(rows[rowIndex] ?? []), { step, index }]; - return rows; - }, []) - : []; - const wrappedCardColumns = ['xl:col-start-1', 'xl:col-start-3', 'xl:col-start-5', 'xl:col-start-7']; - const wrappedArrowColumns = ['xl:col-start-2', 'xl:col-start-4', 'xl:col-start-6']; + const maxVisibleSteps = 4; + const [stepWindowStart, setStepWindowStart] = useState(0); + const maxWindowStart = Math.max(0, steps.length - maxVisibleSteps); + const visibleStepItems = steps + .map((step, index) => ({ step, index })) + .slice(stepWindowStart, stepWindowStart + maxVisibleSteps); + const placeholderCount = Math.max(0, maxVisibleSteps - visibleStepItems.length); + const canMovePrev = stepWindowStart > 0; + const canMoveNext = stepWindowStart < maxWindowStart; + + useEffect(() => { + setStepWindowStart((current) => Math.min(current, maxWindowStart)); + }, [maxWindowStart]); + + const moveStepWindow = (direction) => { + setStepWindowStart((current) => Math.min(maxWindowStart, Math.max(0, current + direction))); + }; const renderStepCard = (step, index, className) => (