Skip to content

Commit c8e4c95

Browse files
authored
New: Allow any component to use mobileBody for smaller devices (fixes #538)
1 parent 4d6f06e commit c8e4c95

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

templates/header.jsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { classes, prefixClasses, compile } from 'core/js/reactHelpers';
55

66
/**
77
* Content header for displayTitle, body, instruction text, etc.
8-
* instruction and mobileInstruction will switch automatically
8+
* body / mobileBody and instruction / mobileInstruction will switch automatically
99
* @param {Object} props
1010
* @param {string} [props.displayTitle]
1111
* @param {string} [props.body]
1212
* @param {string} [props.instruction]
13+
* @param {string} [props.mobileBody]
1314
* @param {string} [props.mobileInstruction]
1415
* @param {string} [props._type]
1516
* @param {string} [props._component]
@@ -22,6 +23,7 @@ export default function Header(props) {
2223
displayTitle,
2324
body,
2425
instruction,
26+
mobileBody,
2527
mobileInstruction,
2628
_type,
2729
_component,
@@ -33,6 +35,9 @@ export default function Header(props) {
3335
_extension && _extension.toLowerCase()
3436
].filter(Boolean)
3537
} = props;
38+
const sizedBody = (mobileBody && !device.isScreenSizeMin('medium')) ?
39+
mobileBody :
40+
body;
3641
const sizedInstruction = (mobileInstruction && !device.isScreenSizeMin('medium')) ?
3742
mobileInstruction :
3843
instruction;
@@ -69,9 +74,9 @@ export default function Header(props) {
6974
</div>
7075
}
7176

72-
{body &&
77+
{sizedBody &&
7378
<div className={prefixClasses(classNamePrefixes, ['__body'])}>
74-
<div className={prefixClasses(classNamePrefixes, ['__body-inner'])} dangerouslySetInnerHTML={{ __html: compile(body, props) }}>
79+
<div className={prefixClasses(classNamePrefixes, ['__body-inner'])} dangerouslySetInnerHTML={{ __html: compile(sizedBody, props) }}>
7580
</div>
7681
</div>
7782
}

templates/partials/component.hbs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
{{component_description}}
1515

16-
{{#if body}}
16+
{{#any body mobileBody}}
1717
<div class="component__body {{lowercase _component}}__body">
1818
<div class="component__body-inner {{lowercase _component}}__body-inner">
1919
{{{compile body}}}
2020
</div>
2121
</div>
22-
{{/if}}
22+
{{/any}}
2323

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

0 commit comments

Comments
 (0)