File tree Expand file tree Collapse file tree 1 file changed +18
-22
lines changed
Expand file tree Collapse file tree 1 file changed +18
-22
lines changed Original file line number Diff line number Diff line change 11import React from "react"
22import { List , Box , SxProps } from "@mui/material"
33
4- const SpacedList = ( {
5- itemSpacing,
6- sx,
7- children
8- } : {
4+ interface SpacedListProps {
95 itemSpacing : number
106 sx ?: SxProps
117 children ?: React . ReactNode
12- } ) => {
8+ }
9+
10+ const SpacedList = ( { itemSpacing, sx, children } : SpacedListProps ) => {
11+ const childrenArray = React . Children . toArray ( children )
12+ const lastIndex = childrenArray . length - 1
13+
1314 return (
14- < List disablePadding sx = { { ...sx } } >
15- { React . Children . map ( children , ( child , idx ) => {
16- const baseKey = ( child as React . ReactElement ) ?. key ?? "idx" ;
17- const key = `${ String ( baseKey ) } -${ idx } ` ;
18- return (
19- < Box
20- key = { key }
21- sx = { {
22- marginBottom :
23- idx < React . Children . count ( children ) - 1 ? itemSpacing : 0 ,
24- } }
25- >
26- { child }
27- </ Box >
28- ) ;
29- } ) }
15+ < List disablePadding sx = { sx } >
16+ { childrenArray . map ( ( child , idx ) => (
17+ < Box
18+ key = { idx }
19+ sx = { {
20+ marginBottom : idx < lastIndex ? itemSpacing : 0
21+ } }
22+ >
23+ { child }
24+ </ Box >
25+ ) ) }
3026 </ List >
3127 )
3228}
You can’t perform that action at this time.
0 commit comments