forked from WordPress/gutenberg
-
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.
Plugin: Heading Block Initial Attempt
Here is an initial attempt at using the current API for a heading block. I just guessed as to how this should be structured, honestly have no idea but I tried to mimic the codebase the best I could.
- Loading branch information
1 parent
8e62d60
commit d66bbea
Showing
4 changed files
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default function EditableHeading( { value, headingType } ) { | ||
const headingsMap = { | ||
H1: 'h1', | ||
H2: 'h2', | ||
H3: 'h3', | ||
H4: 'h4', | ||
H5: 'h5', | ||
H6: 'h6', | ||
}; | ||
|
||
const mapHeading = ( nodeName ) => headingsMap[ nodeName ]; | ||
|
||
return wp.element.createElement( mapHeading( headingType ), null, value ); | ||
} |
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,23 @@ | ||
const { query, html, prop } = wp.blocks.query; | ||
|
||
wp.blocks.registerBlock( 'wp/heading', { | ||
title: 'Heading', | ||
icon: 'heading', | ||
|
||
attributes: { | ||
value: query( 'h1,h2,h3,h4,h5,h6', html() ), | ||
headingType: query( 'h1,h2,h3,h4,h5,h6', prop( 'nodeName' ) ), | ||
}, | ||
|
||
edit( attributes, onChange ) { | ||
return wp.element.createElement( wp.blocks.EditableHeading, { | ||
value: attributes.value, | ||
headingType: attributes.headingType, | ||
onChange: ( value ) => onChange( { value } ) | ||
} ); | ||
}, | ||
|
||
save( attributes ) { | ||
return wp.element.createElement( 'p', null, attributes.value ); | ||
} | ||
} ); |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
import './text-block'; | ||
import './heading-block'; |