Skip to content

Commit

Permalink
Merge pull request #5 from DekodeInteraktiv/custom-classname
Browse files Browse the repository at this point in the history
Add custom classnames to blocks
  • Loading branch information
olethomas authored Feb 16, 2022
2 parents 1ea7263 + 537b804 commit 21a70ec
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/templates/innerblocks/plugin.php.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ namespace {{phpnamespace}}\Blocks\{{phpnamespaceslug}};
* @return string
*/
function render( array $attributes, string $content ) : string {
$wrapper_attributes = get_block_wrapper_attributes();
$wrapper_attributes = get_block_wrapper_attributes( [
'class' => '{{namespace}}-{{slug}}',
] );
return sprintf( '
<div %s>
<div class="wp-block-{{namespace}}-{{slug}}__blocks">
<div class="{{namespace}}-{{slug}}__blocks">
%s
</div>
</div>',
Expand Down
4 changes: 3 additions & 1 deletion lib/templates/innerblocks/src/edit.js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const TEMPLATE = [];
const ALLOWED_BLOCKS = [];

export default function Edit() {
const blockProps = useBlockProps();
const blockProps = useBlockProps( {
className: '{{namespace}}-{{slug}}',
} );

return (
<div {...blockProps}>
Expand Down
2 changes: 1 addition & 1 deletion lib/templates/innerblocks/src/style.css.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.wp-block-{{namespace}}-{{slug}} {
.{{namespace}}-{{slug}} {
border: 1px solid #000;
padding: 1rem;
}
4 changes: 3 additions & 1 deletion lib/templates/plain/plugin.php.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ namespace {{phpnamespace}}\Blocks\{{phpnamespaceslug}};
* @return string
*/
function render( array $attributes ) : string {
$wrapper_attributes = get_block_wrapper_attributes();
$wrapper_attributes = get_block_wrapper_attributes( [
'class' => '{{namespace}}-{{slug}}',
] );
return sprintf( '
<div %s>
Expand Down
4 changes: 3 additions & 1 deletion lib/templates/plain/src/edit.js.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { useBlockProps } from '@wordpress/block-editor';
import { __ } from '@wordpress/i18n';

export default function Edit() {
const blockProps = useBlockProps();
const blockProps = useBlockProps( {
className: '{{namespace}}-{{slug}}',
} );

return <div {...blockProps}>{__('{{title}}', '{{namespace}}')}</div>;
}
2 changes: 1 addition & 1 deletion lib/templates/plain/src/style.css.mustache
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.wp-block-{{namespace}}-{{slug}} {
.{{namespace}}-{{slug}} {
border: 1px solid #000;
padding: 1rem;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dekode/create-project-base-block",
"version": "1.0.1",
"version": "1.1.0",
"description": "Generates PHP, JS and CSS code for registering a block for a WordPress plugin.",
"author": "Dekode Interaktiv AS",
"license": "GPL-2.0-or-later",
Expand Down

0 comments on commit 21a70ec

Please sign in to comment.