-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic heading block #423
Changes from all commits
2849506
8502267
6cc0116
1b0f6c4
f90d96e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { registerBlock, query } from 'api'; | ||
import Editable from 'components/editable'; | ||
|
||
const { html, prop } = query; | ||
|
||
registerBlock( 'core/heading', { | ||
title: wp.i18n.__( 'Heading' ), | ||
|
||
icon: 'heading', | ||
|
||
category: 'common', | ||
|
||
attributes: { | ||
content: html( 'h1,h2,h3,h4,h5,h6' ), | ||
tag: prop( 'h1,h2,h3,h4,h5,h6', 'nodeName' ), | ||
align: prop( 'h1,h2,h3,h4,h5,h6', 'style.textAlign' ) | ||
}, | ||
|
||
controls: [ | ||
...'123456'.split( '' ).map( ( level ) => ( { | ||
icon: 'heading', | ||
text: level, | ||
title: wp.i18n.sprintf( wp.i18n.__( 'Heading %s' ), level ), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good too. Does it matter much? Sorry for my ignorance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I'll not claim to be a localization expert, but perhaps as a hint to the translator that it's expected to be translated with a number vs. any arbitrary string could affect the translated text. Also prevents said arbitrary strings if we're very intentional that it's not to be expected (as a result of some potentially buggy code). |
||
isActive: ( { tag } ) => 'H' + level === tag, | ||
onClick( attributes, setAttributes ) { | ||
setAttributes( { tag: 'H' + level } ); | ||
} | ||
} ) ) | ||
], | ||
|
||
edit( { attributes, setAttributes } ) { | ||
const { content, tag, align } = attributes; | ||
|
||
return ( | ||
<Editable | ||
tagName={ tag } | ||
value={ content } | ||
onChange={ ( value ) => setAttributes( { content: value } ) } | ||
style={ align ? { textAlign: align } : null } | ||
/> | ||
); | ||
}, | ||
|
||
save( { attributes } ) { | ||
const { align, tag: Tag, content } = attributes; | ||
|
||
return ( | ||
<Tag | ||
style={ align ? { textAlign: align } : null } | ||
dangerouslySetInnerHTML={ { __html: content } } /> | ||
); | ||
} | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import './freeform'; | ||
import './heading'; | ||
import './image'; | ||
import './text'; | ||
import './list'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,13 @@ import './style.scss'; | |
import Button from '../button'; | ||
import Dashicon from '../dashicon'; | ||
|
||
function IconButton( { icon, label, className, ...additionalProps } ) { | ||
function IconButton( { icon, children, label, className, ...additionalProps } ) { | ||
const classes = classnames( 'editor-icon-button', className ); | ||
|
||
return ( | ||
<Button { ...additionalProps } aria-label={ label } className={ classes }> | ||
<Dashicon icon={ icon } /> | ||
{ children ? <span>{ children }</span> : null } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the span wrapper on |
||
</Button> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.editor-icon-button { | ||
display: flex; | ||
align-items: center; | ||
width: 36px; | ||
min-width: 36px; | ||
height: 36px; | ||
border: none; | ||
background: none; | ||
|
@@ -14,4 +14,8 @@ | |
color: $blue-medium; | ||
} | ||
} | ||
|
||
span { | ||
font-size: 12px; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This styling seems very targeted at the heading use-case. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great question to be asking. The icon-button should be just that, an icon button, so any text added should not so much be a label as it should be something to go with the icon itself. In this case, implying a heading size. But it could also be used for quote styles, or possibly even gallery styles (i.e. quote 2 or gallery 3). Tying together with your comment #436 (review), I will open a PR to add a label that makes this clear. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need
[ ...array ]
. We could just usearray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Future controls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough