-
Notifications
You must be signed in to change notification settings - Fork 808
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
[Experiment] Blocks: Add a new shared Button block #15370
Conversation
Thank you for the great PR description! When this PR is ready for review, please apply the Scheduled Jetpack release: May 5, 2020. |
I've tried this with the Eventbrite block in #15377.
cc @mtias that might have some answers! |
Ok! I think I've addressed 2 out of 3 issues!
|
Before | After | |
---|---|---|
Click on Button | ||
Click outside Button |
This is not a perfect solution, but it definitely feels better.
We could add some vertical margin to make sure that there's always at least some clickable area for the parent block, but I don't have any strong opinions about it.
@Copons I implemented this in my contact form block updates in #15362 I select the parent block in the child block here: Then check for differences between the child block attribute value, and the parent block attribute value: This works, but I'm sure there is a better way, it might give you some ideas though. |
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __experimentalUseGradient as useGradient } from '@wordpress/block-editor'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Should this be capitalized? UseGradient
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't: useGradient
is a hook, like useEffect
.
Thanks @apeatling, that's really interesting! I'm playing around that example, and it's indeed of great value. Example (based roughly on Eventbrite)Eventbrite has an // Parent block
<InnerBlocks template={ [ [
'jetpack/button',
{
passthroughAttributes: {
uniqueId: 'eventId', // { buttonAttribute: 'parentAttribute' }
},
}
] ] } /> // Button block
withSelect( ( select, { attributes, clientId } ) => {
const { passthroughAttributes } = attributes;
// { uniqueId: 'eventId' }
const { getBlockAttributes, getBlockHierarchyRootClientId } = select( 'core/block-editor' );
const parentAttributes = getBlockAttributes( getBlockHierarchyRootClientId( clientId ) );
const mappedAttributes = mapValues( passthroughAttributes, key => parentAttributes[ key ] );
// { uniqueId: 123456 } (actual parent's `eventId` value)
// Discard all equals attributes
const attributesToSync = pickBy( mappedAttributes, ( value, key ) => value !== attributes[ key ] );
return { attributesToSync };
} )( ButtonEdit );
function ButtonEdit( { attributesToSync, setAttributes } ) {
useEffect( () => {
if ( ! isEmpty( attributesToSync ) ) {
setAttributes( attributesToSync );
}
}, [ setAttributes, attributesToSync ] );
} |
bd15da3
to
9cd3feb
Compare
@Automattic/explorers I think this is already way too big to handle. There are two clear outstanding tasks, but we should take care of them in follow ups:
This is not currently urgent, but reviews are appreciated nonetheless! 🙇♂️ |
This is looking good. The only thing I noticed was that the button display in the front end and the editor looks off, but this isn't just a problem with this block, I see it with buttons in all our blocks: This might be an issue with my Jetpack/Gutenberg setup. Edit: I just updated my Gutenberg install and this fixed itself! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good, lets merge and iterate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I enter a custom text for the button content, it does not appear on the frontend.
For some reason, this makes me lose all blocks in the editor in WordPress 5.3.2. Anyone else can reproduce?
extensions/blocks/button/index.js
Outdated
export const settings = { | ||
title: __( 'Button', 'jetpack' ), | ||
icon, | ||
category: supportsCollections() ? 'grow' : 'jetpack', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be in formatting
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this block doesn't show up in the inserter, this doesn't matter much.
Though, I've updated this to layout
, which is the Core Button category.
keywords: [], | ||
supports: { | ||
html: false, | ||
inserter: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL. Fancy.
Fixed, it was an incorrect
I'm testing with Also, I've pushed a fix for the Revue example, adding the inner blocks definition in there as well. |
@Copons Sorry I wasn't meaning to imply that you should do it. 😀 I wanted to make sure that's an option for when this is merged that I can implement. Totally agree no more should go into this PR, I can always open a followup PR after. 👍 |
textColor, | ||
} ) { | ||
const ButtonContrastChecker = ( | ||
<ContrastChecker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only seems to show when the colors are hovered. Once I move the mouse away it disappears...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. One small issue that I think we can fix in a follow up PR...
Caution: This PR has changes that must be merged to WordPress.com |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped | ||
if ( false !== strpos( $content, 'wp-block-jetpack-revue__fallback' ) ) { | ||
echo $content; | ||
} else { | ||
echo get_deprecated_v1_revue_button( $attributes ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think you could add a comment to explain what's going on here? It took me a minute to understand where that class was coming from.
r206525-wpcom |
Found a fix for this in #15597 |
r206618-wpcom (removing a file missed by r206525-wpcom) |
Alternative approach to #14920
See #14935
Changes proposed in this Pull Request:
In #14920 I've tried creating a Button component, complete with utility functions, ready to be used inside existing blocks, replacing our many re-implementations of the Core's Button block.
Watching some WPBlockTalk talks and talking with @apeatling made me rethink this approach, and try with
InnerBlocks
, which would have many UX improvements over the Button components.Unfortunately, we still can't use the Core's Button as-is. Our use cases are different, and we need different features, and more flexibility.
Some features of this new
jetpack/button
block:a
,input type="submit"
,button type"submit"
. (If saved in post content, it's forced asa
because otherwise the WPCOM KSES would strip it).Before committing to this approach, we should see if it actually works for all blocks currently using buttons.
Examples: #15377
Note for @Automattic/explorers
Most of this PR is copypasted from #14920.
Namely, the Button block files is pretty much
===
the Button component from the other PR, but with adjusted attribute names (buttonTextColor
becomestextColor
as it's clear that it refers to the button now).The big differences are in how it's used by Revue.
This PR is slightly larger because changing from component to inner block makes the deprecation/migration a bit more verbose (especially in the PHP side).
Minor note: there's currently no fill/outline style variations. We can easily add them in a second moment if we want (and we do: Eventbrite uses them!)
Testing instructions:
Proposed changelog entry for your changes: