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

Inserter: Preview saved block on hover #4246

Merged
merged 6 commits into from
Feb 7, 2018
Merged

Conversation

youknowriad
Copy link
Contributor

closes #4106

This PR tries to show a preview of the block to be inserted at the bottom of the inserter menu.
Ideas to improve the design are welcome.

I believe we could introduce a sampleAttributes property for blocks to make this preview more compelling using the sample attributes.

Maybe we could consider dropping the margins between the blocks in the inserter to avoid the flickering effect when moving from a block to another.

screen shot 2018-01-03 at 13 58 50

@youknowriad youknowriad added the Needs Design Feedback Needs general design feedback. label Jan 3, 2018
@youknowriad youknowriad self-assigned this Jan 3, 2018
@youknowriad youknowriad requested review from mtias and jasmussen January 3, 2018 13:00
@mtias
Copy link
Member

mtias commented Jan 3, 2018

I believe we could introduce a sampleAttributes property for blocks to make this preview more compelling using the sample attributes.

My thought was an example property, modelled in a way that could be supplied to testing as well.

@@ -56,6 +64,8 @@ export default class InserterGroup extends Component {
ref={ bindReferenceNode( block.name ) }
tabIndex={ current === block.name || disabled ? null : '-1' }
disabled={ disabled }
onMouseEnter={ this.hoverBlock( ( block ) ) }
Copy link
Member

Choose a reason for hiding this comment

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

Redundant inner parentheses?

@@ -39,6 +39,14 @@ export default class InserterGroup extends Component {
}
}

hoverBlock( block ) {
Copy link
Member

Choose a reason for hiding this comment

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

The function name doesn't seem entirely accurate. This is not the hover handler itself; it creates a hover handler. Maybe: createToggleBlockHover ?

Also: Maybe it's worthwhile to check this.props.onHover before returning anything here? That way, we could e.g. return null; and avoid creating new function references (i.e. forcing React to reconcile changing function handlers).

@@ -1,3 +1,7 @@
$content-height: 250px;
Copy link
Member

Choose a reason for hiding this comment

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

My understanding is these assigned variables are global to all stylesheets, and this seems like it might be a common name. Maybe worth prefixing to act as namespace if we want the variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point

example: {
content: `
<?php
echo "Beep Beeb Boop";
Copy link
Member

Choose a reason for hiding this comment

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

🤖

Copy link
Member

Choose a reason for hiding this comment

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

Personally I'd find this reasonable to inline in the sense that even stylistically this is something I'd have on one line:

example: {
	content: '<?php echo "Beep Beep Boop"; ?>',
},

Copy link
Member

Choose a reason for hiding this comment

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

Typo: "Beeb" -> "Beep"

@youknowriad youknowriad force-pushed the try/block-preview branch 2 times, most recently from 3919ca3 to f444541 Compare January 4, 2018 09:11
@youknowriad
Copy link
Contributor Author

I added the example API and tried it for the "code" block only.

  • Can I have some thoughts for this PR? Do you think I should remove the "margin" from the inserter items to avoid the flickering?

  • What else can I do to polish this?

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

The placement below the inserter doesn't work particularly well when the inserter opens downward (i.e. for new posts), where I'm seeing the preview clipping the bottom of the viewport and unable to be scrolled.

Clipping

@@ -32,6 +32,10 @@ registerBlockType( 'core/code', {
},
},

example: {
content: '<?php echo "Beep Beep Boop";?>',
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Minor: PHP Guidelines recommend single quotes:

If you’re not evaluating anything in the string, use single quotes.

https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#single-and-double-quotes

@@ -0,0 +1,39 @@
/**
* External dependencie
Copy link
Member

Choose a reason for hiding this comment

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

Typo: "dependencie" -> "dependencies"

@mtias
Copy link
Member

mtias commented Jan 10, 2018

@jasmussen @youknowriad I think this might need a few more iterations, what do you think of enabling only for "saved blocks" initially? That provides immediate value and requires less consideration of dummy data since saved blocks, by their nature, don't need it.

@jasmussen
Copy link
Contributor

I think it's fine to start small and test. 👍 👍

@youknowriad
Copy link
Contributor Author

Should I remove the "example" API for now?

@mtias
Copy link
Member

mtias commented Jan 10, 2018

Should I remove the "example" API for now?

I don't mind retaining it but not documented.

@youknowriad
Copy link
Contributor Author

youknowriad commented Jan 12, 2018

I updated this, it's now limited to the reusable blocks and I also updated the design of the inserter "blocks" by removing the margin in favor of a padding to avoid the flickering when we move the mouse between saved blocks.

@youknowriad
Copy link
Contributor Author

Can I have a final review here?

@jasmussen
Copy link
Contributor

I think visually this looks pretty good. But I'm getting a few errors on hover:

screen shot 2018-01-15 at 10 30 33

screen shot 2018-01-15 at 10 30 30

@youknowriad
Copy link
Contributor Author

@jasmussen I'm not able to reproduce the error. Do you know what kind of reusable block produces this error?

@jasmussen
Copy link
Contributor

I just left the office, I may not be able to reproduce at home, but it's an old installation with lots of reusable blocks created across different versions. I'm the same session I noticed a reusable block in the recent tab that was actually deleted.

@mtias
Copy link
Member

mtias commented Jan 15, 2018

I was reliably reproducing this as well.

@aduth
Copy link
Member

aduth commented Jan 16, 2018

Was the issue I noted in #4246 (review) addressed ?

The placement below the inserter doesn't work particularly well when the inserter opens downward (i.e. for new posts), where I'm seeing the preview clipping the bottom of the viewport and unable to be scrolled.

@youknowriad
Copy link
Contributor Author

@aduth The issue was not handled but not sure what can we do about it? Any ideas? Should we show the preview on the right of the inserter instead? cc @jasmussen

@jasmussen
Copy link
Contributor

The effect of the preview when the inserter opens upwards is a blinking effect where you hover over a saved block and the preview kicks in moving the hovered block upwards, and then it goes for a loop.

Can we just show the preview above the inserter, instead of below it, when the inserter opens upwards?

@youknowriad
Copy link
Contributor Author

@jasmussen That's another issue, we probably can do what you suggest but it doesn't solve the "scrolling" issue if there's not enough space.

@jasmussen
Copy link
Contributor

Ah, understood.

How about we solve this in two phases. For now, we decide that this is a desktop only enhancement, with no preview on mobile — hover doesn't work too well there anyway. And given that, we show the preview on the right instead of above or below. We can also make it smaller.

@youknowriad
Copy link
Contributor Author

Ok, I moved the preview to the right, I think it's better.

@youknowriad youknowriad force-pushed the try/block-preview branch 2 times, most recently from 2f68d7e to 67b89c8 Compare January 19, 2018 13:57
@mtias
Copy link
Member

mtias commented Jan 26, 2018

I've been able to break it by creating a paragraph block, saving as reusable, selecting it on the editor canvas, then opening the inserter and hovering over it. The editor crashes with:

TypeError: Cannot read property 'getBoundingClientRect' of null at Editable.getFocusPosition (http://localhost/wp-content/plugins/gutenberg/blocks/build/index.js?ver=1516926147:3023:38)

Should be easy to reproduce.

@youknowriad
Copy link
Contributor Author

Good catch @mtias this commit e977dc4 should fix the issue. We were hardcoding selectors that do not exist in all contexts.

@youknowriad
Copy link
Contributor Author

This should be ready for a final review.

@jasmussen
Copy link
Contributor

I dig it!
screen shot 2018-01-31 at 14 00 14

👍 👍 from me, visually

@mtias
Copy link
Member

mtias commented Jan 31, 2018

@jasmussen I was seeing a few inconsistencies in the visual display of fonts, etc, that I think we should address. Might be worth applying default styles to a generic .wp-block selector and making sure we use that on the preview panel.

@jasmussen
Copy link
Contributor

On which previewed blocks did you see these issues?

@jasmussen
Copy link
Contributor

I see what you mean:

screen shot 2018-02-01 at 09 17 48

I pushed a little polish:

screen shot 2018-02-01 at 09 36 18

screen shot 2018-02-01 at 09 36 23

screen shot 2018-02-01 at 09 36 28

screen shot 2018-02-01 at 09 36 31

screen shot 2018-02-01 at 09 36 38

Not necessary for this PR, or perhaps at all, but this seems like an ideal use case for shadow dom.

@youknowriad
Copy link
Contributor Author

@jasmussen Unfortunately, we can't use shadow dom because it doesn't work on Firefox and can't be polyfilled properly.

@jasmussen
Copy link
Contributor

Unfortunately, we can't use shadow dom because it doesn't work on Firefox and can't be polyfilled properly.

(ノಠ益ಠ)ノ彡┻━┻

No worries, it was mostly a case of "it would be nice" :)

@gziolo
Copy link
Member

gziolo commented Feb 1, 2018

It will look amazing as soon as we add example property to all blocks 🥇

@youknowriad
Copy link
Contributor Author

I'm thinking we can merge this right?

@mtias
Copy link
Member

mtias commented Feb 7, 2018

@jasmussen we can use a class like .wp-block to assign the fonts, default sizes, etc, in the first place. Instead of relying on the general cascade.

@youknowriad youknowriad merged commit d744a97 into master Feb 7, 2018
@youknowriad youknowriad deleted the try/block-preview branch February 7, 2018 13:57
@youknowriad youknowriad changed the title Inserter: Preview block on hover Inserter: Preview saved block on hover Feb 7, 2018
@youknowriad
Copy link
Contributor Author

I wonder if .wp-block is not the generated className of the reusable block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Design Feedback Needs general design feedback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider showing block preview when hovering block in inserter
5 participants