Skip to content

Commit

Permalink
Fix: Guards for missing configs (fixes #195) (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverfoster authored Jun 10, 2024
1 parent 182b229 commit fb59fe5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions js/BoxMenuView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ class BoxMenuView extends MenuView {

className() {
const backgroundImages = this.model.get('_boxMenu')?._backgroundImage;
const backgroundImage = backgroundImages[`_${device.screenSize}`] ?? backgroundImages._small;
const backgroundImage = backgroundImages?.[`_${device.screenSize}`] ?? backgroundImages?._small;
const textAlignment = this.model.get('_boxMenu')?._menuHeader?._textAlignment;

return [
`${super.className()} boxmenu`,
backgroundImage && 'has-bg-image',
textAlignment._title && `title-align-${textAlignment._title}`,
textAlignment._body && `body-align-${textAlignment._body}`,
textAlignment._instruction && `instruction-align-${textAlignment._instruction}`
textAlignment?._title && `title-align-${textAlignment._title}`,
textAlignment?._body && `body-align-${textAlignment._body}`,
textAlignment?._instruction && `instruction-align-${textAlignment._instruction}`
].join(' ');
}

Expand Down
18 changes: 9 additions & 9 deletions templates/boxMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ export default function BoxMenu (props) {

// set menu background image
const backgroundImages = _boxMenu?._backgroundImage;
const backgroundImage = backgroundImages[`_${device.screenSize}`] ?? backgroundImages._small;
const backgroundImage = backgroundImages?.[`_${device.screenSize}`] ?? backgroundImages?._small;
// set menu background styles
const styles = _boxMenu._backgroundStyles;
const styles = _boxMenu?._backgroundStyles || {};

// set header background image
const header = _boxMenu?._menuHeader;
const headerBackgroundImages = header._backgroundImage;
const headerBackgroundImage = headerBackgroundImages[`_${device.screenSize}`] ?? headerBackgroundImages._small;
const headerBackgroundImages = header?._backgroundImage;
const headerBackgroundImage = headerBackgroundImages?.[`_${device.screenSize}`] ?? headerBackgroundImages?._small;
// set header background styles
const headerBackgroundStyles = header._backgroundStyles;
const headerBackgroundStyles = header?._backgroundStyles || {};
// set header minimum height
const headerMinimumHeights = header._minimumHeights;
const headerMinimumHeight = headerMinimumHeights[`_${device.screenSize}`] ?? headerMinimumHeights._small;
const headerMinimumHeights = header?._minimumHeights;
const headerMinimumHeight = headerMinimumHeights?.[`_${device.screenSize}`] ?? headerMinimumHeights?._small;

return (
<>
Expand All @@ -40,7 +40,7 @@ export default function BoxMenu (props) {
className="background"
aria-hidden="true"
style={{
backgroundImage: 'url(' + backgroundImage + ')',
backgroundImage: backgroundImage && 'url(' + backgroundImage + ')',
backgroundRepeat: styles._backgroundRepeat,
backgroundSize: styles._backgroundSize,
backgroundPosition: styles._backgroundPosition
Expand All @@ -66,7 +66,7 @@ export default function BoxMenu (props) {
className="background"
aria-hidden="true"
style={{
backgroundImage: 'url(' + headerBackgroundImage + ')',
backgroundImage: headerBackgroundImage && 'url(' + headerBackgroundImage + ')',
backgroundRepeat: headerBackgroundStyles._backgroundRepeat,
backgroundSize: headerBackgroundStyles._backgroundSize,
backgroundPosition: headerBackgroundStyles._backgroundPosition
Expand Down

0 comments on commit fb59fe5

Please sign in to comment.