/** * BLOCK: animate-blocks/animate */ // Import block dependencies import anchorPlacementOptions from './anchor-placement-options'; import animationOptions from './animation-options'; import easingOptions from './easing-options'; const { __ } = wp.i18n; const { registerBlockType } = wp.blocks; const { Fragment } = wp.element; const { InnerBlocks, InspectorControls, } = wp.editor; const { PanelBody, TextControl, SelectControl, ToggleControl, RangeControl, } = wp.components; const { applyFilters } = wp.hooks; let defaultOptions = { animation: animationOptions && animationOptions.length > 0 ? animationOptions[ 0 ].value : 'fade', offset: 120, delay: 0, duration: 400, easing: easingOptions && easingOptions.length > 0 ? easingOptions[ 0 ].value : 'ease', once: true, mirror: false, anchorPlacement: anchorPlacementOptions && anchorPlacementOptions.length > 0 ? anchorPlacementOptions[ 0 ].value : 'top-bottom', }; defaultOptions = applyFilters( 'animateBlocks.defaultOptions', defaultOptions ); registerBlockType( 'animate-blocks/animate', { title: __( 'Animate Block', 'animate-blocks' ), icon: 'controls-forward', category: 'layout', description: __( 'Animate blocks inside this container.', 'animate-blocks' ), attributes: { animation: { type: 'string', default: defaultOptions.animation, }, offset: { type: 'number', default: defaultOptions.offset, }, delay: { type: 'number', default: defaultOptions.delay, }, duration: { type: 'number', default: defaultOptions.duration, }, easing: { type: 'string', default: defaultOptions.easing, }, once: { type: 'boolean', default: defaultOptions.once, }, mirror: { type: 'boolean', default: defaultOptions.mirror, }, anchorPlacement: { type: 'string', default: defaultOptions.anchorPlacement, }, }, edit( { attributes, setAttributes, className } ) { const { animation = '', offset, delay, duration, easing, once, mirror, anchorPlacement, } = attributes; return ( setAttributes( { animation: selectedOption } ) } /> setAttributes( { delay: value } ) } min={ 0 } max={ 3000 } step={ 50 } /> setAttributes( { duration: value } ) } min={ 0 } max={ 3000 } step={ 50 } /> setAttributes( { offset: value } ) } /> setAttributes( { easing: selectedOption } ) } /> setAttributes( { once: checked } ) } /> setAttributes( { mirror: checked } ) } /> setAttributes( { anchorPlacement: selectedOption } ) } />
); }, save( { attributes, className } ) { const { animation = '', offset, delay, duration, easing, once, mirror, anchorPlacement, } = attributes; return (
); }, } );