@@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
33import cn from 'classnames'
44import scrollSmooth from 'scroll-smooth'
55import Scrollparent from 'scrollparent'
6+ import debounce from 'lodash.debounce'
67import {
78 Arrow ,
89 Close ,
@@ -101,6 +102,7 @@ class Tour extends Component {
101102 }
102103 this . helper = createRef ( )
103104 this . helperElement = null
105+ this . debouncedShowStep = debounce ( this . showStep , 70 )
104106 }
105107
106108 componentDidMount ( ) {
@@ -162,8 +164,8 @@ class Tour extends Component {
162164 }
163165 }
164166 )
165- // TODO: debounce it.
166- window . addEventListener ( 'resize' , this . showStep , false )
167+
168+ window . addEventListener ( 'resize' , this . debouncedShowStep , false )
167169 window . addEventListener ( 'keydown' , this . keyDownHandler , false )
168170 }
169171
@@ -282,7 +284,7 @@ class Tour extends Component {
282284 observer : null ,
283285 }
284286 } , this . onBeforeClose )
285- window . removeEventListener ( 'resize' , this . showStep )
287+ window . removeEventListener ( 'resize' , this . debouncedShowStep )
286288 window . removeEventListener ( 'keydown' , this . keyDownHandler )
287289 }
288290
@@ -405,6 +407,7 @@ class Tour extends Component {
405407 prevStep,
406408 rounded,
407409 accentColor,
410+ CustomHelper,
408411 } = this . props
409412
410413 const {
@@ -477,82 +480,108 @@ class Tour extends Component {
477480 } ) }
478481 accentColor = { accentColor }
479482 >
480- { this . props . children }
481- { steps [ current ] &&
482- ( typeof steps [ current ] . content === 'function'
483- ? steps [ current ] . content ( {
484- close : onRequestClose ,
485- goTo : this . gotoStep ,
486- inDOM,
487- step : current + 1 ,
488- } )
489- : steps [ current ] . content ) }
490- { showNumber && (
491- < Badge data-tour-elem = "badge" >
492- { typeof badgeContent === 'function'
493- ? badgeContent ( current + 1 , steps . length )
494- : current + 1 }
495- </ Badge >
496- ) }
497- { ( showButtons || showNavigation ) && (
498- < Controls data-tour-elem = "controls" >
499- { showButtons && (
500- < Arrow
501- onClick = {
502- typeof prevStep === 'function' ? prevStep : this . prevStep
503- }
504- disabled = { current === 0 }
505- label = { prevButton ? prevButton : null }
506- />
483+ { CustomHelper ? (
484+ < CustomHelper
485+ current = { current }
486+ totalSteps = { steps . length }
487+ gotoStep = { this . gotoStep }
488+ close = { onRequestClose }
489+ content = {
490+ steps [ current ] &&
491+ ( typeof steps [ current ] . content === 'function'
492+ ? steps [ current ] . content ( {
493+ close : onRequestClose ,
494+ goTo : this . gotoStep ,
495+ inDOM,
496+ step : current + 1 ,
497+ } )
498+ : steps [ current ] . content )
499+ }
500+ >
501+ { this . props . children }
502+ </ CustomHelper >
503+ ) : (
504+ < >
505+ { this . props . children }
506+ { steps [ current ] &&
507+ ( typeof steps [ current ] . content === 'function'
508+ ? steps [ current ] . content ( {
509+ close : onRequestClose ,
510+ goTo : this . gotoStep ,
511+ inDOM,
512+ step : current + 1 ,
513+ } )
514+ : steps [ current ] . content ) }
515+ { showNumber && (
516+ < Badge data-tour-elem = "badge" >
517+ { typeof badgeContent === 'function'
518+ ? badgeContent ( current + 1 , steps . length )
519+ : current + 1 }
520+ </ Badge >
507521 ) }
508-
509- { showNavigation && (
510- < Navigation data-tour-elem = "navigation" >
511- { steps . map ( ( s , i ) => (
512- < Dot
513- key = { `${ s . selector ? s . selector : 'undef' } _${ i } ` }
514- onClick = { ( ) => this . gotoStep ( i ) }
515- current = { current }
516- index = { i }
517- disabled = { current === i || disableDotsNavigation }
518- showNumber = { showNavigationNumber }
519- data-tour-elem = "dot"
520- className = { cn ( CN . dot . base , {
521- [ CN . dot . active ] : current === i ,
522- } ) }
522+ { ( showButtons || showNavigation ) && (
523+ < Controls data-tour-elem = "controls" >
524+ { showButtons && (
525+ < Arrow
526+ onClick = {
527+ typeof prevStep === 'function'
528+ ? prevStep
529+ : this . prevStep
530+ }
531+ disabled = { current === 0 }
532+ label = { prevButton ? prevButton : null }
523533 />
524- ) ) }
525- </ Navigation >
534+ ) }
535+
536+ { showNavigation && (
537+ < Navigation data-tour-elem = "navigation" >
538+ { steps . map ( ( s , i ) => (
539+ < Dot
540+ key = { `${ s . selector ? s . selector : 'undef' } _${ i } ` }
541+ onClick = { ( ) => this . gotoStep ( i ) }
542+ current = { current }
543+ index = { i }
544+ disabled = { current === i || disableDotsNavigation }
545+ showNumber = { showNavigationNumber }
546+ data-tour-elem = "dot"
547+ className = { cn ( CN . dot . base , {
548+ [ CN . dot . active ] : current === i ,
549+ } ) }
550+ />
551+ ) ) }
552+ </ Navigation >
553+ ) }
554+
555+ { showButtons && (
556+ < Arrow
557+ onClick = {
558+ current === steps . length - 1
559+ ? lastStepNextButton
560+ ? onRequestClose
561+ : ( ) => { }
562+ : typeof nextStep === 'function'
563+ ? nextStep
564+ : this . nextStep
565+ }
566+ disabled = {
567+ ! lastStepNextButton && current === steps . length - 1
568+ }
569+ inverted
570+ label = {
571+ lastStepNextButton && current === steps . length - 1
572+ ? lastStepNextButton
573+ : nextButton
574+ ? nextButton
575+ : null
576+ }
577+ />
578+ ) }
579+ </ Controls >
526580 ) }
527581
528- { showButtons && (
529- < Arrow
530- onClick = {
531- current === steps . length - 1
532- ? lastStepNextButton
533- ? onRequestClose
534- : ( ) => { }
535- : typeof nextStep === 'function'
536- ? nextStep
537- : this . nextStep
538- }
539- disabled = {
540- ! lastStepNextButton && current === steps . length - 1
541- }
542- inverted
543- label = {
544- lastStepNextButton && current === steps . length - 1
545- ? lastStepNextButton
546- : nextButton
547- ? nextButton
548- : null
549- }
550- />
551- ) }
552- </ Controls >
582+ { showCloseButton ? < Close onClick = { onRequestClose } /> : null }
583+ </ >
553584 ) }
554-
555- { showCloseButton ? < Close onClick = { onRequestClose } /> : null }
556585 </ Guide >
557586 </ Portal >
558587 )
0 commit comments