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

[28][29][31] Width and Height block settings #39

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions inc/blocks/image-comparison/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@
},
"containerHeight": {
"type": "string",
"default": "500px"
"default": "auto"
},
"containerWidth": {
"type": "string",
"default": "500px"
"default": "auto"
}
},
"supports": {
Expand Down
30 changes: 21 additions & 9 deletions src/blocks/image-comparison/components/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
const [contentWidth] = useSettings('layout.contentSize');

const {
align,
overflow,
dividerInitialPosition,
dividerAxis,
Expand Down Expand Up @@ -72,20 +73,31 @@ const Edit = ({ attributes, setAttributes, clientId }) => {
}
}, [contentWidth]);

useEffect(() => {
if (['wide', 'full'].includes(align)) {
setAttributes({
containerHeight: 'auto',
containerWidth: 'auto',
});
}
}, [align, setAttributes]);

/**
* Retrieve the inner blocks
*/
const [{ innerBlocks }] = wp.data.select('core/block-editor').getBlocksByClientId(clientId);

/**
* Determine whether to allow the resize handles to be
* displayed based on if an image is assigned or not
*/
innerBlocks.forEach((block) => {
if (block?.attributes?.id) {
shouldDisplayResize = true;
}
});
if (!['wide', 'full'].includes(align)) {
/**
* Determine whether to allow the resize handles to be
* displayed based on if an image is assigned or not
*/
innerBlocks.forEach((block) => {
if (block?.attributes?.id) {
shouldDisplayResize = true;
}
});
}

/**
* Only ever display the right, bottom, and bottomRight handles
Expand Down