Skip to content

Commit

Permalink
Issue #27 - Add showBatch toggle to Block list
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbingwide committed Feb 21, 2019
1 parent 56c2627 commit 641ae6e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
25 changes: 21 additions & 4 deletions blocks/oik-blocklist/blocklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Fragment = wp.element.Fragment;
import { BlockiconStyled } from '../oik-blockicon/blockicons.js';
import { getNameSpace} from './blockprefix.js';

function BlockListStyled( prefix, showBlockTypeName, showTitle, showDescription, ...props ) {
function BlockListStyled( prefix, showBlockTypeName, showTitle, showDescription, showBatch, ...props ) {
//var block = getBlockType( blockname ) ;
//var blockicon = BlockiconStyled( blockname, props );
//var blockTypeName = showBlockTypeName ? <div>{ blockname }</div> : null;
Expand All @@ -28,13 +28,25 @@ function BlockListStyled( prefix, showBlockTypeName, showTitle, showDescription,
//block_types = block_types.sortByField( "name");
block_types = block_types.sort( (a, b) => a.title.localeCompare(b.title));
//console.log( block_types );
return(

if ( showBatch ) {
var blocklist = <pre>
cd ~/public_html/wp-content/plugins/oik-shortcodes/admin
{block_types.map( (block) => BlockCreateItem( block )) }
</pre>
} else
{
var blocklist =
<dl>

{ block_types.map ( ( block ) => BlockListItem( block ) )}
{block_types.map((block) => BlockListItem(block))}
</dl>
}
;



);
return( blocklist );


}
Expand Down Expand Up @@ -63,4 +75,9 @@ function BlockListItem( block ) {
);
}

function BlockCreateItem( block ) {
console.log( block );
return( <Fragment><br/>oikwp oik-create-blocks.php {block.name} "{block.title}" component url=blocks.wp-a2z.org</Fragment> );
}

export { BlockListStyled };
6 changes: 6 additions & 0 deletions blocks/oik-blocklist/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@
}
}

}

.wp-block-oik-block-blocklist {
pre {
font-size: 12px;
}
}
32 changes: 28 additions & 4 deletions blocks/oik-blocklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,15 @@ export default registerBlockType(
showDescription: {
type: 'boolean',
default: true
},

showBatch: {
type: 'boolean',
default: false
}



},


Expand All @@ -116,13 +123,20 @@ export default registerBlockType(
props.setAttributes( { showDescription: ! props.attributes.showDescription } );
}

const onChangeShowBatch = ( event ) => {
props.setAttributes( { showBatch: ! props.attributes.showBatch } );
}

var blocklist = BlockListStyled( props.attributes.prefix,
props.attributes.showBlockTypeName,
props.attributes.showTitle,
props.attributes.showDescription,
props.attributes.showBatch,
props );




return [
<InspectorControls >
<PanelBody>
Expand All @@ -148,11 +162,20 @@ export default registerBlockType(
/>

</PanelRow>
<PanelRow>
<ToggleControl
label={ __( 'Show block description' ) }
checked={ !! props.attributes.showDescription }
onChange={ onChangeShowDescription }

/>

</PanelRow>
<PanelRow>
<ToggleControl
label={ __( 'Show block description' ) }
checked={ !! props.attributes.showDescription }
onChange={ onChangeShowDescription }
label={ __( 'Show batch commands' ) }
checked={ !! props.attributes.showBatch }
onChange={ onChangeShowBatch }

/>

Expand All @@ -167,6 +190,7 @@ export default registerBlockType(
<div className={ props.className }>
{ blocklist }
</div>
,


];
Expand All @@ -177,7 +201,7 @@ export default registerBlockType(
/>
*/
save: props => {
return BlockListStyled( props.attributes.prefix, props.attributes.showBlockTypeName, props.attributes.showTitle, props.attributes.showDescription, props );
return BlockListStyled( props.attributes.prefix, props.attributes.showBlockTypeName, props.attributes.showTitle, props.attributes.showDescription, props.attributes.showBatch, props );
},
},
);

0 comments on commit 641ae6e

Please sign in to comment.