/**
 * Site Kit by Google, Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * External dependencies
 */
import PropTypes from 'prop-types';
import classnames from 'classnames';

/**
 * WordPress dependencies
 */
import { useState, useCallback } from '@wordpress/element';

/**
 * Internal dependencies
 */
import { CircularProgress } from '../material-components';
import Button from './Button';

export default function SpinnerButton( props ) {
	const { className, onClick = () => {}, ...restProps } = props;

	const [ processing, setProcessing ] = useState( false );

	const handleClick = useCallback(
		async ( ...params ) => {
			setProcessing( true );
			await onClick( ...params );
			setProcessing( false );
		},
		[ onClick ]
	);

	return (
		<Button
			className={ classnames(
				className,
				'googlesitekit-button-icon--spinner',
				{
					'googlesitekit-button-icon--spinner__running': processing,
				}
			) }
			trailingIcon={
				processing ? <CircularProgress size={ 14 } /> : undefined
			}
			onClick={ handleClick }
			{ ...restProps }
		/>
	);
}

SpinnerButton.propTypes = {
	className: PropTypes.string,
	onClick: PropTypes.func,
};

@@ -781,16 +781,27 @@
 Callback
+, useEffect
  %7D from 
@@ -822,16 +822,16 @@
 ement';%0A
-
 %0A/**%0A * 
@@ -1004,17 +1004,19 @@
 %09const %7B
- 
+%0A%09%09
 classNam
@@ -1017,17 +1017,19 @@
 assName,
- 
+%0A%09%09
 onClick 
@@ -1039,17 +1039,46 @@
 ) =%3E %7B%7D,
- 
+%0A%09%09forceProcessing = false,%0A%09%09
 ...restP
@@ -1081,17 +1081,18 @@
 estProps
- 
+%0A%09
 %7D = prop
@@ -1323,16 +1323,100 @@
  %5D%0A%09);%0A%0A
+%09useEffect( () =%3E %7B%0A%09%09setProcessing( forceProcessing );%0A%09%7D, %5B forceProcessing %5D );%0A%0A
 %09return 
@@ -1796,16 +1796,16 @@
 string,%0A
-
 %09onClick
@@ -1822,11 +1822,45 @@
 s.func,%0A
+%09forceProcessing: PropTypes.bool,%0A
 %7D;%0A

Add forceProcessing prop. Set processing based on forceProcessing value.