diff --git a/src/components/SideBySide.js b/src/components/SideBySide.js index 19c076694..f60443e0a 100644 --- a/src/components/SideBySide.js +++ b/src/components/SideBySide.js @@ -1,18 +1,31 @@ -import React from 'react'; +import React, { Children, Fragment } from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; - import styles from './SideBySide.module.scss'; +import splitUsing from '../utils/splitUsing'; +import splitWhen from '../utils/splitWhen'; + +const isMdxType = (child, type) => child?.props?.mdxType === type; -const SideBySide = ({ className, children, type, dir }) => { - const childObjects = React.Children.toArray(children); - const side = childObjects.find((child) => child?.props?.mdxType === type); - const rest = childObjects.filter((child) => child !== side); +const SideBySide = ({ className, children, type }) => { + const childObjects = Children.toArray(children); + const rendersRightColumn = childObjects.some((child) => + isMdxType(child, type) + ); + const sections = splitUsing(childObjects, (child) => + isMdxType(child, type) + ).map((section) => splitWhen(section, (child) => isMdxType(child, type))); return ( -