| 1 |
/** |
| 2 |
* External dependencies. |
| 3 |
*/ |
| 4 |
import classnames from 'classnames'; |
| 5 |
|
| 6 |
/** |
| 7 |
* WordPress dependencies. |
| 8 |
*/ |
| 9 |
import { WPElement } from '@wordpress/element'; |
| 10 |
|
| 11 |
/** |
| 12 |
* Progress bar component. |
| 13 |
* |
| 14 |
* @param {object} props Component props. |
| 15 |
* @param {number} props.current Current value. |
| 16 |
* @param {number} props.total Current total. |
| 17 |
* @param {boolean} props.isComplete If operation is complete. |
| 18 |
* @param {boolean} props.isFailed If sync has failed. |
| 19 |
* @returns {WPElement} Component. |
| 20 |
*/ |
| 21 |
export default ({ isComplete, isFailed, current, total }) => { |
| 22 |
const now = total ? Math.floor((current / total) * 100) : 100; |
| 23 |
|
| 24 |
return ( |
| 25 |
<div |
| 26 |
aria-valuemax={100} |
| 27 |
aria-valuemin={0} |
| 28 |
aria-valuenow={now} |
| 29 |
className={classnames('ep-sync-progress-bar', { |
| 30 |
'ep-sync-progress-bar--complete': isComplete, |
| 31 |
'ep-sync-progress-bar--failed': isFailed, |
| 32 |
})} |
| 33 |
role="progressbar" |
| 34 |
> |
| 35 |
<div |
| 36 |
className="ep-sync-progress-bar__progress" |
| 37 |
style={{ minWidth: `${now}%` }} |
| 38 |
>{`${now}%`}</div> |
| 39 |
</div> |
| 40 |
); |
| 41 |
}; |
| 42 |
|