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

Early List block implementation (no UI yet) #358

Merged
merged 17 commits into from
Apr 7, 2017
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
8 changes: 8 additions & 0 deletions editor/assets/stylesheets/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ body.toplevel_page_gutenberg {
svg {
fill: currentColor;
}

ul {
list-style-type: disc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be generic across the entire editor canvas or specific to the blocks we're implementing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep these generic as these styles can be applied to the generic freeform block as well. In the future these might go away if we decide that the list block can support multiple styles of lists.
Without these styles the default list style type is none in the wp-admin page.

}

ol {
list-style-type: decimal;
}
}

.gutenberg__editor {
Expand Down
2 changes: 2 additions & 0 deletions editor/blocks/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import './freeform';
import './text';
import './list';

40 changes: 40 additions & 0 deletions editor/blocks/list/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const Editable = wp.blocks.Editable;
const { html, prop } = wp.blocks.query;

wp.blocks.registerBlock( 'core/list', {
title: wp.i18n.__( 'List' ),
icon: 'editor-ul',
category: 'common',

attributes: {
listType: prop( 'ol,ul', 'nodeName' ),
items: wp.blocks.query.query(
'li',
{
value: html()
}
)
},

edit( { attributes, onChange } ) {
const { listType = 'ol', items = [] } = attributes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When not default, listType will be uppercased (nodeName). Should the default be uppercased as well? See note below about Editable tagName.

const value = items.map( item => {
return `<li>${ item.value }</li>`;
} ).join( '' );

return (
<Editable
tagName={ listType }
value={ value }
onChange={ onChange } />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can improve this in a future pull request, but just FYI that this isn't really doing anything. You'll probably want to set this up so that onChange specifically updates the items entries.

);
},

save( { attributes } ) {
const { listType = 'ol', items = [] } = attributes;
const children = items.map( ( item, index ) => (
<li key={ index } dangerouslySetInnerHTML={ { __html: item.value } } />
) );
return wp.element.createElement( listType.toLowerCase(), null, children );
}
} );
10 changes: 7 additions & 3 deletions languages/gutenberg.pot
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"X-Generator: babel-plugin-wp-i18n\n"

#: editor/header/mode-switcher/index.js:31
msgctxt "Name for the Text editor tab (formerly HTML)"
msgid "Text"
msgstr ""

#: editor/blocks/freeform/index.js:4
msgid "Freeform"
msgstr ""

#: editor/header/mode-switcher/index.js:31
msgctxt "Name for the Text editor tab (formerly HTML)"
msgid "Text"
#: editor/blocks/list/index.js:5
msgid "List"
msgstr ""

#: editor/header/mode-switcher/index.js:30
Expand Down
5 changes: 5 additions & 0 deletions post-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ window._wpGutenbergPost = {
'<p>By shipping early and often you have the unique competitive advantage of hearing from real people what they think of your work, which in best case helps you anticipate market direction, and in worst case gives you a few people rooting for you that you can email when your team pivots to a new idea. Nothing can recreate the crucible of real usage.</p>',
'<!-- /wp:core/text -->',

'<!-- wp:core/list -->',
'<ul><li>Ship early</li><li>Ship often</li><li>Listen to feedback from real people</li><li>Anticipate market direction</li></ul>',
'<!-- /wp:core/list -->',

'<!-- wp:core/embed url:https://www.youtube.com/watch?v=Nl6U7UotA-M -->',
'<iframe width="560" height="315" src="//www.youtube.com/embed/Nl6U7UotA-M" frameborder="0" allowfullscreen></iframe>',
'<!-- /wp:core/embed -->',
].join( '' ),
},
};