@khanacademy/wonder-blocks-grid 1.0.35 → 1.0.37
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 +15 -0
- package/dist/index.js +222 -0
- package/dist/index.js.flow +2 -0
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-grid
|
|
2
2
|
|
|
3
|
+
## 1.0.37
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 496119f2: Cleanup WB interdependencies
|
|
8
|
+
- Updated dependencies [496119f2]
|
|
9
|
+
- @khanacademy/wonder-blocks-core@4.6.2
|
|
10
|
+
- @khanacademy/wonder-blocks-layout@1.4.15
|
|
11
|
+
|
|
12
|
+
## 1.0.36
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- @khanacademy/wonder-blocks-core@4.6.1
|
|
17
|
+
|
|
3
18
|
## 1.0.35
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var wonderBlocksLayout = require('@khanacademy/wonder-blocks-layout');
|
|
7
|
+
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
8
|
+
var aphrodite = require('aphrodite');
|
|
9
|
+
|
|
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
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n["default"] = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
|
+
|
|
30
|
+
const WIDE_SCREEN = "@media (min-width: 1168px)";
|
|
31
|
+
const styles = aphrodite.StyleSheet.create({
|
|
32
|
+
row: {
|
|
33
|
+
flexDirection: "row",
|
|
34
|
+
alignItems: "center",
|
|
35
|
+
width: "100%"
|
|
36
|
+
},
|
|
37
|
+
rowMaxWidth: {
|
|
38
|
+
[WIDE_SCREEN]: {
|
|
39
|
+
margin: "0 auto"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
cellGrow: {
|
|
43
|
+
flexGrow: 1
|
|
44
|
+
},
|
|
45
|
+
cellFixed: {
|
|
46
|
+
flexShrink: 0
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const flexBasis = size => {
|
|
51
|
+
return {
|
|
52
|
+
MsFlexBasis: size,
|
|
53
|
+
MsFlexPreferredSize: size,
|
|
54
|
+
WebkitFlexBasis: size,
|
|
55
|
+
flexBasis: size
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
class Cell extends React__namespace.Component {
|
|
60
|
+
static isClassOf(instance) {
|
|
61
|
+
return instance && instance.type && instance.type.__IS_CELL__;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static getCols(props, mediaSize) {
|
|
65
|
+
if (!props.smallCols && !props.mediumCols && !props.largeCols && !props.cols) {
|
|
66
|
+
return undefined;
|
|
67
|
+
} else if (props.smallCols && mediaSize === "small") {
|
|
68
|
+
return props.smallCols;
|
|
69
|
+
} else if (props.mediumCols && mediaSize === "medium") {
|
|
70
|
+
return props.mediumCols;
|
|
71
|
+
} else if (props.largeCols && mediaSize === "large") {
|
|
72
|
+
return props.largeCols;
|
|
73
|
+
} else if (typeof props.cols === "function") {
|
|
74
|
+
return props.cols(mediaSize);
|
|
75
|
+
} else if (props.cols) {
|
|
76
|
+
return props.cols;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static shouldDisplay(props, mediaSize) {
|
|
83
|
+
const cols = Cell.getCols(props, mediaSize);
|
|
84
|
+
return cols !== null && cols !== 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
render() {
|
|
88
|
+
const {
|
|
89
|
+
children,
|
|
90
|
+
style
|
|
91
|
+
} = this.props;
|
|
92
|
+
return React__namespace.createElement(wonderBlocksLayout.MediaLayout, null, ({
|
|
93
|
+
mediaSize,
|
|
94
|
+
mediaSpec
|
|
95
|
+
}) => {
|
|
96
|
+
const spec = mediaSpec[mediaSize];
|
|
97
|
+
|
|
98
|
+
if (!spec) {
|
|
99
|
+
throw new Error(`mediaSpec.${mediaSize} is undefined`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const {
|
|
103
|
+
totalColumns,
|
|
104
|
+
gutterWidth,
|
|
105
|
+
marginWidth
|
|
106
|
+
} = spec;
|
|
107
|
+
const cols = Cell.getCols(this.props, mediaSize);
|
|
108
|
+
|
|
109
|
+
if (cols === undefined || cols === null || cols === 0) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (cols > totalColumns) {
|
|
114
|
+
throw new Error(`Specified columns ${cols} is greater than the maximum ` + `${totalColumns} at the ${mediaSize} grid size.`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const contentWidth = `(100% - ${gutterWidth * (totalColumns - 1)}px - ${marginWidth * 2}px)`;
|
|
118
|
+
const calcWidth = `calc(${contentWidth} * ${cols / totalColumns} + ${gutterWidth * (cols - 1)}px)`;
|
|
119
|
+
const contents = typeof children === "function" ? children({
|
|
120
|
+
mediaSize,
|
|
121
|
+
totalColumns,
|
|
122
|
+
cols
|
|
123
|
+
}) : children;
|
|
124
|
+
return React__namespace.createElement(wonderBlocksCore.View, {
|
|
125
|
+
style: [styles.cellFixed, flexBasis(calcWidth), style]
|
|
126
|
+
}, contents);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
Cell.defaultProps = {
|
|
132
|
+
smallCols: 0,
|
|
133
|
+
mediumCols: 0,
|
|
134
|
+
largeCols: 0,
|
|
135
|
+
cols: 0
|
|
136
|
+
};
|
|
137
|
+
Cell.__IS_CELL__ = true;
|
|
138
|
+
|
|
139
|
+
class Gutter extends React__namespace.Component {
|
|
140
|
+
render() {
|
|
141
|
+
return React__namespace.createElement(wonderBlocksLayout.MediaLayout, null, ({
|
|
142
|
+
mediaSize,
|
|
143
|
+
mediaSpec
|
|
144
|
+
}) => {
|
|
145
|
+
const spec = mediaSpec[mediaSize];
|
|
146
|
+
|
|
147
|
+
if (!spec) {
|
|
148
|
+
throw new Error(`mediaSpec.${mediaSize} is undefined`);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const {
|
|
152
|
+
gutterWidth
|
|
153
|
+
} = spec;
|
|
154
|
+
|
|
155
|
+
if (!wonderBlocksLayout.queryMatchesSize(this.props.mediaQuery, mediaSize)) {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
160
|
+
size: gutterWidth
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
Gutter.defaultProps = {
|
|
167
|
+
mediaQuery: "all"
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
class Row extends React__namespace.Component {
|
|
171
|
+
render() {
|
|
172
|
+
const {
|
|
173
|
+
style,
|
|
174
|
+
children
|
|
175
|
+
} = this.props;
|
|
176
|
+
return React__namespace.createElement(wonderBlocksLayout.MediaLayout, null, ({
|
|
177
|
+
mediaSize,
|
|
178
|
+
mediaSpec
|
|
179
|
+
}) => {
|
|
180
|
+
const spec = mediaSpec[mediaSize];
|
|
181
|
+
|
|
182
|
+
if (!spec) {
|
|
183
|
+
throw new Error(`mediaSpec.${mediaSize} is undefined`);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const {
|
|
187
|
+
marginWidth,
|
|
188
|
+
maxWidth,
|
|
189
|
+
totalColumns
|
|
190
|
+
} = spec;
|
|
191
|
+
const shouldDisplay = wonderBlocksLayout.queryMatchesSize(this.props.mediaQuery, mediaSize);
|
|
192
|
+
|
|
193
|
+
if (!shouldDisplay) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const contents = typeof children === "function" ? children({
|
|
198
|
+
mediaSize,
|
|
199
|
+
totalColumns
|
|
200
|
+
}) : children;
|
|
201
|
+
const filteredContents = React__namespace.Children.toArray(contents).filter(item => Cell.isClassOf(item) ? Cell.shouldDisplay(item.props, mediaSize) : true).reduce((acc, elem, index) => [].concat(acc, [elem, React__namespace.createElement(Gutter, {
|
|
202
|
+
key: `gutter-${index}`
|
|
203
|
+
})]), []).slice(0, -1);
|
|
204
|
+
return React__namespace.createElement(wonderBlocksCore.View, {
|
|
205
|
+
style: [styles.row, !!maxWidth && styles.rowMaxWidth, !!maxWidth && {
|
|
206
|
+
maxWidth
|
|
207
|
+
}, style]
|
|
208
|
+
}, React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
209
|
+
size: marginWidth
|
|
210
|
+
}), filteredContents, React__namespace.createElement(wonderBlocksLayout.Strut, {
|
|
211
|
+
size: marginWidth
|
|
212
|
+
}));
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
Row.defaultProps = {
|
|
218
|
+
mediaQuery: "all"
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
exports.Cell = Cell;
|
|
222
|
+
exports.Row = Row;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-grid",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.37",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
19
|
"@khanacademy/wonder-blocks-color": "^1.2.0",
|
|
20
|
-
"@khanacademy/wonder-blocks-core": "^4.6.
|
|
20
|
+
"@khanacademy/wonder-blocks-core": "^4.6.2",
|
|
21
|
+
"@khanacademy/wonder-blocks-layout": "^1.4.15",
|
|
21
22
|
"@khanacademy/wonder-blocks-spacing": "^3.0.5"
|
|
22
23
|
},
|
|
23
24
|
"peerDependencies": {
|
|
@@ -25,6 +26,6 @@
|
|
|
25
26
|
"react": "16.14.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"wb-dev-build-settings": "^0.
|
|
29
|
+
"wb-dev-build-settings": "^0.7.0"
|
|
29
30
|
}
|
|
30
|
-
}
|
|
31
|
+
}
|