({
items,
availableWidth,
getItemKey,
renderItem,
footer,
marginTop = 0,
}: GridLayoutProps<T>)
| 13 | } |
| 14 | |
| 15 | function GridLayoutInner<T>({ |
| 16 | items, |
| 17 | availableWidth, |
| 18 | getItemKey, |
| 19 | renderItem, |
| 20 | footer, |
| 21 | marginTop = 0, |
| 22 | }: GridLayoutProps<T>): ReactNode { |
| 23 | const { columns, columnWidth, columnGroups } = useGridLayout(items, availableWidth) |
| 24 | |
| 25 | if (items.length === 0) return null |
| 26 | |
| 27 | // Unified structure for both single and multi-column layouts |
| 28 | // Using a consistent DOM structure prevents reconciliation issues during resize transitions |
| 29 | const isMultiColumn = columns > 1 |
| 30 | |
| 31 | return ( |
| 32 | <box |
| 33 | style={{ |
| 34 | flexDirection: 'column', |
| 35 | gap: isMultiColumn ? 1 : 0, |
| 36 | width: '100%', |
| 37 | marginTop, |
| 38 | }} |
| 39 | > |
| 40 | <box |
| 41 | style={{ |
| 42 | flexDirection: 'row', |
| 43 | gap: isMultiColumn ? 1 : 0, |
| 44 | width: '100%', |
| 45 | alignItems: 'flex-start', |
| 46 | }} |
| 47 | > |
| 48 | {columnGroups.map((columnItems, colIdx) => { |
| 49 | const columnKey = columnItems[0] |
| 50 | ? getItemKey(columnItems[0]) |
| 51 | : `col-${colIdx}` |
| 52 | return ( |
| 53 | <box |
| 54 | key={columnKey} |
| 55 | style={{ |
| 56 | flexDirection: 'column', |
| 57 | gap: 0, |
| 58 | flexGrow: 1, |
| 59 | flexShrink: 1, |
| 60 | flexBasis: 0, |
| 61 | // Use MIN_COLUMN_WIDTH instead of 0 to prevent columns from collapsing |
| 62 | // to zero during resize transitions (prevents 2→1 column transition bug) |
| 63 | minWidth: MIN_COLUMN_WIDTH, |
| 64 | }} |
| 65 | > |
| 66 | {columnItems.map((item, idx) => ( |
| 67 | <box key={getItemKey(item)} style={{ width: '100%' }}> |
| 68 | {renderItem(item, idx, columnWidth)} |
| 69 | </box> |
| 70 | ))} |
| 71 | </box> |
| 72 | ) |
nothing calls this directly
no test coverage detected