woocommerce-paypal-payments/modules/ppcp-settings/resources/js/Components/ReusableComponents/Navigation.js

43 lines
926 B
JavaScript
Raw Normal View History

2024-10-24 06:35:48 +02:00
import { Button } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
2024-10-24 13:54:50 +02:00
const Navigation = ( {
setStep,
setCompleted,
2024-10-24 13:54:50 +02:00
currentStep,
stepperOrder,
canProceeedCallback = () => true,
} ) => {
const navigateBy = ( stepDirection ) => {
let newStep = currentStep + stepDirection;
if ( isNaN( newStep ) || newStep < 0 ) {
console.warn( 'Invalid next step:', newStep );
newStep = 0;
}
if ( newStep >= stepperOrder.length ) {
setCompleted( true );
} else {
setStep( newStep );
2024-10-24 13:54:50 +02:00
}
};
2024-10-24 06:35:48 +02:00
return (
<div className="ppcp-r-navigation">
<Button variant="tertiary" onClick={ () => navigateBy( -1 ) }>
2024-10-24 06:35:48 +02:00
{ __( 'Back', 'woocommerce-paypal-payments' ) }
</Button>
<Button
variant="primary"
2024-10-24 13:54:50 +02:00
disabled={ ! canProceeedCallback() }
onClick={ () => navigateBy( 1 ) }
2024-10-24 06:35:48 +02:00
>
{ __( 'Next', 'woocommerce-paypal-payments' ) }
</Button>
</div>
);
};
export default Navigation;