@khanacademy/wonder-blocks-layout 1.4.1 → 1.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/index.js CHANGED
@@ -1,277 +1,15 @@
1
- import { createContext, createElement, Component } from 'react';
1
+ import _extends from '@babel/runtime/helpers/extends';
2
+ import { createContext, Component, createElement } from 'react';
2
3
  import Spacing from '@khanacademy/wonder-blocks-spacing';
3
4
  import { StyleSheet } from 'aphrodite';
4
5
  import { View } from '@khanacademy/wonder-blocks-core';
5
6
 
6
- function _classCallCheck(instance, Constructor) {
7
- if (!(instance instanceof Constructor)) {
8
- throw new TypeError("Cannot call a class as a function");
9
- }
10
- }
11
-
12
- function _defineProperties(target, props) {
13
- for (var i = 0; i < props.length; i++) {
14
- var descriptor = props[i];
15
- descriptor.enumerable = descriptor.enumerable || false;
16
- descriptor.configurable = true;
17
- if ("value" in descriptor) descriptor.writable = true;
18
- Object.defineProperty(target, descriptor.key, descriptor);
19
- }
20
- }
21
-
22
- function _createClass(Constructor, protoProps, staticProps) {
23
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
24
- if (staticProps) _defineProperties(Constructor, staticProps);
25
- return Constructor;
26
- }
27
-
28
- function _defineProperty(obj, key, value) {
29
- if (key in obj) {
30
- Object.defineProperty(obj, key, {
31
- value: value,
32
- enumerable: true,
33
- configurable: true,
34
- writable: true
35
- });
36
- } else {
37
- obj[key] = value;
38
- }
39
-
40
- return obj;
41
- }
42
-
43
- function _extends() {
44
- _extends = Object.assign || function (target) {
45
- for (var i = 1; i < arguments.length; i++) {
46
- var source = arguments[i];
47
-
48
- for (var key in source) {
49
- if (Object.prototype.hasOwnProperty.call(source, key)) {
50
- target[key] = source[key];
51
- }
52
- }
53
- }
54
-
55
- return target;
56
- };
57
-
58
- return _extends.apply(this, arguments);
59
- }
60
-
61
- function _inherits(subClass, superClass) {
62
- if (typeof superClass !== "function" && superClass !== null) {
63
- throw new TypeError("Super expression must either be null or a function");
64
- }
65
-
66
- subClass.prototype = Object.create(superClass && superClass.prototype, {
67
- constructor: {
68
- value: subClass,
69
- writable: true,
70
- configurable: true
71
- }
72
- });
73
- if (superClass) _setPrototypeOf(subClass, superClass);
74
- }
75
-
76
- function _getPrototypeOf(o) {
77
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
78
- return o.__proto__ || Object.getPrototypeOf(o);
79
- };
80
- return _getPrototypeOf(o);
81
- }
82
-
83
- function _setPrototypeOf(o, p) {
84
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
85
- o.__proto__ = p;
86
- return o;
87
- };
88
-
89
- return _setPrototypeOf(o, p);
90
- }
91
-
92
- function _isNativeReflectConstruct() {
93
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
94
- if (Reflect.construct.sham) return false;
95
- if (typeof Proxy === "function") return true;
96
-
97
- try {
98
- Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
99
- return true;
100
- } catch (e) {
101
- return false;
102
- }
103
- }
104
-
105
- function _assertThisInitialized(self) {
106
- if (self === void 0) {
107
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
108
- }
109
-
110
- return self;
111
- }
112
-
113
- function _possibleConstructorReturn(self, call) {
114
- if (call && (typeof call === "object" || typeof call === "function")) {
115
- return call;
116
- }
117
-
118
- return _assertThisInitialized(self);
119
- }
120
-
121
- function _createSuper(Derived) {
122
- var hasNativeReflectConstruct = _isNativeReflectConstruct();
123
-
124
- return function _createSuperInternal() {
125
- var Super = _getPrototypeOf(Derived),
126
- result;
127
-
128
- if (hasNativeReflectConstruct) {
129
- var NewTarget = _getPrototypeOf(this).constructor;
130
-
131
- result = Reflect.construct(Super, arguments, NewTarget);
132
- } else {
133
- result = Super.apply(this, arguments);
134
- }
135
-
136
- return _possibleConstructorReturn(this, result);
137
- };
138
- }
139
-
140
- function _slicedToArray(arr, i) {
141
- return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
142
- }
143
-
144
- function _toConsumableArray(arr) {
145
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
146
- }
147
-
148
- function _arrayWithoutHoles(arr) {
149
- if (Array.isArray(arr)) return _arrayLikeToArray(arr);
150
- }
151
-
152
- function _arrayWithHoles(arr) {
153
- if (Array.isArray(arr)) return arr;
154
- }
155
-
156
- function _iterableToArray(iter) {
157
- if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
158
- }
159
-
160
- function _iterableToArrayLimit(arr, i) {
161
- if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
162
- var _arr = [];
163
- var _n = true;
164
- var _d = false;
165
- var _e = undefined;
166
-
167
- try {
168
- for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
169
- _arr.push(_s.value);
170
-
171
- if (i && _arr.length === i) break;
172
- }
173
- } catch (err) {
174
- _d = true;
175
- _e = err;
176
- } finally {
177
- try {
178
- if (!_n && _i["return"] != null) _i["return"]();
179
- } finally {
180
- if (_d) throw _e;
181
- }
182
- }
183
-
184
- return _arr;
185
- }
186
-
187
- function _unsupportedIterableToArray(o, minLen) {
188
- if (!o) return;
189
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
190
- var n = Object.prototype.toString.call(o).slice(8, -1);
191
- if (n === "Object" && o.constructor) n = o.constructor.name;
192
- if (n === "Map" || n === "Set") return Array.from(o);
193
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
194
- }
195
-
196
- function _arrayLikeToArray(arr, len) {
197
- if (len == null || len > arr.length) len = arr.length;
198
-
199
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
200
-
201
- return arr2;
202
- }
203
-
204
- function _nonIterableSpread() {
205
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
206
- }
207
-
208
- function _nonIterableRest() {
209
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
210
- }
211
-
212
- function _createForOfIteratorHelper(o, allowArrayLike) {
213
- var it;
214
-
215
- if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
216
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
217
- if (it) o = it;
218
- var i = 0;
219
-
220
- var F = function () {};
221
-
222
- return {
223
- s: F,
224
- n: function () {
225
- if (i >= o.length) return {
226
- done: true
227
- };
228
- return {
229
- done: false,
230
- value: o[i++]
231
- };
232
- },
233
- e: function (e) {
234
- throw e;
235
- },
236
- f: F
237
- };
238
- }
239
-
240
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
241
- }
242
-
243
- var normalCompletion = true,
244
- didErr = false,
245
- err;
246
- return {
247
- s: function () {
248
- it = o[Symbol.iterator]();
249
- },
250
- n: function () {
251
- var step = it.next();
252
- normalCompletion = step.done;
253
- return step;
254
- },
255
- e: function (e) {
256
- didErr = true;
257
- err = e;
258
- },
259
- f: function () {
260
- try {
261
- if (!normalCompletion && it.return != null) it.return();
262
- } finally {
263
- if (didErr) throw err;
264
- }
265
- }
266
- };
267
- }
268
-
269
7
  // All possible valid media sizes
270
- var VALID_MEDIA_SIZES = ["small", "medium", "large"];
271
- var mediaDefaultSpecLargeMarginWidth = Spacing.large_24; // The default spec for media layout, currently available in
8
+ const VALID_MEDIA_SIZES = ["small", "medium", "large"];
9
+ const mediaDefaultSpecLargeMarginWidth = Spacing.large_24; // The default spec for media layout, currently available in
272
10
  // three different settings (roughly mobile, tablet, and desktop).
273
11
 
274
- var MEDIA_DEFAULT_SPEC = {
12
+ const MEDIA_DEFAULT_SPEC = {
275
13
  small: {
276
14
  query: "(max-width: 767px)",
277
15
  totalColumns: 4,
@@ -293,7 +31,7 @@ var MEDIA_DEFAULT_SPEC = {
293
31
  }
294
32
  }; // Used for internal tools
295
33
 
296
- var MEDIA_INTERNAL_SPEC = {
34
+ const MEDIA_INTERNAL_SPEC = {
297
35
  large: {
298
36
  query: "(min-width: 1px)",
299
37
  totalColumns: 12,
@@ -302,7 +40,7 @@ var MEDIA_INTERNAL_SPEC = {
302
40
  }
303
41
  }; // The default used for modals
304
42
 
305
- var MEDIA_MODAL_SPEC = {
43
+ const MEDIA_MODAL_SPEC = {
306
44
  small: {
307
45
  query: "(max-width: 767px)",
308
46
  totalColumns: 4,
@@ -317,24 +55,18 @@ var MEDIA_MODAL_SPEC = {
317
55
  }
318
56
  };
319
57
 
320
- var defaultContext = {
58
+ const defaultContext = {
321
59
  ssrSize: "large",
322
60
  mediaSpec: MEDIA_DEFAULT_SPEC
323
61
  };
324
- var MediaLayoutContext = createContext(defaultContext);
62
+ var MediaLayoutContext = /*#__PURE__*/createContext(defaultContext);
325
63
 
326
- var queries = [].concat(_toConsumableArray(Object.values(MEDIA_DEFAULT_SPEC).map(function (spec) {
327
- return spec.query;
328
- })), _toConsumableArray(Object.values(MEDIA_INTERNAL_SPEC).map(function (spec) {
329
- return spec.query;
330
- })), _toConsumableArray(Object.values(MEDIA_MODAL_SPEC).map(function (spec) {
331
- return spec.query;
332
- })));
333
- var mediaQueryLists = {}; // eslint-disable-next-line flowtype/require-exact-type
64
+ const queries = [].concat(Object.values(MEDIA_DEFAULT_SPEC).map(spec => spec.query), Object.values(MEDIA_INTERNAL_SPEC).map(spec => spec.query), Object.values(MEDIA_MODAL_SPEC).map(spec => spec.query));
65
+ const mediaQueryLists = {}; // eslint-disable-next-line flowtype/require-exact-type
334
66
 
335
67
  // If for some reason we're not able to resolve the current media size we
336
68
  // fall back to this state.
337
- var DEFAULT_SIZE = "large";
69
+ const DEFAULT_SIZE = "large";
338
70
 
339
71
  /**
340
72
  * `MediaLayout` is responsible for changing the rendering of contents at
@@ -342,267 +74,185 @@ var DEFAULT_SIZE = "large";
342
74
  * to specify different breakpoint configurations. By default it uses
343
75
  * `MEDIA_DEFAULT_SPEC`. See media-layout-context.js for additiional options.
344
76
  */
345
- var MediaLayoutInternal = /*#__PURE__*/function (_React$Component) {
346
- _inherits(MediaLayoutInternal, _React$Component);
347
-
348
- var _super = _createSuper(MediaLayoutInternal);
349
-
77
+ class MediaLayoutInternal extends Component {
350
78
  // A collection of thunks that's used to clean up event listeners
351
79
  // when the component is unmounted.
352
- function MediaLayoutInternal(props) {
353
- var _this;
354
-
355
- _classCallCheck(this, MediaLayoutInternal);
356
-
357
- _this = _super.call(this, props);
358
-
359
- _defineProperty(_assertThisInitialized(_this), "cleanupThunks", void 0);
360
-
361
- _this.state = {
80
+ constructor(props) {
81
+ super(props);
82
+ this.state = {
362
83
  size: undefined
363
84
  };
364
- _this.cleanupThunks = [];
365
- return _this;
85
+ this.cleanupThunks = [];
366
86
  }
367
87
 
368
- _createClass(MediaLayoutInternal, [{
369
- key: "componentDidMount",
370
- value: function componentDidMount() {
371
- var _this2 = this;
88
+ componentDidMount() {
89
+ // TODO(WB-534): handle changes to mediaSpec prop
90
+ const entries = Object.entries(this.props.mediaSpec);
372
91
 
373
- // TODO(WB-534): handle changes to mediaSpec prop
374
- var entries = Object.entries(this.props.mediaSpec);
92
+ for (const [size, spec] of entries) {
93
+ const mql = mediaQueryLists[spec.query]; // during SSR there are no MediaQueryLists
375
94
 
376
- var _loop = function _loop() {
377
- var _entries$_i = _slicedToArray(_entries[_i], 2),
378
- size = _entries$_i[0],
379
- spec = _entries$_i[1];
380
-
381
- var mql = mediaQueryLists[spec.query]; // during SSR there are no MediaQueryLists
95
+ if (!mql) {
96
+ continue;
97
+ }
382
98
 
383
- if (!mql) {
384
- return "continue";
99
+ const listener = e => {
100
+ if (e.matches) {
101
+ this.setState({
102
+ size
103
+ });
385
104
  }
105
+ };
386
106
 
387
- var listener = function listener(e) {
388
- if (e.matches) {
389
- _this2.setState({
390
- size: size
391
- });
392
- }
393
- };
107
+ mql.addListener(listener);
108
+ this.cleanupThunks.push(() => mql.removeListener(listener));
109
+ }
110
+ }
394
111
 
395
- mql.addListener(listener);
112
+ componentWillUnmount() {
113
+ // Remove our listeners.
114
+ this.cleanupThunks.forEach(cleaup => cleaup());
115
+ }
396
116
 
397
- _this2.cleanupThunks.push(function () {
398
- return mql.removeListener(listener);
399
- });
400
- };
117
+ getCurrentSize(spec) {
118
+ // If we have a state with the current size in it then we always want
119
+ // to use that. This will happen if the viewport changes sizes after
120
+ // we've already initialized.
121
+ if (this.state.size) {
122
+ return this.state.size;
123
+ } else {
124
+ const entries = Object.entries(this.props.mediaSpec);
401
125
 
402
- for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
403
- var _ret = _loop();
126
+ for (const [size, _spec] of entries) {
127
+ const mql = mediaQueryLists[_spec.query];
404
128
 
405
- if (_ret === "continue") continue;
406
- }
407
- }
408
- }, {
409
- key: "componentWillUnmount",
410
- value: function componentWillUnmount() {
411
- // Remove our listeners.
412
- this.cleanupThunks.forEach(function (cleaup) {
413
- return cleaup();
414
- });
415
- }
416
- }, {
417
- key: "getCurrentSize",
418
- value: function getCurrentSize(spec) {
419
- // If we have a state with the current size in it then we always want
420
- // to use that. This will happen if the viewport changes sizes after
421
- // we've already initialized.
422
- if (this.state.size) {
423
- return this.state.size;
424
- } else {
425
- var entries = Object.entries(this.props.mediaSpec);
426
-
427
- for (var _i2 = 0, _entries2 = entries; _i2 < _entries2.length; _i2++) {
428
- var _entries2$_i = _slicedToArray(_entries2[_i2], 2),
429
- size = _entries2$_i[0],
430
- _spec = _entries2$_i[1];
431
-
432
- var mql = mediaQueryLists[_spec.query];
433
-
434
- if (mql.matches) {
435
- return size;
436
- }
129
+ if (mql.matches) {
130
+ return size;
437
131
  }
438
132
  }
133
+ }
439
134
 
440
- return DEFAULT_SIZE;
441
- } // We assume that we're running on the server (or, at least, an unsupported
442
- // environment) if there is no window object or matchMedia function
443
- // available.
444
-
445
- }, {
446
- key: "isServerSide",
447
- value: function isServerSide() {
448
- return typeof window === "undefined" || !window.matchMedia;
449
- } // Generate a mock Aphrodite StyleSheet based upon the current mediaSize
450
- // We do this by looking at all of the stylesheets specified in the
451
- // styleSheets prop and then all of the individual styles. We merge the
452
- // styles together
453
- // TODO(WB-533): move to util.js to make it easier to test
454
-
455
- }, {
456
- key: "getMockStyleSheet",
457
- value: function getMockStyleSheet(mediaSize) {
458
- var styleSheets = this.props.styleSheets;
459
- var mockStyleSheet = {}; // If no stylesheets were specified then we just return an empty object
460
-
461
- if (!styleSheets) {
462
- return mockStyleSheet;
463
- } // Go through all of the stylesheets that were specified
464
-
465
-
466
- for (var _i3 = 0, _Object$keys = Object.keys(styleSheets); _i3 < _Object$keys.length; _i3++) {
467
- var styleSize = _Object$keys[_i3];
468
- var styleSheet = styleSheets[styleSize];
469
-
470
- if (!styleSheet) {
471
- continue;
472
- } // And then through each key of each stylesheet
473
-
135
+ return DEFAULT_SIZE;
136
+ } // We assume that we're running on the server (or, at least, an unsupported
137
+ // environment) if there is no window object or matchMedia function
138
+ // available.
474
139
 
475
- for (var _i4 = 0, _Object$keys2 = Object.keys(styleSheet); _i4 < _Object$keys2.length; _i4++) {
476
- var name = _Object$keys2[_i4];
477
140
 
478
- if (Object.prototype.hasOwnProperty.call(mockStyleSheet, name)) {
479
- continue;
480
- } // We create an entry that combines the values from all of
481
- // the stylesheets together in least-specific to most-specific
482
- // priority (thus small/medium/large styles will always have
483
- // precedence over "all" or mdOrSmaller/mdOrLarger/etc.).
141
+ isServerSide() {
142
+ return typeof window === "undefined" || !window.matchMedia;
143
+ } // Generate a mock Aphrodite StyleSheet based upon the current mediaSize
144
+ // We do this by looking at all of the stylesheets specified in the
145
+ // styleSheets prop and then all of the individual styles. We merge the
146
+ // styles together
147
+ // TODO(WB-533): move to util.js to make it easier to test
484
148
 
485
149
 
486
- mockStyleSheet[name] = [styleSheets.all && styleSheets.all[name], mediaSize === "small" && [styleSheets.mdOrSmaller && styleSheets.mdOrSmaller[name], styleSheets.small && styleSheets.small[name]], mediaSize === "medium" && [styleSheets.mdOrSmaller && styleSheets.mdOrSmaller[name], styleSheets.mdOrLarger && styleSheets.mdOrLarger[name], styleSheets.medium && styleSheets.medium[name]], mediaSize === "large" && [styleSheets.mdOrLarger && styleSheets.mdOrLarger[name], styleSheets.large && styleSheets.large[name]]];
487
- }
488
- }
150
+ getMockStyleSheet(mediaSize) {
151
+ const {
152
+ styleSheets
153
+ } = this.props;
154
+ const mockStyleSheet = {}; // If no stylesheets were specified then we just return an empty object
489
155
 
156
+ if (!styleSheets) {
490
157
  return mockStyleSheet;
491
- }
492
- }, {
493
- key: "render",
494
- value: function render() {
495
- var _this$props = this.props,
496
- children = _this$props.children,
497
- mediaSpec = _this$props.mediaSpec,
498
- ssrSize = _this$props.ssrSize,
499
- overrideSize = _this$props.overrideSize; // We need to create the MediaQueryLists during the first render in order
500
- // to query whether any of them match.
501
-
502
- if (!this.isServerSide()) {
503
- var _iterator = _createForOfIteratorHelper(queries.filter(function (query) {
504
- return !mediaQueryLists[query];
505
- })),
506
- _step;
507
-
508
- try {
509
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
510
- var query = _step.value;
511
- mediaQueryLists[query] = window.matchMedia(query);
512
- }
513
- } catch (err) {
514
- _iterator.e(err);
515
- } finally {
516
- _iterator.f();
517
- }
518
- } // We need to figure out what the current media size is
519
- // If an override has been specified, we use that.
520
- // If we're rendering on the server then we use the default
521
- // SSR rendering size.
522
- // Otherwise we attempt to get the current size based on
523
- // the current MediaSpec.
524
-
525
-
526
- var mediaSize = overrideSize || this.isServerSide() && ssrSize || this.getCurrentSize(mediaSpec); // Generate a mock stylesheet
527
-
528
- var styles = this.getMockStyleSheet(mediaSize);
529
- return children({
530
- mediaSize: mediaSize,
531
- mediaSpec: mediaSpec,
532
- styles: styles
533
- });
534
- }
535
- }]);
158
+ } // Go through all of the stylesheets that were specified
536
159
 
537
- return MediaLayoutInternal;
538
- }(Component); // gen-snapshot-tests.js only understands `export default class ...`
539
160
 
161
+ for (const styleSize of Object.keys(styleSheets)) {
162
+ const styleSheet = styleSheets[styleSize];
540
163
 
541
- var MediaLayout = /*#__PURE__*/function (_React$Component2) {
542
- _inherits(MediaLayout, _React$Component2);
164
+ if (!styleSheet) {
165
+ continue;
166
+ } // And then through each key of each stylesheet
543
167
 
544
- var _super2 = _createSuper(MediaLayout);
545
168
 
546
- function MediaLayout() {
547
- _classCallCheck(this, MediaLayout);
169
+ for (const name of Object.keys(styleSheet)) {
170
+ if ( // $FlowIgnore[method-unbinding]
171
+ Object.prototype.hasOwnProperty.call(mockStyleSheet, name)) {
172
+ continue;
173
+ } // We create an entry that combines the values from all of
174
+ // the stylesheets together in least-specific to most-specific
175
+ // priority (thus small/medium/large styles will always have
176
+ // precedence over "all" or mdOrSmaller/mdOrLarger/etc.).
548
177
 
549
- return _super2.apply(this, arguments);
550
- }
551
178
 
552
- _createClass(MediaLayout, [{
553
- key: "render",
554
- value: function render() {
555
- var _this3 = this;
556
-
557
- // We listen to the MediaLayoutContext to see what defaults we're
558
- // being given (this can be overriden by wrapping this component in
559
- // a MediaLayoutContext.Consumer).
560
- return /*#__PURE__*/createElement(MediaLayoutContext.Consumer, null, function (_ref) {
561
- var overrideSize = _ref.overrideSize,
562
- ssrSize = _ref.ssrSize,
563
- mediaSpec = _ref.mediaSpec;
564
- return /*#__PURE__*/createElement(MediaLayoutInternal, _extends({}, _this3.props, {
565
- overrideSize: overrideSize,
566
- ssrSize: ssrSize,
567
- mediaSpec: mediaSpec
568
- }));
569
- });
179
+ mockStyleSheet[name] = [styleSheets.all && styleSheets.all[name], mediaSize === "small" && [styleSheets.mdOrSmaller && styleSheets.mdOrSmaller[name], styleSheets.small && styleSheets.small[name]], mediaSize === "medium" && [styleSheets.mdOrSmaller && styleSheets.mdOrSmaller[name], styleSheets.mdOrLarger && styleSheets.mdOrLarger[name], styleSheets.medium && styleSheets.medium[name]], mediaSize === "large" && [styleSheets.mdOrLarger && styleSheets.mdOrLarger[name], styleSheets.large && styleSheets.large[name]]];
180
+ }
570
181
  }
571
- }]);
572
182
 
573
- return MediaLayout;
574
- }(Component);
183
+ return mockStyleSheet;
184
+ }
185
+
186
+ render() {
187
+ const {
188
+ children,
189
+ mediaSpec,
190
+ ssrSize,
191
+ overrideSize
192
+ } = this.props; // We need to create the MediaQueryLists during the first render in order
193
+ // to query whether any of them match.
194
+
195
+ if (!this.isServerSide()) {
196
+ for (const query of queries.filter(query => !mediaQueryLists[query])) {
197
+ mediaQueryLists[query] = window.matchMedia(query);
198
+ }
199
+ } // We need to figure out what the current media size is
200
+ // If an override has been specified, we use that.
201
+ // If we're rendering on the server then we use the default
202
+ // SSR rendering size.
203
+ // Otherwise we attempt to get the current size based on
204
+ // the current MediaSpec.
205
+
206
+
207
+ const mediaSize = overrideSize || this.isServerSide() && ssrSize || this.getCurrentSize(mediaSpec); // Generate a mock stylesheet
208
+
209
+ const styles = this.getMockStyleSheet(mediaSize);
210
+ return children({
211
+ mediaSize,
212
+ mediaSpec,
213
+ styles
214
+ });
215
+ }
216
+
217
+ } // gen-snapshot-tests.js only understands `export default class ...`
218
+
219
+
220
+ class MediaLayout extends Component {
221
+ render() {
222
+ // We listen to the MediaLayoutContext to see what defaults we're
223
+ // being given (this can be overriden by wrapping this component in
224
+ // a MediaLayoutContext.Consumer).
225
+ return /*#__PURE__*/createElement(MediaLayoutContext.Consumer, null, ({
226
+ overrideSize,
227
+ ssrSize,
228
+ mediaSpec
229
+ }) => /*#__PURE__*/createElement(MediaLayoutInternal, _extends({}, this.props, {
230
+ overrideSize: overrideSize,
231
+ ssrSize: ssrSize,
232
+ mediaSpec: mediaSpec
233
+ })));
234
+ }
235
+
236
+ }
575
237
 
576
238
  /**
577
239
  * Expands to fill space between sibling components.
578
240
  *
579
241
  * Assumes parent is a View.
580
242
  */
581
- var Spring = /*#__PURE__*/function (_React$Component) {
582
- _inherits(Spring, _React$Component);
583
-
584
- var _super = _createSuper(Spring);
585
-
586
- function Spring() {
587
- _classCallCheck(this, Spring);
588
-
589
- return _super.apply(this, arguments);
243
+ class Spring extends Component {
244
+ render() {
245
+ const {
246
+ style
247
+ } = this.props;
248
+ return /*#__PURE__*/createElement(View, {
249
+ "aria-hidden": "true",
250
+ style: [styles.grow, style]
251
+ });
590
252
  }
591
253
 
592
- _createClass(Spring, [{
593
- key: "render",
594
- value: function render() {
595
- var style = this.props.style;
596
- return /*#__PURE__*/createElement(View, {
597
- "aria-hidden": "true",
598
- style: [styles.grow, style]
599
- });
600
- }
601
- }]);
602
-
603
- return Spring;
604
- }(Component);
605
- var styles = StyleSheet.create({
254
+ }
255
+ const styles = StyleSheet.create({
606
256
  grow: {
607
257
  flexGrow: 1
608
258
  }
@@ -613,34 +263,21 @@ var styles = StyleSheet.create({
613
263
  *
614
264
  * Assumes parent is a View.
615
265
  */
616
- var Strut = /*#__PURE__*/function (_React$Component) {
617
- _inherits(Strut, _React$Component);
618
-
619
- var _super = _createSuper(Strut);
620
-
621
- function Strut() {
622
- _classCallCheck(this, Strut);
623
-
624
- return _super.apply(this, arguments);
266
+ class Strut extends Component {
267
+ render() {
268
+ const {
269
+ size,
270
+ style
271
+ } = this.props;
272
+ return /*#__PURE__*/createElement(View, {
273
+ "aria-hidden": "true",
274
+ style: [strutStyle(size), style]
275
+ });
625
276
  }
626
277
 
627
- _createClass(Strut, [{
628
- key: "render",
629
- value: function render() {
630
- var _this$props = this.props,
631
- size = _this$props.size,
632
- style = _this$props.style;
633
- return /*#__PURE__*/createElement(View, {
634
- "aria-hidden": "true",
635
- style: [strutStyle(size), style]
636
- });
637
- }
638
- }]);
639
-
640
- return Strut;
641
- }(Component);
278
+ }
642
279
 
643
- var strutStyle = function strutStyle(size) {
280
+ const strutStyle = size => {
644
281
  return {
645
282
  width: size,
646
283
  MsFlexBasis: size,
@@ -661,7 +298,7 @@ var strutStyle = function strutStyle(size) {
661
298
  * @param {MediaQuery} mediaQuery
662
299
  * @param {MediaSize} mediaSize
663
300
  */
664
- var queryMatchesSize = function queryMatchesSize(mediaQuery, mediaSize) {
301
+ const queryMatchesSize = (mediaQuery, mediaSize) => {
665
302
  switch (mediaQuery) {
666
303
  case "all":
667
304
  return true;
@@ -682,7 +319,7 @@ var queryMatchesSize = function queryMatchesSize(mediaQuery, mediaSize) {
682
319
  return mediaSize === "large";
683
320
 
684
321
  default:
685
- throw new Error("Unsupported mediaSize: ".concat(mediaSize));
322
+ throw new Error(`Unsupported mediaSize: ${mediaSize}`);
686
323
  }
687
324
  };
688
325