-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Block variations: Add block-supports flag to add variation specific classname #61864
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
6fe71ec
d42c4d1
1081fe4
6cd7199
608bfd6
d9036b6
4de031b
b1bd36c
3cb6023
e384ec7
5dce388
e99838e
cb9430a
b47cc1f
2bde392
1568b02
818af29
b34a14e
8515de7
2df5db7
d625240
faac58c
c8b9a6a
2b215d7
0af2def
962a5ae
173bef2
5cccab7
cff8fcc
50a0044
0d34163
aaaa855
e819f54
7cf6f8e
6ad4153
bc3fb00
a37f5d3
25f7a71
6f016b3
d369a97
7350ced
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,3 +339,33 @@ export const getLayoutSupport = ( nameOrType ) => | |
*/ | ||
export const hasStyleSupport = ( nameOrType ) => | ||
styleSupportKeys.some( ( key ) => hasBlockSupport( nameOrType, key ) ); | ||
|
||
/** | ||
* Returns true if the block defines support for block class name. | ||
* | ||
* @param {string|Object} nameOrType Block name or type object. | ||
* @return {boolean} Whether the block supports the feature. | ||
*/ | ||
export const hasBlockClassNameSupport = ( nameOrType ) => { | ||
const classNameSupport = getBlockSupport( nameOrType, 'className', true ); | ||
|
||
if ( typeof classNameSupport === 'boolean' ) { | ||
return classNameSupport; | ||
} | ||
|
||
// classNameSupport can be an object. If it doesn't have a `block` key, | ||
// we default to true. | ||
return ( | ||
! Object.hasOwn( classNameSupport, 'block' ) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be equivalent with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think so, yeah. Are you suggesting we replace it with that? 🙂 (Personally, I find it a bit easier to read if we keep it as-is: We've fetched the value of |
||
classNameSupport.block === true | ||
); | ||
}; | ||
|
||
/** | ||
* Returns true if the block defines support for variation class name. | ||
* | ||
* @param {string|Object} nameOrType Block name or type object. | ||
* @return {boolean} Whether the block supports the feature. | ||
*/ | ||
export const hasVariationClassNameSupport = ( nameOrType ) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we default to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was originally hoping to do that (and discussed it with @gziolo again today), but I've come to the conclusion that it's too much of a risk. As you mentioned elsewhere, setting this to Having to add those for any block with variations that wants to use this new feature seemed like a bit of a hassle at first, but I now think it's an okay tradeoff. It's probably worse for plugins (and authors) that include a large number of blocks -- and for Core itself -- but even then, not all blocks come with variations, and it's a one time change. IMO, it's reasonable to ask extenders to enable this feature manually (and to add a deprecation) in exchange for a useful enhancement. Since we might also need a server-side part (which will require a robust way of determining the active variation), it makes even more sense to require extenders to opt into this new feature explicitly, as it gives them control over adding this new class name, and allows them to fix their |
||
hasBlockSupport( nameOrType, 'className.variation', false ); |
Uh oh!
There was an error while loading. Please reload this page.