Skip to content

Commit

Permalink
New: Allow any component to use mobileBody for smaller devices (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
swashbuck authored May 29, 2024
1 parent 4d6f06e commit c8e4c95
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions templates/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { classes, prefixClasses, compile } from 'core/js/reactHelpers';

/**
* Content header for displayTitle, body, instruction text, etc.
* instruction and mobileInstruction will switch automatically
* body / mobileBody and instruction / mobileInstruction will switch automatically
* @param {Object} props
* @param {string} [props.displayTitle]
* @param {string} [props.body]
* @param {string} [props.instruction]
* @param {string} [props.mobileBody]
* @param {string} [props.mobileInstruction]
* @param {string} [props._type]
* @param {string} [props._component]
Expand All @@ -22,6 +23,7 @@ export default function Header(props) {
displayTitle,
body,
instruction,
mobileBody,
mobileInstruction,
_type,
_component,
Expand All @@ -33,6 +35,9 @@ export default function Header(props) {
_extension && _extension.toLowerCase()
].filter(Boolean)
} = props;
const sizedBody = (mobileBody && !device.isScreenSizeMin('medium')) ?
mobileBody :
body;
const sizedInstruction = (mobileInstruction && !device.isScreenSizeMin('medium')) ?
mobileInstruction :
instruction;
Expand Down Expand Up @@ -69,9 +74,9 @@ export default function Header(props) {
</div>
}

{body &&
{sizedBody &&
<div className={prefixClasses(classNamePrefixes, ['__body'])}>
<div className={prefixClasses(classNamePrefixes, ['__body-inner'])} dangerouslySetInnerHTML={{ __html: compile(body, props) }}>
<div className={prefixClasses(classNamePrefixes, ['__body-inner'])} dangerouslySetInnerHTML={{ __html: compile(sizedBody, props) }}>
</div>
</div>
}
Expand Down
4 changes: 2 additions & 2 deletions templates/partials/component.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

{{component_description}}

{{#if body}}
{{#any body mobileBody}}
<div class="component__body {{lowercase _component}}__body">
<div class="component__body-inner {{lowercase _component}}__body-inner">
{{{compile body}}}
</div>
</div>
{{/if}}
{{/any}}

{{#any instruction mobileInstruction}}
<div class="component__instruction {{lowercase _component}}__instruction">
Expand Down

0 comments on commit c8e4c95

Please sign in to comment.