Skip to content

Commit

Permalink
Implement image block placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed May 2, 2017
1 parent 734e188 commit e4b84ea
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 10 deletions.
20 changes: 20 additions & 0 deletions blocks/library/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import './style.scss';
import { registerBlock, query } from 'api';
import Editable from 'components/editable';
// TODO: Revisit when we have a common components solution
import Dashicon from '../../../editor/components/dashicon';
import Button from '../../../editor/components/button';

const { attr, children } = query;

Expand Down Expand Up @@ -78,6 +81,23 @@ registerBlock( 'core/image', {
edit( { attributes, setAttributes, focus, setFocus } ) {
const { url, alt, caption } = attributes;

if ( ! url ) {
return (
<div className="blocks-image is-placeholder">
<div className="blocks-image__placeholder-label">
<Dashicon icon="format-image" />
{ wp.i18n.__( 'Image' ) }
</div>
<div className="blocks-image__placeholder-instructions">
{ wp.i18n.__( 'Drag image here or insert from media library' ) }
</div>
<Button isLarge>
{ wp.i18n.__( 'Insert from Media Library' ) }
</Button>
</div>
);
}

return (
<figure className="blocks-image">
<img src={ url } alt={ alt } />
Expand Down
22 changes: 22 additions & 0 deletions blocks/library/image/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,25 @@
width: 100%;
}
}

.blocks-image.is-placeholder {
margin: -15px;
padding: 6em 0;
border: 2px solid $light-gray-500;
text-align: center;
}

.blocks-image__placeholder-label {
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;

.dashicon {
margin-right: 1ch;
}
}

.blocks-image__placeholder-instructions {
margin: 1.8em 0;
}
2 changes: 1 addition & 1 deletion editor/modes/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
position: absolute;
top: 0;
bottom: 0;
left: 33px;
left: 35px;
right: 0;
border: 2px solid transparent;
transition: 0.2s border-color;
Expand Down
26 changes: 17 additions & 9 deletions languages/gutenberg.pot
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ msgid "Strikethrough"
msgstr ""

#: blocks/components/editable/index.js:29
#: blocks/library/image/index.js:41
#: blocks/library/image/index.js:44
#: blocks/library/list/index.js:25
msgid "Align left"
msgstr ""

#: blocks/components/editable/index.js:34
#: blocks/library/image/index.js:47
#: blocks/library/image/index.js:50
#: blocks/library/list/index.js:33
msgid "Align center"
msgstr ""

#: blocks/components/editable/index.js:39
#: blocks/library/image/index.js:53
#: blocks/library/image/index.js:56
#: blocks/library/list/index.js:41
msgid "Align right"
msgstr ""
Expand All @@ -46,7 +46,7 @@ msgid "Embed"
msgstr ""

#: blocks/library/embed/index.js:33
#: blocks/library/image/index.js:87
#: blocks/library/image/index.js:107
msgid "Write caption…"
msgstr ""

Expand All @@ -62,16 +62,24 @@ msgstr ""
msgid "Heading %s"
msgstr ""

#: blocks/library/image/index.js:25
#: blocks/library/image/index.js:62
msgid "No alignment"
msgstr ""

#: blocks/library/image/index.js:68
msgid "Wide width"
msgstr ""

#: blocks/library/image/index.js:89
msgid "Image"
msgstr ""

#: blocks/library/image/index.js:59
msgid "No alignment"
#: blocks/library/image/index.js:92
msgid "Drag image here or insert from media library"
msgstr ""

#: blocks/library/image/index.js:65
msgid "Wide width"
#: blocks/library/image/index.js:95
msgid "Insert from Media Library"
msgstr ""

#: blocks/library/list/index.js:11
Expand Down

0 comments on commit e4b84ea

Please sign in to comment.