Skip to content

Commit

Permalink
fix: Ensure Steps handles a single child. Use the Children utility in…
Browse files Browse the repository at this point in the history
…stead
  • Loading branch information
jerelmiller committed Jun 11, 2020
1 parent a0cfad4 commit 3a6cf85
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions src/components/Steps.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import React from 'react';
import { Children, cloneElement } from 'react';
import PropTypes from 'prop-types';
import { isMdxType } from '../utils/mdx';

const Steps = ({ children }) => {
// get the number of steps
const totalSteps = children.filter(
(child) => child?.props?.mdxType === 'Step'
const totalSteps = Children.toArray(children).filter((child) =>
isMdxType(child, 'Step')
).length;

// return the children with additional props
return (
<>
{children.map((child, index) => ({
...child,
props: {
...child.props,
number: index + 1,
total: totalSteps,
},
}))}
</>
return Children.map(children, (child, index) =>
cloneElement(child, { number: index + 1, total: totalSteps })
);
};

Expand Down

0 comments on commit 3a6cf85

Please sign in to comment.