Skip to content

Commit

Permalink
add useScreenHeight prop
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanMiu committed Jul 23, 2024
1 parent 0798660 commit a261a59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/Blocks/Maps/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const MapsSchema = (props) => {
{
id: 'default',
title: 'Default',
fields: ['url', 'title', 'align', 'height'],
fields: ['url', 'title', 'align', 'height', 'useScreenHeight'],
},
],

Expand Down Expand Up @@ -63,6 +63,11 @@ export const MapsSchema = (props) => {
),
description: props.intl.formatMessage(messages.CSSMapHeightDescription),
},
useScreenHeight: {
title: 'Use screen height',
type: 'boolean',
default: false,
},
},
required: [],
};
Expand Down
9 changes: 5 additions & 4 deletions src/EmbedMap/EmbedMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ const messages = defineMessages({
},
});

function getHeight(height, screen) {
function getHeight(data, screen) {
const { height, useScreenHeight } = data;
const asNumber = isNumber(Number(height)) && !isNaN(Number(height));
if (asNumber) {
return `${height}px`;
}
return height || (screen ? screen.page.height - 50 : 400);
return height || (useScreenHeight && screen ? screen.page.height - 50 : 400);
}

function EmbedMap({ data, intl, id, screen }) {
Expand Down Expand Up @@ -78,7 +79,7 @@ function EmbedMap({ data, intl, id, screen }) {
<PrivacyProtection
data={data}
id={id}
height={getHeight(data.height, screen)}
height={getHeight(data, screen)}
useVisibilitySensor={data.useVisibilitySensor ?? true}
>
<iframe
Expand All @@ -88,7 +89,7 @@ function EmbedMap({ data, intl, id, screen }) {
className="google-map"
frameBorder="0"
allowFullScreen
style={{ height: getHeight(data.height, screen) }}
style={{ height: getHeight(data, screen) }}
/>
</PrivacyProtection>
</div>
Expand Down

0 comments on commit a261a59

Please sign in to comment.