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

Cover: Video - Add position controls #22531

Merged
merged 38 commits into from
Jul 15, 2020

Conversation

ItsJonQ
Copy link

@ItsJonQ ItsJonQ commented May 21, 2020

focal-demo

This update adds positioning controls for video backgrounds within the Cover block. Previous to this image, the positioning controls (powered by the FocalPointPicker component) were available only to image backgrounds.

✨ New Features

Click to reposition

The position values can be updated by clicking anywhere in the preview area.

Keyboard arrow key support

Screen Capture on 2020-05-21 at 14-53-25

Up, Down, Left, Right keyboard keys will adjust the position values.

Hold Shift to jump by 10

Holding Shift will jump the values, rounded to the nearest 10. This works for boht dragging and keyboard arrow inputs.

New InputControls

The top and left values use a new NumberControl component. This component includes many features, such as dragging to update, jumping values by holding Shift, and automatic number rounding.

Grid

A 9x9 grid appears anytime a value is updated by any interaction (drag, click, etc...)

🛠 Fixes

  • Enable <FocalPointPicker /> to reset values based on undo actions in the editor.

How has this been tested?

This has been tested locally in Storybook and local Gutenberg.

To test...

  • Pull down the branch
  • Run npm install
  • Run npm run dev to fire up local Gutenberg
  • Add a Cover block
  • Add a video background (Here's a sample video to download)
  • Adjust the position
  • Ensure it works in the editor and on the front-end of the site

Types of changes

  • Add video preview support to FocalPointPicker
  • Substantial refactors to FocalPointPicker
  • Adds Flex component to @wordpress/components as a layout-based primitive
  • Update Cover video position rendering in edit.js and save.js

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.

Resolves: #22509

@ItsJonQ ItsJonQ added [Type] Enhancement A suggestion for improvement. [Package] Components /packages/components [Block] Cover Affects the Cover Block - used to display content laid over a background image [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi labels May 21, 2020
@ItsJonQ ItsJonQ requested a review from mtias May 21, 2020 19:05
@ItsJonQ ItsJonQ self-assigned this May 21, 2020
* Internal dependencies
*/
import { color } from '../../utils/style-mixins';

Copy link
Author

Choose a reason for hiding this comment

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

Migrated and improved styles from the previous styles.scss file.

@github-actions
Copy link

github-actions bot commented May 21, 2020

Size Change: +1.41 kB (0%)

Total Size: 1.14 MB

Filename Size Change
build/block-directory/index.js 7.68 kB +1 B
build/block-editor/index.js 115 kB +1 B
build/block-library/index.js 132 kB +90 B (0%)
build/components/index.js 201 kB +1.76 kB (0%)
build/components/style-rtl.css 15.6 kB -223 B (1%)
build/components/style.css 15.6 kB -218 B (1%)
build/edit-post/index.js 304 kB +1 B
build/edit-site/index.js 16.8 kB -1 B
build/edit-widgets/index.js 9.35 kB +1 B
build/format-library/index.js 7.72 kB -1 B
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.67 kB 0 B
build/api-fetch/index.js 3.39 kB 0 B
build/autop/index.js 2.82 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/style-rtl.css 944 B 0 B
build/block-directory/style.css 945 B 0 B
build/block-editor/style-rtl.css 10.8 kB 0 B
build/block-editor/style.css 10.8 kB 0 B
build/block-library/editor-rtl.css 7.6 kB 0 B
build/block-library/editor.css 7.59 kB 0 B
build/block-library/style-rtl.css 7.77 kB 0 B
build/block-library/style.css 7.77 kB 0 B
build/block-library/theme-rtl.css 728 B 0 B
build/block-library/theme.css 729 B 0 B
build/block-serialization-default-parser/index.js 1.88 kB 0 B
build/block-serialization-spec-parser/index.js 3.1 kB 0 B
build/blocks/index.js 48.2 kB 0 B
build/compose/index.js 9.67 kB 0 B
build/core-data/index.js 11.5 kB 0 B
build/data-controls/index.js 1.29 kB 0 B
build/data/index.js 8.46 kB 0 B
build/date/index.js 5.38 kB 0 B
build/deprecated/index.js 772 B 0 B
build/dom-ready/index.js 569 B 0 B
build/dom/index.js 3.23 kB 0 B
build/edit-navigation/index.js 10.8 kB 0 B
build/edit-navigation/style-rtl.css 1.08 kB 0 B
build/edit-navigation/style.css 1.08 kB 0 B
build/edit-post/style-rtl.css 5.6 kB 0 B
build/edit-post/style.css 5.6 kB 0 B
build/edit-site/style-rtl.css 3.04 kB 0 B
build/edit-site/style.css 3.04 kB 0 B
build/edit-widgets/style-rtl.css 2.45 kB 0 B
build/edit-widgets/style.css 2.45 kB 0 B
build/editor/editor-styles-rtl.css 537 B 0 B
build/editor/editor-styles.css 539 B 0 B
build/editor/index.js 45.1 kB 0 B
build/editor/style-rtl.css 3.78 kB 0 B
build/editor/style.css 3.78 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 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.13 kB 0 B
build/html-entities/index.js 622 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 709 B 0 B
build/keyboard-shortcuts/index.js 2.51 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.12 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.32 kB 0 B
build/notices/index.js 1.79 kB 0 B
build/nux/index.js 3.4 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.4 kB 0 B
build/priority-queue/index.js 789 B 0 B
build/redux-routine/index.js 2.85 kB 0 B
build/rich-text/index.js 13.9 kB 0 B
build/server-side-render/index.js 2.71 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.06 kB 0 B
build/viewport/index.js 1.85 kB 0 B
build/warning/index.js 1.13 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@ItsJonQ
Copy link
Author

ItsJonQ commented May 22, 2020

@jasmussen Provided a design suggestion in the issue. Will attempt it now 🙌

@ItsJonQ
Copy link
Author

ItsJonQ commented May 22, 2020

@jasmussen We have "side" label alignments for Inputs :D

Screen Shot 2020-05-22 at 1 35 08 PM

Note! This is done at the InputControl component level. That means that we can more easily side-align labels in the future in a consistent manner (if we choose to)

@ItsJonQ
Copy link
Author

ItsJonQ commented May 22, 2020

@jasmussen Based on your mockup, do you think we should remove the extra padding around the media (when possible)?

Screen Shot 2020-05-22 at 1 38 00 PM

Doing so would change the height of the preview. We could set min/max values to ensure it doesn't get too wonky.

It comes down to... do we want the preview to have a consistent height (currently 200px) or not 😊

Would love your thoughts!

@ItsJonQ
Copy link
Author

ItsJonQ commented Jun 9, 2020

@jasmussen Amazing! Thank you <3

@ItsJonQ
Copy link
Author

ItsJonQ commented Jun 10, 2020

Update! Re: Code Review

I intentionally left the FocalPointPicker component as a class component for this PR. There have been many changes. I think converting it to a functional component on top of it will make it harder to review.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

That component is still a monster :) but It's a nicer monster with these focused subcomponents.

packages/block-library/src/cover/edit.js Outdated Show resolved Hide resolved
packages/block-library/src/cover/save.js Outdated Show resolved Hide resolved
export default function FocalPoint( {
coordinates = { left: '50%', top: '50%' },
isDragging = false,
...props
Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed you do that often (spread extra props) and I'm having trouble figuring out why or whether I consider this a good or bad practice. Are these needed? I know I personally try to avoid them if possible as they can lead to react warnings and can be hard to follow.

Copy link
Author

Choose a reason for hiding this comment

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

For component libraries, prop spreading is common and often the default. The reason is because the consumer should be able to use HTML approved properties (like aria-* or data-*) just like they would on any HTML element. Not only that, but on* event callbacks should be available as well.

A (mostly) reliable solution for handling React warnings is that inner components often have prop filtering built in. In the case of components created with @emotion/styled, they filter out non React/HTML props before passing it down to elements like <div />, <input />, etc...

Copy link
Contributor

Choose a reason for hiding this comment

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

For component libraries, prop spreading is common and often the default. The reason is because the consumer should be able to use HTML approved properties (like aria-* or data-) just like they would on any HTML element. Not only that, but on event callbacks should be available as well.

When I use FocalPointPicker as a user, I don't know its internals whether it's a div, a button, or just a string... which makes me think, I don't know what HTML prop are approved. This also makes it harder to be compatible with mobile. A block doing < FocalPointPicker some-dom-specific-prop="something" /> won't translate properly to mobile.

It makes me wonder if we should try to move away from these iteratively.

packages/components/src/focal-point-picker/grid.js Outdated Show resolved Hide resolved
packages/components/src/focal-point-picker/index.js Outdated Show resolved Hide resolved
Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

This is looking very good 👍

@ItsJonQ
Copy link
Author

ItsJonQ commented Jul 15, 2020

@youknowriad Thank you for reviewing this @youknowriad + @jasmussen ! I'll merge it up 🙌

@ItsJonQ ItsJonQ merged commit ff313a7 into master Jul 15, 2020
@ItsJonQ ItsJonQ deleted the try/cover-video-background-focal-points branch July 15, 2020 17:59
@github-actions github-actions bot added this to the Gutenberg 8.6 milestone Jul 15, 2020
@youknowriad
Copy link
Contributor

Looks like this PR might have introduced a JavaScript unit test error on master 😬

@ItsJonQ
Copy link
Author

ItsJonQ commented Jul 15, 2020

@youknowriad Uh oh!! Will look into that now

@ItsJonQ
Copy link
Author

ItsJonQ commented Jul 15, 2020

@youknowriad PR incoming with fix~!

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 [Feature] Design Tools Tools that impact the appearance of blocks both to expand the number of tools and improve the experi [Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cover: Video - Add position controls
3 participants