@khanacademy/wonder-blocks-grid 1.0.24

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/index.js ADDED
@@ -0,0 +1,787 @@
1
+ module.exports =
2
+ /******/ (function(modules) { // webpackBootstrap
3
+ /******/ // The module cache
4
+ /******/ var installedModules = {};
5
+ /******/
6
+ /******/ // The require function
7
+ /******/ function __webpack_require__(moduleId) {
8
+ /******/
9
+ /******/ // Check if module is in cache
10
+ /******/ if(installedModules[moduleId]) {
11
+ /******/ return installedModules[moduleId].exports;
12
+ /******/ }
13
+ /******/ // Create a new module (and put it into the cache)
14
+ /******/ var module = installedModules[moduleId] = {
15
+ /******/ i: moduleId,
16
+ /******/ l: false,
17
+ /******/ exports: {}
18
+ /******/ };
19
+ /******/
20
+ /******/ // Execute the module function
21
+ /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22
+ /******/
23
+ /******/ // Flag the module as loaded
24
+ /******/ module.l = true;
25
+ /******/
26
+ /******/ // Return the exports of the module
27
+ /******/ return module.exports;
28
+ /******/ }
29
+ /******/
30
+ /******/
31
+ /******/ // expose the modules object (__webpack_modules__)
32
+ /******/ __webpack_require__.m = modules;
33
+ /******/
34
+ /******/ // expose the module cache
35
+ /******/ __webpack_require__.c = installedModules;
36
+ /******/
37
+ /******/ // define getter function for harmony exports
38
+ /******/ __webpack_require__.d = function(exports, name, getter) {
39
+ /******/ if(!__webpack_require__.o(exports, name)) {
40
+ /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
41
+ /******/ }
42
+ /******/ };
43
+ /******/
44
+ /******/ // define __esModule on exports
45
+ /******/ __webpack_require__.r = function(exports) {
46
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
+ /******/ }
49
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
50
+ /******/ };
51
+ /******/
52
+ /******/ // create a fake namespace object
53
+ /******/ // mode & 1: value is a module id, require it
54
+ /******/ // mode & 2: merge all properties of value into the ns
55
+ /******/ // mode & 4: return value when already ns object
56
+ /******/ // mode & 8|1: behave like require
57
+ /******/ __webpack_require__.t = function(value, mode) {
58
+ /******/ if(mode & 1) value = __webpack_require__(value);
59
+ /******/ if(mode & 8) return value;
60
+ /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
61
+ /******/ var ns = Object.create(null);
62
+ /******/ __webpack_require__.r(ns);
63
+ /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
64
+ /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
65
+ /******/ return ns;
66
+ /******/ };
67
+ /******/
68
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
69
+ /******/ __webpack_require__.n = function(module) {
70
+ /******/ var getter = module && module.__esModule ?
71
+ /******/ function getDefault() { return module['default']; } :
72
+ /******/ function getModuleExports() { return module; };
73
+ /******/ __webpack_require__.d(getter, 'a', getter);
74
+ /******/ return getter;
75
+ /******/ };
76
+ /******/
77
+ /******/ // Object.prototype.hasOwnProperty.call
78
+ /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
79
+ /******/
80
+ /******/ // __webpack_public_path__
81
+ /******/ __webpack_require__.p = "";
82
+ /******/
83
+ /******/
84
+ /******/ // Load entry module and return exports
85
+ /******/ return __webpack_require__(__webpack_require__.s = 5);
86
+ /******/ })
87
+ /************************************************************************/
88
+ /******/ ([
89
+ /* 0 */
90
+ /***/ (function(module, exports) {
91
+
92
+ module.exports = require("react");
93
+
94
+ /***/ }),
95
+ /* 1 */
96
+ /***/ (function(module, exports) {
97
+
98
+ module.exports = require("@khanacademy/wonder-blocks-spacing");
99
+
100
+ /***/ }),
101
+ /* 2 */
102
+ /***/ (function(module, exports) {
103
+
104
+ module.exports = require("@khanacademy/wonder-blocks-core");
105
+
106
+ /***/ }),
107
+ /* 3 */
108
+ /***/ (function(module, exports) {
109
+
110
+ module.exports = require("aphrodite");
111
+
112
+ /***/ }),
113
+ /* 4 */
114
+ /***/ (function(module, exports) {
115
+
116
+ function _extends() {
117
+ module.exports = _extends = Object.assign || function (target) {
118
+ for (var i = 1; i < arguments.length; i++) {
119
+ var source = arguments[i];
120
+
121
+ for (var key in source) {
122
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
123
+ target[key] = source[key];
124
+ }
125
+ }
126
+ }
127
+
128
+ return target;
129
+ };
130
+
131
+ module.exports["default"] = module.exports, module.exports.__esModule = true;
132
+ return _extends.apply(this, arguments);
133
+ }
134
+
135
+ module.exports = _extends;
136
+ module.exports["default"] = module.exports, module.exports.__esModule = true;
137
+
138
+ /***/ }),
139
+ /* 5 */
140
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
141
+
142
+ "use strict";
143
+ // ESM COMPAT FLAG
144
+ __webpack_require__.r(__webpack_exports__);
145
+
146
+ // EXPORTS
147
+ __webpack_require__.d(__webpack_exports__, "Cell", function() { return /* reexport */ cell_Cell; });
148
+ __webpack_require__.d(__webpack_exports__, "Row", function() { return /* reexport */ row_Row; });
149
+
150
+ // EXTERNAL MODULE: external "react"
151
+ var external_react_ = __webpack_require__(0);
152
+
153
+ // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/extends.js
154
+ var helpers_extends = __webpack_require__(4);
155
+ var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends);
156
+
157
+ // EXTERNAL MODULE: external "@khanacademy/wonder-blocks-spacing"
158
+ var wonder_blocks_spacing_ = __webpack_require__(1);
159
+ var wonder_blocks_spacing_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_spacing_);
160
+
161
+ // EXTERNAL MODULE: external "aphrodite"
162
+ var external_aphrodite_ = __webpack_require__(3);
163
+
164
+ // EXTERNAL MODULE: external "@khanacademy/wonder-blocks-core"
165
+ var wonder_blocks_core_ = __webpack_require__(2);
166
+
167
+ // CONCATENATED MODULE: ./packages/wonder-blocks-layout/dist/es/index.js
168
+
169
+
170
+
171
+
172
+ // All possible valid media sizes
173
+
174
+ const VALID_MEDIA_SIZES = ["small", "medium", "large"];
175
+ const mediaDefaultSpecLargeMarginWidth = wonder_blocks_spacing_default.a.large_24; // The default spec for media layout, currently available in
176
+ // three different settings (roughly mobile, tablet, and desktop).
177
+
178
+ const MEDIA_DEFAULT_SPEC = {
179
+ small: {
180
+ query: "(max-width: 767px)",
181
+ totalColumns: 4,
182
+ gutterWidth: wonder_blocks_spacing_default.a.medium_16,
183
+ marginWidth: wonder_blocks_spacing_default.a.medium_16
184
+ },
185
+ medium: {
186
+ query: "(min-width: 768px) and (max-width: 1023px)",
187
+ totalColumns: 8,
188
+ gutterWidth: wonder_blocks_spacing_default.a.xLarge_32,
189
+ marginWidth: wonder_blocks_spacing_default.a.large_24
190
+ },
191
+ large: {
192
+ query: "(min-width: 1024px)",
193
+ totalColumns: 12,
194
+ gutterWidth: wonder_blocks_spacing_default.a.xLarge_32,
195
+ marginWidth: mediaDefaultSpecLargeMarginWidth,
196
+ maxWidth: 1120 + mediaDefaultSpecLargeMarginWidth * 2
197
+ }
198
+ }; // Used for internal tools
199
+
200
+ const MEDIA_INTERNAL_SPEC = {
201
+ large: {
202
+ query: "(min-width: 1px)",
203
+ totalColumns: 12,
204
+ gutterWidth: wonder_blocks_spacing_default.a.xLarge_32,
205
+ marginWidth: wonder_blocks_spacing_default.a.medium_16
206
+ }
207
+ }; // The default used for modals
208
+
209
+ const MEDIA_MODAL_SPEC = {
210
+ small: {
211
+ query: "(max-width: 767px)",
212
+ totalColumns: 4,
213
+ gutterWidth: wonder_blocks_spacing_default.a.medium_16,
214
+ marginWidth: wonder_blocks_spacing_default.a.medium_16
215
+ },
216
+ large: {
217
+ query: "(min-width: 768px)",
218
+ totalColumns: 12,
219
+ gutterWidth: wonder_blocks_spacing_default.a.xLarge_32,
220
+ marginWidth: wonder_blocks_spacing_default.a.xxLarge_48
221
+ }
222
+ };
223
+ const defaultContext = {
224
+ ssrSize: "large",
225
+ mediaSpec: MEDIA_DEFAULT_SPEC
226
+ };
227
+ var MediaLayoutContext = /*#__PURE__*/Object(external_react_["createContext"])(defaultContext);
228
+ 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));
229
+ const mediaQueryLists = {}; // eslint-disable-next-line flowtype/require-exact-type
230
+ // If for some reason we're not able to resolve the current media size we
231
+ // fall back to this state.
232
+
233
+ const DEFAULT_SIZE = "large";
234
+ /**
235
+ * `MediaLayout` is responsible for changing the rendering of contents at
236
+ * differently sized viewports. `MediaLayoutContext.Provider` can be used
237
+ * to specify different breakpoint configurations. By default it uses
238
+ * `MEDIA_DEFAULT_SPEC`. See media-layout-context.js for additiional options.
239
+ */
240
+
241
+ class es_MediaLayoutInternal extends external_react_["Component"] {
242
+ // A collection of thunks that's used to clean up event listeners
243
+ // when the component is unmounted.
244
+ constructor(props) {
245
+ super(props);
246
+ this.state = {
247
+ size: undefined
248
+ };
249
+ this.cleanupThunks = [];
250
+ }
251
+
252
+ componentDidMount() {
253
+ // TODO(WB-534): handle changes to mediaSpec prop
254
+ const entries = Object.entries(this.props.mediaSpec);
255
+
256
+ for (const [size, spec] of entries) {
257
+ const mql = mediaQueryLists[spec.query]; // during SSR there are no MediaQueryLists
258
+
259
+ if (!mql) {
260
+ continue;
261
+ }
262
+
263
+ const listener = e => {
264
+ if (e.matches) {
265
+ this.setState({
266
+ size
267
+ });
268
+ }
269
+ };
270
+
271
+ mql.addListener(listener);
272
+ this.cleanupThunks.push(() => mql.removeListener(listener));
273
+ }
274
+ }
275
+
276
+ componentWillUnmount() {
277
+ // Remove our listeners.
278
+ this.cleanupThunks.forEach(cleaup => cleaup());
279
+ }
280
+
281
+ getCurrentSize(spec) {
282
+ // If we have a state with the current size in it then we always want
283
+ // to use that. This will happen if the viewport changes sizes after
284
+ // we've already initialized.
285
+ if (this.state.size) {
286
+ return this.state.size;
287
+ } else {
288
+ const entries = Object.entries(this.props.mediaSpec);
289
+
290
+ for (const [size, _spec] of entries) {
291
+ const mql = mediaQueryLists[_spec.query];
292
+
293
+ if (mql.matches) {
294
+ return size;
295
+ }
296
+ }
297
+ }
298
+
299
+ return DEFAULT_SIZE;
300
+ } // We assume that we're running on the server (or, at least, an unsupported
301
+ // environment) if there is no window object or matchMedia function
302
+ // available.
303
+
304
+
305
+ isServerSide() {
306
+ return typeof window === "undefined" || !window.matchMedia;
307
+ } // Generate a mock Aphrodite StyleSheet based upon the current mediaSize
308
+ // We do this by looking at all of the stylesheets specified in the
309
+ // styleSheets prop and then all of the individual styles. We merge the
310
+ // styles together
311
+ // TODO(WB-533): move to util.js to make it easier to test
312
+
313
+
314
+ getMockStyleSheet(mediaSize) {
315
+ const {
316
+ styleSheets
317
+ } = this.props;
318
+ const mockStyleSheet = {}; // If no stylesheets were specified then we just return an empty object
319
+
320
+ if (!styleSheets) {
321
+ return mockStyleSheet;
322
+ } // Go through all of the stylesheets that were specified
323
+
324
+
325
+ for (const styleSize of Object.keys(styleSheets)) {
326
+ const styleSheet = styleSheets[styleSize];
327
+
328
+ if (!styleSheet) {
329
+ continue;
330
+ } // And then through each key of each stylesheet
331
+
332
+
333
+ for (const name of Object.keys(styleSheet)) {
334
+ if ( // $FlowIgnore[method-unbinding]
335
+ Object.prototype.hasOwnProperty.call(mockStyleSheet, name)) {
336
+ continue;
337
+ } // We create an entry that combines the values from all of
338
+ // the stylesheets together in least-specific to most-specific
339
+ // priority (thus small/medium/large styles will always have
340
+ // precedence over "all" or mdOrSmaller/mdOrLarger/etc.).
341
+
342
+
343
+ 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]]];
344
+ }
345
+ }
346
+
347
+ return mockStyleSheet;
348
+ }
349
+
350
+ render() {
351
+ const {
352
+ children,
353
+ mediaSpec,
354
+ ssrSize,
355
+ overrideSize
356
+ } = this.props; // We need to create the MediaQueryLists during the first render in order
357
+ // to query whether any of them match.
358
+
359
+ if (!this.isServerSide()) {
360
+ for (const query of queries.filter(query => !mediaQueryLists[query])) {
361
+ mediaQueryLists[query] = window.matchMedia(query);
362
+ }
363
+ } // We need to figure out what the current media size is
364
+ // If an override has been specified, we use that.
365
+ // If we're rendering on the server then we use the default
366
+ // SSR rendering size.
367
+ // Otherwise we attempt to get the current size based on
368
+ // the current MediaSpec.
369
+
370
+
371
+ const mediaSize = overrideSize || this.isServerSide() && ssrSize || this.getCurrentSize(mediaSpec); // Generate a mock stylesheet
372
+
373
+ const styles = this.getMockStyleSheet(mediaSize);
374
+ return children({
375
+ mediaSize,
376
+ mediaSpec,
377
+ styles
378
+ });
379
+ }
380
+
381
+ } // gen-snapshot-tests.js only understands `export default class ...`
382
+
383
+
384
+ class es_MediaLayout extends external_react_["Component"] {
385
+ render() {
386
+ // We listen to the MediaLayoutContext to see what defaults we're
387
+ // being given (this can be overriden by wrapping this component in
388
+ // a MediaLayoutContext.Consumer).
389
+ return /*#__PURE__*/Object(external_react_["createElement"])(MediaLayoutContext.Consumer, null, ({
390
+ overrideSize,
391
+ ssrSize,
392
+ mediaSpec
393
+ }) => /*#__PURE__*/Object(external_react_["createElement"])(es_MediaLayoutInternal, extends_default()({}, this.props, {
394
+ overrideSize: overrideSize,
395
+ ssrSize: ssrSize,
396
+ mediaSpec: mediaSpec
397
+ })));
398
+ }
399
+
400
+ }
401
+ /**
402
+ * Expands to fill space between sibling components.
403
+ *
404
+ * Assumes parent is a View.
405
+ */
406
+
407
+
408
+ class es_Spring extends external_react_["Component"] {
409
+ render() {
410
+ const {
411
+ style
412
+ } = this.props;
413
+ return /*#__PURE__*/Object(external_react_["createElement"])(wonder_blocks_core_["View"], {
414
+ "aria-hidden": "true",
415
+ style: [styles.grow, style]
416
+ });
417
+ }
418
+
419
+ }
420
+
421
+ const styles = external_aphrodite_["StyleSheet"].create({
422
+ grow: {
423
+ flexGrow: 1
424
+ }
425
+ });
426
+ /**
427
+ * A component for inserting fixed space between components.
428
+ *
429
+ * Assumes parent is a View.
430
+ */
431
+
432
+ class es_Strut extends external_react_["Component"] {
433
+ render() {
434
+ const {
435
+ size,
436
+ style
437
+ } = this.props;
438
+ return /*#__PURE__*/Object(external_react_["createElement"])(wonder_blocks_core_["View"], {
439
+ "aria-hidden": "true",
440
+ style: [strutStyle(size), style]
441
+ });
442
+ }
443
+
444
+ }
445
+
446
+ const strutStyle = size => {
447
+ return {
448
+ width: size,
449
+ MsFlexBasis: size,
450
+ MsFlexPreferredSize: size,
451
+ WebkitFlexBasis: size,
452
+ flexBasis: size,
453
+ flexShrink: 0
454
+ };
455
+ };
456
+ /**
457
+ * Return where a media size matches a media query.
458
+ *
459
+ * examples:
460
+ * - `queryMatchesSize("all", "small")` returns `true`
461
+ * - `queryMatchesSize("mdOrLarger", "small")` returns `false`
462
+ *
463
+ * @param {MediaQuery} mediaQuery
464
+ * @param {MediaSize} mediaSize
465
+ */
466
+
467
+
468
+ const queryMatchesSize = (mediaQuery, mediaSize) => {
469
+ switch (mediaQuery) {
470
+ case "all":
471
+ return true;
472
+
473
+ case "small":
474
+ return mediaSize === "small";
475
+
476
+ case "mdOrSmaller":
477
+ return mediaSize === "medium" || mediaSize === "small";
478
+
479
+ case "medium":
480
+ return mediaSize === "medium";
481
+
482
+ case "mdOrLarger":
483
+ return mediaSize === "medium" || mediaSize === "large";
484
+
485
+ case "large":
486
+ return mediaSize === "large";
487
+
488
+ default:
489
+ throw new Error(`Unsupported mediaSize: ${mediaSize}`);
490
+ }
491
+ };
492
+
493
+
494
+ // CONCATENATED MODULE: ./packages/wonder-blocks-grid/src/util/styles.js
495
+
496
+ const WIDE_SCREEN = "@media (min-width: 1168px)";
497
+ const styles_styles = external_aphrodite_["StyleSheet"].create({
498
+ row: {
499
+ flexDirection: "row",
500
+ alignItems: "center",
501
+ width: "100%"
502
+ },
503
+ rowMaxWidth: {
504
+ [WIDE_SCREEN]: {
505
+ margin: "0 auto"
506
+ }
507
+ },
508
+ cellGrow: {
509
+ flexGrow: 1
510
+ },
511
+ cellFixed: {
512
+ flexShrink: 0
513
+ }
514
+ });
515
+ /* harmony default export */ var util_styles = (styles_styles);
516
+ // CONCATENATED MODULE: ./packages/wonder-blocks-grid/src/util/utils.js
517
+ const flexBasis = size => {
518
+ return {
519
+ MsFlexBasis: size,
520
+ MsFlexPreferredSize: size,
521
+ WebkitFlexBasis: size,
522
+ flexBasis: size
523
+ };
524
+ };
525
+ // CONCATENATED MODULE: ./packages/wonder-blocks-grid/src/components/cell.js
526
+
527
+
528
+
529
+
530
+
531
+
532
+ /**
533
+ * A Cell is a container whose width is set based on the width of the
534
+ * specified columns at the current grid size. You will specify the number
535
+ * of columns that you want this component to span at each grid size.
536
+ * This component should only be used as a child of a [Row](#row).
537
+ *
538
+ * This component renders a [View](#view) that
539
+ * uses Flex Box and has a [flex-basis](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-basis)
540
+ * of the specified "width" and [flex-shrink](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink)
541
+ * of 0.
542
+ *
543
+ * By default (with no properties specified) it will display at all
544
+ * grid sizes. If you specify the `smallCols`, `mediumCols`, `largeCols`, or
545
+ * `cols` props then the component will only be shown at those grid sizes and
546
+ * using the specified column width.
547
+ */
548
+ class cell_Cell extends external_react_["Component"] {
549
+ static isClassOf(instance) {
550
+ return instance && instance.type && instance.type.__IS_CELL__;
551
+ }
552
+
553
+ static getCols(props, mediaSize) {
554
+ // If no option was specified then we just return undefined,
555
+ // components may handle this case differently.
556
+ // We go through all the ways in which a fixed width can be
557
+ // specified and find the one that matches our current grid size.
558
+ if (!props.smallCols && !props.mediumCols && !props.largeCols && !props.cols) {
559
+ return undefined;
560
+ } else if (props.smallCols && mediaSize === "small") {
561
+ return props.smallCols;
562
+ } else if (props.mediumCols && mediaSize === "medium") {
563
+ return props.mediumCols;
564
+ } else if (props.largeCols && mediaSize === "large") {
565
+ return props.largeCols;
566
+ } else if (typeof props.cols === "function") {
567
+ return props.cols(mediaSize);
568
+ } else if (props.cols) {
569
+ return props.cols;
570
+ } // If nothing applies then we return null (usually resulting
571
+ // in the component not being rendered)
572
+
573
+
574
+ return null;
575
+ } // HACK(kevinb): we use a stack method here because we can't get a ref to
576
+ // each cell in a row without cloning them all.
577
+
578
+
579
+ static shouldDisplay(props, mediaSize) {
580
+ const cols = cell_Cell.getCols(props, mediaSize);
581
+ return cols !== null && cols !== 0;
582
+ }
583
+
584
+ render() {
585
+ const {
586
+ children,
587
+ style
588
+ } = this.props;
589
+ return /*#__PURE__*/external_react_["createElement"](es_MediaLayout, null, ({
590
+ mediaSize,
591
+ mediaSpec
592
+ }) => {
593
+ const spec = mediaSpec[mediaSize];
594
+
595
+ if (!spec) {
596
+ throw new Error(`mediaSpec.${mediaSize} is undefined`);
597
+ } // Get the settings for this particular size of grid
598
+
599
+
600
+ const {
601
+ totalColumns,
602
+ gutterWidth,
603
+ marginWidth
604
+ } = spec;
605
+ const cols = cell_Cell.getCols(this.props, mediaSize); // If no columns are specified then we just don't render this cell
606
+
607
+ if (cols === undefined || cols === null || cols === 0) {
608
+ return null;
609
+ }
610
+
611
+ if (cols > totalColumns) {
612
+ throw new Error(`Specified columns ${cols} is greater than the maximum ` + `${totalColumns} at the ${mediaSize} grid size.`);
613
+ } // We need to start by calculating the total width of all the "content"
614
+ // We do this by starting with the full width (100%) and then
615
+ // subtracting all of the gutter spaces inbetween the cells
616
+ // (gutterWidth * (totalColumns - 1)) and the width of the two margins
617
+ // (marginWidth * 2).
618
+
619
+
620
+ const contentWidth = `(100% - ${gutterWidth * (totalColumns - 1)}px - ${marginWidth * 2}px)`; // Now that we have the full width we can calculate the width of this
621
+ // particular cell by multiplying the full width (allCellWidth) by
622
+ // the ratio of this cell (cols / totalColumns). But we then need to
623
+ // add back in the missing gutter widths:
624
+ // (gutterWidth * (cols - 1)). This gives us to full width of
625
+ // this particular cell.
626
+
627
+ const calcWidth = `calc(${contentWidth} * ${cols / totalColumns} + ${gutterWidth * (cols - 1)}px)`; // If the contents are a function then we call it with the mediaSize,
628
+ // totalColumns, and cols properties and render the return value.
629
+
630
+ const contents = typeof children === "function" ? children({
631
+ mediaSize,
632
+ totalColumns,
633
+ cols
634
+ }) : children; // Render a fixed-width cell (flex-basis: size, flex-shrink: 0)
635
+ // that matches the intended width of the cell
636
+
637
+ return /*#__PURE__*/external_react_["createElement"](wonder_blocks_core_["View"], {
638
+ style: [util_styles.cellFixed, flexBasis(calcWidth), style]
639
+ }, contents);
640
+ });
641
+ }
642
+
643
+ }
644
+ cell_Cell.defaultProps = {
645
+ smallCols: 0,
646
+ mediumCols: 0,
647
+ largeCols: 0,
648
+ cols: 0
649
+ };
650
+ cell_Cell.__IS_CELL__ = true;
651
+ // CONCATENATED MODULE: ./packages/wonder-blocks-grid/src/components/gutter.js
652
+
653
+
654
+
655
+ /**
656
+ * Gutter is a component whose width is set based on the size of grid currently
657
+ * being displayed. Used for spacing out cells from each other. The gutter
658
+ * itself doesn't hold any content, it just spaces it out.
659
+ *
660
+ * Gutters are inserted automatically inside of a [Row](#row) in-between Cells.
661
+ * You may only need to use Gutters if you're manually building your own
662
+ * sub-grid, or some-such (this should be relatively rare).
663
+ *
664
+ * By default (with no properties specified) it will display at all
665
+ * grid sizes. If you specify the `small`, `medium`, or `large`
666
+ * props then the component will only be shown at those grid sizes.
667
+ */
668
+ class gutter_Gutter extends external_react_["Component"] {
669
+ render() {
670
+ return /*#__PURE__*/external_react_["createElement"](es_MediaLayout, null, ({
671
+ mediaSize,
672
+ mediaSpec
673
+ }) => {
674
+ const spec = mediaSpec[mediaSize];
675
+
676
+ if (!spec) {
677
+ throw new Error(`mediaSpec.${mediaSize} is undefined`);
678
+ }
679
+
680
+ const {
681
+ gutterWidth
682
+ } = spec;
683
+
684
+ if (!queryMatchesSize(this.props.mediaQuery, mediaSize)) {
685
+ return null;
686
+ }
687
+
688
+ return /*#__PURE__*/external_react_["createElement"](es_Strut, {
689
+ size: gutterWidth
690
+ });
691
+ });
692
+ }
693
+
694
+ }
695
+ gutter_Gutter.defaultProps = {
696
+ mediaQuery: "all"
697
+ };
698
+ // CONCATENATED MODULE: ./packages/wonder-blocks-grid/src/components/row.js
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+ /**
707
+ * A Row holds all of the Cells that make up the contents of the grid. A row
708
+ * also provides the margins on the sides and inserts the gutter spacing
709
+ * in-between the cells. Typically this component will hold a [Cell](#cell),
710
+ * but it can also include any elements that could fit in a
711
+ * [flexbox](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox).
712
+ *
713
+ * This component will automatically attempt to insert [Gutters](#gutter)
714
+ * in-between all child elements. Additionally, it'll perform some basic checks
715
+ * to ensure that no impossible layouts are accidentally generated.
716
+ *
717
+ * Typically this component will be used as a child of a [Grid](#grid-1),
718
+ * but it's not a requirement, you can use it as a descendant, as well.
719
+ *
720
+ * By default (with no properties specified) it will display at all
721
+ * grid sizes. If you specify the `small`, `medium`, or `large`
722
+ * props then the component will only be shown at those grid sizes.
723
+ */
724
+ class row_Row extends external_react_["Component"] {
725
+ render() {
726
+ const {
727
+ style,
728
+ children
729
+ } = this.props;
730
+ return /*#__PURE__*/external_react_["createElement"](es_MediaLayout, null, ({
731
+ mediaSize,
732
+ mediaSpec
733
+ }) => {
734
+ const spec = mediaSpec[mediaSize];
735
+
736
+ if (!spec) {
737
+ throw new Error(`mediaSpec.${mediaSize} is undefined`);
738
+ }
739
+
740
+ const {
741
+ marginWidth,
742
+ maxWidth,
743
+ totalColumns
744
+ } = spec;
745
+ const shouldDisplay = queryMatchesSize(this.props.mediaQuery, mediaSize); // Don't render the row if it's been disabled at this size
746
+
747
+ if (!shouldDisplay) {
748
+ return null;
749
+ } // If the contents are a function then we call it with the mediaSize and
750
+ // totalColumns properties and render the return value.
751
+
752
+
753
+ const contents = typeof children === "function" ? children({
754
+ mediaSize,
755
+ totalColumns
756
+ }) : children;
757
+ const filteredContents = external_react_["Children"].toArray(contents).filter( // Flow doesn't let us check .type on a non-null React.Node so
758
+ // we have to cast it to any.
759
+ item => cell_Cell.isClassOf(item) ? cell_Cell.shouldDisplay(item.props, mediaSize) : true) // Intersperse Gutter elements between the cells.
760
+ .reduce((acc, elem, index) => [].concat(acc, [elem, /*#__PURE__*/external_react_["createElement"](gutter_Gutter, {
761
+ key: `gutter-${index}`
762
+ })]), []) // We only want gutters between each cell in the row. The reduce
763
+ // adds a gutter after every cell so we need to remove the last
764
+ // element which is an unnecessary gutteer.
765
+ .slice(0, -1);
766
+ return /*#__PURE__*/external_react_["createElement"](wonder_blocks_core_["View"], {
767
+ style: [util_styles.row, !!maxWidth && util_styles.rowMaxWidth, !!maxWidth && {
768
+ maxWidth
769
+ }, style]
770
+ }, /*#__PURE__*/external_react_["createElement"](es_Strut, {
771
+ size: marginWidth
772
+ }), filteredContents, /*#__PURE__*/external_react_["createElement"](es_Strut, {
773
+ size: marginWidth
774
+ }));
775
+ });
776
+ }
777
+
778
+ }
779
+ row_Row.defaultProps = {
780
+ mediaQuery: "all"
781
+ };
782
+ // CONCATENATED MODULE: ./packages/wonder-blocks-grid/src/index.js
783
+
784
+
785
+
786
+ /***/ })
787
+ /******/ ]);