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

Block API: consolidate the API to declare className and anchor support #2507

Closed
wants to merge 2 commits into from

Conversation

youknowriad
Copy link
Contributor

related to #2035

This exposes the current property in the blockAPI:

const block = {
   // ...
   support: {
      generatedClassname: false // automatically generate a wrapper's classname (default: true)
      className: false // allow adding a custom className using the inspector (default: true)
      anchor: true, // allow adding an anchor (default: false)
   }
};

Instead of the current className and supportAnchor.

This also splits className attribute into two generatedClassname and className. I did this because it makes sense to allow a custom classname for some blocks without generating an automattic one. For example: paragraphs, heading, lists

@youknowriad youknowriad requested a review from aduth August 23, 2017 08:37
@codecov
Copy link

codecov bot commented Aug 23, 2017

Codecov Report

Merging #2507 into master will decrease coverage by 0.11%.
The diff coverage is 42.1%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2507      +/-   ##
==========================================
- Coverage    28.7%   28.59%   -0.12%     
==========================================
  Files         167      167              
  Lines        5103     5144      +41     
  Branches      849      865      +16     
==========================================
+ Hits         1465     1471       +6     
- Misses       3086     3107      +21     
- Partials      552      566      +14
Impacted Files Coverage Δ
blocks/library/paragraph/index.js 29.16% <ø> (ø) ⬆️
blocks/library/html/index.js 23.07% <ø> (ø) ⬆️
blocks/library/shortcode/index.js 50% <ø> (ø) ⬆️
blocks/library/more/index.js 30% <ø> (ø) ⬆️
blocks/library/list/index.js 6.97% <ø> (ø) ⬆️
blocks/library/heading/index.js 23.8% <ø> (ø) ⬆️
editor/modes/visual-editor/block.js 0% <0%> (ø) ⬆️
...ditor/sidebar/block-inspector/advanced-controls.js 0% <0%> (ø) ⬆️
blocks/api/factory.js 89.65% <100%> (ø) ⬆️
blocks/api/parser.js 98.11% <100%> (ø) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4d4bf0a...09a2770. Read the comment docs.

@youknowriad youknowriad changed the title Block API: consolidate the APi to declare className and anchor support Block API: consolidate the API to declare className and anchor support Aug 23, 2017
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Can we use "supports" instead of "support" for consistency with related PHP APIs (register_post_type, register_taxonomy)

Doesn't behavior of generated class name depend on where we decide with #2035 ?

This is part of why I wanted these to be opt-in only. There's too much fragmentation (generated vs. custom vs. default class names), inconsistency (auto-application in save but not edit), and variation (defaulting to true vs. false, other value types like a default class string).

It'd be so nice if this were just:

supports: [ 'className', 'anchor' ],

Then assigning generated class name if developer decides to, not automatically.

@@ -64,20 +65,22 @@ class BlockInspectorAdvancedControls extends Component {
render() {
const { selectedBlock, post } = this.props;
const blockType = getBlockType( selectedBlock.name );
if ( false === blockType.className && ! blockType.supportAnchor ) {
const supportAnchor = blockType.support && !! blockType.support.anchor;
const supportCustomClassname = isUndefined( get( blockType, 'support.className' ) ) || blockType.support.className;
Copy link
Member

Choose a reason for hiding this comment

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

Seems like the previous implementation was simpler? false !== support.className

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does not account of undefined support value

@@ -21,7 +21,10 @@ registerBlockType( 'core/more', {

useOnce: true,

className: false,
support: {
generatedClassname: false,
Copy link
Member

@aduth aduth Aug 23, 2017

Choose a reason for hiding this comment

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

The camel-casing of className is inconsistent here (Classname vs. className). I think we ought to call this generatedClassName.

Aside: I like import classnames from 'classnames'; only because camel-casing in the case of NPM dependencies should be on the basis of dash-delimiters (i.e. classNames if it were class-names).

@youknowriad
Copy link
Contributor Author

It'd be so nice if this were just:
supports: [ 'className', 'anchor' ],
Then assigning generated class name if developer decides to, not automatically.

This is a good API indeed. I'm just trying to accomodate our current needs. @mtias wanted the classNames to stay opt-out.

And dropping the generatedClassname, I also personally agree. Once the decision is made, we shall drop the support key.

@aduth
Copy link
Member

aduth commented Aug 23, 2017

@mtias wanted the classNames to stay opt-out.

Then @mtias needs to defend his position against increasingly unintuitive block implementations it's incurred 😆

@youknowriad
Copy link
Contributor Author

At its current state, this fixes issues like #2552 should we merge it or wait until a decision has been made about the opt-in className?

@aduth
Copy link
Member

aduth commented Aug 28, 2017

For #2552, couldn't we put together a simpler pull request to remove this line?

className: false,

@youknowriad
Copy link
Contributor Author

@aduth no, because we don't want the generated className for headings

@youknowriad
Copy link
Contributor Author

Any update, decision on this? I think this is still better than what we currently have.

@aduth
Copy link
Member

aduth commented Sep 7, 2017

Still very conflicted about this. Left some related comments at #2474 (comment).

@youknowriad
Copy link
Contributor Author

@aduth I agree that it's a good opportunity to proof the extensibility patterns, I think this will change the current behaviour a bit, but probably for a better tradeoff. I'd be happy to poc on that if no one is

@youknowriad
Copy link
Contributor Author

closing this, we'll try to build this using an extensibility API

@youknowriad youknowriad deleted the update/support-block-api branch September 18, 2017 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants