Conversation
f9bfdc5 to
20b2fb6
Compare
mcsf
left a comment
There was a problem hiding this comment.
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:
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, 🚢 !
blocks/library/button/index.js
Outdated
| setButtonBackgroundColor={ ( value ) => setAttributes( { color: value } ) } | ||
| setButtonText={ ( value ) => setAttributes( { text: value } ) } | ||
| setButtonTextColor={ ( value ) => setAttributes( { textColor: value } ) } | ||
| setButtonUrl={ ( value ) => setAttributes( { url: value } ) } |
There was a problem hiding this comment.
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 && |
There was a problem hiding this comment.
As mentioned in the other file, focus && is the typical form anyway :).
blocks/library/button/index.js
Outdated
| { ...{ className, focus, setAttributes, url, setFocus, title } } | ||
| buttonBackgroundColor={ color } | ||
| buttonText={ text } | ||
| buttonTextColor={ textColor } |
There was a problem hiding this comment.
Similarly, buttonUrl is a duplicate of url. Pick your favorite. :)
blocks/library/button/index.js
Outdated
| </InspectorControls> | ||
| } | ||
| </span>, | ||
| <ButtonControls key="buttonControls" |
There was a problem hiding this comment.
It doesn't look like setAttributes is needed in ButtonControls, since setters are now provided for every datum (setButtonText, etc.).
blocks/library/cover-image/index.js
Outdated
| 'has-parallax': hasParallax, | ||
| } | ||
| ); | ||
| const focusedEditable = focus ? focus.editable || 'title' : null; |
There was a problem hiding this comment.
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.
blocks/library/cover-image/index.js
Outdated
| buttonUrl: { | ||
| type: 'string', | ||
| }, | ||
| showButton: { |
There was a problem hiding this comment.
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, | |||
There was a problem hiding this comment.
Missing line break before align
|
I don't think we should be importing an internal like 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. |
8fc557d to
8459b01
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
|
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. |
|
|
||
| .button-container { | ||
| .blocks-format-toolbar__link-modal { | ||
| z-index: 2; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
blocks/library/cover-image/index.js
Outdated
| </form> | ||
| } | ||
| { focus && | ||
| <InspectorControls key="inspector"> |
blocks/library/cover-image/index.js
Outdated
| ) : null } | ||
|
|
||
| { hasButton && | ||
| <span key="button" className="button-container aligncenter" style={ { backgroundColor: buttonBackgroundColor } } > |
blocks/library/cover-image/index.js
Outdated
| </div> | ||
| ) : null } | ||
|
|
||
| { hasButton && |
There was a problem hiding this comment.
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; | ||
|
|
||
There was a problem hiding this comment.
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:
| } | ||
|
|
||
| .button-container { | ||
| top: 100px; |
There was a problem hiding this comment.
It might be simpler to use margins here instead of relative positioning.
|
|
||
| .button-container { | ||
| top: 100px; | ||
| font-family: $default-font; |
There was a problem hiding this comment.
Why do we explicitly override the font family?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Do we need !important? Is this an issue of specificity? We should avoid !important as much as possible.
blocks/library/cover-image/index.js
Outdated
| { focusedEditable === 'button' && | ||
| <form | ||
| className="blocks-format-toolbar__link-modal" | ||
| onSubmit={ ( event ) => event.preventDefault() }> |
There was a problem hiding this comment.
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.
|
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. |
3fb89ee to
ed6c5f9
Compare
|
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. |
|
What about calling the toggle "call to action"? (cc @jasmussen @karmatosed for thoughts.) |
|
Call to action works for me @mtias. |
|
Hi @mtias, @karmatosed the toggle text was updated to "Call to action" as suggested :) |
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.
620595d to
4d227e8
Compare
|
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. |
|
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? |


Description
This PR adds an optional button to the cover image. Allowing button customization options. As specified in issue #2765.
Testing
Screenshots:
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.