Skip to content

Commit

Permalink
Merge pull request #379 from WordPress/add/image-block
Browse files Browse the repository at this point in the history
Implement image block
  • Loading branch information
aduth authored Apr 7, 2017
2 parents b8b59db + 1293313 commit c057011
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
49 changes: 49 additions & 0 deletions editor/blocks/image/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { attr, html } = wp.blocks.query;
const Editable = wp.blocks.Editable;

wp.blocks.registerBlock( 'core/image', {
title: wp.i18n.__( 'Image' ),

icon: 'format-image',

category: 'common',

attributes: {
url: attr( 'img', 'src' ),
alt: attr( 'img', 'alt' ),
caption: html( 'figcaption' )
},

edit( { attributes, isSelected, setAttributes } ) {
const { url, alt, caption } = attributes;

return (
<figure>
<img src={ url } alt={ alt } />
{ caption || isSelected ? (
<Editable
tagName="figcaption"
placeholder={ wp.i18n.__( 'Write caption…' ) }
value={ caption }
onChange={ ( value ) => setAttributes( { caption: value } ) } />
) : null }
</figure>
);
},

save( { attributes } ) {
const { url, alt, caption } = attributes;
const img = <img src={ url } alt={ alt } />;

if ( ! caption ) {
return img;
}

return (
<figure>
{ img }
<figcaption dangerouslySetInnerHTML={ { __html: caption } } />
</figure>
);
}
} );
1 change: 1 addition & 0 deletions editor/blocks/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './freeform';
import './image';
import './text';
import './list';

1 change: 1 addition & 0 deletions editor/modes/visual-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function VisualEditorBlock( props ) {
} ) ) } />
) : null }
<BlockEdit
isSelected={ isSelected }
attributes={ block.attributes }
setAttributes={ setAttributes } />
</div>
Expand Down
8 changes: 8 additions & 0 deletions languages/gutenberg.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ msgstr ""
msgid "Freeform"
msgstr ""

#: editor/blocks/image/index.js:26
msgid "Write caption…"
msgstr ""

#: editor/blocks/image/index.js:5
msgid "Image"
msgstr ""

#: editor/blocks/list/index.js:5
msgid "List"
msgstr ""
Expand Down

0 comments on commit c057011

Please sign in to comment.