File size: 2,035 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Gridicon } from '@automattic/components';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import { Fragment } from 'react';
import type { SiteDetails } from '@automattic/data-stores';

import './style.scss';

function getStepClassName( currentStep: number, step: number ) {
	return clsx( {
		'step-current': currentStep === step,
		'step-next': currentStep < step,
		'step-complete': currentStep > step,
	} );
}

function CheckMarkOrNumber( { currentStep, step }: { currentStep: number; step: number } ) {
	if ( currentStep > step ) {
		return (
			<span className="clone-flow-step-progress__step-circle">
				<Gridicon icon="checkmark" size={ 16 } />
			</span>
		);
	}

	return (
		<span className="clone-flow-step-progress__step-circle">
			<span>{ step }</span>
		</span>
	);
}

type StepKey = 'destination' | 'clonePoint' | 'configure';

interface Step {
	key: StepKey;
	label: string;
}

interface Props {
	currentStep: StepKey;
	selectedSite?: SiteDetails | null;
}

export default function CloneFlowStepProgress( { currentStep }: Props ) {
	const translate = useTranslate();

	const steps: Step[] = [
		{ key: 'destination', label: translate( 'Set destination' ) },
		{ key: 'clonePoint', label: translate( 'Select point to copy' ) },
		{ key: 'configure', label: translate( 'Configure' ) },
	];

	const currentStepIndex = Math.max(
		steps.findIndex( ( step ) => step.key === currentStep ),
		0
	);

	return (
		<div className="clone-flow-step-progress">
			{ steps.map( ( { key, label }, index ) => (
				<Fragment key={ key }>
					<div
						className={ `clone-flow-step-progress__step ${ getStepClassName(
							currentStepIndex,
							index
						) }` }
					>
						<CheckMarkOrNumber currentStep={ currentStepIndex + 1 } step={ index + 1 } />
						<span className="clone-flow-step-progress__step-name">{ label }</span>
					</div>

					{ index < steps.length - 1 && (
						<div className="clone-flow-step-progress__step-separator" />
					) }
				</Fragment>
			) ) }
		</div>
	);
}