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

Light quote block, introduce block HoC #22803

Closed
wants to merge 4 commits into from
Closed

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Jun 1, 2020

Description

This PR makes the quote block a light block. Since the wrapper is using another component, we also need to support this use case. I've added the block to support this, while block.Figure etc. (properties on the HoC) can still be used as a shorthand of course (instead of having to call the HoC).

Note that I've also also added capitalisation of the elements because these are actually components. I've left the lowercase properties, we don't have to be strict about it.

How has this been tested?

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.

@github-actions
Copy link

github-actions bot commented Jun 1, 2020

Size Change: -339 B (0%)

Total Size: 1.12 MB

Filename Size Change
build/block-editor/index.js 106 kB -122 B (0%)
build/block-library/index.js 126 kB +21 B (0%)
build/components/index.js 193 kB -238 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.62 kB 0 B
build/api-fetch/index.js 3.4 kB 0 B
build/autop/index.js 2.83 kB 0 B
build/blob/index.js 620 B 0 B
build/block-directory/index.js 6.75 kB 0 B
build/block-directory/style-rtl.css 892 B 0 B
build/block-directory/style.css 892 B 0 B
build/block-editor/style-rtl.css 11.4 kB 0 B
build/block-editor/style.css 11.4 kB 0 B
build/block-library/editor-rtl.css 7.87 kB 0 B
build/block-library/editor.css 7.88 kB 0 B
build/block-library/style-rtl.css 7.72 kB 0 B
build/block-library/style.css 7.72 kB 0 B
build/block-library/theme-rtl.css 684 B 0 B
build/block-library/theme.css 686 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/components/style-rtl.css 19.5 kB 0 B
build/components/style.css 19.5 kB 0 B
build/compose/index.js 9.31 kB 0 B
build/core-data/index.js 11.4 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.47 kB 0 B
build/deprecated/index.js 771 B 0 B
build/dom-ready/index.js 568 B 0 B
build/dom/index.js 3.17 kB 0 B
build/edit-navigation/index.js 8.25 kB 0 B
build/edit-navigation/style-rtl.css 918 B 0 B
build/edit-navigation/style.css 919 B 0 B
build/edit-post/index.js 302 kB 0 B
build/edit-post/style-rtl.css 5.43 kB 0 B
build/edit-post/style.css 5.43 kB 0 B
build/edit-site/index.js 15 kB 0 B
build/edit-site/style-rtl.css 2.96 kB 0 B
build/edit-site/style.css 2.96 kB 0 B
build/edit-widgets/index.js 8.83 kB 0 B
build/edit-widgets/style-rtl.css 2.4 kB 0 B
build/edit-widgets/style.css 2.4 kB 0 B
build/editor/editor-styles-rtl.css 425 B 0 B
build/editor/editor-styles.css 428 B 0 B
build/editor/index.js 44.7 kB 0 B
build/editor/style-rtl.css 4.26 kB 0 B
build/editor/style.css 4.27 kB 0 B
build/element/index.js 4.65 kB 0 B
build/escape-html/index.js 733 B 0 B
build/format-library/index.js 7.72 kB 0 B
build/format-library/style-rtl.css 502 B 0 B
build/format-library/style.css 502 B 0 B
build/hooks/index.js 2.13 kB 0 B
build/html-entities/index.js 621 B 0 B
build/i18n/index.js 3.56 kB 0 B
build/is-shallow-equal/index.js 711 B 0 B
build/keyboard-shortcuts/index.js 2.52 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 226 B 0 B
build/list-reusable-blocks/style.css 226 B 0 B
build/media-utils/index.js 5.3 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 616 B 0 B
build/nux/style.css 613 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.5 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 14.8 kB 0 B
build/server-side-render/index.js 2.68 kB 0 B
build/shortcode/index.js 1.7 kB 0 B
build/token-list/index.js 1.28 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.14 kB 0 B
build/wordcount/index.js 1.17 kB 0 B

compressed-size-action

@ZebulanStanphill ZebulanStanphill added the [Block] Quote Affects the Quote Block label Jun 1, 2020
@ellatrix ellatrix changed the title Light quote block, introduce withBlockWrapper Light quote block, introduce block HoC Jun 1, 2020
@ZebulanStanphill ZebulanStanphill added [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement. labels Jun 1, 2020
@@ -183,31 +183,31 @@ function BlockListBlock( {
<>
{ blockEdit }
{ mode === 'html' && (
<Block.div __unstableIsHtml>
<block.Div __unstableIsHtml>
Copy link
Member Author

Choose a reason for hiding this comment

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

As noted in the PR description, the Div is actually the component, not block.

Copy link
Member Author

@ellatrix ellatrix Jun 1, 2020

Choose a reason for hiding this comment

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

And block.Div is shorthand for block( 'div' ) (which otherwise must be added on a separate line outside the component).

export const Block = ExtendedBlockComponent;
ELEMENTS.forEach( ( element ) => {
const ElementBlock = block( element );
block[ element ] = ElementBlock;
Copy link
Member

Choose a reason for hiding this comment

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

Should we deprecate the lowercase shortcuts? If so, we should probably add a comment here about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since it's experimental, we could just remove it, but I suspect it might be used by plugins by now so I'm hesitant to remove it since it's just one line.

Copy link
Member

@ZebulanStanphill ZebulanStanphill Jun 1, 2020

Choose a reason for hiding this comment

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

Personally, I think it's confusing to allow both, so we should at least deprecate the lowercase versions, even if we never remove them.

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, that's true!

@ZebulanStanphill
Copy link
Member

This change causes some weirdness on Twenty Twenty due to its editor styles that were compensating for the "heavy" block wrapper:
image

Side note: this is also a good example of the fragility of the auto-margin-everything approach to handling block "alignment". Anything that overrides the horizontal margins on the outer wrapper of a block will cause issues like this. The negative-margins-for-wide-and-full-width-blocks approach, although feeling somewhat hacky (and running into problems with scrollbar widths and vw unit calculations), doesn't have this problem.

@youknowriad
Copy link
Contributor

I feel the light block wrapper usage is becoming too complex and we need to take a step back and consider what APIs we want to offer. Also related to the discussion we had a few weeks ago with @aduth and others on #core-editor

I think the conclusion was that our preferred API would be:

<Block as={ Component } />

and on situations where we need a component instead of an element (RichText, InnerBlocks) we'd do

const BlockDiv = block( 'div' ); // like this PR proposes

and then on the render function

<RichText tagName={ BlockDiv } />

So, just two APIs. I think ideally we avoid the shortcuts Block.* or block.* to save both some bytes and limit the API surface.


Another related thing is that we have some components that use as prop and others that use tagName, it feels like we should unify across our code base (while mainting fallbacks for BC). Seems like as is a bit nicer, what do you all think?

@ellatrix
Copy link
Member Author

ellatrix commented Jun 2, 2020

@youknowriad Ok, then I think I'd prefer a single block HoC API. The as prop is nice but not possible to use in all cases.

@ellatrix
Copy link
Member Author

ellatrix commented Jun 2, 2020

Ideally, I wanted it be a hook useBlock( ref ), but that's not possible yet. :) We'll need to wait for some refactoring inside the block.

@ellatrix
Copy link
Member Author

ellatrix commented Jun 5, 2020

I'm still a bit torn about custom block components and a HoC. This will mean that the block author will need to handle merging props such as event handlers, classes and styles. If something goes wrong here, it could result in the block not working correctly.

@youknowriad
Copy link
Contributor

This will mean that the block author will need to handle merging props such as event handlers, classes and styles. If something goes wrong here, it could result in the block not working correctly.

I agree that it's not great and ideally it's the opposite direction: "CustomComponent renders <Block as />

but I still see a value of the HoC to avoid having Block.* shortcut for RichText and InnerBlocks. ex: BlockDiv = block( 'div' )

@ellatrix
Copy link
Member Author

ellatrix commented Jun 5, 2020

@youknowriad We cannot have <Block as={ Component }> because animated doesn't support it passing components like that, only strings. animated can either be a HoC or used as animated.*, which is what I'm mirroring here.

I agree that we shouldn't add extra complexity though. I've removed the elements array in favour of mirroring it from animated.

If we want as, we'll have to request it upstream, and in that case I've rather request for it to be built-in in useSpring. I don't see a reason why the animation cannot be fully done as a hook if it's provided with the reference.

For now though, we seem to be limited by either a Component with a HoC or predefinitions for tagNames.

@ellatrix
Copy link
Member Author

ellatrix commented Jun 5, 2020

If we weren't blocked by use-spring rendering a component, we could have a super simple API useBlock( ref ) that adds event listeners and attributes.

@ZebulanStanphill
Copy link
Member

Yeah, it sounds to me like we need to request a solution from react-spring. I see @ellatrix has already opened an issue for it: pmndrs/react-spring#1042

@ZebulanStanphill
Copy link
Member

...Aaaand I just finished reading the issue and see you already found a solution: #22936. (Probably should have done that before posting my previous comment. 😛)

@ellatrix
Copy link
Member Author

Closing in favour of #23034.

@ellatrix ellatrix closed this Jun 12, 2020
@ellatrix ellatrix deleted the try/light-quote branch June 12, 2020 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Quote Affects the Quote Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants