/**
* BLOCK: Atomic Blocks Notice
*/
// Import block dependencies and components
import classnames from 'classnames';
import Inspector from './components/inspector';
import NoticeBox from './components/notice';
import DismissButton from './components/button';
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,
} = wp.editor;
class ABNoticeBlock extends Component {
render() {
// Setup the attributes
const {
attributes: {
noticeTitle,
noticeContent,
noticeAlignment,
noticeBackgroundColor,
noticeTitleColor,
noticeDismiss
},
setAttributes
} = this.props;
return [
// Show the alignment toolbar on focus
setAttributes( { noticeAlignment: value } ) }
/>
,
// Show the block controls on focus
,
// Show the block markup in the editor
{ // Check if the notice is dismissible and output the button
( noticeDismiss && noticeDismiss === 'ab-dismissable' ) && (
{ icons.dismiss }
) }
setAttributes( { noticeTitle: value } ) }
/>
setAttributes( { noticeContent: value } ) }
/>
];
}
}
// Register the block
registerBlockType( 'atomic-blocks/ab-notice', {
title: __( 'AB Notice', 'atomic-blocks' ),
description: __( 'Add a stylized text notice.', 'atomic-blocks' ),
icon: 'format-aside',
category: 'atomic-blocks',
keywords: [
__( 'notice', 'atomic-blocks' ),
__( 'message', 'atomic-blocks' ),
__( 'atomic', 'atomic-blocks' ),
],
attributes: {
noticeTitle: {
type: 'string',
selector: '.ab-notice-title',
},
noticeContent: {
type: 'array',
selector: '.ab-notice-text',
source: 'children',
},
noticeAlignment: {
type: 'string',
},
noticeBackgroundColor: {
type: 'string',
default: '#00d1b2'
},
noticeTextColor: {
type: 'string',
default: '#32373c'
},
noticeTitleColor: {
type: 'string',
default: '#fff'
},
noticeFontSize: {
type: 'number',
default: 18
},
noticeDismiss: {
type: 'string',
default: '',
},
},
// Render the block components
edit: ABNoticeBlock,
// Save the attributes and markup
save: function( props ) {
// Setup the attributes
const {
noticeTitle,
noticeContent,
noticeBackgroundColor,
noticeTitleColor,
noticeDismiss
} = props.attributes;
// Save the block markup for the front end
return (
{ ( noticeDismiss && noticeDismiss === 'ab-dismissable' ) && (
{ icons.dismiss }
) }
{ noticeTitle && (
) }
{ noticeContent && (
) }
);
},
} );