| Server IP : 104.26.5.103 / Your IP : 216.73.216.4 Web Server : nginx/1.27.1 System : Linux in-5 5.15.0-143-generic #153-Ubuntu SMP Fri Jun 13 19:10:45 UTC 2025 x86_64 User : arabianexpress ( 1872) PHP Version : 8.0.30 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /storage/v9321/leapdubai/public_html/wp-content/plugins/tablepress/admin/js/common/ |
Upload File : |
/**
* JavaScript code for the "Alert" component.
*
* @package TablePress
* @subpackage Views JavaScript
* @author Tobias Bäthge
* @since 3.1.0
*/
/**
* WordPress dependencies.
*/
import { useCallback, useRef } from 'react';
import {
Button,
__experimentalHStack as HStack, // eslint-disable-line @wordpress/no-unsafe-wp-apis
Icon,
Modal,
__experimentalVStack as VStack, // eslint-disable-line @wordpress/no-unsafe-wp-apis
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies.
*/
import { TablePressIcon } from '../../img/tablepress-icon';
/**
* Returns the Alert component's JSX markup.
*
* @param {Object} props Component props.
* @param {string} props.title Title of the alert. No header will be shown if this is not set.
* @param {string} props.text Text of the alert.
* @param {Function} props.onConfirm Callback to confirm the alert.
* @param {Object} props.modalProps Additional props for the Modal.
* @return {Object} Alert component.
*/
const Alert = ( { title, text, onConfirm, modalProps } ) => {
const confirmButtonRef = useRef();
const handleEnter = useCallback(
( event ) => {
// Avoid triggering the action when a button is focused, as this can cause a double submission.
const isConfirmButton = event.target === confirmButtonRef.current;
if ( ! isConfirmButton && 'Enter' === event.key ) {
onConfirm();
event.preventDefault(); // This prevents that the triggering button is "clicked" (via "Enter") again.
}
},
[ onConfirm ],
);
return (
<Modal
icon={ <Icon icon={ TablePressIcon } size="36" style={ { display: 'flex', marginRight: '1rem' } } /> }
title={ title }
__experimentalHideHeader={ undefined === title }
isDismissible={ false }
shouldCloseOnEsc={ false }
shouldCloseOnClickOutside={ false }
onKeyDown={ handleEnter }
{ ...modalProps }
>
<VStack spacing={ 8 }>
<span>
{ text }
</span>
<HStack alignment="right">
<Button
ref={ confirmButtonRef }
variant="primary"
text={ __( 'OK', 'tablepress' ) }
onClick={ onConfirm }
/>
</HStack>
</VStack>
</Modal>
);
};
export { Alert };