| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import { InnerBlocks, RichText } from '@wordpress/block-editor'; |
| 4 |
import { Component } from '@wordpress/element'; |
| 5 |
import { applyFilters } from '@wordpress/hooks'; |
| 6 |
|
| 7 |
import metadata from './block.json'; |
| 8 |
|
| 9 |
const { name } = metadata; |
| 10 |
|
| 11 |
export default [ |
| 12 |
// v2.23.2 |
| 13 |
{ |
| 14 |
...metadata, |
| 15 |
attributes: { |
| 16 |
number: { |
| 17 |
type: 'string', |
| 18 |
source: 'html', |
| 19 |
selector: '.ghostkit-counter-box-number-wrap', |
| 20 |
default: '77', |
| 21 |
}, |
| 22 |
animateInViewport: { |
| 23 |
type: 'boolean', |
| 24 |
default: false, |
| 25 |
}, |
| 26 |
animateInViewportFrom: { |
| 27 |
type: 'number', |
| 28 |
default: 0, |
| 29 |
}, |
| 30 |
numberPosition: { |
| 31 |
type: 'string', |
| 32 |
default: 'top', |
| 33 |
}, |
| 34 |
numberSize: { |
| 35 |
type: 'number', |
| 36 |
}, |
| 37 |
showContent: { |
| 38 |
type: 'boolean', |
| 39 |
default: true, |
| 40 |
}, |
| 41 |
numberColor: { |
| 42 |
type: 'string', |
| 43 |
}, |
| 44 |
hoverNumberColor: { |
| 45 |
type: 'string', |
| 46 |
}, |
| 47 |
url: { |
| 48 |
type: 'string', |
| 49 |
}, |
| 50 |
target: { |
| 51 |
type: 'string', |
| 52 |
}, |
| 53 |
rel: { |
| 54 |
type: 'string', |
| 55 |
}, |
| 56 |
}, |
| 57 |
save: class BlockSave extends Component { |
| 58 |
render() { |
| 59 |
const { |
| 60 |
number, |
| 61 |
animateInViewport, |
| 62 |
numberPosition, |
| 63 |
showContent, |
| 64 |
url, |
| 65 |
target, |
| 66 |
rel, |
| 67 |
} = this.props.attributes; |
| 68 |
|
| 69 |
let { animateInViewportFrom } = this.props.attributes; |
| 70 |
|
| 71 |
animateInViewportFrom = parseFloat(animateInViewportFrom); |
| 72 |
|
| 73 |
let className = classnames( |
| 74 |
'ghostkit-counter-box', |
| 75 |
url && 'ghostkit-counter-box-with-link' |
| 76 |
); |
| 77 |
className = applyFilters( |
| 78 |
'ghostkit.blocks.className', |
| 79 |
className, |
| 80 |
{ |
| 81 |
name, |
| 82 |
...this.props, |
| 83 |
} |
| 84 |
); |
| 85 |
|
| 86 |
const classNameNumber = classnames( |
| 87 |
'ghostkit-counter-box-number', |
| 88 |
`ghostkit-counter-box-number-align-${ |
| 89 |
numberPosition || 'left' |
| 90 |
}` |
| 91 |
); |
| 92 |
|
| 93 |
return ( |
| 94 |
<div className={className}> |
| 95 |
{url ? ( |
| 96 |
<a |
| 97 |
className="ghostkit-counter-box-link" |
| 98 |
href={url} |
| 99 |
target={target || false} |
| 100 |
rel={rel || false} |
| 101 |
> |
| 102 |
<span /> |
| 103 |
</a> |
| 104 |
) : null} |
| 105 |
<div className={classNameNumber}> |
| 106 |
<RichText.Content |
| 107 |
tagName="div" |
| 108 |
className={`ghostkit-counter-box-number-wrap${ |
| 109 |
animateInViewport |
| 110 |
? ' ghostkit-count-up' |
| 111 |
: '' |
| 112 |
}`} |
| 113 |
value={number} |
| 114 |
{...{ |
| 115 |
'data-count-from': |
| 116 |
animateInViewport && |
| 117 |
animateInViewportFrom |
| 118 |
? animateInViewportFrom |
| 119 |
: null, |
| 120 |
}} |
| 121 |
/> |
| 122 |
</div> |
| 123 |
{showContent ? ( |
| 124 |
<div className="ghostkit-counter-box-content"> |
| 125 |
<InnerBlocks.Content /> |
| 126 |
</div> |
| 127 |
) : null} |
| 128 |
</div> |
| 129 |
); |
| 130 |
} |
| 131 |
}, |
| 132 |
}, |
| 133 |
]; |
| 134 |
|