-
Notifications
You must be signed in to change notification settings - Fork 0
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
[28][29][31] Width and Height block settings #39
base: main
Are you sure you want to change the base?
Conversation
Fixes an issue where editing settings.layout.contentSize in theme.json would not change the width of the block.
This was needed to fix 'Arrow function has a complexity of 12. Maximum allowed is 10' JS lint error
This reverts commit 8c657d8.
This was needed to fix 'Arrow function has a complexity of 12. Maximum allowed is 10' JS lint error
settings.layout
alignment values are being overridden settings.layout
alignment values are being overridden
settings.layout
alignment values are being overridden 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.
Hey @PaulREnglish thanks for the work on this, I've left a couple of changes below on this please.
I've also consolidated the dependent PRs description/testing steps into this one and closed 38 as these will be easier to review and test them together with code overlapping and being dependent on each other.
1) These changes will generate the below PHP warnings from image-comparison/render.php
with default usage.
Warning: Undefined array key "align"
Warning: Undefined array key "containerHeight"
Warning: Undefined array key "align"
Warning: Undefined array key "containerWidth"
2) I should of been clearer in the issue here, so apologies for that.
The ResizableBox and WIDTH / HEIGHT settings panel should still be available when using Align left
, Align center
and Align right
alignment options otherwise you cannot correctly control the block when these are set.
The reference to the settings.layout values in the issue was meant to be specifically for the values you can supply to this property in theme.json
, so apologies for not being clear on that.
Again thanks for the work on this, if you need any assistance or would like to go over any of the points raised please feel free to reach out.
/** | ||
* Get the container's size. If this has not been set by | ||
* the user then we overwrite the default size of the block | ||
* with the theme's defined contentSize, if it exists. | ||
* | ||
* @returns { | ||
* width: string | ||
* height: string | ||
* } The size containing the height and width of the block's container. | ||
*/ | ||
const getContainerSize = () => { | ||
if (attributes.align) { | ||
return { | ||
containerWidth: 'auto', | ||
containerHeight: 'auto', | ||
}; | ||
} | ||
|
||
let containerHeight = '500px'; | ||
if (attributes.containerHeight) { | ||
containerHeight = attributes.containerHeight; | ||
} | ||
|
||
let containerWidth = '500px'; | ||
if (attributes.containerWidth) { | ||
containerWidth = attributes.containerWidth; | ||
} else if (contentWidth) { | ||
containerWidth = contentWidth; | ||
} | ||
|
||
return { | ||
containerHeight, | ||
containerWidth, | ||
}; | ||
}; | ||
|
||
const { containerHeight, containerWidth } = getContainerSize(); |
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 don't think this function will be needed? If the containerHeight
and containerWidth
attributes aren't set then the block just needs to respond to it's parent element, the nullish coalescing operator (??
) might hopefully be enough to handle this?
I'm not sure where the 500px
default width and height values have come from as currently this will lead to a visual discrepancy between editor and frontend, steps to reproduce this;
- Add Image Comparison block
- Add 2 images
- Save
The block in editor will end up with the height of 500px
, if you then visit the frontend you'll see that the block is displaying as expected (height scaling with the width), are the 500px
values required?
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.
Thanks for the review! I added the 500px
values to make it backwards compatible as that was the default value used in block.json
before I changed it to null
. (See here)
I'll have a look into the visual discrepancy and see what I can do about it.
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.
Hey @PaulREnglish thanks for the explanation, I think we may be able to avoid needing to do that and should try to avoid setting any width or height pixel values until the user specifically sets them and let the original image size then respond to it's container by default.
I'm not sure of the reason they were set to default to 500px
originally as well, I may be overlooking something here though but please let me know if I can assist with anything on this 👍
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.
Will do thanks!
Description
Fixes #28, #29 & #31
Assigns the Image Comparisons
containerHeight
andcontainerWidth
values a default ofnull
. This is to avoid an issue where the block won't scale to the new width if thesettings.layout.contentSize
setting intheme.json
is changed and the user has not set a width yet.Fixes an issue where the alignment options in the block toolbar have no effect due to it being overridden by the
containerHeight
andcontainerWidth
attribute styles that are passed into theResizableBox
component. Instead, we now set thecontainerWidth
andcontainerHeight
toauto
if the alignment attribute has been set.Change Log
containerHeight
andcontainerWidth
values not specifically set the by user would not scale when thesettings.layout.contentSize
setting in theme.json would change.Steps to test
Issue #28
Issue #29
Screenshots/Videos
http://bigbite.im/v/KfN5NC (#28)
http://bigbite.im/v/3piqUx (#29)
Checklist: