Skip to content

Commit

Permalink
Rename registerBlockStyleVariation to registerBlockStyle and export it
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jul 18, 2018
1 parent 9f25b65 commit 8e977d8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions blocks/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export {
isSharedBlock,
getChildBlockNames,
hasChildBlocks,
registerBlockStyle,
} from './registration';
export {
isUnmodifiedDefaultBlock,
Expand Down
2 changes: 1 addition & 1 deletion blocks/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export const hasChildBlocks = ( blockName ) => {
* @param {string} blockName Name of block (example: “core/latest-posts”).
* @param {Object} styleVariation Object containing `name` which is the class name applied to the block and `label` which identifies the variation to the user.
*/
export const registerBlockStyleVariation = ( blockName, styleVariation ) => {
export const registerBlockStyle = ( blockName, styleVariation ) => {
addFilter( 'blocks.registerBlockType', blockName + '/' + styleVariation.name, ( settings, name ) => {
if ( blockName !== name ) {
return settings;
Expand Down
10 changes: 5 additions & 5 deletions blocks/api/test/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
getBlockSupport,
hasBlockSupport,
isSharedBlock,
registerBlockStyleVariation,
registerBlockStyle,
} from '../registration';

describe( 'blocks', () => {
Expand Down Expand Up @@ -596,14 +596,14 @@ describe( 'blocks', () => {
} );
} );

describe( 'registerBlockStyleVariation', () => {
describe( 'registerBlockStyle', () => {
afterEach( () => {
removeFilter( 'blocks.registerBlockType', 'my-plugin/block-without-styles/big' );
removeFilter( 'blocks.registerBlockType', 'my-plugin/block-without-styles/small' );
} );

it( 'should add styles', () => {
registerBlockStyleVariation( 'my-plugin/block-without-styles', { name: 'big', label: 'Big style' } );
registerBlockStyle( 'my-plugin/block-without-styles', { name: 'big', label: 'Big style' } );
const settings = registerBlockType( 'my-plugin/block-without-styles', defaultBlockSettings );

expect( settings.styles ).toEqual( [
Expand All @@ -612,8 +612,8 @@ describe( 'blocks', () => {
} );

it( 'should accumulate styles', () => {
registerBlockStyleVariation( 'my-plugin/block-without-styles', { name: 'small', label: 'Small style' } );
registerBlockStyleVariation( 'my-plugin/block-without-styles', { name: 'big', label: 'Big style' } );
registerBlockStyle( 'my-plugin/block-without-styles', { name: 'small', label: 'Small style' } );
registerBlockStyle( 'my-plugin/block-without-styles', { name: 'big', label: 'Big style' } );
const settings = registerBlockType( 'my-plugin/block-without-styles', {
...defaultBlockSettings,
styles: [ { name: 'normal', label: 'Normal style' } ],
Expand Down

0 comments on commit 8e977d8

Please sign in to comment.