| 1 |
import { useBlockProps } from '@wordpress/block-editor'; |
| 2 |
import { applyFilters } from '@wordpress/hooks'; |
| 3 |
|
| 4 |
import metadata from './block.json'; |
| 5 |
|
| 6 |
const { name } = metadata; |
| 7 |
|
| 8 |
/** |
| 9 |
* Block Save Class. |
| 10 |
* |
| 11 |
* @param props |
| 12 |
*/ |
| 13 |
export default function BlockSave(props) { |
| 14 |
const { |
| 15 |
fileUrl, |
| 16 |
fileWidth, |
| 17 |
fileHeight, |
| 18 |
trigger, |
| 19 |
loop, |
| 20 |
direction, |
| 21 |
speed, |
| 22 |
width, |
| 23 |
} = props.attributes; |
| 24 |
|
| 25 |
let className = 'ghostkit-lottie'; |
| 26 |
|
| 27 |
className = applyFilters('ghostkit.blocks.className', className, { |
| 28 |
name, |
| 29 |
...props, |
| 30 |
}); |
| 31 |
|
| 32 |
const blockProps = useBlockProps.save({ |
| 33 |
className, |
| 34 |
'data-trigger': trigger, |
| 35 |
style: |
| 36 |
fileWidth && fileHeight |
| 37 |
? { |
| 38 |
'--gkt-lottie__ar': `${fileWidth} / ${fileHeight}`, |
| 39 |
'--gkt-lottie__width': width, |
| 40 |
} |
| 41 |
: {}, |
| 42 |
}); |
| 43 |
|
| 44 |
return ( |
| 45 |
<div {...blockProps}> |
| 46 |
<lottie-player |
| 47 |
src={fileUrl} |
| 48 |
direction={direction} |
| 49 |
background="transparent" |
| 50 |
mode="normal" |
| 51 |
{...(trigger !== 'scroll' ? { speed } : {})} |
| 52 |
{...(trigger !== 'scroll' && loop ? { loop: 'loop' } : {})} |
| 53 |
{...(!trigger ? { autoplay: 'autoplay' } : {})} |
| 54 |
{...(trigger === 'hover' ? { hover: 'hover' } : {})} |
| 55 |
style={{ |
| 56 |
width: '100%', |
| 57 |
height: 'auto', |
| 58 |
}} |
| 59 |
/> |
| 60 |
</div> |
| 61 |
); |
| 62 |
} |
| 63 |
|