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

Inspector: Bootstrapping the block inspector API (Slot & Fill) #1050

Merged
merged 4 commits into from
Jun 9, 2017

Conversation

youknowriad
Copy link
Contributor

Closes #672

  • In this PR, I'm bootstraping the block inspector API.
  • It works in the exact same way as the Controls API. We have a "Insepector.Controls" slot that can be filled inside the edit function of the blocks using the InspectorControls wrapper.
  • We'll probably provide a bunch of inspector controls, in this PR I'm creating the TextControl.
  • As an example, I'm adding the image "alt" control to the inspector.

Once this merged, we'll have to create separate issues to implement the inspector for each block.

@youknowriad youknowriad added the [Feature] Blocks Overall functionality of blocks label Jun 7, 2017
@youknowriad youknowriad added this to the Beta milestone Jun 7, 2017
@youknowriad youknowriad self-assigned this Jun 7, 2017
@youknowriad youknowriad requested review from mtias, jasmussen and aduth June 7, 2017 10:11
@jasmussen
Copy link
Contributor

Nice!

There doesn't seem to be a lot to see there yet, except when selecting the image block. I'm assuming this is intended!

Can we have the name of the block in the breadcrumb trail?

I.e. Post → Image instead of Post → Block?

screen shot 2017-06-07 at 12 34 58

Also, question: if we should decide that the inspector works best as a modal that you open from a button on the quick toolbar, as opposed to overlaying the sidebar, would this be a difficult change from this approach?

@youknowriad
Copy link
Contributor Author

Right! there's not much to see here aside the image block.

Also, question: if we should decide that the inspector works best as a modal that you open from a button on the quick toolbar, as opposed to overlaying the sidebar, would this be a difficult change from this approach?

Yep, I expect this API to stay close to what we have in this PR. The wrapper InspectorControls may change a bit, but its content (the controls) not that much.

And the header should show the block title now

@mtias mtias removed this from the Beta milestone Jun 7, 2017
@jasmussen
Copy link
Contributor

Stellar! ✨

@youknowriad youknowriad force-pushed the add/block-inspector-api branch from 2177227 to dad3a1e Compare June 8, 2017 10:56
@youknowriad
Copy link
Contributor Author

@aduth do you have some thoughts on this?

render() {
const { label, value, onChange } = this.props;
const id = 'inspector-text-control-' + this.instanceId;
const updateValue = ( event ) => onChange( event.target.value );
Copy link
Member

Choose a reason for hiding this comment

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

I'm sympathetic to the jsx-no-bind rule's reasoning despite finding it to be far too restricting at times. At least when we already have a component class, I think it might be reasonable to prefer creating callbacks as bound instance members.

isActive: ( { align } ) => 'right' === align,
onClick: toggleAlignment( 'right' ),
},
{
icon: 'align-wide',
title: wp.i18n.__( 'Wide width' ),
icon: 'align-width',
Copy link
Member

Choose a reason for hiding this comment

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

This broke the icon 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shame on me


const inspector = focus && (
<InspectorControls key="inspector">
<TextControl label={ __( 'Alternate Text' ) } value={ alt } onChange={ updateAlt } />
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if there might be a pattern we can create here for making it easier to bind the attribute and change handlers, something like what LinkedStateMixin (deprecated) was meant to provide.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm afraid if we come up with something like that, it would add a new thing to understand.


if ( ! url ) {
const uploadButtonProps = { isLarge: true };
const setMediaURL = ( media ) => setAttributes( { url: media.url } );
return (
return [
inspector,
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 be showing inspector options (Alt Text) when the image is a placeholder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Aha! Interesting.

Probably not — we need to think about what shows on the frontend. And if you actually publish an image placeholder (forget to fill it out), I'm assuming you'll see nothing. But if we've offered you to fill out the alt text of a placeholder, feels like there's an implicit expectation that you should see something. So I do agree, probably we shouldn't show anything but the basic alignments for placeholders.

@youknowriad
Copy link
Contributor Author

Merging this soon if no concerns.

@youknowriad youknowriad merged commit 6dea0df into master Jun 9, 2017
@youknowriad youknowriad deleted the add/block-inspector-api branch June 9, 2017 15:02
@ellatrix
Copy link
Member

For me this completely broke the block inspector. I don't see anything for text blocks for example.

@youknowriad
Copy link
Contributor Author

@iseulde This is intended, the text block didn't declare any inspector control yet, we only have a control for image blocks right now.

@mtias
Copy link
Member

mtias commented Jun 11, 2017

This also took me by surprise. :)

If the goal is to still duplicate controls (alignment, formatting) we should render some placeholder so that it doesn't look entirely broken. If we don't want to do this in general, we should not show the inspector sidebar at all for blocks that don't register controls there.

@youknowriad
Copy link
Contributor Author

@mtias Could be a solution to hide the inspector entirely for blocks without inspector controls, but I didn't want to go too fast here because we may introduce generic inspector controls for all blocks (I'm thinking ID or class control for all blocks for example)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants