2020-02-19 10:51:15 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import classNames from 'classnames';
|
2023-10-20 11:26:09 +00:00
|
|
|
import { Spinner } from '@woocommerce/blocks-components';
|
2020-02-19 10:51:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './style.scss';
|
|
|
|
|
2022-02-07 09:34:30 +00:00
|
|
|
interface LoadingMaskProps {
|
|
|
|
children?: React.ReactNode | React.ReactNode[];
|
|
|
|
className?: string;
|
|
|
|
screenReaderLabel?: string;
|
|
|
|
showSpinner?: boolean;
|
|
|
|
isLoading?: boolean;
|
|
|
|
}
|
2021-06-16 12:44:40 +00:00
|
|
|
// @todo Find a way to block buttons/form components when LoadingMask isLoading
|
2020-02-19 10:51:15 +00:00
|
|
|
const LoadingMask = ( {
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
screenReaderLabel,
|
|
|
|
showSpinner = false,
|
2020-02-21 14:08:57 +00:00
|
|
|
isLoading = true,
|
2022-02-07 09:34:30 +00:00
|
|
|
}: LoadingMaskProps ): JSX.Element => {
|
2020-02-19 10:51:15 +00:00
|
|
|
return (
|
2020-06-17 09:53:42 +00:00
|
|
|
<div
|
2021-06-16 12:44:40 +00:00
|
|
|
className={ classNames( className, {
|
|
|
|
'wc-block-components-loading-mask': isLoading,
|
|
|
|
} ) }
|
2020-06-17 09:53:42 +00:00
|
|
|
>
|
2021-06-16 12:44:40 +00:00
|
|
|
{ isLoading && showSpinner && <Spinner /> }
|
2020-02-19 10:51:15 +00:00
|
|
|
<div
|
2021-06-16 12:44:40 +00:00
|
|
|
className={ classNames( {
|
|
|
|
'wc-block-components-loading-mask__children': isLoading,
|
|
|
|
} ) }
|
|
|
|
aria-hidden={ isLoading }
|
2020-02-19 10:51:15 +00:00
|
|
|
>
|
|
|
|
{ children }
|
|
|
|
</div>
|
2021-06-16 12:44:40 +00:00
|
|
|
{ isLoading && (
|
|
|
|
<span className="screen-reader-text">
|
|
|
|
{ screenReaderLabel ||
|
2023-12-12 22:12:36 +00:00
|
|
|
__( 'Loading…', 'woocommerce' ) }
|
2021-06-16 12:44:40 +00:00
|
|
|
</span>
|
|
|
|
) }
|
2020-02-19 10:51:15 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default LoadingMask;
|