-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #24 - Add additional fields to oik-blockicon, clone to oik-bloc…
…kinfo
- Loading branch information
1 parent
ba3d1f0
commit fd6c7ed
Showing
7 changed files
with
428 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/* | ||
* Block icons select control | ||
* | ||
* I don't fully understand when to use `function Blah` vs `class Blah extends Component` | ||
* I supposed it's just a syntax thing.. modern JavaScript ES2015 vs original. | ||
* So here we have a mixture. | ||
* | ||
* @copyright (C) Copyright Bobbing Wide 2019 | ||
* @author Herb Miller @bobbingwide | ||
* | ||
*/ | ||
|
||
const { Component, Fragment } = wp.element; | ||
const{ getBlockTypes, getBlockType } = wp.blocks; | ||
const { BlockIcon } = wp.editor; | ||
const { SelectControl } = wp.components; | ||
|
||
function BlockiconsSelect( { value, onChange, ...props } ) { | ||
|
||
const options = getOptions(); | ||
//console.log( options ); | ||
options.sort( compareValues ); | ||
//console.log( options ); | ||
|
||
return ( | ||
|
||
|
||
<SelectControl label="Blocks" value={ value } options={ options } onChange={ onChange } /> | ||
); | ||
//this.renderBlockiconList(); | ||
|
||
} | ||
|
||
function compareValues(a, b) { | ||
if (a.value < b.value ) | ||
return -1; | ||
if (a.value > b.value ) | ||
return 1; | ||
return 0; | ||
} | ||
|
||
|
||
function getOptions() { | ||
var block_types = getBlockTypes(); | ||
const options = block_types.map ( ( block ) => getBlockiconOption( block ) ); | ||
//console.log( options ); | ||
return options; | ||
} | ||
|
||
function getBlockiconOption( block ) { | ||
//var label = BlockiconStyled( block.name ); | ||
|
||
var label = getOptionLabel( block ); | ||
var value = block.name; | ||
return {'label': label, 'value': value }; | ||
} | ||
|
||
/** | ||
* So how do I get the icon into the option label? | ||
* It seems it's not possible. | ||
* | ||
* @param block | ||
* @returns {string} | ||
*/ | ||
|
||
function getOptionLabel( block ) { | ||
var label = `${block.name} - ${ block.title }`; | ||
return label; | ||
} | ||
|
||
|
||
class BlockiconList extends Component { | ||
|
||
renderBlockiconList() { | ||
var block_types = getBlockTypes(); | ||
/*console.log( block_types );*/ | ||
return( | ||
<ul> | ||
{ block_types.map ( ( block ) => this.renderBlockicon( block ) )} | ||
</ul> | ||
); | ||
|
||
} | ||
|
||
renderBlockicon( block ) { | ||
/* { block.icon */ | ||
/* console.log( block ); */ | ||
return( <li> | ||
<BlockIcon icon={block.icon.src} /> | ||
{block.name } {block.title } | ||
</li> ); | ||
} | ||
|
||
} | ||
|
||
function BlockiconStyled( blockname, showBlockTypeName, showTitle, showDescription, ...props ) { | ||
var block = getBlockType( blockname ) ; | ||
var blockTypeName = showBlockTypeName ? <div>{ blockname }</div> : null; | ||
var blockTitle = showTitle ? <div> {block.title } </div> : null; | ||
var blockDescription = showDescription ? <div> { block.description } </div> : null; | ||
|
||
return( | ||
<Fragment> | ||
<div className={ props.className } > | ||
{ block ? <BlockIcon icon={ block.icon.src } /> : <p>Hmm</p> } | ||
</div> | ||
{ blockTypeName } | ||
{ blockTitle } | ||
{ blockDescription } | ||
</Fragment> | ||
|
||
); | ||
} | ||
|
||
|
||
export { BlockiconsSelect, BlockiconStyled }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.wp-block-oik-block-blockicon { | ||
.is-style-svg64 { | ||
svg { | ||
width: 64px; | ||
height: 64px; | ||
max-height: 64px; | ||
max-width: 64px; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.