| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import metadata from './block.json'; |
| 4 |
|
| 5 |
const { name } = metadata; |
| 6 |
|
| 7 |
import { |
| 8 |
RichText, |
| 9 |
useBlockProps, |
| 10 |
useInnerBlocksProps, |
| 11 |
} from '@wordpress/block-editor'; |
| 12 |
import { applyFilters } from '@wordpress/hooks'; |
| 13 |
|
| 14 |
/** |
| 15 |
* Block Save Class. |
| 16 |
* |
| 17 |
* @param props |
| 18 |
*/ |
| 19 |
export default function BlockSave(props) { |
| 20 |
const { attributes } = props; |
| 21 |
const { |
| 22 |
number, |
| 23 |
animateInViewport, |
| 24 |
numberPosition, |
| 25 |
numberAlign, |
| 26 |
showContent, |
| 27 |
url, |
| 28 |
ariaLabel, |
| 29 |
target, |
| 30 |
rel, |
| 31 |
} = attributes; |
| 32 |
|
| 33 |
let { animateInViewportFrom } = attributes; |
| 34 |
|
| 35 |
animateInViewportFrom = parseFloat(animateInViewportFrom); |
| 36 |
|
| 37 |
let className = classnames( |
| 38 |
'ghostkit-counter-box', |
| 39 |
url && 'ghostkit-counter-box-with-link' |
| 40 |
); |
| 41 |
className = applyFilters('ghostkit.blocks.className', className, { |
| 42 |
name, |
| 43 |
...props, |
| 44 |
}); |
| 45 |
|
| 46 |
const classNameNumber = classnames( |
| 47 |
'ghostkit-counter-box-number', |
| 48 |
`ghostkit-counter-box-number-align-${numberPosition || 'left'}`, |
| 49 |
numberPosition === 'top' |
| 50 |
? `ghostkit-counter-box-number-top-align-${numberAlign || 'center'}` |
| 51 |
: '' |
| 52 |
); |
| 53 |
|
| 54 |
const blockProps = useBlockProps.save({ className }); |
| 55 |
const innerBlockProps = useInnerBlocksProps.save({ |
| 56 |
className: 'ghostkit-counter-box-content', |
| 57 |
}); |
| 58 |
|
| 59 |
return ( |
| 60 |
<div {...blockProps}> |
| 61 |
{url ? ( |
| 62 |
<a |
| 63 |
className="ghostkit-counter-box-link" |
| 64 |
href={url} |
| 65 |
target={target || null} |
| 66 |
rel={rel || null} |
| 67 |
aria-label={ariaLabel || null} |
| 68 |
> |
| 69 |
<span /> |
| 70 |
</a> |
| 71 |
) : null} |
| 72 |
<div className={classNameNumber}> |
| 73 |
<RichText.Content |
| 74 |
tagName="div" |
| 75 |
className={`ghostkit-counter-box-number-wrap${ |
| 76 |
animateInViewport ? ' ghostkit-count-up' : '' |
| 77 |
}`} |
| 78 |
value={number} |
| 79 |
{...{ |
| 80 |
'data-count-from': |
| 81 |
animateInViewport && animateInViewportFrom |
| 82 |
? animateInViewportFrom |
| 83 |
: null, |
| 84 |
}} |
| 85 |
/> |
| 86 |
</div> |
| 87 |
{showContent ? <div {...innerBlockProps} /> : null} |
| 88 |
</div> |
| 89 |
); |
| 90 |
} |
| 91 |
|