Skip to content
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 standfirst/subhead block #2091

Merged
merged 1 commit into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions blocks/library/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ import './video';
import './audio';
import './block';
import './paragraph';
import './subhead';
6 changes: 6 additions & 0 deletions blocks/library/subhead/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Overwrite .editor-visual-editor p
.editor-visual-editor p.wp-block-subhead {
color: $dark-gray-300;
font-size: 1.1em;
font-style: italic;
}
91 changes: 91 additions & 0 deletions blocks/library/subhead/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import './editor.scss';
import './style.scss';
import { registerBlockType, createBlock } from '../../api';
import Editable from '../../editable';
import InspectorControls from '../../inspector-controls';
import BlockDescription from '../../block-description';

registerBlockType( 'core/subhead', {
title: __( 'Subhead' ),

icon: 'text',

category: 'common',

useOnce: true,

attributes: {
content: {
type: 'array',
source: 'children',
selector: 'p',
},
},

transforms: {
from: [
{
type: 'block',
blocks: [ 'core/paragraph' ],
transform: ( { content } ) => {
return createBlock( 'core/subhead', {
content,
} );
},
},
],
to: [
{
type: 'block',
blocks: [ 'core/paragraph' ],
transform: ( { content } ) => {
return createBlock( 'core/paragraph', {
content,
} );
},
},
],
},

edit( { attributes, setAttributes, focus, setFocus, className } ) {
const { content, placeholder } = attributes;

return [
focus && (
<InspectorControls key="inspector">
<BlockDescription>
<p>{ __( 'Explanatory text under the main heading of an article.' ) }</p>
</BlockDescription>
</InspectorControls>
),
<Editable
tagName="p"
key="editable"
value={ content }
onChange={ ( nextContent ) => {
setAttributes( {
content: nextContent,
} );
} }
focus={ focus }
onFocus={ setFocus }
className={ className }
placeholder={ placeholder || __( 'Write subhead…' ) }
/>,
];
},

save( { attributes, className } ) {
const { content } = attributes;

return <p className={ className }>{ content }</p>;
},
} );
5 changes: 5 additions & 0 deletions blocks/library/subhead/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
p.wp-block-subhead {
font-size: 1.1em;
font-style: italic;
opacity: 0.75;
}
3 changes: 3 additions & 0 deletions blocks/test/fixtures/core__subhead.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:core/subhead -->
<p class="wp-block-subhead">This is a <em>subhead</em>.</p>
<!-- /wp:core/subhead -->
18 changes: 18 additions & 0 deletions blocks/test/fixtures/core__subhead.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"uid": "_uid_0",
"name": "core/subhead",
"isValid": true,
"attributes": {
"content": [
"This is a ",
{
"type": "em",
"children": "subhead"
},
"."
]
},
"originalContent": "<p class=\"wp-block-subhead\">This is a <em>subhead</em>.</p>"
}
]
11 changes: 11 additions & 0 deletions blocks/test/fixtures/core__subhead.parsed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"blockName": "core/subhead",
"attrs": null,"innerBlocks": [],
"innerHTML": "\n<p class=\"wp-block-subhead\">This is a <em>subhead</em>.</p>\n"
},
{
"attrs": {},
"innerHTML": "\n"
}
]
3 changes: 3 additions & 0 deletions blocks/test/fixtures/core__subhead.serialized.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<!-- wp:subhead -->
<p class="wp-block-subhead">This is a <em>subhead</em>.</p>
<!-- /wp:subhead -->