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) => (
@@ -687,46 +693,59 @@ function FlowRow({ )}
- {isWrappedStepLayout ? ( -
- {stepRows.map((row, rowIndex) => ( -
+ {steps.length > maxVisibleSteps && ( + <> + + + + )} +
+ {visibleStepItems.map(({ step, index }, itemIndex) => ( +
+ {renderStepCard(step, index, 'min-w-0')} + {itemIndex < visibleStepItems.length - 1 && ( + + )}
))} -
- ) : ( -
- {steps.map((step, index) => ( - - {renderStepCard(step, index, isSingleStepLayout ? 'w-full max-w-[320px]' : 'min-w-0 flex-1')} - {index < steps.length - 1 && ( -
- - -
- )} -
+ {Array.from({ length: placeholderCount }).map((_, index) => ( +
+ ))} + {visibleStepItems.slice(0, -1).map((item, index) => ( +
- )} +
); }