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

Full Height Alignment Toolbar: Implementation + Cover integration. #26615

Merged
merged 16 commits into from
Nov 23, 2020

Conversation

retrofox
Copy link
Contributor

@retrofox retrofox commented Oct 30, 2020

Description

This PR adds the Full Height Toolbar Alignment component to the block editor package, as well as its implementation to Media & Text and Cover blocks.

I did my first attempt to achieve this a long time ago in this PR. Although I couldn't finish it, it was very good to get feedback. I collected all ideas and implemented a solution (mostly a suggestion actually) to try to tackle all requirements. Spoiler Alter: Alignments never was for beginners.

Fixes #16385

Previous PRs #16738 #19767

Approach

Unlike the block alignment options, Full Height Alignment can be thought of as an independent alignment type. It can be applied independently of other alignments, but also, it works very very well together with these block alignment options, where the combination empowers the design-layout capability.

The buttons disposition in the toolbar could be something like the following:

image

Above, it shows the toolbar alignment options next to the full height alignment option.

Note: I did the icon, 100% opened to change it

Integrating with Cover block

The Cover block is a lovely case to see in action because this block also has implemented the min-height control. So the goal here is integrating this control with the Full Height Alignment. I'd like to say it was my idea, but it wasn't. Thanks, @mtias

In the following example, the block has full width, full height, content position left bottom and fixed background.

Screen Shot 2020-11-04 at 7 13 10 PM

The result is very nice:

full-height-cover-7

Full Height Alignment and Dimensions control.

I've connected both components to be consistent in the way that it applies the height to the cover block. In this case, Full Height Aligents acts just as a shorthand to apply height to 100vh. You can at any time change or those values, and the button gets "untoggled" once that happens. In fact, It doesn't add any new attribute to the block.

From Button to Control From Control to Button
full-height-cover-10 full-height-cover-11

How has this been tested?

  • Apply these changes
  • Play with the components

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

@retrofox retrofox added [Type] Enhancement A suggestion for improvement. Needs Design Feedback Needs general design feedback. [Block] Cover Affects the Cover Block - used to display content laid over a background image labels Oct 30, 2020
@github-actions
Copy link

github-actions bot commented Oct 30, 2020

Size Change: +334 B (0%)

Total Size: 1.2 MB

Filename Size Change
build/block-editor/index.js 133 kB +194 B (0%)
build/block-library/index.js 148 kB +140 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.8 kB 0 B
build/api-fetch/index.js 3.42 kB 0 B
build/autop/index.js 2.83 kB 0 B
build/blob/index.js 665 B 0 B
build/block-directory/index.js 8.72 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/style-rtl.css 11.3 kB 0 B
build/block-editor/style.css 11.3 kB 0 B
build/block-library/editor-rtl.css 8.96 kB 0 B
build/block-library/editor.css 8.96 kB 0 B
build/block-library/style-rtl.css 8.23 kB 0 B
build/block-library/style.css 8.23 kB 0 B
build/block-library/theme-rtl.css 792 B 0 B
build/block-library/theme.css 793 B 0 B
build/block-serialization-default-parser/index.js 1.87 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/blocks/index.js 48.1 kB 0 B
build/components/index.js 172 kB 0 B
build/components/style-rtl.css 15.3 kB 0 B
build/components/style.css 15.3 kB 0 B
build/compose/index.js 9.93 kB 0 B
build/core-data/index.js 14.8 kB 0 B
build/data-controls/index.js 827 B 0 B
build/data/index.js 9.71 kB 0 B
build/date/index.js 11.2 kB 0 B
build/deprecated/index.js 769 B 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.92 kB 0 B
build/edit-navigation/index.js 11.2 kB 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.45 kB 0 B
build/edit-post/style.css 6.44 kB 0 B
build/edit-site/index.js 23.5 kB 0 B
build/edit-site/style-rtl.css 3.86 kB 0 B
build/edit-site/style.css 3.86 kB 0 B
build/edit-widgets/index.js 26.4 kB 0 B
build/edit-widgets/style-rtl.css 3.13 kB 0 B
build/edit-widgets/style.css 3.13 kB 0 B
build/editor/editor-styles-rtl.css 476 B 0 B
build/editor/editor-styles.css 478 B 0 B
build/editor/index.js 43.3 kB 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.85 kB 0 B
build/element/index.js 4.62 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 6.86 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.16 kB 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 698 B 0 B
build/keyboard-shortcuts/index.js 2.85 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.1 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.31 kB 0 B
build/notices/index.js 1.82 kB 0 B
build/nux/index.js 3.42 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 790 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/reusable-blocks/index.js 3.07 kB 0 B
build/rich-text/index.js 13.4 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.69 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.05 kB 0 B
build/viewport/index.js 1.86 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

@retrofox retrofox force-pushed the update/add-full-height-alignment-toolbar branch from 44c8e93 to 066ad89 Compare October 30, 2020 23:00
@jasmussen
Copy link
Contributor

Thank you for working on this. This is what I see:

full

Since we last discussed this feature, I've had a chance to think a bit more about how it might behave. Specifically, we might want to have the toolbar button for just a few blocks, but instead of applying a classname (is-full-height-aligned), we might want to simply set an inline style, like you can with Cover:

cover

The reason being that height is a little different from width in a web that is mostly a vertical flow of content. For width, it might make sense to have specific width presets (and indeed allow these on all block, #25973), which could look like this in the sidebar:

Screenshot 2020-11-02 at 09 25 19

But height should probably remain flexible and fluid, and have an input field. It could probably still have a toolbar button, like this PR adds, but it should only be applied to a few blocks. But the design is a bit tricky. Here's an attempt at a better icon:

5

SVG:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M5 9h1.5V6.5H9V5H5v4zm1.5 6H5v4h4v-1.5H6.5V15zM15 5v1.5h2.5V9H19V5h-4zm2.5 12.5H15V19h4v-4h-1.5v2.5z" fill-rule="evenodd" clip-rule="evenodd" fill="#1e1e1e"/></svg>

I know the removal of the classname is a bit of a change from the initial discussions. I'd be curious for thoughts by @jameskoster, @ItsJonQ and @mtias

@jameskoster
Copy link
Contributor

Having a toolbar button to quickly set the height to 100vh seems like a handy shortcut, but I would agree it's probably best restricted to just a few blocks.

It may be something to discuss in another issue, but I find the alignment icons themselves quite tricky to understand, particularly wide and full width. If we're going to add an icon for full height, I wonder if we might revisit and attempt to find consistency across all these alignment icons?

@retrofox
Copy link
Contributor Author

retrofox commented Nov 2, 2020

Thanks, @jasmussen for your review

Thank you for working on this. This is what I see:

Sorry, do you see something wrong there? Just in case, the full height is applied to the block, not to the image component.

1 2 3
image image image

If you'd like to stretch full height, you should enable Crop image to fill entire column. This is an expected behavior, correct?

Specifically, we might want to have the toolbar button for just a few blocks...

This PR adds Full Height only to Media & Text and Cover blocks.

..., but instead of applying a classname (is-full-height-aligned), we might want to simply set an inline style, like you can with Cover:

Sounds good to me. Going to work on this.

For width, it might make sense to have specific width presets (and indeed allow these on all block, #25973), which could look like this in the sidebar:

Looks great to me. Just let's keep in mind that I think it worths refactoring the current implementation before starting to iterate over this since if I'm not wrong, this component is defined in the core/cover component. We should expose it to make it easily usable.

But height should probably remain flexible and fluid, and have an input field.

👍

It could probably still have a toolbar button, like this PR adds, but it should only be applied to a few blocks.

It's added to only two blocks :-D

But the design is a bit tricky. Here's an attempt at a better icon:

Excellent.

@retrofox
Copy link
Contributor Author

retrofox commented Nov 2, 2020

Thanks, James.

Having a toolbar button to quickly set the height to 100vh seems like a handy shortcut, but I would agree it's probably best restricted to just a few blocks.

Yes, agree :-D

It may be something to discuss in another issue, but I find the alignment icons themselves quite tricky to understand, particularly wide and full width. If we're going to add an icon for full height, I wonder if we might revisit and attempt to find consistency across all these alignment icons?

The reason why I've put it in a different section of the toolbar is that the most powerful feature of this ( seemingly simple) alignment is the combination with other alignment types.

Just FYI, we've discussed a lot in the previous PR.

@jasmussen
Copy link
Contributor

@jameskoster

It may be something to discuss in another issue, but I find the alignment icons themselves quite tricky to understand, particularly wide and full width. If we're going to add an icon for full height, I wonder if we might revisit and attempt to find consistency across all these alignment icons?

Absolutely. I was having the same thought notably with the Media & Text toolbar, which becomes very abstract with the black bar icons.

Sorry, do you see something wrong there? Just in case, the full height is applied to the block, not to the image component.

No no, the feature is working fine! The GIF was perhaps misleading because the image was too low resolution to fill the vertical height.

Looks great to me. Just let's keep in mind that I think it worths refactoring the current implementation before starting to iterate over this since if I'm not wrong, this component is defined in the core/cover component. We should expose it to make it easily usable.

Yes indeed. For starters, though, I think the approach to agree on is whether we should remove the full-height classname and replace it with an inline style. I think that could be a good first step to unifying the dimensions.

@retrofox
Copy link
Contributor Author

retrofox commented Nov 2, 2020

Yes indeed. For starters, though, I think the approach to agree on is whether we should remove the full-height classname and replace it with an inline style. I think that could be a good first step to unifying the dimensions.

It already applies the height using inline styles in the cover block. I was thinking if we could remove the Media & Text part, and iterate in another follow-up PR for this block.

@retrofox
Copy link
Contributor Author

retrofox commented Nov 2, 2020

Updated icon here e73765c

before after
image image

@retrofox
Copy link
Contributor Author

retrofox commented Nov 2, 2020

Since we last discussed this feature, I've had a chance to think a bit more about how it might behave. Specifically, we might want to have the toolbar button for just a few blocks, but instead of applying a classname (is-full-height-aligned), we might want to simply set an inline style, like you can with Cover:

Just to be clear, it applies inline style right now in this PR :-D. I've written a section about this in the PR description.

@jasmussen
Copy link
Contributor

Just to be clear, it applies inline style right now in this PR :-D. I've written a section about this in the PR description.

Thank you for the clarification, definitely worth looking closely at the bottom of your PR description 🙈 — I blame this week being unusually exhausting.

What I'm saying though, is that we need to not have the CSS class at all:

Screenshot 2020-11-02 at 15 05 36

The way I see it, this should only be two controls:

  • A height input field with optional vh unit
  • A toolbar toggle

Those two could/should play together as you do now, insofar as if the height is set to 100vh, the button is toggled. Is that possible to do?

@retrofox
Copy link
Contributor Author

retrofox commented Nov 2, 2020

What I'm saying though, is that we need to not have the CSS class at all:

Let me clean the Media & Text part, for now, from this PR. I'd like to keep working with the cover because this block has the min-height unit control implemented. We need to be consistent between both components.

Just to be clear, it applies inline style right now in this PR :-D. I've written a section about this in the PR description.

Thank you for the clarification, definitely worth looking closely at the bottom of your PR description 🙈 — I blame this week being unusually exhausting.

:-) No worries.

What I'm saying though, is that we need to not have the CSS class at all:

Screenshot 2020-11-02 at 15 05 36

What I'm saying though, is that we need to not have the CSS class at all:

Let me clean the Media & Text part (it handles the heigh via CSS class), for now, from this PR. I'd like to keep working with the cover because this block has the min-height unit control implemented. We need to be consistent between both components (full height and unit controls)

The way I see it, this should only be two controls:

  • A height input field with optional vh unit

Already implemented in the cover component, correct?

image

  • A toolbar toggle

Already implemented in this PR.

Those two could/should play together as you do now, insofar as if the height is set to 100vh, the button is toggled. Is that possible to do?

It is at all! and this is something that I did before but... (always there is "but") there is a minor issue here that made me add the toggle in the sidebar (I tried to explain it in the PR too 😅)

It worths mentioning that at least for the cover block and in this implementation, the full height alignment is slightly different than just applying min-height: 100vh, basically because we want to guarantee the block doesn't stretch more than the screen. In behind, it also applies height: 100vh :smart:

does it make sense of this concern for you?

@retrofox
Copy link
Contributor Author

retrofox commented Nov 2, 2020

  • A height input field with optional vh unit

Keep in mind that unit control applies min-height to the cover, instead of height.

image

Just saying because this small difference could be an issue if we aren't totally aware.

@jasmussen
Copy link
Contributor

Yep, that's a good differentiation, thank you for the clarification. It does seem like we'll only ever want one field for height, if we can do with it, whether that's min-height or plain height. I think I understand the problem, and I also think I need to give my brain a rest to think more about it 😅

The difficult part here is getting the interface right!

@retrofox
Copy link
Contributor Author

retrofox commented Nov 2, 2020

In terms of functionality, if we don't apply hight to the block, it will stretch if the content forces it.

Screen Shot 2020-11-02 at 12 39 36 PM

Applying height to the block, it will try to keep this value to 100vh, independently of its content. In other words, it will follow the viewport height (green arrow). If we apply min-height: 100vh, the block height will stretch wrapping the content (pink).

@retrofox
Copy link
Contributor Author

retrofox commented Nov 2, 2020

Toggle 100vh by clicking on Full Height toolbar button

full-height-cover-10

Toggle active state of Full Height toolbar button, setting the min-height from block sidebar.

full-height-cover-11

@retrofox
Copy link
Contributor Author

retrofox commented Nov 2, 2020

The way I see it, this should only be two controls:

  • A height input field with optional vh unit
  • A toolbar toggle

Those two could/should play together as you do now, insofar as if the height is set to 100vh, the button is toggled. Is that possible to do?

Addressed here, and also added some gifs here.

@jasmussen
Copy link
Contributor

This is getting there:

current state

I would say the user experience is now very close:

  • The fullscreen button is a shortcut to set 100vh in the sidebar
  • You can at any time change or those values, and the button gets "untoggled" once that happens

Markup also looks good:

Screenshot 2020-11-03 at 10 09 18

This is growing on me, but because it touches both the cover block and the min-height values, this needs a little sanity checking. Here are a few that have worked on related properties: @sirreal @nosolosw @jorgefilipecosta — thanks for checking!

Visually, I would like to see a small change to the toolbar as it looks here:

Screenshot 2020-11-03 at 10 08 11

Can we do this instead:

Screenshot 2020-11-03 at 10 08 11

That is — the fullscreen button feels like it belongs with the other alignments.

@retrofox retrofox force-pushed the update/add-full-height-alignment-toolbar branch from f0b85e1 to 0c3c30e Compare November 5, 2020 14:18
@retrofox
Copy link
Contributor Author

retrofox commented Nov 5, 2020

@retrofox, I've been watching this PR and excited to see it get in! ❤️

I prefer "Toggle full height" to those other options personally. "Toggle" seems to align nicely with the "Change" verb that is used for the other toolbar icons. And with "toggle" you don't need to specify the on/off state with words.

yeah... I agree honestly, but I liked to play with the dynamic label. Removed ✔️

@retrofox retrofox force-pushed the update/add-full-height-alignment-toolbar branch 2 times, most recently from 523b32f to d2cc739 Compare November 11, 2020 13:45
@retrofox retrofox changed the title Full Height Alignment Toolbar: First approach. Cover integration. Full Height Alignment Toolbar: Implementation + Cover integration. Nov 16, 2020
Copy link
Member

@jorgefilipecosta jorgefilipecosta left a comment

Choose a reason for hiding this comment

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

I left some suggestions that may simplify the code but from the functional point of view it works well 👍

packages/block-library/src/cover/edit.js Outdated Show resolved Hide resolved
@@ -264,6 +266,47 @@ function CoverEdit( {
const onSelectMedia = attributesFromMedia( setAttributes );
const isBlogUrl = isBlobURL( url );

const [ prevMinHeightValue, setPrevMinHeightValue ] = useState( minHeight );
Copy link
Member

Choose a reason for hiding this comment

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

I guess these two state values could share the same useState call the value being an object with properties minHeight and minHeightUnit that could be directly passed to set attributes. These change also aligns with probable change we will have to do make minHeightUnit and minHeight a single attribute (a string that can contain multiple CSS valid properties).

If we don't initiate the state of previous to minHeight, minHeightUnit e.g: keep them undefined and also follow the suggestion of setting the previous values inside toggleMinFullHeight we can also probably remove the need for this condition bellow "// If there aren't previous values, take the default ones.".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice suggestion. Going to refactoring using an object.

These change also aligns with probable change we will have to do make minHeightUnit and minHeight a single attribute (a string that can contain multiple CSS valid properties).

💯 agree.
I did this approach in the Background Size implementation. The data is stored in the backgroundSize attribute (string)ready to be used in the inline style. The block takes over of parsing and converting from/to this attribute to get the data usable by the UI components.

Happy to do this in a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Cover Affects the Cover Block - used to display content laid over a background image 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.

Blocks: Full Screen alignment/display option on several blocks
6 participants