PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.8.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.8.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / Admin / package / preload / components / button / button.js

button.js in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.8.0, at src/Performance/Admin/package/preload/components/button/button.js

55 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies
3 */
4 import { Button, Tooltip } from '@wordpress/components';
5 import { __ } from '@wordpress/i18n';
6 import { store as preloadStore } from '../../store';
7 import { useDispatch } from '@wordpress/data';
8
9 /**
10 * @param {boolean} isPreloading Whether we are preloading.
11 * @param {string} text The translated button text.
12 * @param {string} label The translated Tooltip text.
13 * @param {boolean} force Whether we are force preloading the entire site.
14 * @param {boolean} hidden If we are preloading, one of the buttons should be hidden.
15 */
16 export default function PreloadButton( { isPreloading, text, label, force = false, hidden = false } ) {
17 if (hidden) {
18 return null;
19 }
20
21 const { startPreloader, cancelPreloader } = useDispatch(preloadStore);
22
23 const handleClick = async () => {
24 if (isPreloading) {
25 await cancelPreloader();
26 } else {
27 await startPreloader(force);
28 }
29 };
30
31 const buttonText = isPreloading
32 ? __('Cancel Preloading', 'solid-performance')
33 : text;
34
35 const button = (
36 <Button
37 variant="secondary"
38 onClick={handleClick}
39 >
40 {buttonText}
41 </Button>
42 );
43
44 const isLongLabel = label?.length > 80;
45 const tooltipClassName = isLongLabel ? 'swpsp-preload-long-tooltip' : '';
46
47 return label ? (
48 <Tooltip text={label} className={tooltipClassName}>
49 {button}
50 </Tooltip>
51 ) : (
52 button
53 );
54 };
55