import React from 'react' ; const getAttachedChildren = ( children ) => { const childrenArray = React . Children . toArray ( children ) ; if ( childrenArray . length <= 1 ) { return childrenArray ; } const trailingChildren = childrenArray . slice ( 1 ) ; trailingChildren . pop ( ) ; const marginProp = { ... { ml : 0 , mr : 0 , roundedRight : 0 , roundedLeft : 0 } , } ; const leftElemProp = { ... { mr : 0 , roundedRight : 0 } , } ; const rightElemProp = { ... { ml : 0 , roundedLeft : 0 } , } ; const trailingChildrenWithSpacing = trailingChildren . map ( ( child ) => { return React . cloneElement ( child , marginProp , child . props . children ) ; } ) ; return [ React . cloneElement ( childrenArray [ 0 ] , leftElemProp , childrenArray [ 0 ] . props . children ) , ... trailingChildrenWithSpacing , React . cloneElement ( childrenArray [ childrenArray . length - 1 ] , rightElemProp , childrenArray [ childrenArray . length - 1 ] . props . children ) , ] ; } ; export default getAttachedChildren ;