Skip to content

Commit

Permalink
Template-04-controls-esnext - updated template to match https://githu…
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bui committed Jun 6, 2020
1 parent 52d40da commit 94e469d
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 83 deletions.
12 changes: 7 additions & 5 deletions packages/create-block/lib/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ const predefinedBlockTemplates = {
],
wpScriptsEnabled: true,
},
esnextControls: {
'controls-esnext': {
defaultValues: {
// namespace,
slug: 'esnext-controls',
title: 'ESNext Controls Example',
description: 'Example of controls block – build step required.',
slug: 'controls-esnext',
title: 'Controls ESNext',
description:
'Example block written with ESNext standard and JSX support – build step required.',
dashicon: 'universal-access-alt',
category: 'layout',
},
},
};
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/**
* The following styles get applied inside the editor only.
*
* Replace them with your own styles or remove the file completely.
* Note that these styles are loaded *after* common styles, so that
* editor-specific styles using the same selectors will take precedence.
*/

.wp-block-gutenberg-examples-example-04-controls-esnext {
color: #fff;
background: #00a8db;
border: 2px solid #0D72B2;
padding: 20px;
font-family: sans-serif;
}
.wp-block-{{namespace}}-{{slug}} {
border: 1px dotted red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ import { registerBlockType } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*
*
*
*/
import './style.scss';
import Edit from './edit';
import save from './save';

This comment has been minimized.

Copy link
@intelijens

intelijens Jun 6, 2020

I should probably add these back in since we actually added styles 😕
I should also add better comments ... 😴

import {
RichText,
AlignmentToolbar,
BlockControls,
} from '@wordpress/block-editor';

/**
* Every block starts by registering a new block type definition.
Expand Down Expand Up @@ -51,6 +55,23 @@ registerBlockType( '{{namespace}}/{{slug}}', {
*/
category: '{{category}}',

/**
*
*
*
*/
attributes: {
content: {
type: 'array',
source: 'children',
selector: 'p',
},
alignment: {
type: 'string',
default: 'none',
},
},

{{#dashicon}}
/**
* An icon property should be specified to make it easier to identify a block.
Expand All @@ -59,21 +80,58 @@ registerBlockType( '{{namespace}}/{{slug}}', {
icon: '{{dashicon}}',

{{/dashicon}}
/**
* Optional block extended support features.
*/
supports: {
// Removes support for an HTML mode.
html: false,
},

/**
* @see ./edit.js
*
*/
edit: Edit,
edit: ( props ) => {
const {
attributes: { content, alignment },
className,
} = props;

const onChangeContent = ( newContent ) => {
props.setAttributes( { content: newContent } );
};

const onChangeAlignment = ( newAlignment ) => {
props.setAttributes( {
alignment: newAlignment === undefined ? 'none' : newAlignment,
} );
};

return (
<div>
{
<BlockControls>
<AlignmentToolbar
value={ alignment }
onChange={ onChangeAlignment }
/>
</BlockControls>
}
<RichText
className={ className }
style={ { textAlign: alignment } }
tagName="p"
onChange={ onChangeContent }
value={ content }
/>
</div>
);
},

/**
* @see ./save.js
*
*/
save,

save: ( props ) => {
return (
<RichText.Content
className={ `gutenberg-examples-align-${ props.attributes.alignment }` }
tagName="p"
value={ props.attributes.content }
/>
);
},
} );

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
/**
* The following styles get applied both on the front of your site
* and in the editor.
*
* Replace them with your own styles or remove the file completely.
* Note that these styles are loaded *before* editor styles, so that
* editor-specific styles using the same selectors will take precedence.
*/
.wp-block-gutenberg-examples-example-04-controls-esnext {
color: #fff;
background: #00a8db;
border: 2px solid #0D72B2;
padding: 20px;
font-family: sans-serif;
}

.gutenberg-examples-align-left {
text-align: left;
}

.gutenberg-examples-align-center {
text-align: center;
}

.gutenberg-examples-align-right {
text-align: right;
}

.wp-block-{{namespace}}-{{slug}} {
background-color: theme(button);
Expand Down

0 comments on commit 94e469d

Please sign in to comment.