-
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
Implement image alignment controls #416
Conversation
Nice! Seems like we're missing a few of the niceties from the multi instance prototype. Here's a video: https://cloudup.com/cCULEOFR95p Essentially — as soon as the image is floated, the block boundaries look weird on the floated element. Also, the text block takes focus when clicking — I think we did some z-indexing to fix this in the multi instance prototype. @youknowriad do you have more info? |
This is a really hard task IMO. In the current implementation, only the block itself is aware of this attribute. This is problematic because we can not update the styling of the parent Two options here if we want to apply the styling to the container div
Edit: There's a third option (an enhancement of the first one) where we can have an optional |
blocks/library/image/index.js
Outdated
}, | ||
|
||
controls: [ | ||
{ |
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.
Is the full-bleed or whatever we call that missing?
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.
No, it's not an alignment. It's a width manipulation.
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.
But it's a control.
blocks/library/image/index.js
Outdated
@@ -6,6 +6,22 @@ import Editable from 'components/editable'; | |||
|
|||
const { attr, html } = query; | |||
|
|||
function Image( { url, alt, align } ) { |
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.
Probably useful to document here.
I'm ok merging this as a first path and exploring the improvements/solutions separately. |
2793467
to
3e50f25
Compare
I've rebased to resolve conflicts and address a few points of the feedback. Handling the float is particularly challenging, as @youknowriad highlighted earlier. Floated content in general can be difficult, but especially so in our case of trying to shield the block implementation from too much of the editor rendering details. I've tried to hack on a few ideas this afternoon on how the block alone might be able to render its contents as floated while preserving padding, margins, z-index, and border of the surrounding controls, but have struggled to come to any universal solution. We'd likely need some way for the block listing to become aware that there is floated content. @youknowriad's
None of these I'm particularly happy with. Of course, the ideal case is that through some CSS wizardry we could allow the block's content to be floated. |
Yeah, I'd say this is on about a similar level as some of the ideas in my previous comment. The issue with all of these is trying to seek a good balance where neither the block nor the block listing needs to have excessive knowledge about the other. In many of these examples, we're very much targeting alignment/floating as being a common characteristic of a block, and therefore engrain this knowledge into the block list rendering. But... I don't know that we necessarily want to make that assumption. Another couple ideas to make this generic:
|
editor/modes/visual-editor/block.js
Outdated
@@ -148,6 +167,8 @@ class VisualEditorBlock extends wp.element.Component { | |||
onMouseMove={ this.maybeHover } | |||
onMouseLeave={ onMouseLeave } | |||
className={ className } | |||
data-type={ block.blockType } | |||
{ ...getBlockAttributesAsProps( block.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.
Nice workaround :)
I think we should propose an opt-in behaviour (maybe leave it undocumented until needed) and use it in core blocks. I'm a bit concerned with the too many data-*
attributes we'll end up with.
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.
In all cases, blocks should be aware of the existence of a wrapper div, thus, I think we should move the getBlockAttributesAsProps
function to the block API. Each block could decide to add any attribute to its parent div.
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.
In all cases, blocks should be aware of the existence of a wrapper div, thus, I think we should move the
getBlockAttributesAsProps
function to the block API. Each block could decide to add any attribute to its parent div.
Yeah, I considered that, and it makes more sense now that I reflect on how the styles already make it clear that the block must be aware of the wrapper element. Your suggestion also addresses worries of computing and assigning attributes unnecessarily, dealing with complex attribute types (more accurately, not dealing with), and lends more flexibility to the block to define different / additional props to apply.
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 bounced back and forth on a few names, or whether this could somehow be integrated into the edit
function itself (via callback, or a special shaped return value including metadata).
How does getEditWrapperProps
sound to you?
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's a good name for now but could be changed later if we settle on changing the edit
name
The approach I took in 7fd79a1 is to encode block attributes as So now there's float-y goodness: |
* @param {string} align Alignment value | ||
* @return {Function} Attribute setter | ||
*/ | ||
function applyOrUnset( align ) { |
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.
Shouldn't this just be toggle? :D
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.
You're too slow @mtias *! But yeah, toggle is appropriate too.
Edit: * Re: Having been merged seconds prior.
This pull request seeks to implement alignment controls for the image block.
Implementation notes:
Image
was extracted to a top-of-file common control to more easily maintain common behaviors betweenedit
andsave
variationsalign
from theclassName
is a bit ugly with the current setup. I'm very inclined to change this to a comment-serialized attribute and support legacy class-based alignment with a compatibility layer like the one explored in Propose block APIs for backwards compatibility #413Testing instructions: