{"size": 621, "ext": "js", "max_stars_repo_path": "src/Progress/Progress.js", "max_stars_repo_name": "vigosan/react-declarative-wizard", "max_stars_repo_stars_event_min_datetime": "2017-10-04T08:24:42.000Z", "max_stars_repo_stars_event_max_datetime": "2020-02-14T04:29:13.000Z", "max_issues_repo_path": "src/Progress/Progress.js", "max_issues_repo_name": "vigosan/react-declarative-wizard", "max_issues_repo_issues_event_min_datetime": "2017-10-04T09:53:45.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-04T08:58:06.000Z", "max_forks_repo_path": "src/Progress/Progress.js", "max_forks_repo_name": "vigosan/react-declarative-wizard", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 8, "max_issues_count": 9, "max_forks_count": null, "avg_line_length": 24.84, "max_line_length": 78, "alphanum_fraction": 0.6586151369}
import React from 'react';
import PropTypes from 'prop-types';
import WizardContext from '../context';

const Progress = ({ children, render }) => (
  <WizardContext.Consumer>
    {({ activeStepIndex, totalSteps }) => {
      const percentage = ((activeStepIndex + 1) * 100) / totalSteps;

      if (render) {
        return render({ percentage });
      }

      return typeof children === 'function' ? children(percentage) : children;
    }}
  </WizardContext.Consumer>
);

Progress.propTypes = {
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
  render: PropTypes.func,
};

export default Progress;
