/** * BLOCK: Atomic Blocks Profile Box */ // Import block dependencies and components import classnames from 'classnames'; import Inspector from './components/inspector'; import ProfileBox from './components/profile'; import SocialIcons from './components/social'; import AvatarColumn from './components/avatar'; import icons from './components/icons'; // Import styles 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 components const { RichText, AlignmentToolbar, BlockControls, InspectorControls, MediaUpload, } = wp.editor; // Register Inspector components const { Button, } = wp.components; const blockAttributes = { profileName: { type: 'array', source: 'children', selector: '.ab-profile-name', }, profileTitle: { type: 'array', source: 'children', selector: '.ab-profile-title', }, profileContent: { type: 'array', selector: '.ab-profile-text', source: 'children', }, profileAlignment: { type: 'string', }, profileImgURL: { type: 'string', source: 'attribute', attribute: 'src', selector: 'img', }, profileImgID: { type: 'number', }, profileBackgroundColor: { type: 'string', default: '#f2f2f2' }, profileTextColor: { type: 'string', default: '#32373c' }, profileLinkColor: { type: 'string', default: '#392f43' }, profileFontSize: { type: 'number', default: 18 }, profileAvatarShape: { type: 'string', default: 'square', }, twitter: { type: 'url', }, facebook: { type: 'url', }, instagram: { type: 'url', }, pinterest: { type: 'url', }, google: { type: 'url', }, youtube: { type: 'url', }, github: { type: 'url', }, linkedin: { type: 'url', }, email: { type: 'url', }, website: { type: 'url', }, }; const ALLOWED_MEDIA_TYPES = [ 'image' ]; class ABAuthorProfileBlock extends Component { render() { // Setup the attributes const { attributes: { profileName, profileTitle, profileContent, profileAlignment, profileImgURL, profileImgID, profileFontSize, profileBackgroundColor, profileTextColor, profileLinkColor, twitter, facebook, instagram, pinterest, google, youtube, github, email, website, profileAvatarShape }, attributes, isSelected, editable, className, setAttributes } = this.props; const onSelectImage = img => { setAttributes( { profileImgID: img.id, profileImgURL: img.url, } ); }; return [ // Show the block alignment controls on focus setAttributes( { profileAlignment: value } ) } /> , // Show the block controls on focus , // Show the block markup in the editor
setAttributes( { profileImgID: img.id, profileImgURL: img.url, } ) } allowed={ ALLOWED_MEDIA_TYPES } type="image" value={ profileImgID } render={ ( { open } ) => ( ) } >
setAttributes( { profileName: value } ) } /> setAttributes( { profileTitle: value } ) } /> setAttributes( { profileContent: value } ) } />
]; } } // Register the block registerBlockType( 'atomic-blocks/ab-profile-box', { title: __( 'AB Profile Box', 'atomic-blocks' ), description: __( 'Add a profile box with bio info and social media links.', 'atomic-blocks' ), icon: 'admin-users', category: 'atomic-blocks', keywords: [ __( 'author', 'atomic-blocks' ), __( 'profile', 'atomic-blocks' ), __( 'atomic', 'atomic-blocks' ), ], // Setup the block attributes attributes: blockAttributes, // Render the block components edit: ABAuthorProfileBlock, // Save the block markup save: function( props ) { // Setup the attributes const { profileName, profileTitle, profileContent, profileAlignment, profileImgURL, profileImgID, profileFontSize, profileBackgroundColor, profileTextColor, profileLinkColor, twitter, facebook, instagram, pinterest, google, youtube, github, linkedin, email, website, profileAvatarShape } = props.attributes; return ( // Save the block markup for the front end { profileImgURL && (
avatar
) }
{ profileName && ( ) } { profileTitle && ( ) } { profileContent && ( ) }
); }, } );