| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import metadata from './block.json'; |
| 4 |
|
| 5 |
const { name } = metadata; |
| 6 |
|
| 7 |
import { RichText, useBlockProps } from '@wordpress/block-editor'; |
| 8 |
import { applyFilters } from '@wordpress/hooks'; |
| 9 |
|
| 10 |
/** |
| 11 |
* Block Save Class. |
| 12 |
* |
| 13 |
* @param props |
| 14 |
*/ |
| 15 |
export default function BlockSave(props) { |
| 16 |
const { |
| 17 |
caption, |
| 18 |
percent, |
| 19 |
striped, |
| 20 |
showCount, |
| 21 |
countPrefix, |
| 22 |
countSuffix, |
| 23 |
animateInViewport, |
| 24 |
} = props.attributes; |
| 25 |
|
| 26 |
let className = 'ghostkit-progress'; |
| 27 |
|
| 28 |
className = applyFilters('ghostkit.blocks.className', className, { |
| 29 |
name, |
| 30 |
...props, |
| 31 |
}); |
| 32 |
|
| 33 |
const blockProps = useBlockProps.save({ className }); |
| 34 |
|
| 35 |
return ( |
| 36 |
<div {...blockProps}> |
| 37 |
{!RichText.isEmpty(caption) ? ( |
| 38 |
<div className="ghostkit-progress-caption"> |
| 39 |
<RichText.Content value={caption} /> |
| 40 |
</div> |
| 41 |
) : null} |
| 42 |
{showCount ? ( |
| 43 |
<div |
| 44 |
className="ghostkit-progress-bar-count" |
| 45 |
style={{ width: `${percent}%` }} |
| 46 |
> |
| 47 |
<div> |
| 48 |
<span>{countPrefix}</span> |
| 49 |
<span>{percent}</span> |
| 50 |
<span>{countSuffix}</span> |
| 51 |
</div> |
| 52 |
</div> |
| 53 |
) : null} |
| 54 |
<div |
| 55 |
className={classnames( |
| 56 |
'ghostkit-progress-wrap', |
| 57 |
striped && 'ghostkit-progress-bar-striped' |
| 58 |
)} |
| 59 |
> |
| 60 |
<div |
| 61 |
className={classnames( |
| 62 |
'ghostkit-progress-bar', |
| 63 |
animateInViewport && 'ghostkit-count-up' |
| 64 |
)} |
| 65 |
role="progressbar" |
| 66 |
aria-valuenow={percent} |
| 67 |
aria-valuemin="0" |
| 68 |
aria-valuemax="100" |
| 69 |
/> |
| 70 |
</div> |
| 71 |
</div> |
| 72 |
); |
| 73 |
} |
| 74 |
|