Skip to content

Commit

Permalink
fix: add back step counter within a tutorial section
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Oct 16, 2020
1 parent 74b219e commit ee58f46
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/TutorialSection.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from 'react';
import React, { Children, cloneElement } from 'react';
import PropTypes from 'prop-types';
import { css } from '@emotion/core';
import { isMdxType } from '../utils/mdx';

const TutorialSection = ({ children }) => {
const totalSteps = Children.toArray(children).filter((child) =>
isMdxType(child, 'TutorialStep')
).length;
let step = 1;

return (
<section
css={css`
Expand All @@ -13,7 +19,13 @@ const TutorialSection = ({ children }) => {
}
`}
>
{children}
{Children.map(children, (child) => {
if (isMdxType(child, 'TutorialStep')) {
return cloneElement(child, { stepNumber: step++, totalSteps });
}

return child;
})}
</section>
);
};
Expand Down

0 comments on commit ee58f46

Please sign in to comment.