| 26 | } |
| 27 | |
| 28 | const Space: React.FC<SpaceProps> = props => { |
| 29 | |
| 30 | const { space } = React.useContext(ConfigContext); |
| 31 | |
| 32 | const { |
| 33 | className, |
| 34 | style, |
| 35 | children, |
| 36 | size = space?.size || 'small', |
| 37 | direction = 'horizontal', |
| 38 | align, |
| 39 | split, |
| 40 | wrap = false, |
| 41 | ...otherProps |
| 42 | } = props; |
| 43 | |
| 44 | const childNodes = React.Children.toArray(children); |
| 45 | |
| 46 | const mergedAlign = direction === 'horizontal' && align === undefined ? 'center' : align; |
| 47 | const cn = classNames( |
| 48 | 'space', |
| 49 | `space-${direction}`, |
| 50 | { |
| 51 | [`space-align-${mergedAlign}`]: mergedAlign, |
| 52 | }, |
| 53 | className, |
| 54 | ); |
| 55 | |
| 56 | const nodes = childNodes.map((child: any, i) => { |
| 57 | |
| 58 | const key = child && child.key || `space-item-${i}`; |
| 59 | |
| 60 | return <> |
| 61 | <div className='space-item' key={key}> |
| 62 | {child} |
| 63 | </div> |
| 64 | {i < childNodes.length && split && ( |
| 65 | <span className={`${className}-split`} style={style}> |
| 66 | {split} |
| 67 | </span> |
| 68 | )} |
| 69 | </> |
| 70 | }); |
| 71 | |
| 72 | const otherStyles: React.CSSProperties = {}; |
| 73 | |
| 74 | const [horizontalSize, verticalSize] = React.useMemo( |
| 75 | () => |
| 76 | ((Array.isArray(size) ? size : [size, size]) as [SizeType, SizeType]).map(item => |
| 77 | getNumberSize(item), |
| 78 | ), |
| 79 | [size] |
| 80 | ); |
| 81 | |
| 82 | otherStyles.columnGap = horizontalSize; |
| 83 | otherStyles.rowGap = verticalSize; |
| 84 | |
| 85 | if (wrap) { |
nothing calls this directly
no test coverage detected