const { __ } = wp.i18n;
const {
registerBlockType
} = wp.blocks;
const {
InspectorControls,
ColorPalette,
MediaUpload,
BlockControls,
AlignmentToolbar,
InnerBlocks
} = wp.editor;
const {
PanelBody,
PanelRow,
TextControl
} = wp.components;
const {
Fragment
} = wp.element;
registerBlockType('advanced-blocks/parallax', {
title: "Parallax",
icon: 'image-flip-vertical',
category: 'advanced-blocks',
supports: {
align: true
},
attributes: {
overlayColor: {
type: 'string',
default: 'transparent'
},
backgroundImage: {
type: 'string',
default: null // no image by default!
},
maxContentWidth: {
type: 'string',
default: '600px'
}
},
// props are passed to edit by default
// props contains things like setAttributes and attributes
edit(props) {
// we are peeling off the things we need
const {
setAttributes,
attributes,
className, // The class name as a string!
focus // this is "true" when the user clicks on the block
} = props;
const { overlayColor, backgroundImage, maxContentWidth } = props.attributes;
//create a handler that will set the color when you click on the ColorPalette
function onOverlayColorChange(changes) {
setAttributes({
overlayColor: changes
})
}
// handles image object
function onImageSelect(imageObject) {
setAttributes({
backgroundImage: imageObject.sizes.full.url
})
}
function onMaxContentWidthChange(changes) {
setAttributes({
maxContentWidth: changes
})
}
return ([
{ __('This block is a placeholder for other blocks. Assign a background image to this block and it will use a parallax scrolling effect. Make sure you added one or more blocks into the Parallax block as well. ;)') } { __('Overlay Color') } { __('Background Image') }