Skip to content

Cover Image Block: Added button.#3047

Closed
jorgefilipecosta wants to merge 2 commits intomasterfrom
add/button-cover-image
Closed

Cover Image Block: Added button.#3047
jorgefilipecosta wants to merge 2 commits intomasterfrom
add/button-cover-image

Conversation

@jorgefilipecosta
Copy link
Copy Markdown
Member

@jorgefilipecosta jorgefilipecosta commented Oct 18, 2017

Description

This PR adds an optional button to the cover image. Allowing button customization options. As specified in issue #2765.

Testing

  1. Add a cover image. Verify everything works as before.
  2. Add a button verify things worked as before.
  3. In the cover image enable show button
  4. Customize the button of the cover image see things worked as expected.
  5. Save the post see the result, see if the result is ok.
  6. Open a post with a cover image and button created before this changes and see if they load as expected.

Screenshots:

screen shot 2017-10-18 at 09 37 44

Notes:

In order to not repeat button block code, 2 components were extracted one that renders button editor and other that render button for saving. This 2 components can be used by other blocks that need a button.
The CSS was a little by trial error maybe it can be improved, but in my tries, this looked like the simplest way.

@jorgefilipecosta jorgefilipecosta added [Feature] Blocks Overall functionality of blocks Needs Design Feedback Needs general design feedback. [Feature] UI Components Impacts or related to the UI component system [Type] Enhancement A suggestion for improvement. labels Oct 18, 2017
@jorgefilipecosta jorgefilipecosta self-assigned this Oct 18, 2017
@jorgefilipecosta jorgefilipecosta requested a review from mcsf October 18, 2017 09:31
Copy link
Copy Markdown
Contributor

@mcsf mcsf left a comment

Choose a reason for hiding this comment

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

Nice work!

I identified a few things, though no big blocker.

The CSS was a little by trial error maybe it can be improved, but in my tries, this looked like the simplest way.

Worth mentioning that, while this looks great on the Gutenberg Theme, it doesn't always on Twenty Fifteen:

screen shot 2017-10-18 at 13 31 16

Finally, this PR makes a previous issue more prominent: the placeholder text for Cover Image isn't always positioned to match the title field, potentially resulting in a user's inability to focus the field. See screencast. Let's revisit that separately.

Assuming the little things are addressed, 🚢 !

setButtonBackgroundColor={ ( value ) => setAttributes( { color: value } ) }
setButtonText={ ( value ) => setAttributes( { text: value } ) }
setButtonTextColor={ ( value ) => setAttributes( { textColor: value } ) }
setButtonUrl={ ( value ) => setAttributes( { url: value } ) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

focus is already passed as a prop, so we have duplication. Since the name “focus” is already customary, should we just get rid of showInspector?

<IconButton icon="editor-break" label={ __( 'Apply' ) } type="submit" />
</form>
}
{ showInspector &&
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As mentioned in the other file, focus && is the typical form anyway :).

{ ...{ className, focus, setAttributes, url, setFocus, title } }
buttonBackgroundColor={ color }
buttonText={ text }
buttonTextColor={ textColor }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similarly, buttonUrl is a duplicate of url. Pick your favorite. :)

</InspectorControls>
}
</span>,
<ButtonControls key="buttonControls"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It doesn't look like setAttributes is needed in ButtonControls, since setters are now provided for every datum (setButtonText, etc.).

'has-parallax': hasParallax,
}
);
const focusedEditable = focus ? focus.editable || 'title' : null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is my personal take on mixing infix operators, but I don't trust that we all know the full operator precedence table to make sure we don't write something we don't mean. :)

In other words, this may be unambiguous for the interpreter, but it's ambiguous for us. I suggest focus ? ( focus.editable || 'title' ) : null.

buttonUrl: {
type: 'string',
},
showButton: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor: I would prefer hasButton (or even shouldShowButton, though lengthier), since in other contexts showButton could be read as an action.

@@ -0,0 +1,16 @@
export default ( { align,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing line break before align

@mtias
Copy link
Copy Markdown
Member

mtias commented Oct 18, 2017

I don't think we should be importing an internal like /button/button-render from another block. At most, it should be a reusable piece in /blocks/{colorable-button} that other blocks could leverage. But still, I don't think it's a great strategy going forwards.

The right solution is going to be nested blocks and specifying which blocks are included by the default. In this case, since it's an interim solution, I would still duplicate the code for the button and keep it as an internal of cover image.

@jorgefilipecosta jorgefilipecosta force-pushed the add/button-cover-image branch 3 times, most recently from 8fc557d to 8459b01 Compare October 19, 2017 13:57
@codecov
Copy link
Copy Markdown

codecov bot commented Oct 19, 2017

Codecov Report

Merging #3047 into master will decrease coverage by 0.04%.
The diff coverage is 8.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3047      +/-   ##
==========================================
- Coverage   31.36%   31.31%   -0.05%     
==========================================
  Files         223      223              
  Lines        6393     6403      +10     
  Branches     1136     1139       +3     
==========================================
  Hits         2005     2005              
- Misses       3685     3692       +7     
- Partials      703      706       +3
Impacted Files Coverage Δ
blocks/library/cover-image/index.js 23.52% <8.33%> (-9.81%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5ebeca...4d227e8. Read the comment docs.

@jorgefilipecosta
Copy link
Copy Markdown
Member Author

jorgefilipecosta commented Oct 19, 2017

Hi @mcsf, @mtias, thank you for your feedback 👍 I think I addressed all fo it, including the case where editable not matched placeholder position (nice catch). Regarding the problem, in some themes, a margin is set for h2 and I made a rule that sets the margin to 0 inside our block which is essential for things to look nice.

aduth
aduth previously requested changes Oct 19, 2017

.button-container {
.blocks-format-toolbar__link-modal {
z-index: 2;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To help maintain sensible z-index, there is a mapping entry and corresponding function that any z-index property should be using:

https://github.com/WordPress/gutenberg/blob/master/editor/assets/stylesheets/_z-index.scss

}

.button-container {
.blocks-format-toolbar__link-modal {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to nest this so much? Part of the benefit of our BEM-like pattern for CSS naming is that we're guaranteed a reasonable amount of uniqueness, so unless specificity or context matters, it's usually safe to put at the top level.

</form>
}
{ focus &&
<InspectorControls key="inspector">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need key?

) : null }

{ hasButton &&
<span key="button" className="button-container aligncenter" style={ { backgroundColor: buttonBackgroundColor } } >
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need key?

</div>
) : null }

{ hasButton &&
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it possible for us to be able to infer hasButton based on presence of other button related attributes, rather than creating a separate one specifically for it? Maybe when toggling "Show Button", we assign buttonText as an empty string, then detect hasButton as buttonText !== undefined (or typeof buttonText === 'string')?

justify-content: center;
align-items: center;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not explicitly documented for CSS guidelines, but in general we should remove trailing whitespace.

PHP reference: https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#remove-trailing-spaces

I also suggest downloading an EditorConfig plugin for your editor, which should simplify this task for you since we include a configuration file:

http://editorconfig.org/#download

}

.button-container {
top: 100px;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It might be simpler to use margins here instead of relative positioning.


.button-container {
top: 100px;
font-family: $default-font;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we explicitly override the font family?

Copy link
Copy Markdown
Member Author

@jorgefilipecosta jorgefilipecosta Oct 23, 2017

Choose a reason for hiding this comment

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

Hi @aduth, this logic was already being applied in button code. I did some checks and without it, in some themes, we use other fonts that don't look as nice in the button. So, for now, I kept this font family override.

}

.wp-block-cover-image > h2 {
margin: 0px !important;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need !important? Is this an issue of specificity? We should avoid !important as much as possible.

{ focusedEditable === 'button' &&
<form
className="blocks-format-toolbar__link-modal"
onSubmit={ ( event ) => event.preventDefault() }>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we render this as a form if we're not doing anything form-like with it? Seems we could just as easily drop the form and avoid assigning type="submit" to the icon button.

@aduth
Copy link
Copy Markdown
Member

aduth commented Oct 19, 2017

Also, this has me desperately wishing for proper block nesting, as the many additional attributes necessary to support a button in this block is less than ideal.

@jorgefilipecosta jorgefilipecosta force-pushed the add/button-cover-image branch 3 times, most recently from 3fb89ee to ed6c5f9 Compare October 23, 2017 14:25
@jorgefilipecosta
Copy link
Copy Markdown
Member Author

Hi @aduth thank you a lot for your feedback and tips! It was applied. I agree that nesting would be a better solution, as soon as we have nesting available, I can refactor this logic and show button toggle UI to automatically add a button inside. The downside is that the change may make the blocks of this version incompatible.

@mtias
Copy link
Copy Markdown
Member

mtias commented Oct 24, 2017

image

Placeholder text can get stuck.

@mtias
Copy link
Copy Markdown
Member

mtias commented Oct 24, 2017

What about calling the toggle "call to action"? (cc @jasmussen @karmatosed for thoughts.)

@ellatrix
Copy link
Copy Markdown
Member

@matias See #2865.

@karmatosed
Copy link
Copy Markdown
Member

Call to action works for me @mtias.

@jorgefilipecosta
Copy link
Copy Markdown
Member Author

Hi @mtias, @karmatosed the toggle text was updated to "Call to action" as suggested :)

@aduth aduth dismissed their stale review October 26, 2017 21:09

Dismissing my "Needs Changes" review, but I'm personally of the opinion that we put more effort toward block nesting and avoid this interim solution altogether.

@jorgefilipecosta
Copy link
Copy Markdown
Member Author

Thank you for your reviews @aduth 👍 I understand that nesting would be a better approach if we prefer to wait I can revisit this and implement it when nesting is ready.

@jorgefilipecosta
Copy link
Copy Markdown
Member Author

Hi @mtias, what is your opinion should we merge this PR that adds a button to cover image as a setting and make it available on next release or it is better to wait for nesting and rethink this changes when nesting is ready?

@gziolo gziolo deleted the add/button-cover-image branch May 7, 2018 11:15
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 [Feature] UI Components Impacts or related to the UI component system Needs Design Feedback Needs general design feedback. [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants