@khanacademy/wonder-blocks-cell 2.2.1 → 2.2.4

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