/** * BLOCK: Atomic Blocks Testimonial */ // Import block dependencies and components import classnames from 'classnames'; import Inspector from './components/inspector'; import Testimonial from './components/testimonial'; import icons from './components/icons'; // Import CSS import './styles/style.scss'; import './styles/editor.scss'; // Internationalization const { __ } = wp.i18n; // Extend component const { Component } = wp.element; // Register block const { registerBlockType } = wp.blocks; // Register editor components const { RichText, AlignmentToolbar, BlockControls, BlockAlignmentToolbar, MediaUpload, } = wp.editor; // Register components const { Button, SelectControl, } = wp.components; const ALLOWED_MEDIA_TYPES = [ 'image' ]; class ABTestimonialBlock extends Component { render() { // Setup the attributes const { attributes: { testimonialName, testimonialTitle, testimonialContent, testimonialAlignment, testimonialImgURL, testimonialImgID, testimonialBackgroundColor, testimonialTextColor, testimonialFontSize, testimonialCiteAlign }, attributes, isSelected, editable, className, setAttributes } = this.props; const onSelectImage = img => { setAttributes( { testimonialImgID: img.id, testimonialImgURL: img.url, } ); }; return [ // Show the alignment toolbar on focus setAttributes( { testimonialAlignment: value } ) } /> , // Show the block controls on focus , // Show the block markup in the editor setAttributes( { testimonialContent: value } ) } />
setAttributes( { testimonialImgID: img.id, testimonialImgURL: img.url, } ) } allowed={ ALLOWED_MEDIA_TYPES } type="image" value={ testimonialImgID } render={ ( { open } ) => ( ) } >
this.props.setAttributes( { testimonialName: value } ) } /> this.props.setAttributes( { testimonialTitle: value } ) } />
]; } } // Register the block registerBlockType( 'atomic-blocks/ab-testimonial', { title: __( 'AB Testimonial', 'atomic-blocks' ), description: __( 'Add a user testimonial with a name and title.', 'atomic-blocks' ), icon: 'format-quote', category: 'atomic-blocks', keywords: [ __( 'testimonial', 'atomic-blocks' ), __( 'quote', 'atomic-blocks' ), __( 'atomic', 'atomic-blocks' ), ], attributes: { testimonialName: { type: 'array', selector: '.ab-testimonial-name', source: 'children', }, testimonialTitle: { type: 'array', selector: '.ab-testimonial-title', source: 'children', }, testimonialContent: { type: 'array', selector: '.ab-testimonial-text', source: 'children', }, testimonialAlignment: { type: 'string', }, testimonialImgURL: { type: 'string', source: 'attribute', attribute: 'src', selector: 'img', }, testimonialImgID: { type: 'number', }, testimonialBackgroundColor: { type: 'string', default: '#f2f2f2' }, testimonialTextColor: { type: 'string', default: '#32373c' }, testimonialFontSize: { type: 'number', default: 18, }, testimonialCiteAlign: { type: 'string', default: 'left-aligned', }, }, // Render the block components edit: ABTestimonialBlock, // Save the attributes and markup save: function( props ) { // Setup the attributes const { testimonialName, testimonialTitle, testimonialContent, testimonialAlignment, testimonialImgURL, testimonialImgID, testimonialBackgroundColor, testimonialTextColor, testimonialFontSize, testimonialCiteAlign } = props.attributes; // Save the block markup for the front end return (
{ testimonialImgURL && (
avatar
) } { testimonialName && ( ) } { testimonialTitle && ( ) }
); }, } );