Skip to content

Commit 504d994

Browse files
committed
Mobile inline styles support
1 parent 1b860ac commit 504d994

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

__tests__/shared/components/Contentful/Image/__snapshots__/Image.jsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`Matches shallow shapshot 1`] = `
44
<div
55
id="image-1"
6+
style={Object {}}
67
>
78
<InlineSVG
89
baseURL=""

__tests__/shared/components/Contentful/MemberCard/__snapshots__/MemberCard.jsx.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Matches shallow shapshot 1`] = `
4-
<a>
4+
<a
5+
style={Object {}}
6+
>
57
<div>
68
<div
79
style={

src/shared/utils/contentful.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import { removeTrailingSlash } from 'utils/url';
99
* @return {Object}
1010
*/
1111
export function fixStyle(style) {
12-
return style ? _.mapKeys(style, (value, key) => _.camelCase(key)) : undefined;
12+
const props = _.omitBy(style, !_.isObject);
13+
const mediaQueries = _.pickBy(
14+
style,
15+
(propVal, mQuery) => _.isObject(propVal) && window.matchMedia(mQuery).matches,
16+
);
17+
const merged = _.merge(props, ..._.values(mediaQueries));
18+
return merged ? _.mapKeys(merged, (value, key) => _.camelCase(key)) : undefined;
1319
}
1420

1521
// Concatenates a base and segment and handles optional trailing slashes

0 commit comments

Comments
 (0)