-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Improve block settings and its methods #401
Comments
Also regarding the block settings: I've been thinking a bit about the way we're declaring controls. Currently it looks something like this: {
icon: 'editor-alignright',
title: wp.i18n.__( 'Align right' ),
isActive: ( { align } ) => 'right' === align,
onClick( attributes, setAttributes ) {
setAttributes( { align: 'right' } );
}
} Which is quite verbose. Maybe it makes sense to just specify the new attribute(s) the block needs to have when this control is clicked? To see if it's active we'd just look at the current attributes. {
icon: 'editor-alignright',
title: wp.i18n.__( 'Align right' ),
attributes: { align: 'right' }
} Any concerns? |
My first reaction was that this would only work well for the very simple cases. The more I'm looking through mockups though, the less I'm able to find cases where blocks need more granular control. One subtle nuance of this behavior worth noting is that if the attribute value is already the current value, clicking the button again effectively resets it to a default state. How do we infer what the default state would be? For text it's nothing, for an image it's explicitly the "none" alignment, for a heading it's the Also, will a control need to ever do more than toggle an attribute of a block? I guess I'd assumed yes. Perhaps something like displaying a modal which could affect the block by asynchronously a deferred call to the Maybe this syntax is still supported but effectively treated as a shorthand to the underlying equivalents achieved in the current API. Aside: I think we ought to create a separate issue for this discussion. |
Ignoring preexisting knowledge, what would one expect to be the result of calling a React component's I'm not terribly attached to the naming though. |
I've thought about this too, but are there really any buttons that need to do two different actions (toggle)? Should clicking an active button render it to the default attribute, or should there be a button for that? Looking at the mockups there seem to be explicit buttons for all of these examples. I agree though that the current methods should still be supported for more advanced controls. |
This is how alignment controls work for text and images in the current editor and I assumed would be the same here. I don't have a strong preference one way or the other. |
For an image it's nothing also, not "none". You don't want to be adding that class to all images if it wasn't there already. Empty is a valid state. |
Depends if we're talking about what the current editor does now, how we want to represent the none state in a block, or what the new editor will be expected to output.
There's also the case of how to handle images which may have been manually inserted or modified to omit the |
Since the editor has two parts, Visual and Text Mode, it is optional to use the Visual part. So that should not affect the original content. If I switch back and forth, will it mangle my content? The current editor has been known to do that. That's one of the reasons I stay out of it. |
Possibly name |
Yeah, something about the "for" feels off for me. I'm wondering if we're trying too hard to preserve conciseness. Maybe an intentionally verbose alternative could lend some clarity. A plethora of combination ideas from the top of my head:
|
LOL any combination of these would be fine (funny how that works). Maybe |
Yeah I don't think "View" has as much meaning in a React context. "Component" is not quite accurate since the return value of the function is an element, of whose type can be a component. https://facebook.github.io/react/blog/2015/12/18/react-components-elements-and-instances.html |
Clarifying this further, getEditorElement: class extends Component { The current names haven't bothered me quite as much, or at least I haven't seen a better name in the context of registering the block's settings. In hindsight, even Another idea that comes to mind is nesting variants under an object property, like registerBlockSettings( 'core/text', {
components: {
editor: function() {},
save: function() {}
}
} ); |
I quite like this :) |
Honestly, I'm finding the current the |
settings.edit
andsettings.save
, specially in how they are used in the visual editor block, is confusing to read: are these actions? Do they trigger actions? What would happen when they are called?We should be specially clear on what these are. I'd expect to call them via
block.forEditing
, perhaps. The presence of a settings object that is retrieved throughwp.blocks.getBlockSettings( block.blockType )
doesn't help, but since it is sufficiently private it might be alright. Since edit/save in their current form are descriptions of how these blocks manifest or are represented in different contexts, renaming settings to something else seems like a good thing.The text was updated successfully, but these errors were encountered: