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

Surface alignment toolbar as block control #987

Merged
merged 3 commits into from
Jun 7, 2017
Merged

Conversation

aduth
Copy link
Member

@aduth aduth commented Jun 1, 2017

This pull request effectively reverts behavior introduced in #533 . It serves as a first step toward considering text blocks as individual paragraphs.

Implementation notes:

These changes identified a few pain points:

  • Related to Standardize on children value as array (step 1) #689, treating the text block's content as a single tree blob has the disadvantage of needing to map children when serializing the block. I see this being resolved by either (a) enforcing single paragraph per text block or (b) parsing the text block's content as an array of paragraphs. In both cases we'll need significant refactoring for existing transforms (ideally for the better, not considering paragraph children prop access directly).
  • Related to Implement front-end styling for blocks #963 and concerns over duplicating attributes beginning from Remove and prevent DOM access in block attributes matchers #624, block alignment is another case where we'll want to consider patterns for eliminating duplication between serialized attributes and the markup itself. I'm very tempted to use data- attributes for this (both in styling and sourcing attributes), but did not include this as part of the changes here because this seems better addressed by a formal styling proposal or attributes extraction enhancements (Block parsing and serialization/deserialization #391).

In changes, alignment controls were removed from the list block. I'm not really certain I understand the purpose of list alignment, but could restore the behavior if it's considered desirable.

Testing instructions:

Ensure tests pass:

npm test

Verify that alignment behavior continues to work without regression, except that it applies to an entire block now. Serializing should encode the alignment attribute in block comments, and should be preserved when loading an existing post.

@aduth aduth added the [Feature] Blocks Overall functionality of blocks label Jun 1, 2017
@@ -8,10 +8,11 @@ import { Fill } from 'react-slot-fill';
*/
import { Toolbar } from 'components';

export default function BlockControls( { controls } ) {
export default function BlockControls( { controls, children } ) {
return (
<Fill name="Formatting.Toolbar">
<Toolbar controls={ controls } />
Copy link
Contributor

Choose a reason for hiding this comment

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

we probably should make controls optional and avoid including this if no controls are provided

Copy link
Member Author

Choose a reason for hiding this comment

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

Technically it is optional, and <Toolbar /> will not render itself when omitted:

https://github.com/WordPress/gutenberg/blob/97ee1a3/components/toolbar/index.js#L13-L15

Example: Included Text and Quote block changes render <BlockControls /> without controls prop.

return (
<blockquote className={ `blocks-quote blocks-quote-style-${ style }` }>
return [
focus && (
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about the focus check, I guess we could avoid it by hiding the controls using CSS instead of removing them completely from the DOM.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've grown more okay with it. Seems reasonable to expect that the render logic should be responsible for deciding if controls should be shown depending on whether the block currently has focus.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM 👍

I have some notes that could be resolved separately though.

  • Should we keep the alignments when splitting a text block?
  • Should we keep the alignments when transforming blocks (text 2 quote, quote 2 text)

@youknowriad
Copy link
Contributor

Oh I just noticed the alignment is not working on quotes (working only on the cite)

@aduth
Copy link
Member Author

aduth commented Jun 5, 2017

Oh I just noticed the alignment is not working on quotes (working only on the cite)

Good catch. I had styles on the block's Editables reversed (intended for text, not cite). Fixed in 17c066b.

Copy link
Member

@ellatrix ellatrix left a comment

Choose a reason for hiding this comment

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

Works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants