import { h, Component } from 'preact'; import PropTypes from 'prop-types'; export class Navigation extends Component { /** * A function to render the progress stepper within the `Navigation` component. * By default, it does not show the stepper for the first slide (the `IntroSlide` component). * It builds a list of `` elements correseponding to the slides, and adds an "active" * class to any slide that has already been seen or is currently being seen. * * @returns {String} The HTML markup for the stepper. */ createStepper() { const { currentSlideIndex, slidesCount } = this.props; if (currentSlideIndex === 0) { return ''; } const stepsList = []; // We do not show the stepper on the IntroSlide so we start with `i = 1`. for (let i = 1; i < slidesCount; i += 1) { const active = i <= currentSlideIndex; stepsList.push(); } return (
{stepsList}
); } /** * A function to render the text for the "next-button" within the `Navigation` component. * By default, it renders "Continue" for every slide. * If the slide can be skipped, it renders "Skip for now". * On the final slide, it renders "Finish". * * @returns {String} The HTML markup for the stepper. */ buttonText() { const { canSkip, currentSlideIndex, slidesCount } = this.props; if (slidesCount - 1 === currentSlideIndex) { return 'Finish'; } if (canSkip) { return 'Skip for now'; } return 'Continue'; } render() { const { next, prev, hideNext, hidePrev, disabled, canSkip, className, } = this.props; return ( ); } } Navigation.propTypes = { disabled: PropTypes.bool, canSkip: PropTypes.bool, class: PropTypes.string, prev: PropTypes.func.isRequired, next: PropTypes.string.isRequired, hideNext: PropTypes.bool, hidePrev: PropTypes.bool, slidesCount: PropTypes.number.isRequired, currentSlideIndex: PropTypes.number.isRequired, }; Navigation.defaultProps = { disabled: false, canSkip: false, hideNext: false, hidePrev: false, class: '', };