@khanacademy/wonder-blocks-grid 1.0.38 → 1.0.39

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 CHANGED
@@ -8,25 +8,39 @@ var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
8
8
  var aphrodite = require('aphrodite');
9
9
 
10
10
  function _interopNamespace(e) {
11
- if (e && e.__esModule) return e;
12
- var n = Object.create(null);
13
- if (e) {
14
- Object.keys(e).forEach(function (k) {
15
- if (k !== 'default') {
16
- var d = Object.getOwnPropertyDescriptor(e, k);
17
- Object.defineProperty(n, k, d.get ? d : {
18
- enumerable: true,
19
- get: function () { return e[k]; }
20
- });
21
- }
11
+ if (e && e.__esModule) return e;
12
+ var n = Object.create(null);
13
+ if (e) {
14
+ Object.keys(e).forEach(function (k) {
15
+ if (k !== 'default') {
16
+ var d = Object.getOwnPropertyDescriptor(e, k);
17
+ Object.defineProperty(n, k, d.get ? d : {
18
+ enumerable: true,
19
+ get: function () { return e[k]; }
22
20
  });
23
- }
24
- n["default"] = e;
25
- return Object.freeze(n);
21
+ }
22
+ });
23
+ }
24
+ n["default"] = e;
25
+ return Object.freeze(n);
26
26
  }
27
27
 
28
28
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
29
29
 
30
+ function _setPrototypeOf(o, p) {
31
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
32
+ o.__proto__ = p;
33
+ return o;
34
+ };
35
+ return _setPrototypeOf(o, p);
36
+ }
37
+
38
+ function _inheritsLoose(subClass, superClass) {
39
+ subClass.prototype = Object.create(superClass.prototype);
40
+ subClass.prototype.constructor = subClass;
41
+ _setPrototypeOf(subClass, superClass);
42
+ }
43
+
30
44
  const WIDE_SCREEN = "@media (min-width: 1168px)";
31
45
  const styles = aphrodite.StyleSheet.create({
32
46
  row: {
@@ -56,12 +70,15 @@ const flexBasis = size => {
56
70
  };
57
71
  };
58
72
 
59
- class Cell extends React__namespace.Component {
60
- static isClassOf(instance) {
61
- return instance && instance.type && instance.type.__IS_CELL__;
73
+ let Cell = function (_React$Component) {
74
+ _inheritsLoose(Cell, _React$Component);
75
+ function Cell() {
76
+ return _React$Component.apply(this, arguments) || this;
62
77
  }
63
-
64
- static getCols(props, mediaSize) {
78
+ Cell.isClassOf = function isClassOf(instance) {
79
+ return instance && instance.type && instance.type.__IS_CELL__;
80
+ };
81
+ Cell.getCols = function getCols(props, mediaSize) {
65
82
  if (!props.smallCols && !props.mediumCols && !props.largeCols && !props.cols) {
66
83
  return undefined;
67
84
  } else if (props.smallCols && mediaSize === "small") {
@@ -75,16 +92,14 @@ class Cell extends React__namespace.Component {
75
92
  } else if (props.cols) {
76
93
  return props.cols;
77
94
  }
78
-
79
95
  return null;
80
- }
81
-
82
- static shouldDisplay(props, mediaSize) {
96
+ };
97
+ Cell.shouldDisplay = function shouldDisplay(props, mediaSize) {
83
98
  const cols = Cell.getCols(props, mediaSize);
84
99
  return cols !== null && cols !== 0;
85
- }
86
-
87
- render() {
100
+ };
101
+ var _proto = Cell.prototype;
102
+ _proto.render = function render() {
88
103
  const {
89
104
  children,
90
105
  style
@@ -94,26 +109,21 @@ class Cell extends React__namespace.Component {
94
109
  mediaSpec
95
110
  }) => {
96
111
  const spec = mediaSpec[mediaSize];
97
-
98
112
  if (!spec) {
99
113
  throw new Error(`mediaSpec.${mediaSize} is undefined`);
100
114
  }
101
-
102
115
  const {
103
116
  totalColumns,
104
117
  gutterWidth,
105
118
  marginWidth
106
119
  } = spec;
107
120
  const cols = Cell.getCols(this.props, mediaSize);
108
-
109
121
  if (cols === undefined || cols === null || cols === 0) {
110
122
  return null;
111
123
  }
112
-
113
124
  if (cols > totalColumns) {
114
125
  throw new Error(`Specified columns ${cols} is greater than the maximum ` + `${totalColumns} at the ${mediaSize} grid size.`);
115
126
  }
116
-
117
127
  const contentWidth = `(100% - ${gutterWidth * (totalColumns - 1)}px - ${marginWidth * 2}px)`;
118
128
  const calcWidth = `calc(${contentWidth} * ${cols / totalColumns} + ${gutterWidth * (cols - 1)}px)`;
119
129
  const contents = typeof children === "function" ? children({
@@ -125,9 +135,9 @@ class Cell extends React__namespace.Component {
125
135
  style: [styles.cellFixed, flexBasis(calcWidth), style]
126
136
  }, contents);
127
137
  });
128
- }
129
-
130
- }
138
+ };
139
+ return Cell;
140
+ }(React__namespace.Component);
131
141
  Cell.defaultProps = {
132
142
  smallCols: 0,
133
143
  mediumCols: 0,
@@ -136,39 +146,45 @@ Cell.defaultProps = {
136
146
  };
137
147
  Cell.__IS_CELL__ = true;
138
148
 
139
- class Gutter extends React__namespace.Component {
140
- render() {
149
+ let Gutter = function (_React$Component) {
150
+ _inheritsLoose(Gutter, _React$Component);
151
+ function Gutter() {
152
+ return _React$Component.apply(this, arguments) || this;
153
+ }
154
+ var _proto = Gutter.prototype;
155
+ _proto.render = function render() {
141
156
  return React__namespace.createElement(wonderBlocksLayout.MediaLayout, null, ({
142
157
  mediaSize,
143
158
  mediaSpec
144
159
  }) => {
145
160
  const spec = mediaSpec[mediaSize];
146
-
147
161
  if (!spec) {
148
162
  throw new Error(`mediaSpec.${mediaSize} is undefined`);
149
163
  }
150
-
151
164
  const {
152
165
  gutterWidth
153
166
  } = spec;
154
-
155
167
  if (!wonderBlocksLayout.queryMatchesSize(this.props.mediaQuery, mediaSize)) {
156
168
  return null;
157
169
  }
158
-
159
170
  return React__namespace.createElement(wonderBlocksLayout.Strut, {
160
171
  size: gutterWidth
161
172
  });
162
173
  });
163
- }
164
-
165
- }
174
+ };
175
+ return Gutter;
176
+ }(React__namespace.Component);
166
177
  Gutter.defaultProps = {
167
178
  mediaQuery: "all"
168
179
  };
169
180
 
170
- class Row extends React__namespace.Component {
171
- render() {
181
+ let Row = function (_React$Component) {
182
+ _inheritsLoose(Row, _React$Component);
183
+ function Row() {
184
+ return _React$Component.apply(this, arguments) || this;
185
+ }
186
+ var _proto = Row.prototype;
187
+ _proto.render = function render() {
172
188
  const {
173
189
  style,
174
190
  children
@@ -178,22 +194,18 @@ class Row extends React__namespace.Component {
178
194
  mediaSpec
179
195
  }) => {
180
196
  const spec = mediaSpec[mediaSize];
181
-
182
197
  if (!spec) {
183
198
  throw new Error(`mediaSpec.${mediaSize} is undefined`);
184
199
  }
185
-
186
200
  const {
187
201
  marginWidth,
188
202
  maxWidth,
189
203
  totalColumns
190
204
  } = spec;
191
205
  const shouldDisplay = wonderBlocksLayout.queryMatchesSize(this.props.mediaQuery, mediaSize);
192
-
193
206
  if (!shouldDisplay) {
194
207
  return null;
195
208
  }
196
-
197
209
  const contents = typeof children === "function" ? children({
198
210
  mediaSize,
199
211
  totalColumns
@@ -211,9 +223,9 @@ class Row extends React__namespace.Component {
211
223
  size: marginWidth
212
224
  }));
213
225
  });
214
- }
215
-
216
- }
226
+ };
227
+ return Row;
228
+ }(React__namespace.Component);
217
229
  Row.defaultProps = {
218
230
  mediaQuery: "all"
219
231
  };
@@ -1,2 +1,9 @@
1
- // @flow
2
- export * from "../src/index";
1
+ /**
2
+ * Flowtype definitions for index
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ declare export { default as Cell } from "./components/cell";
9
+ declare export { default as Row } from "./components/row";
@@ -0,0 +1,3 @@
1
+ import type { StyleDeclaration } from "aphrodite";
2
+ declare const styles: StyleDeclaration;
3
+ export default styles;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Flowtype definitions for styles
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import type { StyleDeclaration } from "aphrodite";
9
+ declare var styles: StyleDeclaration;
10
+ declare export default typeof styles;
@@ -0,0 +1,2 @@
1
+ import type { StyleType } from "@khanacademy/wonder-blocks-core";
2
+ export declare const flexBasis: (size: number | string) => StyleType;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Flowtype definitions for utils
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import type { StyleType } from "@khanacademy/wonder-blocks-core";
9
+ declare export var flexBasis: (size: number | string) => StyleType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-grid",
3
- "version": "1.0.38",
3
+ "version": "1.0.39",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -8,7 +8,7 @@
8
8
  "description": "Grid components for Wonder Blocks design system.",
9
9
  "main": "dist/index.js",
10
10
  "module": "dist/es/index.js",
11
- "source": "src/index.js",
11
+ "types": "dist/index.d.ts",
12
12
  "scripts": {
13
13
  "test": "echo \"Error: no test specified\" && exit 1"
14
14
  },
@@ -16,16 +16,16 @@
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.18.6",
19
- "@khanacademy/wonder-blocks-color": "^1.2.1",
20
- "@khanacademy/wonder-blocks-core": "^4.7.0",
21
- "@khanacademy/wonder-blocks-layout": "^1.4.16",
22
- "@khanacademy/wonder-blocks-spacing": "^3.0.5"
19
+ "@khanacademy/wonder-blocks-color": "^1.2.2",
20
+ "@khanacademy/wonder-blocks-core": "^4.8.0",
21
+ "@khanacademy/wonder-blocks-layout": "^1.4.17",
22
+ "@khanacademy/wonder-blocks-spacing": "^3.0.6"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "aphrodite": "^1.2.5",
26
26
  "react": "16.14.0"
27
27
  },
28
28
  "devDependencies": {
29
- "wb-dev-build-settings": "^0.7.1"
29
+ "wb-dev-build-settings": "^0.7.2"
30
30
  }
31
31
  }
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  import * as React from "react";
4
2
  import {render} from "@testing-library/react";
5
3
 
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import * as React from "react";
3
2
 
4
3
  import {MediaLayout} from "@khanacademy/wonder-blocks-layout";
@@ -9,42 +8,37 @@ import type {StyleType} from "@khanacademy/wonder-blocks-core";
9
8
  import styles from "../util/styles";
10
9
  import {flexBasis} from "../util/utils";
11
10
 
12
- type Props = {|
11
+ type Props = {
13
12
  /** The number of columns this cell should span on a Small Grid. */
14
- smallCols: number,
15
-
13
+ smallCols: number;
16
14
  /** The number of columns this cell should span on a Medium Grid. */
17
- mediumCols: number,
18
-
15
+ mediumCols: number;
19
16
  /** The number of columns this cell should span on a Large Grid. */
20
- largeCols: number,
21
-
17
+ largeCols: number;
22
18
  /** The number of columns this should should span by default. */
23
- cols: number | ((mediaSize: MediaSize) => number),
24
-
19
+ cols: number | ((mediaSize: MediaSize) => number);
25
20
  /**
26
21
  * The child components to populate inside the cell. Can also accept a
27
22
  * function which receives the `mediaSize`, `totalColumns`, and cell
28
23
  * `width` and should return some React Nodes to render.
29
24
  */
30
25
  children:
31
- | React.Node
32
- | (({|
33
- mediaSize: MediaSize,
34
- totalColumns: number,
35
- cols: number,
36
- |}) => React.Node),
37
-
26
+ | React.ReactNode
27
+ | ((arg1: {
28
+ mediaSize: MediaSize;
29
+ totalColumns: number;
30
+ cols: number;
31
+ }) => React.ReactElement);
38
32
  /** The styling to apply to the cell. */
39
- style?: StyleType,
40
- |};
33
+ style?: StyleType;
34
+ };
41
35
 
42
- type DefaultProps = {|
43
- smallCols: $PropertyType<Props, "smallCols">,
44
- mediumCols: $PropertyType<Props, "mediumCols">,
45
- largeCols: $PropertyType<Props, "largeCols">,
46
- cols: $PropertyType<Props, "cols">,
47
- |};
36
+ type DefaultProps = {
37
+ smallCols: Props["smallCols"];
38
+ mediumCols: Props["mediumCols"];
39
+ largeCols: Props["largeCols"];
40
+ cols: Props["cols"];
41
+ };
48
42
 
49
43
  /**
50
44
  * A Cell is a container whose width is set based on the width of the
@@ -63,11 +57,15 @@ type DefaultProps = {|
63
57
  * using the specified column width.
64
58
  */
65
59
  export default class Cell extends React.Component<Props> {
66
- static isClassOf(instance: React.Element<any>): boolean {
60
+ static isClassOf(instance: React.ReactElement<any>): boolean {
61
+ // @ts-expect-error [FEI-5019] - TS2339 - Property '__IS_CELL__' does not exist on type 'string | JSXElementConstructor<any>'.
67
62
  return instance && instance.type && instance.type.__IS_CELL__;
68
63
  }
69
64
 
70
- static getCols(props: Props, mediaSize: MediaSize): ?number {
65
+ static getCols(
66
+ props: Props,
67
+ mediaSize: MediaSize,
68
+ ): number | null | undefined {
71
69
  // If no option was specified then we just return undefined,
72
70
  // components may handle this case differently.
73
71
  // We go through all the ways in which a fixed width can be
@@ -110,13 +108,14 @@ export default class Cell extends React.Component<Props> {
110
108
  cols: 0,
111
109
  };
112
110
 
113
- static __IS_CELL__: boolean = true;
111
+ static __IS_CELL__ = true;
114
112
 
115
- render(): React.Node {
113
+ render(): React.ReactElement | null {
116
114
  const {children, style} = this.props;
117
115
 
118
116
  return (
119
117
  <MediaLayout>
118
+ {/* @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call. */}
120
119
  {({mediaSize, mediaSpec}) => {
121
120
  const spec = mediaSpec[mediaSize];
122
121
  if (!spec) {
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import * as React from "react";
3
2
  import {
4
3
  MediaLayout,
@@ -7,16 +6,16 @@ import {
7
6
  } from "@khanacademy/wonder-blocks-layout";
8
7
  import type {MediaQuery} from "@khanacademy/wonder-blocks-layout";
9
8
 
10
- type Props = {|
9
+ type Props = {
11
10
  /**
12
11
  * Which media should this cell be renderer on. Defaults to all.
13
12
  */
14
- mediaQuery: MediaQuery,
15
- |};
13
+ mediaQuery: MediaQuery;
14
+ };
16
15
 
17
- type DefaultProps = {|
18
- mediaQuery: $PropertyType<Props, "mediaQuery">,
19
- |};
16
+ type DefaultProps = {
17
+ mediaQuery: Props["mediaQuery"];
18
+ };
20
19
 
21
20
  /**
22
21
  * Gutter is a component whose width is set based on the size of grid currently
@@ -36,9 +35,10 @@ export default class Gutter extends React.Component<Props> {
36
35
  mediaQuery: "all",
37
36
  };
38
37
 
39
- render(): React.Node {
38
+ render(): React.ReactElement | null {
40
39
  return (
41
40
  <MediaLayout>
41
+ {/* @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call. */}
42
42
  {({mediaSize, mediaSpec}) => {
43
43
  const spec = mediaSpec[mediaSize];
44
44
  if (!spec) {
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import * as React from "react";
3
2
  import {View} from "@khanacademy/wonder-blocks-core";
4
3
  import {
@@ -13,12 +12,11 @@ import styles from "../util/styles";
13
12
  import Gutter from "./gutter";
14
13
  import Cell from "./cell";
15
14
 
16
- type Props = {|
15
+ type Props = {
17
16
  /**
18
17
  * Which media should this cell be renderer on. Defaults to all.
19
18
  */
20
- mediaQuery: MediaQuery,
21
-
19
+ mediaQuery: MediaQuery;
22
20
  /**
23
21
  * The child components to populate inside the row. Typically this will be
24
22
  * a [Cell](#cell), but it can also include any elements
@@ -27,19 +25,18 @@ type Props = {|
27
25
  * `totalColumns` and should return some React Nodes to render.
28
26
  */
29
27
  children:
30
- | React.Node
31
- | (({|
32
- mediaSize: MediaSize,
33
- totalColumns: number,
34
- |}) => React.Node),
35
-
28
+ | React.ReactNode
29
+ | ((arg1: {
30
+ mediaSize: MediaSize;
31
+ totalColumns: number;
32
+ }) => React.ReactElement);
36
33
  /** The styling to apply to the row. */
37
- style?: StyleType,
38
- |};
34
+ style?: StyleType;
35
+ };
39
36
 
40
- type DefaultProps = {|
41
- mediaQuery: $PropertyType<Props, "mediaQuery">,
42
- |};
37
+ type DefaultProps = {
38
+ mediaQuery: Props["mediaQuery"];
39
+ };
43
40
 
44
41
  /**
45
42
  * A Row holds all of the Cells that make up the contents of the grid. A row
@@ -64,11 +61,12 @@ export default class Row extends React.Component<Props> {
64
61
  mediaQuery: "all",
65
62
  };
66
63
 
67
- render(): React.Node {
64
+ render(): React.ReactElement | null {
68
65
  const {style, children} = this.props;
69
66
 
70
67
  return (
71
68
  <MediaLayout>
69
+ {/* @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call. */}
72
70
  {({mediaSize, mediaSpec}) => {
73
71
  const spec = mediaSpec[mediaSize];
74
72
  if (!spec) {
@@ -93,34 +91,34 @@ export default class Row extends React.Component<Props> {
93
91
  ? children({mediaSize, totalColumns})
94
92
  : children;
95
93
 
96
- const filteredContents: Array<React.Node> =
97
- (React.Children.toArray(contents): Array<React.Node>)
98
- // Go through all of the contents and pre-emptively remove anything
99
- // that shouldn't be rendered.
100
- .filter(
101
- // Flow doesn't let us check .type on a non-null React.Node so
102
- // we have to cast it to any.
103
- (item: any) =>
104
- Cell.isClassOf(item)
105
- ? Cell.shouldDisplay(
106
- item.props,
107
- mediaSize,
108
- )
109
- : true,
110
- )
111
- // Intersperse Gutter elements between the cells.
112
- .reduce(
113
- (acc, elem, index) => [
114
- ...acc,
115
- elem,
116
- <Gutter key={`gutter-${index}`} />,
117
- ],
118
- [],
119
- )
120
- // We only want gutters between each cell in the row. The reduce
121
- // adds a gutter after every cell so we need to remove the last
122
- // element which is an unnecessary gutteer.
123
- .slice(0, -1);
94
+ const filteredContents: Array<React.ReactNode> = (
95
+ React.Children.toArray(
96
+ contents,
97
+ ) as Array<React.ReactNode>
98
+ )
99
+ // Go through all of the contents and pre-emptively remove anything
100
+ // that shouldn't be rendered.
101
+ .filter(
102
+ // TypeScript doesn't let us check .type on a non-null React.Node so
103
+ // we have to cast it to any.
104
+ (item: any) =>
105
+ Cell.isClassOf(item)
106
+ ? Cell.shouldDisplay(item.props, mediaSize)
107
+ : true,
108
+ )
109
+ // Intersperse Gutter elements between the cells.
110
+ .reduce<Array<any>>(
111
+ (acc, elem, index) => [
112
+ ...acc,
113
+ elem,
114
+ <Gutter key={`gutter-${index}`} />,
115
+ ],
116
+ [],
117
+ )
118
+ // We only want gutters between each cell in the row. The reduce
119
+ // adds a gutter after every cell so we need to remove the last
120
+ // element which is an unnecessary gutteer.
121
+ .slice(0, -1);
124
122
 
125
123
  return (
126
124
  <View
@@ -1,3 +1,2 @@
1
- // @flow
2
1
  export {default as Cell} from "./components/cell";
3
2
  export {default as Row} from "./components/row";
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import {StyleSheet} from "aphrodite";
3
2
  import type {StyleDeclaration} from "aphrodite";
4
3
 
@@ -1,4 +1,3 @@
1
- // @flow
2
1
  import type {StyleType} from "@khanacademy/wonder-blocks-core";
3
2
 
4
3
  export const flexBasis = (size: number | string): StyleType => {
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "exclude": ["dist"],
3
+ "extends": "../tsconfig-shared.json",
4
+ "compilerOptions": {
5
+ "outDir": "./dist",
6
+ "rootDir": "src",
7
+ },
8
+ "references": [
9
+ {"path": "../wonder-blocks-color"},
10
+ {"path": "../wonder-blocks-core"},
11
+ {"path": "../wonder-blocks-layout"},
12
+ {"path": "../wonder-blocks-spacing"},
13
+ ]
14
+ }