@khanacademy/wonder-blocks-grid 1.0.29 → 1.0.32

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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @khanacademy/wonder-blocks-grid
2
2
 
3
+ ## 1.0.32
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [34c7aacb]
8
+ - @khanacademy/wonder-blocks-color@1.2.0
9
+
10
+ ## 1.0.31
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [5f4a4297]
15
+ - Updated dependencies [2b96fd59]
16
+ - @khanacademy/wonder-blocks-core@4.3.2
17
+
18
+ ## 1.0.30
19
+
20
+ ### Patch Changes
21
+
22
+ - @khanacademy/wonder-blocks-core@4.3.1
23
+
3
24
  ## 1.0.29
4
25
 
5
26
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -32,32 +32,12 @@ const flexBasis = size => {
32
32
  };
33
33
  };
34
34
 
35
- /**
36
- * A Cell is a container whose width is set based on the width of the
37
- * specified columns at the current grid size. You will specify the number
38
- * of columns that you want this component to span at each grid size.
39
- * This component should only be used as a child of a [Row](#row).
40
- *
41
- * This component renders a [View](#view) that
42
- * uses Flex Box and has a [flex-basis](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-basis)
43
- * of the specified "width" and [flex-shrink](https://developer.mozilla.org/en-US/docs/Web/CSS/flex-shrink)
44
- * of 0.
45
- *
46
- * By default (with no properties specified) it will display at all
47
- * grid sizes. If you specify the `smallCols`, `mediumCols`, `largeCols`, or
48
- * `cols` props then the component will only be shown at those grid sizes and
49
- * using the specified column width.
50
- */
51
35
  class Cell extends React.Component {
52
36
  static isClassOf(instance) {
53
37
  return instance && instance.type && instance.type.__IS_CELL__;
54
38
  }
55
39
 
56
40
  static getCols(props, mediaSize) {
57
- // If no option was specified then we just return undefined,
58
- // components may handle this case differently.
59
- // We go through all the ways in which a fixed width can be
60
- // specified and find the one that matches our current grid size.
61
41
  if (!props.smallCols && !props.mediumCols && !props.largeCols && !props.cols) {
62
42
  return undefined;
63
43
  } else if (props.smallCols && mediaSize === "small") {
@@ -70,14 +50,10 @@ class Cell extends React.Component {
70
50
  return props.cols(mediaSize);
71
51
  } else if (props.cols) {
72
52
  return props.cols;
73
- } // If nothing applies then we return null (usually resulting
74
- // in the component not being rendered)
75
-
53
+ }
76
54
 
77
55
  return null;
78
- } // HACK(kevinb): we use a stack method here because we can't get a ref to
79
- // each cell in a row without cloning them all.
80
-
56
+ }
81
57
 
82
58
  static shouldDisplay(props, mediaSize) {
83
59
  const cols = Cell.getCols(props, mediaSize);
@@ -89,7 +65,7 @@ class Cell extends React.Component {
89
65
  children,
90
66
  style
91
67
  } = this.props;
92
- return /*#__PURE__*/React.createElement(MediaLayout, null, ({
68
+ return React.createElement(MediaLayout, null, ({
93
69
  mediaSize,
94
70
  mediaSpec
95
71
  }) => {
@@ -97,15 +73,14 @@ class Cell extends React.Component {
97
73
 
98
74
  if (!spec) {
99
75
  throw new Error(`mediaSpec.${mediaSize} is undefined`);
100
- } // Get the settings for this particular size of grid
101
-
76
+ }
102
77
 
103
78
  const {
104
79
  totalColumns,
105
80
  gutterWidth,
106
81
  marginWidth
107
82
  } = spec;
108
- const cols = Cell.getCols(this.props, mediaSize); // If no columns are specified then we just don't render this cell
83
+ const cols = Cell.getCols(this.props, mediaSize);
109
84
 
110
85
  if (cols === undefined || cols === null || cols === 0) {
111
86
  return null;
@@ -113,31 +88,16 @@ class Cell extends React.Component {
113
88
 
114
89
  if (cols > totalColumns) {
115
90
  throw new Error(`Specified columns ${cols} is greater than the maximum ` + `${totalColumns} at the ${mediaSize} grid size.`);
116
- } // We need to start by calculating the total width of all the "content"
117
- // We do this by starting with the full width (100%) and then
118
- // subtracting all of the gutter spaces inbetween the cells
119
- // (gutterWidth * (totalColumns - 1)) and the width of the two margins
120
- // (marginWidth * 2).
121
-
122
-
123
- const contentWidth = `(100% - ${gutterWidth * (totalColumns - 1)}px - ${marginWidth * 2}px)`; // Now that we have the full width we can calculate the width of this
124
- // particular cell by multiplying the full width (allCellWidth) by
125
- // the ratio of this cell (cols / totalColumns). But we then need to
126
- // add back in the missing gutter widths:
127
- // (gutterWidth * (cols - 1)). This gives us to full width of
128
- // this particular cell.
129
-
130
- const calcWidth = `calc(${contentWidth} * ${cols / totalColumns} + ${gutterWidth * (cols - 1)}px)`; // If the contents are a function then we call it with the mediaSize,
131
- // totalColumns, and cols properties and render the return value.
91
+ }
132
92
 
93
+ const contentWidth = `(100% - ${gutterWidth * (totalColumns - 1)}px - ${marginWidth * 2}px)`;
94
+ const calcWidth = `calc(${contentWidth} * ${cols / totalColumns} + ${gutterWidth * (cols - 1)}px)`;
133
95
  const contents = typeof children === "function" ? children({
134
96
  mediaSize,
135
97
  totalColumns,
136
98
  cols
137
- }) : children; // Render a fixed-width cell (flex-basis: size, flex-shrink: 0)
138
- // that matches the intended width of the cell
139
-
140
- return /*#__PURE__*/React.createElement(View, {
99
+ }) : children;
100
+ return React.createElement(View, {
141
101
  style: [styles.cellFixed, flexBasis(calcWidth), style]
142
102
  }, contents);
143
103
  });
@@ -152,22 +112,9 @@ Cell.defaultProps = {
152
112
  };
153
113
  Cell.__IS_CELL__ = true;
154
114
 
155
- /**
156
- * Gutter is a component whose width is set based on the size of grid currently
157
- * being displayed. Used for spacing out cells from each other. The gutter
158
- * itself doesn't hold any content, it just spaces it out.
159
- *
160
- * Gutters are inserted automatically inside of a [Row](#row) in-between Cells.
161
- * You may only need to use Gutters if you're manually building your own
162
- * sub-grid, or some-such (this should be relatively rare).
163
- *
164
- * By default (with no properties specified) it will display at all
165
- * grid sizes. If you specify the `small`, `medium`, or `large`
166
- * props then the component will only be shown at those grid sizes.
167
- */
168
115
  class Gutter extends React.Component {
169
116
  render() {
170
- return /*#__PURE__*/React.createElement(MediaLayout, null, ({
117
+ return React.createElement(MediaLayout, null, ({
171
118
  mediaSize,
172
119
  mediaSpec
173
120
  }) => {
@@ -185,7 +132,7 @@ class Gutter extends React.Component {
185
132
  return null;
186
133
  }
187
134
 
188
- return /*#__PURE__*/React.createElement(Strut, {
135
+ return React.createElement(Strut, {
189
136
  size: gutterWidth
190
137
  });
191
138
  });
@@ -196,31 +143,13 @@ Gutter.defaultProps = {
196
143
  mediaQuery: "all"
197
144
  };
198
145
 
199
- /**
200
- * A Row holds all of the Cells that make up the contents of the grid. A row
201
- * also provides the margins on the sides and inserts the gutter spacing
202
- * in-between the cells. Typically this component will hold a [Cell](#cell),
203
- * but it can also include any elements that could fit in a
204
- * [flexbox](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox).
205
- *
206
- * This component will automatically attempt to insert [Gutters](#gutter)
207
- * in-between all child elements. Additionally, it'll perform some basic checks
208
- * to ensure that no impossible layouts are accidentally generated.
209
- *
210
- * Typically this component will be used as a child of a [Grid](#grid-1),
211
- * but it's not a requirement, you can use it as a descendant, as well.
212
- *
213
- * By default (with no properties specified) it will display at all
214
- * grid sizes. If you specify the `small`, `medium`, or `large`
215
- * props then the component will only be shown at those grid sizes.
216
- */
217
146
  class Row extends React.Component {
218
147
  render() {
219
148
  const {
220
149
  style,
221
150
  children
222
151
  } = this.props;
223
- return /*#__PURE__*/React.createElement(MediaLayout, null, ({
152
+ return React.createElement(MediaLayout, null, ({
224
153
  mediaSize,
225
154
  mediaSpec
226
155
  }) => {
@@ -235,36 +164,26 @@ class Row extends React.Component {
235
164
  maxWidth,
236
165
  totalColumns
237
166
  } = spec;
238
- const shouldDisplay = queryMatchesSize(this.props.mediaQuery, mediaSize); // Don't render the row if it's been disabled at this size
167
+ const shouldDisplay = queryMatchesSize(this.props.mediaQuery, mediaSize);
239
168
 
240
169
  if (!shouldDisplay) {
241
170
  return null;
242
- } // If the contents are a function then we call it with the mediaSize and
243
- // totalColumns properties and render the return value.
244
-
171
+ }
245
172
 
246
173
  const contents = typeof children === "function" ? children({
247
174
  mediaSize,
248
175
  totalColumns
249
176
  }) : children;
250
- const filteredContents = React.Children.toArray(contents) // Go through all of the contents and pre-emptively remove anything
251
- // that shouldn't be rendered.
252
- .filter( // Flow doesn't let us check .type on a non-null React.Node so
253
- // we have to cast it to any.
254
- item => Cell.isClassOf(item) ? Cell.shouldDisplay(item.props, mediaSize) : true) // Intersperse Gutter elements between the cells.
255
- .reduce((acc, elem, index) => [].concat(acc, [elem, /*#__PURE__*/React.createElement(Gutter, {
177
+ const filteredContents = React.Children.toArray(contents).filter(item => Cell.isClassOf(item) ? Cell.shouldDisplay(item.props, mediaSize) : true).reduce((acc, elem, index) => [].concat(acc, [elem, React.createElement(Gutter, {
256
178
  key: `gutter-${index}`
257
- })]), []) // We only want gutters between each cell in the row. The reduce
258
- // adds a gutter after every cell so we need to remove the last
259
- // element which is an unnecessary gutteer.
260
- .slice(0, -1);
261
- return /*#__PURE__*/React.createElement(View, {
179
+ })]), []).slice(0, -1);
180
+ return React.createElement(View, {
262
181
  style: [styles.row, !!maxWidth && styles.rowMaxWidth, !!maxWidth && {
263
182
  maxWidth
264
183
  }, style]
265
- }, /*#__PURE__*/React.createElement(Strut, {
184
+ }, React.createElement(Strut, {
266
185
  size: marginWidth
267
- }), filteredContents, /*#__PURE__*/React.createElement(Strut, {
186
+ }), filteredContents, React.createElement(Strut, {
268
187
  size: marginWidth
269
188
  }));
270
189
  });
package/dist/index.js CHANGED
@@ -538,7 +538,7 @@ function (module, __webpack_exports__, __webpack_require__) {
538
538
  "b"]).map(spec => spec.query), Object.values(_util_specs_js__WEBPACK_IMPORTED_MODULE_2__[
539
539
  /* MEDIA_MODAL_SPEC */
540
540
  "c"]).map(spec => spec.query));
541
- const mediaQueryLists = {}; // eslint-disable-next-line flowtype/require-exact-type
541
+ const mediaQueryLists = {}; // eslint-disable-next-line ft-flow/require-exact-type
542
542
  // If for some reason we're not able to resolve the current media size we
543
543
  // fall back to this state.
544
544
 
@@ -692,6 +692,32 @@ function (module, __webpack_exports__, __webpack_require__) {
692
692
 
693
693
  } // gen-snapshot-tests.js only understands `export default class ...`
694
694
 
695
+ /**
696
+ * ***NOTE: The MediaLayout component is being deprecated. Do not use this!!***
697
+ *
698
+ * MediaLayout is a container component that accepts a `styleSheets` object,
699
+ * whose keys are media sizes. It listens for changes to the current media
700
+ * size and passes the current `mediaSize`, `mediaSpec`, and `styles` to
701
+ * `children`, which is a render function taking those three values as an
702
+ * object.
703
+ *
704
+ * Valid keys for the `styleSheets` object are (in order of precedence):
705
+ * - `small`, `medium`, `large`
706
+ * - `mdOrSmaller`, `mdOrLarger`
707
+ * - `all`
708
+ *
709
+ * `MediaLayout` will merge style rules from multiple styles that match the
710
+ * current media query, e.g. `"(min-width: 1024px)"`.
711
+ *
712
+ * The `mediaSpec` is an object with one or more of the following keys:
713
+ * `small`, `medium`, or `large`. Each value contains the following data:
714
+ * - `query: string` e.g. "(min-width: 1024px)"
715
+ * - `totalColumns: number`
716
+ * - `gutterWidth: number`
717
+ * - `marginWidth: number`
718
+ * - `maxWidth: number`
719
+ */
720
+
695
721
 
696
722
  class MediaLayout extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
697
723
  render() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-grid",
3
- "version": "1.0.29",
3
+ "version": "1.0.32",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,9 +15,9 @@
15
15
  "author": "",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
- "@babel/runtime": "^7.16.3",
19
- "@khanacademy/wonder-blocks-color": "^1.1.20",
20
- "@khanacademy/wonder-blocks-core": "^4.3.0",
18
+ "@babel/runtime": "^7.18.6",
19
+ "@khanacademy/wonder-blocks-color": "^1.2.0",
20
+ "@khanacademy/wonder-blocks-core": "^4.3.2",
21
21
  "@khanacademy/wonder-blocks-spacing": "^3.0.5"
22
22
  },
23
23
  "peerDependencies": {
@@ -25,6 +25,6 @@
25
25
  "react": "16.14.0"
26
26
  },
27
27
  "devDependencies": {
28
- "wb-dev-build-settings": "^0.3.0"
28
+ "wb-dev-build-settings": "^0.4.0"
29
29
  }
30
30
  }
@@ -552,7 +552,7 @@ exports[`wonder-blocks-grid example 2 1`] = `
552
552
  "margin": "0 auto",
553
553
  },
554
554
  "alignItems": "center",
555
- "background": "#0a2a66",
555
+ "background": "#0b2149",
556
556
  "borderBottom": "1px solid rgba(255,255,255,0.64)",
557
557
  "borderStyle": "solid",
558
558
  "borderWidth": 0,
@@ -632,7 +632,7 @@ exports[`wonder-blocks-grid example 2 1`] = `
632
632
  "margin": "0 auto",
633
633
  },
634
634
  "alignItems": "center",
635
- "background": "#0a2a66",
635
+ "background": "#0b2149",
636
636
  "borderStyle": "solid",
637
637
  "borderWidth": 0,
638
638
  "boxSizing": "border-box",