Skip to content

Commit

Permalink
feat: created a component that allows for side-by-side content
Browse files Browse the repository at this point in the history
  • Loading branch information
zstix committed Jun 5, 2020
1 parent fb806be commit 82b3414
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/components/SideBySide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';

import styles from './SideBySide.module.scss';

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);

return (
<div className={cx(className, styles.container)}>
<div>{rest}</div>
{side && <div>{side}</div>}
</div>
);
};

SideBySide.propTypes = {
children: PropTypes.node.isRequired,
type: PropTypes.string.isRequired,
className: PropTypes.string,
dir: PropTypes.string,
};

SideBySide.defaultProps = {
dir: 'right',
};

export default SideBySide;
11 changes: 11 additions & 0 deletions src/components/SideBySide.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.container {
display: flex;

div {
flex: 1;
}

div:nth-child(2) {
margin-left: 1rem;
}
}

0 comments on commit 82b3414

Please sign in to comment.