| 1 |
/** |
| 2 |
* WordPress dependencies. |
| 3 |
*/ |
| 4 |
import { Button } from '@wordpress/components'; |
| 5 |
import { WPElement } from '@wordpress/element'; |
| 6 |
import { __ } from '@wordpress/i18n'; |
| 7 |
import { update } from '@wordpress/icons'; |
| 8 |
|
| 9 |
/** |
| 10 |
* Internal dependencies. |
| 11 |
*/ |
| 12 |
import pause from '../icons/pause'; |
| 13 |
import play from '../icons/play'; |
| 14 |
import stop from '../icons/stop'; |
| 15 |
|
| 16 |
/** |
| 17 |
* Sync button component. |
| 18 |
* |
| 19 |
* @param {object} props Component props. |
| 20 |
* @param {boolean} props.disabled If controls are disabled. |
| 21 |
* @param {boolean} props.isPaused If syncing is paused. |
| 22 |
* @param {boolean} props.isSyncing If syncing is in progress. |
| 23 |
* @param {Function} props.onPause Pause button click callback. |
| 24 |
* @param {Function} props.onResume Play button click callback. |
| 25 |
* @param {Function} props.onStop Stop button click callback. |
| 26 |
* @param {Function} props.onSync Sync button click callback. |
| 27 |
* @param {boolean} props.showSync If sync button is shown. |
| 28 |
* @returns {WPElement} Component. |
| 29 |
*/ |
| 30 |
export default ({ disabled, isPaused, isSyncing, onPause, onResume, onStop, onSync, showSync }) => { |
| 31 |
/** |
| 32 |
* Render. |
| 33 |
*/ |
| 34 |
return ( |
| 35 |
<div className="ep-sync-controls"> |
| 36 |
{showSync && !isSyncing ? ( |
| 37 |
<div className="ep-sync-controls__sync"> |
| 38 |
<Button |
| 39 |
className="ep-sync-button ep-sync-button--sync" |
| 40 |
disabled={disabled} |
| 41 |
icon={update} |
| 42 |
isPrimary |
| 43 |
onClick={onSync} |
| 44 |
> |
| 45 |
{__('Sync Now', 'elasticpress')} |
| 46 |
</Button> |
| 47 |
</div> |
| 48 |
) : null} |
| 49 |
|
| 50 |
{isSyncing ? ( |
| 51 |
<> |
| 52 |
<div className="ep-sync-controls__pause-resume"> |
| 53 |
{isPaused ? ( |
| 54 |
<Button |
| 55 |
className="ep-sync-button ep-sync-button--resume" |
| 56 |
disabled={disabled} |
| 57 |
icon={play} |
| 58 |
isPrimary |
| 59 |
onClick={onResume} |
| 60 |
> |
| 61 |
{__('Resume', 'elasticpress')} |
| 62 |
</Button> |
| 63 |
) : ( |
| 64 |
<Button |
| 65 |
className="ep-sync-button ep-sync-button--pause" |
| 66 |
disabled={disabled} |
| 67 |
icon={pause} |
| 68 |
isPrimary |
| 69 |
onClick={onPause} |
| 70 |
> |
| 71 |
{__('Pause', 'elasticpress')} |
| 72 |
</Button> |
| 73 |
)} |
| 74 |
</div> |
| 75 |
|
| 76 |
<div className="ep-sync-controls__stop"> |
| 77 |
<Button |
| 78 |
className="ep-sync-button ep-sync-button--stop" |
| 79 |
icon={stop} |
| 80 |
isSecondary |
| 81 |
onClick={onStop} |
| 82 |
> |
| 83 |
{__('Stop', 'elasticpress')} |
| 84 |
</Button> |
| 85 |
</div> |
| 86 |
</> |
| 87 |
) : null} |
| 88 |
|
| 89 |
{showSync ? ( |
| 90 |
<div className="ep-sync-controls__learn-more"> |
| 91 |
<Button |
| 92 |
href="https://elasticpress.zendesk.com/hc/en-us/articles/5205632443533" |
| 93 |
target="_blank" |
| 94 |
variant="link" |
| 95 |
> |
| 96 |
{__('Learn more', 'elasticpress')} |
| 97 |
</Button> |
| 98 |
</div> |
| 99 |
) : null} |
| 100 |
</div> |
| 101 |
); |
| 102 |
}; |
| 103 |
|