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

Added button (call to action) to cover image using nesting #5232

Closed

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Feb 23, 2018

Description

This PR adds a toggle that allows to easily nest a button inside the cover image block.
This PR also introduces the concept of "managedNesting", when a block declares support for this feature the block is responsible to have to UI to manage nestings inside it (in the cover image that is done using a toggle). So in nested the blocks, we don't allow insert /block appender, and the remove of nested blocks. The block is responsible for having the UI to do that.

The CSS of the cover image had to refactored, we now use flex-direction column and this changed the way we align elements, there including existing ones.

I'm totally open to discussing alternatives approach to this nesting concept if other ideas appear we can change the managedNesting concept.

How Has This Been Tested?

Add a cover image. Use the text alignment verify it still works as expected ( the CSS had to be refactored).
Use the "Call to action" toggle to add a button verify you can use the button block without problems including the alignment/color options. Save the post and see it looks as expected.
Open a post saved with a button inside a cover image and verify it works as expected.

Closes: #2765

Screenshots (jpeg or gifs if applicable):

screen shot 2018-02-25 at 12 57 09

screen shot 2018-02-25 at 12 56 55

screen shot 2018-02-25 at 12 56 37

screen shot 2018-02-25 at 12 52 51

screen shot 2018-02-25 at 12 47 14

@jorgefilipecosta jorgefilipecosta added [Type] Enhancement A suggestion for improvement. [Feature] Blocks Overall functionality of blocks labels Feb 23, 2018
@jorgefilipecosta jorgefilipecosta self-assigned this Feb 23, 2018
@jorgefilipecosta jorgefilipecosta force-pushed the update/add-button-cover-image-nesting branch 4 times, most recently from bbb14d2 to 647eb0d Compare February 25, 2018 13:33
@jorgefilipecosta jorgefilipecosta changed the title In progress- Update/add button (call to action) cover image using nesting Added button (call to action) cover image using nesting Feb 26, 2018
@jorgefilipecosta jorgefilipecosta requested a review from a team February 27, 2018 20:37
jest.mock(
'@wordpress/data',
() => ( {
withSelect() {
Copy link
Member

Choose a reason for hiding this comment

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

This might become hard to maintain. I hope we will find a better way to mock all those HOCs that would work in other cases, too. Latest posts block is another example, where we might have a similar issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I totally agree this may become a problem. I think an option would be for the very used HOCs like withSelect to create a testing util that allows simple predefined mocks, to their behavior.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it makes sense what you said. We need to observe it and performed some refactoring as soon as it becomes hard to maintain 👍

@jasmussen
Copy link
Contributor

Not necessary for this PR, but realized that we aren't limiting the amount of characters you can input. Should we?

screen shot 2018-02-28 at 11 57 03

When I enable the Call To Action toggle, the button that gets inserted is very wide when empty:

screen shot 2018-02-28 at 11 58 31

Possibly something with flex and the faux placeholder state we add.

I'm seeing an odd issue with the alignments toolbar getting duplicated if I click first the cover image, then the button, then the cover image again:

dupilcatealigns

On a meta level, this seems like the right approach for how to use nesting inside the cover image block. Like the idea of limiting the amount of characters, limiting what types of blocks you can insert inside the cover image makes sense too.

@jorgefilipecosta jorgefilipecosta changed the title Added button (call to action) cover image using nesting Added button (call to action) to cover image using nesting Feb 28, 2018
@jorgefilipecosta jorgefilipecosta force-pushed the update/add-button-cover-image-nesting branch from 647eb0d to 6c3c353 Compare February 28, 2018 11:35
@jorgefilipecosta
Copy link
Member Author

jorgefilipecosta commented Feb 28, 2018

Thank you for your review @jasmussen.

When I enable the Call To Action toggle, the button that gets inserted is very wide when empty:

This problem was fixed, sorry I've missed the commit of one stashed CSS rule that made this behaviour correct.

I'm seeing an odd issue with the alignments toolbar getting duplicated if I click first the cover image, then the button, then the cover image again:

Nice finding, this seems like an existing problem that affects all nesting. To replicate it in the columns we can add a column, at the start it was no items in the toolbar, then we can add an image inside the column and focus it. We see the toolbar of the image, then if we focus the column in the column toolbar we see all the items of the image toolbar:
image
I will debug this to find a solution.

@karmatosed
Copy link
Member

karmatosed commented Feb 28, 2018

Not necessary for this PR, but realized that we aren't limiting the amount of characters you can input. Should we?

If it breaks the design, yes we should.

This is a highly popular visual request and awesome to see it being implemented. My comments align with @jasmussen's. I do think we should test this across devices though when a little more polished.

@jorgefilipecosta
Copy link
Member Author

jorgefilipecosta commented Feb 28, 2018

Not necessary for this PR, but realized that we aren't limiting the amount of characters you can input. Should we?

Even before the addition of the button, we could break the cover image design if the heading text we added was huge, unfortunately, we can not solve it by limiting the number of characters.
image
In this case, the number of characters is low but because of the new lines, the design gets wrong (1 becomes invisible and we start typing outside cover image. The height of the container is dependent on number characters, new lines, and the font used/formatting e.g: bold gets more height.
I fear this also happens in other cases in other blocks.
Maybe for this case, we can add max height for the heading and it would make things better?

@jasmussen
Copy link
Contributor

Maybe for this case, we can add max height for the heading and it would make things better?

Probably best we ticket this separatel and explore solutions, so we don't put the whole burden on this PR.

But we could look at making it so you can't use linebreaks. Further improvements could be exploring a character limit.

GoDaddy's site builder does this:

godaddy

const toggleParallax = () => setAttributes( { hasParallax: ! hasParallax } );
const setDimRatio = ( ratio ) => setAttributes( { dimRatio: ratio } );
edit: withSelect( ( select, ownProps ) => ( {
hasCallAction: !! select( 'core/editor' ).getBlocks( ownProps.id ).length,
Copy link
Member

Choose a reason for hiding this comment

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

getBlocks can be an expensive operation since it requires transforming the blocks into its object form, including inner blocks and meta attributes. In this case getBlockOrder would be much cheaper, or even getBlockCount if all you're trying to do is see if there exists an inner block.

@phpbits
Copy link
Contributor

phpbits commented Mar 3, 2018

Wow! Been waiting for this. Any chance you can make it Title, description and buttons? Thanks!

@jorgefilipecosta
Copy link
Member Author

Hi @phpbits, PR #5452 proposes a different approach that should allow that.
I'm closing this PR as we will try to follow the other approach.

@phpbits
Copy link
Contributor

phpbits commented Mar 7, 2018

@jorgefilipecosta awesome news :) Thanks!

@aduth aduth deleted the update/add-button-cover-image-nesting branch January 25, 2019 21:38
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 [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants