@khanacademy/wonder-blocks-cell 2.2.0 → 2.2.3

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-cell
2
2
 
3
+ ## 2.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - @khanacademy/wonder-blocks-clickable@2.2.6
8
+ - @khanacademy/wonder-blocks-core@4.3.1
9
+ - @khanacademy/wonder-blocks-layout@1.4.9
10
+ - @khanacademy/wonder-blocks-typography@1.1.31
11
+
12
+ ## 2.2.2
13
+
14
+ ### Patch Changes
15
+
16
+ - f74b7379: Fixes `CellCore` to set the styles properly (removed `marginLeft: auto` from accessory and expanded the content wrapper).
17
+
18
+ ## 2.2.1
19
+
20
+ ### Patch Changes
21
+
22
+ - eadd9c0d: Fix top vertical alignment between accessories and content
23
+
3
24
  ## 2.2.0
4
25
 
5
26
  ### Minor Changes
package/dist/es/index.js CHANGED
@@ -11,40 +11,16 @@ import Spacing from '@khanacademy/wonder-blocks-spacing';
11
11
 
12
12
  const CellMeasurements = {
13
13
  cellMinHeight: Spacing.xxLarge_48,
14
-
15
- /**
16
- * The cell wrapper's gap.
17
- */
18
14
  cellPadding: {
19
- paddingVertical: Spacing.xSmall_8,
15
+ paddingVertical: Spacing.small_12,
20
16
  paddingHorizontal: Spacing.medium_16
21
17
  },
22
-
23
- /**
24
- * The DetailCell wrapper's gap.
25
- */
26
18
  detailCellPadding: {
27
- paddingVertical: Spacing.small_12,
19
+ paddingVertical: Spacing.medium_16,
28
20
  paddingHorizontal: Spacing.medium_16
29
21
  },
30
-
31
- /**
32
- * The extra vertical spacing added to the title/content wrapper.
33
- */
34
- contentVerticalSpacing: Spacing.xxxSmall_4,
35
-
36
- /**
37
- * The horizontal spacing between the left and right accessory.
38
- */
39
22
  accessoryHorizontalSpacing: Spacing.medium_16
40
23
  };
41
- /**
42
- * Gets the horizontalRule style based on the variant.
43
- * @param {HorizontalRuleVariant} horizontalRule The variant of the horizontal
44
- * rule.
45
- * @returns A styled horizontal rule.
46
- */
47
-
48
24
  const getHorizontalRuleStyles = horizontalRule => {
49
25
  switch (horizontalRule) {
50
26
  case "inset":
@@ -64,9 +40,7 @@ const styles$2 = StyleSheet.create({
64
40
  width: "100%",
65
41
  content: "''",
66
42
  position: "absolute",
67
- // align to the bottom of the cell
68
43
  bottom: 0,
69
- // align border to the right of the cell
70
44
  right: 0,
71
45
  height: Spacing.xxxxSmall_2,
72
46
  boxShadow: `inset 0px -1px 0px ${Color.offBlack8}`
@@ -74,16 +48,11 @@ const styles$2 = StyleSheet.create({
74
48
  },
75
49
  horizontalRuleInset: {
76
50
  ":after": {
77
- // Inset doesn't include the left padding of the cell.
78
51
  width: `calc(100% - ${CellMeasurements.cellPadding.paddingHorizontal}px)`
79
52
  }
80
53
  }
81
54
  });
82
55
 
83
- /**
84
- * Left Accessories can be defined using WB components such as Icon, IconButton,
85
- * or it can even be used for a custom node/component if needed.
86
- */
87
56
  const LeftAccessory = ({
88
57
  leftAccessory,
89
58
  leftAccessoryStyle,
@@ -93,17 +62,13 @@ const LeftAccessory = ({
93
62
  return null;
94
63
  }
95
64
 
96
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(View, {
65
+ return React.createElement(React.Fragment, null, React.createElement(View, {
97
66
  style: [styles$1.accessory, disabled && styles$1.accessoryDisabled, _extends({}, leftAccessoryStyle)]
98
- }, leftAccessory), /*#__PURE__*/React.createElement(Strut, {
67
+ }, leftAccessory), React.createElement(Strut, {
99
68
  size: CellMeasurements.accessoryHorizontalSpacing
100
69
  }));
101
70
  };
102
71
 
103
- /**
104
- * Right Accessories can be defined using WB components such as Icon,
105
- * IconButton, or it can even be used for a custom node/component if needed.
106
- */
107
72
  const RightAccessory = ({
108
73
  rightAccessory,
109
74
  rightAccessoryStyle,
@@ -114,21 +79,13 @@ const RightAccessory = ({
114
79
  return null;
115
80
  }
116
81
 
117
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Strut, {
82
+ return React.createElement(React.Fragment, null, React.createElement(Strut, {
118
83
  size: CellMeasurements.accessoryHorizontalSpacing
119
- }), /*#__PURE__*/React.createElement(View, {
84
+ }), React.createElement(View, {
120
85
  style: [styles$1.accessory, styles$1.accessoryRight, disabled && styles$1.accessoryDisabled, _extends({}, rightAccessoryStyle), active && styles$1.accessoryActive]
121
86
  }, rightAccessory));
122
87
  };
123
88
 
124
- /**
125
- * CellCore is the base cell wrapper. It's used as the skeleton/layout that is
126
- * used by CompactCell and DetailCell (and any other variants).
127
- *
128
- * Both variants share how they render their accessories, and the main
129
- * responsibility of this component is to render the contents that are passed in
130
- * (using the `children` prop).
131
- */
132
89
  const CellCore = props => {
133
90
  const {
134
91
  active,
@@ -150,36 +107,28 @@ const CellCore = props => {
150
107
 
151
108
  const renderCell = eventState => {
152
109
  const horizontalRuleStyles = getHorizontalRuleStyles(horizontalRule);
153
- return /*#__PURE__*/React.createElement(View, {
154
- style: [styles$1.wrapper, // focused applied to the main wrapper to make the border
155
- // outline part of the wrapper
156
- (eventState == null ? void 0 : eventState.focused) && styles$1.focused],
110
+ return React.createElement(View, {
111
+ style: [styles$1.wrapper, (eventState == null ? void 0 : eventState.focused) && styles$1.focused],
157
112
  "aria-current": active ? "true" : undefined
158
- }, /*#__PURE__*/React.createElement(View, {
159
- style: [styles$1.innerWrapper, innerStyle, // custom styles
160
- style, horizontalRuleStyles, disabled && styles$1.disabled, active && styles$1.active, // other states applied to the inner wrapper to blend
161
- // the background color properly
162
- !disabled && (eventState == null ? void 0 : eventState.hovered) && styles$1.hovered, // active + hovered
163
- active && (eventState == null ? void 0 : eventState.hovered) && styles$1.activeHovered, !disabled && (eventState == null ? void 0 : eventState.pressed) && styles$1.pressed, // active + pressed
164
- !disabled && active && (eventState == null ? void 0 : eventState.pressed) && styles$1.activePressed]
165
- }, /*#__PURE__*/React.createElement(LeftAccessory, {
113
+ }, React.createElement(View, {
114
+ style: [styles$1.innerWrapper, innerStyle, style, horizontalRuleStyles, disabled && styles$1.disabled, active && styles$1.active, !disabled && (eventState == null ? void 0 : eventState.hovered) && styles$1.hovered, active && (eventState == null ? void 0 : eventState.hovered) && styles$1.activeHovered, !disabled && (eventState == null ? void 0 : eventState.pressed) && styles$1.pressed, !disabled && active && (eventState == null ? void 0 : eventState.pressed) && styles$1.activePressed]
115
+ }, React.createElement(LeftAccessory, {
166
116
  leftAccessory: leftAccessory,
167
117
  leftAccessoryStyle: leftAccessoryStyle,
168
118
  disabled: disabled
169
- }), /*#__PURE__*/React.createElement(View, {
119
+ }), React.createElement(View, {
170
120
  style: styles$1.content,
171
121
  testId: testId
172
- }, children), /*#__PURE__*/React.createElement(RightAccessory, {
122
+ }, children), React.createElement(RightAccessory, {
173
123
  rightAccessory: rightAccessory,
174
124
  rightAccessoryStyle: rightAccessoryStyle,
175
125
  active: active,
176
126
  disabled: disabled
177
127
  })));
178
- }; // Pressable cell.
179
-
128
+ };
180
129
 
181
130
  if (onClick || href) {
182
- return /*#__PURE__*/React.createElement(Clickable, {
131
+ return React.createElement(Clickable, {
183
132
  disabled: disabled,
184
133
  onClick: onClick,
185
134
  href: href,
@@ -187,8 +136,7 @@ const CellCore = props => {
187
136
  "aria-label": ariaLabel ? ariaLabel : undefined,
188
137
  target: target
189
138
  }, eventState => renderCell(eventState));
190
- } // No click event attached, so just render the cell as-is.
191
-
139
+ }
192
140
 
193
141
  return renderCell();
194
142
  };
@@ -207,42 +155,24 @@ const styles$1 = StyleSheet.create({
207
155
  },
208
156
  content: {
209
157
  alignSelf: "center",
210
- overflowWrap: "break-word",
211
- padding: `${CellMeasurements.contentVerticalSpacing}px 0`
158
+ flex: 1,
159
+ overflowWrap: "break-word"
212
160
  },
213
161
  accessory: {
214
- // Use content width by default.
215
162
  minWidth: "auto",
216
- // Horizontal alignment of the accessory.
217
163
  alignItems: "center",
218
- // Vertical alignment.
219
164
  alignSelf: "center"
220
165
  },
221
166
  accessoryRight: {
222
- // The right accessory will have this color by default. Unless the
223
- // accessory element overrides that color internally.
224
- color: Color.offBlack64,
225
- // Align the right accessory to the right side of the cell, so we can
226
- // prevent the accessory from shifting left, if the content is too
227
- // short.
228
- marginLeft: "auto"
167
+ color: Color.offBlack64
229
168
  },
230
-
231
- /**
232
- * States
233
- */
234
169
  hovered: {
235
170
  background: Color.offBlack8
236
171
  },
237
- // Handling the focus ring internally because clickable doesn't support
238
- // rounded focus ring.
239
172
  focused: {
240
173
  borderRadius: Spacing.xxxSmall_4,
241
174
  outline: `solid ${Spacing.xxxxSmall_2}px ${Color.blue}`,
242
- // The focus ring is not visible when there are stacked cells.
243
- // Using outlineOffset to display the focus ring inside the cell.
244
175
  outlineOffset: -Spacing.xxxxSmall_2,
245
- // To hide the internal corners of the cell.
246
176
  overflow: "hidden"
247
177
  },
248
178
  pressed: {
@@ -275,31 +205,13 @@ const styles$1 = StyleSheet.create({
275
205
 
276
206
  const _excluded$1 = ["title"];
277
207
 
278
- /**
279
- * `CompactCell` is the simplest form of the Cell. It is a compacted-height Cell
280
- * with limited subviews and accessories. Typically they represent additional
281
- * info or selection lists. It has a minimum height of 48px and a non-bold
282
- * title. It does not have subtitles or a progress bar, and in general it has
283
- * less vertical space around text and accessories.
284
- *
285
- * ### Usage
286
- *
287
- * ```jsx
288
- * import {CompactCell} from "@khanacademy/wonder-blocks-cell";
289
- *
290
- * <CompactCell
291
- * title="Compact cell"
292
- * rightAccessory={<Icon icon={icons.caretRight} size="medium" />}
293
- * />
294
- * ```
295
- */
296
208
  function CompactCell(props) {
297
209
  const {
298
210
  title
299
211
  } = props,
300
212
  coreProps = _objectWithoutPropertiesLoose(props, _excluded$1);
301
213
 
302
- return /*#__PURE__*/React.createElement(CellCore, coreProps, typeof title === "string" ? /*#__PURE__*/React.createElement(LabelMedium, null, title) : title);
214
+ return React.createElement(CellCore, coreProps, typeof title === "string" ? React.createElement(LabelMedium, null, title) : title);
303
215
  }
304
216
 
305
217
  const _excluded = ["title", "subtitle1", "subtitle2"];
@@ -313,7 +225,7 @@ const Subtitle = ({
313
225
  }
314
226
 
315
227
  if (typeof subtitle === "string") {
316
- return /*#__PURE__*/React.createElement(LabelSmall, {
228
+ return React.createElement(LabelSmall, {
317
229
  style: !disabled && styles.subtitle
318
230
  }, subtitle);
319
231
  }
@@ -321,27 +233,6 @@ const Subtitle = ({
321
233
  return subtitle;
322
234
  };
323
235
 
324
- /**
325
- * This is a variant of CompactCell that allows adding subtitles, before and
326
- * after the cell title. They typically represent an item that can be
327
- * clicked/tapped to view more complex details. They vary in height depending on
328
- * the presence or absence of subtitles, and they allow for a wide range of
329
- * functionality depending on which accessories are active.
330
- *
331
- * ### Usage
332
- *
333
- * ```jsx
334
- * import {DetailCell} from "@khanacademy/wonder-blocks-cell";
335
- *
336
- * <DetailCell
337
- * leftAccessory={<Icon icon={icons.contentVideo} size="medium" />}
338
- * subtitle1="Subtitle 1"
339
- * title="Detail cell"
340
- * subtitle1="Subtitle 2"
341
- * rightAccessory={<Icon icon={icons.caretRight} size="medium" />}
342
- * />
343
- * ```
344
- */
345
236
  function DetailCell(props) {
346
237
  const {
347
238
  title,
@@ -350,16 +241,16 @@ function DetailCell(props) {
350
241
  } = props,
351
242
  coreProps = _objectWithoutPropertiesLoose(props, _excluded);
352
243
 
353
- return /*#__PURE__*/React.createElement(CellCore, _extends({}, coreProps, {
244
+ return React.createElement(CellCore, _extends({}, coreProps, {
354
245
  innerStyle: styles.innerWrapper
355
- }), /*#__PURE__*/React.createElement(Subtitle, {
246
+ }), React.createElement(Subtitle, {
356
247
  subtitle: subtitle1,
357
248
  disabled: coreProps.disabled
358
- }), subtitle1 && /*#__PURE__*/React.createElement(Strut, {
249
+ }), subtitle1 && React.createElement(Strut, {
359
250
  size: Spacing.xxxxSmall_2
360
- }), typeof title === "string" ? /*#__PURE__*/React.createElement(LabelMedium, null, title) : title, subtitle2 && /*#__PURE__*/React.createElement(Strut, {
251
+ }), typeof title === "string" ? React.createElement(LabelMedium, null, title) : title, subtitle2 && React.createElement(Strut, {
361
252
  size: Spacing.xxxxSmall_2
362
- }), /*#__PURE__*/React.createElement(Subtitle, {
253
+ }), React.createElement(Subtitle, {
363
254
  subtitle: subtitle2,
364
255
  disabled: coreProps.disabled
365
256
  }));
@@ -369,7 +260,6 @@ const styles = StyleSheet.create({
369
260
  subtitle: {
370
261
  color: Color.offBlack64
371
262
  },
372
- // This is to override the default padding of the CellCore innerWrapper.
373
263
  innerWrapper: {
374
264
  padding: `${CellMeasurements.detailCellPadding.paddingVertical}px ${CellMeasurements.detailCellPadding.paddingHorizontal}px`
375
265
  }
package/dist/index.js CHANGED
@@ -126,7 +126,7 @@ const CellMeasurements = {
126
126
  * The cell wrapper's gap.
127
127
  */
128
128
  cellPadding: {
129
- paddingVertical: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.xSmall_8,
129
+ paddingVertical: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.small_12,
130
130
  paddingHorizontal: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.medium_16
131
131
  },
132
132
 
@@ -134,15 +134,10 @@ const CellMeasurements = {
134
134
  * The DetailCell wrapper's gap.
135
135
  */
136
136
  detailCellPadding: {
137
- paddingVertical: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.small_12,
137
+ paddingVertical: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.medium_16,
138
138
  paddingHorizontal: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.medium_16
139
139
  },
140
140
 
141
- /**
142
- * The extra vertical spacing added to the title/content wrapper.
143
- */
144
- contentVerticalSpacing: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.xxxSmall_4,
145
-
146
141
  /**
147
142
  * The horizontal spacing between the left and right accessory.
148
143
  */
@@ -372,8 +367,9 @@ const styles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
372
367
  },
373
368
  content: {
374
369
  alignSelf: "center",
375
- overflowWrap: "break-word",
376
- padding: `${_common_js__WEBPACK_IMPORTED_MODULE_7__[/* CellMeasurements */ "a"].contentVerticalSpacing}px 0`
370
+ // Expand the content to fill the available space.
371
+ flex: 1,
372
+ overflowWrap: "break-word"
377
373
  },
378
374
  accessory: {
379
375
  // Use content width by default.
@@ -386,11 +382,7 @@ const styles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
386
382
  accessoryRight: {
387
383
  // The right accessory will have this color by default. Unless the
388
384
  // accessory element overrides that color internally.
389
- color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4___default.a.offBlack64,
390
- // Align the right accessory to the right side of the cell, so we can
391
- // prevent the accessory from shifting left, if the content is too
392
- // short.
393
- marginLeft: "auto"
385
+ color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4___default.a.offBlack64
394
386
  },
395
387
 
396
388
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-cell",
3
- "version": "2.2.0",
3
+ "version": "2.2.3",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -14,19 +14,19 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@babel/runtime": "^7.16.3",
17
- "@khanacademy/wonder-blocks-clickable": "^2.2.5",
17
+ "@khanacademy/wonder-blocks-clickable": "^2.2.6",
18
18
  "@khanacademy/wonder-blocks-color": "^1.1.20",
19
- "@khanacademy/wonder-blocks-core": "^4.3.0",
20
- "@khanacademy/wonder-blocks-layout": "^1.4.8",
19
+ "@khanacademy/wonder-blocks-core": "^4.3.1",
20
+ "@khanacademy/wonder-blocks-layout": "^1.4.9",
21
21
  "@khanacademy/wonder-blocks-spacing": "^3.0.5",
22
- "@khanacademy/wonder-blocks-typography": "^1.1.30"
22
+ "@khanacademy/wonder-blocks-typography": "^1.1.31"
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.3.0"
29
+ "wb-dev-build-settings": "^0.4.0"
30
30
  },
31
31
  "author": "",
32
32
  "license": "MIT"
@@ -107,14 +107,16 @@ export const DetailCellWithCustomStyles: StoryComponentType = () => (
107
107
  title="Title for article item"
108
108
  subtitle1="Subtitle for article item"
109
109
  subtitle2="Subtitle for article item"
110
- leftAccessory={<Icon icon={icons.contentVideo} size="medium" />}
110
+ leftAccessory={<Icon icon={icons.caretLeft} size="small" />}
111
111
  leftAccessoryStyle={{
112
- minWidth: Spacing.xxLarge_48,
112
+ alignSelf: "flex-start",
113
113
  }}
114
114
  rightAccessory={<Icon icon={icons.caretRight} size="small" />}
115
115
  rightAccessoryStyle={{
116
- minWidth: Spacing.medium_16,
117
- alignSelf: "flex-end",
116
+ alignSelf: "flex-start",
117
+ }}
118
+ style={{
119
+ textAlign: "center",
118
120
  }}
119
121
  />
120
122
  );
@@ -228,8 +228,9 @@ const styles = StyleSheet.create({
228
228
 
229
229
  content: {
230
230
  alignSelf: "center",
231
+ // Expand the content to fill the available space.
232
+ flex: 1,
231
233
  overflowWrap: "break-word",
232
- padding: `${CellMeasurements.contentVerticalSpacing}px 0`,
233
234
  },
234
235
 
235
236
  accessory: {
@@ -245,10 +246,6 @@ const styles = StyleSheet.create({
245
246
  // The right accessory will have this color by default. Unless the
246
247
  // accessory element overrides that color internally.
247
248
  color: Color.offBlack64,
248
- // Align the right accessory to the right side of the cell, so we can
249
- // prevent the accessory from shifting left, if the content is too
250
- // short.
251
- marginLeft: "auto",
252
249
  },
253
250
 
254
251
  /**
@@ -14,7 +14,7 @@ export const CellMeasurements = {
14
14
  * The cell wrapper's gap.
15
15
  */
16
16
  cellPadding: {
17
- paddingVertical: Spacing.xSmall_8,
17
+ paddingVertical: Spacing.small_12,
18
18
  paddingHorizontal: Spacing.medium_16,
19
19
  },
20
20
 
@@ -22,15 +22,10 @@ export const CellMeasurements = {
22
22
  * The DetailCell wrapper's gap.
23
23
  */
24
24
  detailCellPadding: {
25
- paddingVertical: Spacing.small_12,
25
+ paddingVertical: Spacing.medium_16,
26
26
  paddingHorizontal: Spacing.medium_16,
27
27
  },
28
28
 
29
- /**
30
- * The extra vertical spacing added to the title/content wrapper.
31
- */
32
- contentVerticalSpacing: Spacing.xxxSmall_4,
33
-
34
29
  /**
35
30
  * The horizontal spacing between the left and right accessory.
36
31
  */