|
| 1 | +import { useReducer } from 'react'; |
| 2 | + |
| 3 | +import { standardSteps } from './steps'; |
| 4 | + |
| 5 | +import Joyride, { STATUS, Status } from '../../src'; |
| 6 | +import { CallBackProps, Props, Step } from '../../src/types'; |
| 7 | + |
| 8 | +interface CustomOptionsProps extends Omit<Props, 'run' | 'steps'> {} |
| 9 | + |
| 10 | +interface State { |
| 11 | + index: number; |
| 12 | + run: boolean; |
| 13 | + steps: Array<Step>; |
| 14 | +} |
| 15 | + |
| 16 | +const tourSteps = [ |
| 17 | + ...standardSteps.slice(0, 3).map(step => { |
| 18 | + if (step.target === '.mission button') { |
| 19 | + return { |
| 20 | + ...step, |
| 21 | + target: '.mission h2 span', |
| 22 | + }; |
| 23 | + } |
| 24 | + |
| 25 | + return step; |
| 26 | + }), |
| 27 | + { |
| 28 | + target: '.outro h2 span', |
| 29 | + placement: 'top' as const, |
| 30 | + content: "Text only steps — Because sometimes you don't really need a proper heading", |
| 31 | + }, |
| 32 | +]; |
| 33 | + |
| 34 | +export default function CutomOptionss(props: Omit<CustomOptionsProps, 'run' | 'steps'>) { |
| 35 | + const { callback, ...rest } = props; |
| 36 | + const [{ run, steps }, setState] = useReducer( |
| 37 | + (previousState: State, nextState: Partial<State>) => ({ |
| 38 | + ...previousState, |
| 39 | + ...nextState, |
| 40 | + }), |
| 41 | + { |
| 42 | + index: 0, |
| 43 | + run: false, |
| 44 | + steps: tourSteps, |
| 45 | + }, |
| 46 | + ); |
| 47 | + |
| 48 | + const handleClickStart = () => { |
| 49 | + setState({ run: true }); |
| 50 | + }; |
| 51 | + |
| 52 | + const handleJoyrideCallback = (data: CallBackProps) => { |
| 53 | + const { status } = data; |
| 54 | + |
| 55 | + if (([STATUS.FINISHED, STATUS.SKIPPED] as Array<Status>).includes(status)) { |
| 56 | + setState({ run: false }); |
| 57 | + } |
| 58 | + |
| 59 | + setState({ index: data.index }); |
| 60 | + |
| 61 | + callback?.(data); |
| 62 | + }; |
| 63 | + |
| 64 | + return ( |
| 65 | + <div data-test-id="demo"> |
| 66 | + <Joyride |
| 67 | + callback={handleJoyrideCallback} |
| 68 | + continuous |
| 69 | + run={run} |
| 70 | + scrollToFirstStep |
| 71 | + showSkipButton |
| 72 | + steps={steps} |
| 73 | + styles={{ |
| 74 | + buttonClose: { |
| 75 | + color: '#000', |
| 76 | + }, |
| 77 | + buttonNext: { |
| 78 | + backgroundColor: '#a947ff', |
| 79 | + }, |
| 80 | + options: { |
| 81 | + arrowColor: '#5cff47', |
| 82 | + primaryColor: '#ff0000', |
| 83 | + overlayColor: 'rgba(0, 0, 0, 0.3)', |
| 84 | + }, |
| 85 | + tooltip: { |
| 86 | + borderRadius: 8, |
| 87 | + padding: 12, |
| 88 | + }, |
| 89 | + tooltipContent: { |
| 90 | + padding: '1px 8px', |
| 91 | + }, |
| 92 | + }} |
| 93 | + {...rest} |
| 94 | + /> |
| 95 | + <main> |
| 96 | + <div className="hero"> |
| 97 | + <div className="container"> |
| 98 | + <div className="hero__content"> |
| 99 | + <h1> |
| 100 | + <span>Create walkthroughs and guided tours for your ReactJS apps.</span> |
| 101 | + </h1> |
| 102 | + <button data-test-id="start" onClick={handleClickStart} type="button"> |
| 103 | + Let's Go! |
| 104 | + </button> |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + <div className="demo__section projects"> |
| 109 | + <div className="container"> |
| 110 | + <h2> |
| 111 | + <span>Projects</span> |
| 112 | + </h2> |
| 113 | + <div className="list"> |
| 114 | + <div>Installation</div> |
| 115 | + <div>Documentation</div> |
| 116 | + <div>Support </div> |
| 117 | + </div> |
| 118 | + </div> |
| 119 | + </div> |
| 120 | + |
| 121 | + <div className="demo__section mission"> |
| 122 | + <div className="container"> |
| 123 | + <h2> |
| 124 | + <span>Mission</span> |
| 125 | + </h2> |
| 126 | + </div> |
| 127 | + </div> |
| 128 | + <div className="demo__section about"> |
| 129 | + <div className="container"> |
| 130 | + <h2> |
| 131 | + <span>About</span> |
| 132 | + </h2> |
| 133 | + </div> |
| 134 | + </div> |
| 135 | + <div className="demo__section outro"> |
| 136 | + <div className="container"> |
| 137 | + <h2> |
| 138 | + <span>Outro</span> |
| 139 | + </h2> |
| 140 | + </div> |
| 141 | + </div> |
| 142 | + </main> |
| 143 | + </div> |
| 144 | + ); |
| 145 | +} |
0 commit comments