button-next.js
1.47 KB
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
// @ts-check
/**
* External dependencies
*/
import * as React from 'react';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
/**
* @typedef ButtonNextProps
* @property {React.EventHandler<React.MouseEvent<HTMLButtonElement, MouseEvent>>} onClick The click handler.
* @property {string} [checkboxLabel] The label of the checkbox, if there should be one.
* @property {number} stepIndex The index of this button's step.
*/
/**
* The next button.
*
* @param {ButtonNextProps} props The component props.
* @return {React.ReactElement} The component for the step content.
*/
const ButtonNext = ( { onClick, checkboxLabel, stepIndex } ) => {
const [ isCheckboxChecked, setCheckboxChecked ] = useState( false );
// If there's no label for the 'confirmation' checkbox, return a simple button.
if ( ! checkboxLabel ) {
return <button className="btn" onClick={ onClick }>{ __( 'Next Step', 'block-lab' ) }</button>;
}
const inputId = `bl-migration-check-${ stepIndex }`;
return (
<>
<form>
<input
id={ inputId }
type="checkbox"
onClick={ () => {
setCheckboxChecked( ! isCheckboxChecked );
} }
/>
<label htmlFor={ inputId } className="ml-2 font-medium">{ checkboxLabel }</label>
</form>
<button
className="btn"
onClick={ onClick }
disabled={ ! isCheckboxChecked }
>
{ __( 'Next Step', 'block-lab' ) }
</button>
</>
);
};
export default ButtonNext;