Skip to content

Commit

Permalink
Update screen height; Use SidebarPopup frol @plone/volto
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Mar 30, 2021
1 parent 8eaa662 commit 474e66c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
6 changes: 0 additions & 6 deletions src/SidebarPopup/SidebarPopup.jsx

This file was deleted.

4 changes: 3 additions & 1 deletion src/StyleWrapper/StyleWrapperEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const StyleWrapperEdit = (props) => {
};
}, [closeSidebar]);

return (
return selected && isVisible ? (
<SidebarPopup open={selected && isVisible}>
<InlineForm
schema={schema}
Expand All @@ -57,6 +57,8 @@ const StyleWrapperEdit = (props) => {
formData={data}
/>
</SidebarPopup>
) : (
''
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/StyleWrapper/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const StyleSchema = () => ({
},
isScreenHeight: {
title: 'Screen height',
description: 'Block height follows viewport height',
description: 'Maximize block to viewport height',
type: 'boolean',
},
backgroundImage: {
Expand Down
58 changes: 38 additions & 20 deletions src/hocs/withScreenHeight.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,51 @@ export default function withScreenHeight(WrappedComponent) {

const updateHeight = () => {
if (__CLIENT__) {
const headerWrapper = document.querySelector('.header-wrapper');
const contentArea = document.querySelector('.ui.segment.content-area');
const view = document.querySelector(
'.ui.segment.content-area #view #page-document',
const headerWrapper = document.querySelector(
'.header-wrapper:not(.mobile)',
);
let childNth = 0;
const contentArea = document.querySelector('.ui.segment.content-area');
const toolbar = document.querySelector('#toolbar .toolbar.expanded');
const firstHeading = document.querySelector('.documentFirstHeading');
// const view = document.querySelector(
// '.ui.segment.content-area #view #page-document',
// );
// let childNth = 0;

if (view) {
view.childNodes.forEach((child, index) => {
if (child === styleWrapper.current) {
childNth = index;
}
});
}
// if (view) {
// view.childNodes.forEach((child, index) => {
// if (child === styleWrapper.current) {
// childNth = index;
// }
// });
// }

const screenHeight =
window.innerHeight ||
document.documentElement.clientHeight ||
document.body.clientHeight ||
0;

const headerWrapperStyle = headerWrapper
? window.getComputedStyle(headerWrapper)
: {};
const contentAreaStyle =
contentArea && childNth < 2
contentArea && !firstHeading
? window.getComputedStyle(contentArea)
: { marginTop: '0px', paddingTop: '0px' };

const offsetHeight =
childNth < 2
? (headerWrapper?.offsetHeight || 0) +
(pixelToNumber(contentAreaStyle.marginTop) +
pixelToNumber(contentAreaStyle.paddingTop) || 0)
: 0;
(headerWrapperStyle.display !== 'none'
? headerWrapper?.offsetHeight || 0
: 0) +
(pixelToNumber(contentAreaStyle.marginTop) +
pixelToNumber(contentAreaStyle.paddingTop) || 0) +
((toolbar?.offsetHeight || 0) < screenHeight
? toolbar?.offsetHeight || 0
: 0);

setOffsetHeight(offsetHeight || 0);
setScreenHeight(window.innerHeight);
setOffsetHeight(offsetHeight);
setScreenHeight(screenHeight);
}
};

Expand Down

0 comments on commit 474e66c

Please sign in to comment.