@khanacademy/wonder-blocks-cell 1.0.2 → 2.0.2
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 +28 -0
- package/dist/es/index.js +42 -19
- package/dist/index.js +47 -20
- package/package.json +5 -5
- package/src/components/__docs__/{basic-cell.argtypes.js → compact-cell.argtypes.js} +0 -0
- package/src/components/__docs__/{basic-cell.stories.js → compact-cell.stories.js} +54 -51
- package/src/components/__docs__/detail-cell.argtypes.js +2 -2
- package/src/components/__tests__/{basic-cell.test.js → compact-cell.test.js} +17 -15
- package/src/components/{basic-cell.js → compact-cell.js} +10 -8
- package/src/components/detail-cell.js +14 -5
- package/src/components/internal/__tests__/cell-core.test.js +4 -1
- package/src/components/internal/cell-core.js +18 -3
- package/src/components/internal/common.js +8 -0
- package/src/index.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-cell
|
|
2
2
|
|
|
3
|
+
## 2.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [246a921d]
|
|
8
|
+
- @khanacademy/wonder-blocks-core@4.3.0
|
|
9
|
+
- @khanacademy/wonder-blocks-clickable@2.2.5
|
|
10
|
+
- @khanacademy/wonder-blocks-layout@1.4.8
|
|
11
|
+
- @khanacademy/wonder-blocks-typography@1.1.30
|
|
12
|
+
|
|
13
|
+
## 2.0.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 166ecc97: Use `aria-disabled` instead of disabled, fix focused + disabled styles.
|
|
18
|
+
- Updated dependencies [166ecc97]
|
|
19
|
+
- @khanacademy/wonder-blocks-clickable@2.2.4
|
|
20
|
+
|
|
21
|
+
## 2.0.0
|
|
22
|
+
|
|
23
|
+
### Major Changes
|
|
24
|
+
|
|
25
|
+
- 655daa88: Renamed `BasicCell` to `CompactCell` for better clarification of this variant
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- 2630d750: DetailCell: Style tweaks (changing title from bold to regular, changing vertical padding to 16px)
|
|
30
|
+
|
|
3
31
|
## 1.0.2
|
|
4
32
|
|
|
5
33
|
### Patch Changes
|
package/dist/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { LabelMedium,
|
|
3
|
+
import { LabelMedium, LabelSmall } from '@khanacademy/wonder-blocks-typography';
|
|
4
4
|
import _extends from '@babel/runtime/helpers/extends';
|
|
5
5
|
import { StyleSheet } from 'aphrodite';
|
|
6
6
|
import Clickable from '@khanacademy/wonder-blocks-clickable';
|
|
@@ -20,6 +20,14 @@ const CellMeasurements = {
|
|
|
20
20
|
paddingHorizontal: Spacing.medium_16
|
|
21
21
|
},
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* The DetailCell wrapper's gap.
|
|
25
|
+
*/
|
|
26
|
+
detailCellPadding: {
|
|
27
|
+
paddingVertical: Spacing.small_12,
|
|
28
|
+
paddingHorizontal: Spacing.medium_16
|
|
29
|
+
},
|
|
30
|
+
|
|
23
31
|
/**
|
|
24
32
|
* The extra vertical spacing added to the title/content wrapper.
|
|
25
33
|
*/
|
|
@@ -115,7 +123,7 @@ const RightAccessory = ({
|
|
|
115
123
|
|
|
116
124
|
/**
|
|
117
125
|
* CellCore is the base cell wrapper. It's used as the skeleton/layout that is
|
|
118
|
-
* used by
|
|
126
|
+
* used by CompactCell and DetailCell (and any other variants).
|
|
119
127
|
*
|
|
120
128
|
* Both variants share how they render their accessories, and the main
|
|
121
129
|
* responsibility of this component is to render the contents that are passed in
|
|
@@ -134,7 +142,8 @@ const CellCore = props => {
|
|
|
134
142
|
rightAccessoryStyle = undefined,
|
|
135
143
|
style,
|
|
136
144
|
testId,
|
|
137
|
-
"aria-label": ariaLabel
|
|
145
|
+
"aria-label": ariaLabel,
|
|
146
|
+
innerStyle
|
|
138
147
|
} = props;
|
|
139
148
|
|
|
140
149
|
const renderCell = eventState => {
|
|
@@ -142,11 +151,11 @@ const CellCore = props => {
|
|
|
142
151
|
return /*#__PURE__*/React.createElement(View, {
|
|
143
152
|
style: [styles$1.wrapper, // focused applied to the main wrapper to make the border
|
|
144
153
|
// outline part of the wrapper
|
|
145
|
-
(eventState == null ? void 0 : eventState.focused) && styles$1.focused,
|
|
146
|
-
style],
|
|
154
|
+
(eventState == null ? void 0 : eventState.focused) && styles$1.focused],
|
|
147
155
|
"aria-current": active ? "true" : undefined
|
|
148
156
|
}, /*#__PURE__*/React.createElement(View, {
|
|
149
|
-
style: [styles$1.innerWrapper,
|
|
157
|
+
style: [styles$1.innerWrapper, innerStyle, // custom styles
|
|
158
|
+
style, horizontalRuleStyles, disabled && styles$1.disabled, active && styles$1.active, // other states applied to the inner wrapper to blend
|
|
150
159
|
// the background color properly
|
|
151
160
|
!disabled && (eventState == null ? void 0 : eventState.hovered) && styles$1.hovered, // active + hovered
|
|
152
161
|
active && (eventState == null ? void 0 : eventState.hovered) && styles$1.activeHovered, !disabled && (eventState == null ? void 0 : eventState.pressed) && styles$1.pressed, // active + pressed
|
|
@@ -246,7 +255,10 @@ const styles$1 = StyleSheet.create({
|
|
|
246
255
|
background: fade(Color.blue, 0.24)
|
|
247
256
|
},
|
|
248
257
|
disabled: {
|
|
249
|
-
color: Color.offBlack32
|
|
258
|
+
color: Color.offBlack32,
|
|
259
|
+
":hover": {
|
|
260
|
+
cursor: "not-allowed"
|
|
261
|
+
}
|
|
250
262
|
},
|
|
251
263
|
accessoryActive: {
|
|
252
264
|
color: Color.blue
|
|
@@ -260,22 +272,24 @@ const styles$1 = StyleSheet.create({
|
|
|
260
272
|
const _excluded$1 = ["title"];
|
|
261
273
|
|
|
262
274
|
/**
|
|
263
|
-
*
|
|
264
|
-
* with limited subviews and accessories
|
|
265
|
-
*
|
|
275
|
+
* `CompactCell` is the simplest form of the Cell. It is a compacted-height Cell
|
|
276
|
+
* with limited subviews and accessories. Typically they represent additional
|
|
277
|
+
* info or selection lists. It has a minimum height of 48px and a non-bold
|
|
278
|
+
* title. It does not have subtitles or a progress bar, and in general it has
|
|
279
|
+
* less vertical space around text and accessories.
|
|
266
280
|
*
|
|
267
281
|
* ### Usage
|
|
268
282
|
*
|
|
269
283
|
* ```jsx
|
|
270
|
-
* import {
|
|
284
|
+
* import {CompactCell} from "@khanacademy/wonder-blocks-cell";
|
|
271
285
|
*
|
|
272
|
-
* <
|
|
273
|
-
* title="
|
|
286
|
+
* <CompactCell
|
|
287
|
+
* title="Compact cell"
|
|
274
288
|
* rightAccessory={<Icon icon={icons.caretRight} size="medium" />}
|
|
275
289
|
* />
|
|
276
290
|
* ```
|
|
277
291
|
*/
|
|
278
|
-
function
|
|
292
|
+
function CompactCell(props) {
|
|
279
293
|
const {
|
|
280
294
|
title
|
|
281
295
|
} = props,
|
|
@@ -304,8 +318,11 @@ const Subtitle = ({
|
|
|
304
318
|
};
|
|
305
319
|
|
|
306
320
|
/**
|
|
307
|
-
* This is a variant of
|
|
308
|
-
* the cell title.
|
|
321
|
+
* This is a variant of CompactCell that allows adding subtitles, before and
|
|
322
|
+
* after the cell title. They typically represent an item that can be
|
|
323
|
+
* clicked/tapped to view more complex details. They vary in height depending on
|
|
324
|
+
* the presence or absence of subtitles, and they allow for a wide range of
|
|
325
|
+
* functionality depending on which accessories are active.
|
|
309
326
|
*
|
|
310
327
|
* ### Usage
|
|
311
328
|
*
|
|
@@ -329,12 +346,14 @@ function DetailCell(props) {
|
|
|
329
346
|
} = props,
|
|
330
347
|
coreProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
331
348
|
|
|
332
|
-
return /*#__PURE__*/React.createElement(CellCore,
|
|
349
|
+
return /*#__PURE__*/React.createElement(CellCore, _extends({}, coreProps, {
|
|
350
|
+
innerStyle: styles.innerWrapper
|
|
351
|
+
}), /*#__PURE__*/React.createElement(Subtitle, {
|
|
333
352
|
subtitle: subtitle1,
|
|
334
353
|
disabled: coreProps.disabled
|
|
335
354
|
}), subtitle1 && /*#__PURE__*/React.createElement(Strut, {
|
|
336
355
|
size: Spacing.xxxxSmall_2
|
|
337
|
-
}), typeof title === "string" ? /*#__PURE__*/React.createElement(
|
|
356
|
+
}), typeof title === "string" ? /*#__PURE__*/React.createElement(LabelMedium, null, title) : title, subtitle2 && /*#__PURE__*/React.createElement(Strut, {
|
|
338
357
|
size: Spacing.xxxxSmall_2
|
|
339
358
|
}), /*#__PURE__*/React.createElement(Subtitle, {
|
|
340
359
|
subtitle: subtitle2,
|
|
@@ -345,7 +364,11 @@ function DetailCell(props) {
|
|
|
345
364
|
const styles = StyleSheet.create({
|
|
346
365
|
subtitle: {
|
|
347
366
|
color: Color.offBlack64
|
|
367
|
+
},
|
|
368
|
+
// This is to override the default padding of the CellCore innerWrapper.
|
|
369
|
+
innerWrapper: {
|
|
370
|
+
padding: `${CellMeasurements.detailCellPadding.paddingVertical}px ${CellMeasurements.detailCellPadding.paddingHorizontal}px`
|
|
348
371
|
}
|
|
349
372
|
});
|
|
350
373
|
|
|
351
|
-
export {
|
|
374
|
+
export { CompactCell, DetailCell };
|
package/dist/index.js
CHANGED
|
@@ -130,6 +130,14 @@ const CellMeasurements = {
|
|
|
130
130
|
paddingHorizontal: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.medium_16
|
|
131
131
|
},
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* The DetailCell wrapper's gap.
|
|
135
|
+
*/
|
|
136
|
+
detailCellPadding: {
|
|
137
|
+
paddingVertical: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.small_12,
|
|
138
|
+
paddingHorizontal: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_2___default.a.medium_16
|
|
139
|
+
},
|
|
140
|
+
|
|
133
141
|
/**
|
|
134
142
|
* The extra vertical spacing added to the title/content wrapper.
|
|
135
143
|
*/
|
|
@@ -280,7 +288,7 @@ const RightAccessory = ({
|
|
|
280
288
|
|
|
281
289
|
/**
|
|
282
290
|
* CellCore is the base cell wrapper. It's used as the skeleton/layout that is
|
|
283
|
-
* used by
|
|
291
|
+
* used by CompactCell and DetailCell (and any other variants).
|
|
284
292
|
*
|
|
285
293
|
* Both variants share how they render their accessories, and the main
|
|
286
294
|
* responsibility of this component is to render the contents that are passed in
|
|
@@ -299,7 +307,8 @@ const CellCore = props => {
|
|
|
299
307
|
rightAccessoryStyle = undefined,
|
|
300
308
|
style,
|
|
301
309
|
testId,
|
|
302
|
-
"aria-label": ariaLabel
|
|
310
|
+
"aria-label": ariaLabel,
|
|
311
|
+
innerStyle
|
|
303
312
|
} = props;
|
|
304
313
|
|
|
305
314
|
const renderCell = eventState => {
|
|
@@ -307,11 +316,11 @@ const CellCore = props => {
|
|
|
307
316
|
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_3__["View"], {
|
|
308
317
|
style: [styles.wrapper, // focused applied to the main wrapper to make the border
|
|
309
318
|
// outline part of the wrapper
|
|
310
|
-
(eventState == null ? void 0 : eventState.focused) && styles.focused,
|
|
311
|
-
style],
|
|
319
|
+
(eventState == null ? void 0 : eventState.focused) && styles.focused],
|
|
312
320
|
"aria-current": active ? "true" : undefined
|
|
313
321
|
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_3__["View"], {
|
|
314
|
-
style: [styles.innerWrapper,
|
|
322
|
+
style: [styles.innerWrapper, innerStyle, // custom styles
|
|
323
|
+
style, horizontalRuleStyles, disabled && styles.disabled, active && styles.active, // other states applied to the inner wrapper to blend
|
|
315
324
|
// the background color properly
|
|
316
325
|
!disabled && (eventState == null ? void 0 : eventState.hovered) && styles.hovered, // active + hovered
|
|
317
326
|
active && (eventState == null ? void 0 : eventState.hovered) && styles.activeHovered, !disabled && (eventState == null ? void 0 : eventState.pressed) && styles.pressed, // active + pressed
|
|
@@ -411,7 +420,10 @@ const styles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
|
|
|
411
420
|
background: Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__["fade"])(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4___default.a.blue, 0.24)
|
|
412
421
|
},
|
|
413
422
|
disabled: {
|
|
414
|
-
color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4___default.a.offBlack32
|
|
423
|
+
color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4___default.a.offBlack32,
|
|
424
|
+
":hover": {
|
|
425
|
+
cursor: "not-allowed"
|
|
426
|
+
}
|
|
415
427
|
},
|
|
416
428
|
accessoryActive: {
|
|
417
429
|
color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4___default.a.blue
|
|
@@ -438,22 +450,24 @@ const styles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
|
|
|
438
450
|
|
|
439
451
|
|
|
440
452
|
/**
|
|
441
|
-
*
|
|
442
|
-
* with limited subviews and accessories
|
|
443
|
-
*
|
|
453
|
+
* `CompactCell` is the simplest form of the Cell. It is a compacted-height Cell
|
|
454
|
+
* with limited subviews and accessories. Typically they represent additional
|
|
455
|
+
* info or selection lists. It has a minimum height of 48px and a non-bold
|
|
456
|
+
* title. It does not have subtitles or a progress bar, and in general it has
|
|
457
|
+
* less vertical space around text and accessories.
|
|
444
458
|
*
|
|
445
459
|
* ### Usage
|
|
446
460
|
*
|
|
447
461
|
* ```jsx
|
|
448
|
-
* import {
|
|
462
|
+
* import {CompactCell} from "@khanacademy/wonder-blocks-cell";
|
|
449
463
|
*
|
|
450
|
-
* <
|
|
451
|
-
* title="
|
|
464
|
+
* <CompactCell
|
|
465
|
+
* title="Compact cell"
|
|
452
466
|
* rightAccessory={<Icon icon={icons.caretRight} size="medium" />}
|
|
453
467
|
* />
|
|
454
468
|
* ```
|
|
455
469
|
*/
|
|
456
|
-
function
|
|
470
|
+
function CompactCell(props) {
|
|
457
471
|
const {
|
|
458
472
|
title,
|
|
459
473
|
...coreProps
|
|
@@ -461,7 +475,7 @@ function BasicCell(props) {
|
|
|
461
475
|
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_internal_cell_core_js__WEBPACK_IMPORTED_MODULE_2__[/* default */ "a"], coreProps, typeof title === "string" ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_1__["LabelMedium"], null, title) : title);
|
|
462
476
|
}
|
|
463
477
|
|
|
464
|
-
/* harmony default export */ __webpack_exports__["a"] = (
|
|
478
|
+
/* harmony default export */ __webpack_exports__["a"] = (CompactCell);
|
|
465
479
|
|
|
466
480
|
/***/ }),
|
|
467
481
|
/* 10 */
|
|
@@ -481,6 +495,10 @@ function BasicCell(props) {
|
|
|
481
495
|
/* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(7);
|
|
482
496
|
/* harmony import */ var _khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_5__);
|
|
483
497
|
/* harmony import */ var _internal_cell_core_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(8);
|
|
498
|
+
/* harmony import */ var _internal_common_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(3);
|
|
499
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
500
|
+
|
|
501
|
+
|
|
484
502
|
|
|
485
503
|
|
|
486
504
|
|
|
@@ -507,8 +525,11 @@ const Subtitle = ({
|
|
|
507
525
|
};
|
|
508
526
|
|
|
509
527
|
/**
|
|
510
|
-
* This is a variant of
|
|
511
|
-
* the cell title.
|
|
528
|
+
* This is a variant of CompactCell that allows adding subtitles, before and
|
|
529
|
+
* after the cell title. They typically represent an item that can be
|
|
530
|
+
* clicked/tapped to view more complex details. They vary in height depending on
|
|
531
|
+
* the presence or absence of subtitles, and they allow for a wide range of
|
|
532
|
+
* functionality depending on which accessories are active.
|
|
512
533
|
*
|
|
513
534
|
* ### Usage
|
|
514
535
|
*
|
|
@@ -531,12 +552,14 @@ function DetailCell(props) {
|
|
|
531
552
|
subtitle2,
|
|
532
553
|
...coreProps
|
|
533
554
|
} = props;
|
|
534
|
-
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_internal_cell_core_js__WEBPACK_IMPORTED_MODULE_6__[/* default */ "a"],
|
|
555
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_internal_cell_core_js__WEBPACK_IMPORTED_MODULE_6__[/* default */ "a"], _extends({}, coreProps, {
|
|
556
|
+
innerStyle: styles.innerWrapper
|
|
557
|
+
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](Subtitle, {
|
|
535
558
|
subtitle: subtitle1,
|
|
536
559
|
disabled: coreProps.disabled
|
|
537
560
|
}), subtitle1 && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_3__["Strut"], {
|
|
538
561
|
size: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_4___default.a.xxxxSmall_2
|
|
539
|
-
}), typeof title === "string" ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_5__["
|
|
562
|
+
}), typeof title === "string" ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_typography__WEBPACK_IMPORTED_MODULE_5__["LabelMedium"], null, title) : title, subtitle2 && /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_layout__WEBPACK_IMPORTED_MODULE_3__["Strut"], {
|
|
540
563
|
size: _khanacademy_wonder_blocks_spacing__WEBPACK_IMPORTED_MODULE_4___default.a.xxxxSmall_2
|
|
541
564
|
}), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](Subtitle, {
|
|
542
565
|
subtitle: subtitle2,
|
|
@@ -547,6 +570,10 @@ function DetailCell(props) {
|
|
|
547
570
|
const styles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
|
|
548
571
|
subtitle: {
|
|
549
572
|
color: _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_2___default.a.offBlack64
|
|
573
|
+
},
|
|
574
|
+
// This is to override the default padding of the CellCore innerWrapper.
|
|
575
|
+
innerWrapper: {
|
|
576
|
+
padding: `${_internal_common_js__WEBPACK_IMPORTED_MODULE_7__[/* CellMeasurements */ "a"].detailCellPadding.paddingVertical}px ${_internal_common_js__WEBPACK_IMPORTED_MODULE_7__[/* CellMeasurements */ "a"].detailCellPadding.paddingHorizontal}px`
|
|
550
577
|
}
|
|
551
578
|
});
|
|
552
579
|
/* harmony default export */ __webpack_exports__["a"] = (DetailCell);
|
|
@@ -563,8 +590,8 @@ module.exports = require("@khanacademy/wonder-blocks-clickable");
|
|
|
563
590
|
|
|
564
591
|
"use strict";
|
|
565
592
|
__webpack_require__.r(__webpack_exports__);
|
|
566
|
-
/* harmony import */ var
|
|
567
|
-
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "
|
|
593
|
+
/* harmony import */ var _components_compact_cell_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9);
|
|
594
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "CompactCell", function() { return _components_compact_cell_js__WEBPACK_IMPORTED_MODULE_0__["a"]; });
|
|
568
595
|
|
|
569
596
|
/* harmony import */ var _components_detail_cell_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(10);
|
|
570
597
|
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "DetailCell", function() { return _components_detail_cell_js__WEBPACK_IMPORTED_MODULE_1__["a"]; });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-cell",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/runtime": "^7.16.3",
|
|
17
|
-
"@khanacademy/wonder-blocks-clickable": "^2.2.
|
|
17
|
+
"@khanacademy/wonder-blocks-clickable": "^2.2.5",
|
|
18
18
|
"@khanacademy/wonder-blocks-color": "^1.1.20",
|
|
19
|
-
"@khanacademy/wonder-blocks-core": "^4.
|
|
20
|
-
"@khanacademy/wonder-blocks-layout": "^1.4.
|
|
19
|
+
"@khanacademy/wonder-blocks-core": "^4.3.0",
|
|
20
|
+
"@khanacademy/wonder-blocks-layout": "^1.4.8",
|
|
21
21
|
"@khanacademy/wonder-blocks-spacing": "^3.0.5",
|
|
22
|
-
"@khanacademy/wonder-blocks-typography": "^1.1.
|
|
22
|
+
"@khanacademy/wonder-blocks-typography": "^1.1.30"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"aphrodite": "^1.2.5",
|
|
File without changes
|
|
@@ -14,14 +14,16 @@ import type {IconAsset} from "@khanacademy/wonder-blocks-icon";
|
|
|
14
14
|
|
|
15
15
|
import ComponentInfo from "../../../../../.storybook/components/component-info.js";
|
|
16
16
|
import {name, version} from "../../../package.json";
|
|
17
|
-
import
|
|
17
|
+
import CompactCellArgTypes, {
|
|
18
|
+
AccessoryMappings,
|
|
19
|
+
} from "./compact-cell.argtypes.js";
|
|
18
20
|
|
|
19
|
-
import
|
|
21
|
+
import CompactCell from "../compact-cell.js";
|
|
20
22
|
|
|
21
23
|
export default {
|
|
22
|
-
title: "Cell /
|
|
23
|
-
component:
|
|
24
|
-
argTypes:
|
|
24
|
+
title: "Cell / CompactCell",
|
|
25
|
+
component: CompactCell,
|
|
26
|
+
argTypes: CompactCellArgTypes,
|
|
25
27
|
parameters: {
|
|
26
28
|
componentSubtitle: ((
|
|
27
29
|
<ComponentInfo name={name} version={version} />
|
|
@@ -44,19 +46,19 @@ export default {
|
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
|
-
* Default
|
|
49
|
+
* Default CompactCell example. It will be rendered as the first/default story and
|
|
48
50
|
* it can be interacted with the controls panel in the Browser.
|
|
49
51
|
*/
|
|
50
|
-
const Template = (args) => <
|
|
52
|
+
const Template = (args) => <CompactCell {...args} />;
|
|
51
53
|
|
|
52
|
-
export const
|
|
54
|
+
export const DefaultCompactCell: StoryComponentType = Template.bind({});
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
DefaultCompactCell.args = {
|
|
55
57
|
title: "Basic Cell",
|
|
56
58
|
rightAccessory: <Icon icon={icons.caretRight} />,
|
|
57
59
|
};
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
DefaultCompactCell.parameters = {
|
|
60
62
|
chromatic: {
|
|
61
63
|
// We have screenshots of other stories that cover other variants.
|
|
62
64
|
disableSnapshot: true,
|
|
@@ -66,14 +68,14 @@ DefaultBasicCell.parameters = {
|
|
|
66
68
|
/**
|
|
67
69
|
* Only including an accessory on the left.
|
|
68
70
|
*/
|
|
69
|
-
export const
|
|
70
|
-
<
|
|
71
|
+
export const CompactCellLeft: StoryComponentType = () => (
|
|
72
|
+
<CompactCell
|
|
71
73
|
title="Intro to rational & irrational numbers"
|
|
72
74
|
leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
|
|
73
75
|
/>
|
|
74
76
|
);
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
CompactCellLeft.parameters = {
|
|
77
79
|
docs: {
|
|
78
80
|
storyDescription:
|
|
79
81
|
"You can create a minimal cell that only uses a title and an Icon that can be placed on the left or right (or both). In this case, we will place the icon on the left to show you how cell is flexible. Note that you can pass any of the existing WB components such as `Icon`, `IconButton`, `Tooltip`, etc.",
|
|
@@ -83,14 +85,14 @@ BasicCellLeft.parameters = {
|
|
|
83
85
|
/**
|
|
84
86
|
* Only including an accessory on the right.
|
|
85
87
|
*/
|
|
86
|
-
export const
|
|
87
|
-
<
|
|
88
|
+
export const CompactCellRight: StoryComponentType = (args) => (
|
|
89
|
+
<CompactCell
|
|
88
90
|
title="Intro to rational & irrational numbers"
|
|
89
91
|
rightAccessory={<Icon icon={icons.caretRight} size="medium" />}
|
|
90
92
|
/>
|
|
91
93
|
);
|
|
92
94
|
|
|
93
|
-
|
|
95
|
+
CompactCellRight.parameters = {
|
|
94
96
|
docs: {
|
|
95
97
|
storyDescription:
|
|
96
98
|
"You can also create a cell with an accessory placed on the right. Note that you can pass any of the existing WB components such as `Icon`.",
|
|
@@ -100,26 +102,26 @@ BasicCellRight.parameters = {
|
|
|
100
102
|
/**
|
|
101
103
|
* Adding multiline title to verify that the cell's height is correct.
|
|
102
104
|
*/
|
|
103
|
-
export const
|
|
105
|
+
export const CompactCellWithDifferentHeights: StoryComponentType = (args) => (
|
|
104
106
|
<>
|
|
105
|
-
<
|
|
107
|
+
<CompactCell
|
|
106
108
|
title="Single line with short accessory."
|
|
107
109
|
rightAccessory={AccessoryMappings.withCaret}
|
|
108
110
|
/>
|
|
109
111
|
<Strut size={Spacing.xSmall_8} />
|
|
110
|
-
<
|
|
112
|
+
<CompactCell
|
|
111
113
|
title="Single line with tall accessory."
|
|
112
114
|
rightAccessory={AccessoryMappings.withIconText}
|
|
113
115
|
/>
|
|
114
116
|
<Strut size={Spacing.xSmall_8} />
|
|
115
|
-
<
|
|
117
|
+
<CompactCell
|
|
116
118
|
title="Multi line title with tall accessory. Content should fit within the container and the cell height should be consistent no matter the content length."
|
|
117
119
|
rightAccessory={AccessoryMappings.withIconText}
|
|
118
120
|
/>
|
|
119
121
|
</>
|
|
120
122
|
);
|
|
121
123
|
|
|
122
|
-
|
|
124
|
+
CompactCellWithDifferentHeights.parameters = {
|
|
123
125
|
docs: {
|
|
124
126
|
storyDescription:
|
|
125
127
|
"Cells should keep a consistent height no matter the content passed in the title prop. It should also respect a `minHeight` of 48px",
|
|
@@ -127,14 +129,14 @@ BasicCellWithDifferentHeights.parameters = {
|
|
|
127
129
|
};
|
|
128
130
|
|
|
129
131
|
/**
|
|
130
|
-
* A
|
|
132
|
+
* A CompactCell example adding both accessories (left and right)
|
|
131
133
|
*/
|
|
132
134
|
const calendarIcon: IconAsset = {
|
|
133
135
|
small: `M14.22 1.6H13.33V0H11.56V1.6H4.44V0H2.67V1.6H1.78C0.79 1.6 0.01 2.32 0.01 3.2L0 14.4C0 15.28 0.79 16 1.78 16H14.22C15.2 16 16 15.28 16 14.4V3.2C16 2.32 15.2 1.6 14.22 1.6ZM14.22 14.4H1.78V5.6H14.22V14.4ZM3.56 7.2H8V11.2H3.56V7.2Z`,
|
|
134
136
|
};
|
|
135
137
|
|
|
136
|
-
export const
|
|
137
|
-
<
|
|
138
|
+
export const CompactCellBoth: StoryComponentType = () => (
|
|
139
|
+
<CompactCell
|
|
138
140
|
title="Intro to rational & irrational numbers"
|
|
139
141
|
leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
|
|
140
142
|
rightAccessory={
|
|
@@ -143,18 +145,18 @@ export const BasicCellBoth: StoryComponentType = () => (
|
|
|
143
145
|
/>
|
|
144
146
|
);
|
|
145
147
|
|
|
146
|
-
|
|
148
|
+
CompactCellBoth.storyName = "CompactCell with both accessories";
|
|
147
149
|
|
|
148
|
-
|
|
150
|
+
CompactCellBoth.parameters = {
|
|
149
151
|
docs: {
|
|
150
152
|
storyDescription:
|
|
151
153
|
"You can also create a more complex cell with accessories placed on both sides. Note that you can extend the Icon component with custom paths such as the following example.",
|
|
152
154
|
},
|
|
153
155
|
};
|
|
154
156
|
|
|
155
|
-
export const
|
|
156
|
-
<
|
|
157
|
-
title="
|
|
157
|
+
export const CompactCellAccessoryStyles: StoryComponentType = () => (
|
|
158
|
+
<CompactCell
|
|
159
|
+
title="CompactCell with custom accessory styles"
|
|
158
160
|
leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
|
|
159
161
|
leftAccessoryStyle={{
|
|
160
162
|
minWidth: Spacing.xxLarge_48,
|
|
@@ -170,9 +172,10 @@ export const BasicCellAccessoryStyles: StoryComponentType = () => (
|
|
|
170
172
|
/>
|
|
171
173
|
);
|
|
172
174
|
|
|
173
|
-
|
|
175
|
+
CompactCellAccessoryStyles.storyName =
|
|
176
|
+
"CompactCell accessories with custom styles";
|
|
174
177
|
|
|
175
|
-
|
|
178
|
+
CompactCellAccessoryStyles.parameters = {
|
|
176
179
|
docs: {
|
|
177
180
|
storyDescription:
|
|
178
181
|
"Accessories can also be customized to adapt to different sizes and alignments. In this example, we can see how a cell can be customized for both accessories.",
|
|
@@ -182,19 +185,19 @@ BasicCellAccessoryStyles.parameters = {
|
|
|
182
185
|
/**
|
|
183
186
|
* Defining horizontal rule variants
|
|
184
187
|
*/
|
|
185
|
-
export const
|
|
188
|
+
export const CompactCellHorizontalRules: StoryComponentType = () => (
|
|
186
189
|
<>
|
|
187
|
-
<
|
|
190
|
+
<CompactCell
|
|
188
191
|
title="This is a basic cell with an 'inset' horizontal rule"
|
|
189
192
|
leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
|
|
190
193
|
horizontalRule="inset"
|
|
191
194
|
/>
|
|
192
|
-
<
|
|
195
|
+
<CompactCell
|
|
193
196
|
title="This is a basic cell with a 'full-width' horizontal rule"
|
|
194
197
|
leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
|
|
195
198
|
horizontalRule="full-width"
|
|
196
199
|
/>
|
|
197
|
-
<
|
|
200
|
+
<CompactCell
|
|
198
201
|
title="This is a basic cell without a horizontal rule"
|
|
199
202
|
leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
|
|
200
203
|
horizontalRule="none"
|
|
@@ -202,18 +205,18 @@ export const BasicCellHorizontalRules: StoryComponentType = () => (
|
|
|
202
205
|
</>
|
|
203
206
|
);
|
|
204
207
|
|
|
205
|
-
|
|
208
|
+
CompactCellHorizontalRules.storyName = "Defining horizontal rule variants";
|
|
206
209
|
|
|
207
|
-
|
|
210
|
+
CompactCellHorizontalRules.parameters = {
|
|
208
211
|
docs: {
|
|
209
212
|
storyDescription:
|
|
210
213
|
"Cell components can use the `horizontalRule` prop to use a set of predefined variants that we can use to match our needs.",
|
|
211
214
|
},
|
|
212
215
|
};
|
|
213
216
|
|
|
214
|
-
export const
|
|
215
|
-
<
|
|
216
|
-
title="
|
|
217
|
+
export const CompactCellWithCustomStyles: StoryComponentType = () => (
|
|
218
|
+
<CompactCell
|
|
219
|
+
title="CompactCell with a darkBlue background"
|
|
217
220
|
leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
|
|
218
221
|
rightAccessory={<Icon icon={calendarIcon} color={Color.white} />}
|
|
219
222
|
style={{
|
|
@@ -224,7 +227,7 @@ export const BasicCellWithCustomStyles: StoryComponentType = () => (
|
|
|
224
227
|
/>
|
|
225
228
|
);
|
|
226
229
|
|
|
227
|
-
|
|
230
|
+
CompactCellWithCustomStyles.parameters = {
|
|
228
231
|
docs: {
|
|
229
232
|
storyDescription:
|
|
230
233
|
"Cell components can also adapt to different visual needs. One example of this can be done by passing a custom style object to the `style` prop.",
|
|
@@ -232,12 +235,12 @@ BasicCellWithCustomStyles.parameters = {
|
|
|
232
235
|
};
|
|
233
236
|
|
|
234
237
|
/*
|
|
235
|
-
*
|
|
238
|
+
* CompactCell with onClick set
|
|
236
239
|
|
|
237
240
|
*/
|
|
238
241
|
|
|
239
|
-
export const
|
|
240
|
-
<
|
|
242
|
+
export const ClickableCompactCell: StoryComponentType = () => (
|
|
243
|
+
<CompactCell
|
|
241
244
|
title="Intro to rational & irrational numbers"
|
|
242
245
|
rightAccessory={<Icon icon={icons.caretRight} />}
|
|
243
246
|
onClick={() => {}}
|
|
@@ -245,7 +248,7 @@ export const ClickableBasicCell: StoryComponentType = () => (
|
|
|
245
248
|
/>
|
|
246
249
|
);
|
|
247
250
|
|
|
248
|
-
|
|
251
|
+
ClickableCompactCell.parameters = {
|
|
249
252
|
chromatic: {
|
|
250
253
|
// This only includes interactions with the clickable cell, so no need
|
|
251
254
|
// to capture screenshots.
|
|
@@ -257,8 +260,8 @@ ClickableBasicCell.parameters = {
|
|
|
257
260
|
},
|
|
258
261
|
};
|
|
259
262
|
|
|
260
|
-
export const
|
|
261
|
-
<
|
|
263
|
+
export const CompactCellActive: StoryComponentType = () => (
|
|
264
|
+
<CompactCell
|
|
262
265
|
title="Title for article item"
|
|
263
266
|
leftAccessory={
|
|
264
267
|
<Icon icon={icons.contentVideo} size="medium" color="black" />
|
|
@@ -269,15 +272,15 @@ export const BasicCellActive: StoryComponentType = () => (
|
|
|
269
272
|
/>
|
|
270
273
|
);
|
|
271
274
|
|
|
272
|
-
|
|
275
|
+
CompactCellActive.parameters = {
|
|
273
276
|
docs: {
|
|
274
277
|
storyDescription:
|
|
275
278
|
"The cell also supports different states within itself. The different styles are defined internally (e.g hover, focused, pressed, active, disabled) and we allow passing some props to use the `active` or `disabled` state.",
|
|
276
279
|
},
|
|
277
280
|
};
|
|
278
281
|
|
|
279
|
-
export const
|
|
280
|
-
<
|
|
282
|
+
export const CompactCellDisabled: StoryComponentType = () => (
|
|
283
|
+
<CompactCell
|
|
281
284
|
title="Title for article item"
|
|
282
285
|
leftAccessory={AccessoryMappings.withImage}
|
|
283
286
|
rightAccessory={<Icon icon={calendarIcon} size="small" />}
|
|
@@ -286,7 +289,7 @@ export const BasicCellDisabled: StoryComponentType = () => (
|
|
|
286
289
|
/>
|
|
287
290
|
);
|
|
288
291
|
|
|
289
|
-
|
|
292
|
+
CompactCellDisabled.parameters = {
|
|
290
293
|
docs: {
|
|
291
294
|
storyDescription:
|
|
292
295
|
"In the following example we can see how the `disabled` state works. Note that we apply an opacity to all the elements to make it more apparent that the cell is disabled. This includes text, SVG icons, images, etc.",
|
|
@@ -5,28 +5,30 @@ import {render, screen} from "@testing-library/react";
|
|
|
5
5
|
import Icon, {icons} from "@khanacademy/wonder-blocks-icon";
|
|
6
6
|
import {HeadingMedium} from "@khanacademy/wonder-blocks-typography";
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import CompactCell from "../compact-cell.js";
|
|
9
9
|
|
|
10
|
-
describe("
|
|
11
|
-
it("should render the default
|
|
10
|
+
describe("CompactCell", () => {
|
|
11
|
+
it("should render the default CompactCell component", () => {
|
|
12
12
|
// Arrange
|
|
13
13
|
|
|
14
14
|
// Act
|
|
15
|
-
render(<
|
|
15
|
+
render(<CompactCell title="Compact cell" />);
|
|
16
16
|
|
|
17
17
|
// Assert
|
|
18
|
-
expect(screen.getByText("
|
|
18
|
+
expect(screen.getByText("Compact cell")).toBeInTheDocument();
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it("should render the title using a Typography element", () => {
|
|
22
22
|
// Arrange
|
|
23
23
|
|
|
24
24
|
// Act
|
|
25
|
-
render(
|
|
25
|
+
render(
|
|
26
|
+
<CompactCell title={<HeadingMedium>Compact cell</HeadingMedium>} />,
|
|
27
|
+
);
|
|
26
28
|
|
|
27
29
|
// Assert
|
|
28
30
|
expect(
|
|
29
|
-
screen.getByRole("heading", {name: "
|
|
31
|
+
screen.getByRole("heading", {name: "Compact cell"}),
|
|
30
32
|
).toBeInTheDocument();
|
|
31
33
|
});
|
|
32
34
|
|
|
@@ -35,8 +37,8 @@ describe("BasicCell", () => {
|
|
|
35
37
|
|
|
36
38
|
// Act
|
|
37
39
|
render(
|
|
38
|
-
<
|
|
39
|
-
title="
|
|
40
|
+
<CompactCell
|
|
41
|
+
title="Compact cell"
|
|
40
42
|
leftAccessory={
|
|
41
43
|
<Icon icon={icons.caretRight} aria-label="Caret icon" />
|
|
42
44
|
}
|
|
@@ -52,8 +54,8 @@ describe("BasicCell", () => {
|
|
|
52
54
|
|
|
53
55
|
// Act
|
|
54
56
|
render(
|
|
55
|
-
<
|
|
56
|
-
title="
|
|
57
|
+
<CompactCell
|
|
58
|
+
title="Compact cell"
|
|
57
59
|
rightAccessory={
|
|
58
60
|
<Icon icon={icons.caretRight} aria-label="Caret icon" />
|
|
59
61
|
}
|
|
@@ -68,17 +70,17 @@ describe("BasicCell", () => {
|
|
|
68
70
|
// Arrange
|
|
69
71
|
|
|
70
72
|
// Act
|
|
71
|
-
render(<
|
|
73
|
+
render(<CompactCell title="Compact cell" testId="cellId" />);
|
|
72
74
|
|
|
73
75
|
// Assert
|
|
74
|
-
expect(screen.getByTestId("cellId")).toHaveTextContent("
|
|
76
|
+
expect(screen.getByTestId("cellId")).toHaveTextContent("Compact cell");
|
|
75
77
|
});
|
|
76
78
|
|
|
77
79
|
it("should add a button if onClick is set", () => {
|
|
78
80
|
// Arrange
|
|
79
81
|
|
|
80
82
|
// Act
|
|
81
|
-
render(<
|
|
83
|
+
render(<CompactCell title="Compact cell" onClick={jest.fn()} />);
|
|
82
84
|
|
|
83
85
|
// Assert
|
|
84
86
|
expect(screen.getByRole("button")).toBeInTheDocument();
|
|
@@ -87,7 +89,7 @@ describe("BasicCell", () => {
|
|
|
87
89
|
it("should allow clicking the cell if onClick is set", () => {
|
|
88
90
|
// Arrange
|
|
89
91
|
const onClickMock = jest.fn();
|
|
90
|
-
render(<
|
|
92
|
+
render(<CompactCell title="Compact cell" onClick={onClickMock} />);
|
|
91
93
|
|
|
92
94
|
// Act
|
|
93
95
|
screen.getByRole("button").click();
|
|
@@ -8,22 +8,24 @@ import CellCore from "./internal/cell-core.js";
|
|
|
8
8
|
import type {CellProps} from "../util/types.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
* with limited subviews and accessories
|
|
13
|
-
*
|
|
11
|
+
* `CompactCell` is the simplest form of the Cell. It is a compacted-height Cell
|
|
12
|
+
* with limited subviews and accessories. Typically they represent additional
|
|
13
|
+
* info or selection lists. It has a minimum height of 48px and a non-bold
|
|
14
|
+
* title. It does not have subtitles or a progress bar, and in general it has
|
|
15
|
+
* less vertical space around text and accessories.
|
|
14
16
|
*
|
|
15
17
|
* ### Usage
|
|
16
18
|
*
|
|
17
19
|
* ```jsx
|
|
18
|
-
* import {
|
|
20
|
+
* import {CompactCell} from "@khanacademy/wonder-blocks-cell";
|
|
19
21
|
*
|
|
20
|
-
* <
|
|
21
|
-
* title="
|
|
22
|
+
* <CompactCell
|
|
23
|
+
* title="Compact cell"
|
|
22
24
|
* rightAccessory={<Icon icon={icons.caretRight} size="medium" />}
|
|
23
25
|
* />
|
|
24
26
|
* ```
|
|
25
27
|
*/
|
|
26
|
-
function
|
|
28
|
+
function CompactCell(props: CellProps): React.Node {
|
|
27
29
|
const {title, ...coreProps} = props;
|
|
28
30
|
|
|
29
31
|
return (
|
|
@@ -37,4 +39,4 @@ function BasicCell(props: CellProps): React.Node {
|
|
|
37
39
|
);
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
export default
|
|
42
|
+
export default CompactCell;
|
|
@@ -5,9 +5,10 @@ import {StyleSheet} from "aphrodite";
|
|
|
5
5
|
import Color from "@khanacademy/wonder-blocks-color";
|
|
6
6
|
import {Strut} from "@khanacademy/wonder-blocks-layout";
|
|
7
7
|
import Spacing from "@khanacademy/wonder-blocks-spacing";
|
|
8
|
-
import {LabelSmall,
|
|
8
|
+
import {LabelSmall, LabelMedium} from "@khanacademy/wonder-blocks-typography";
|
|
9
9
|
|
|
10
10
|
import CellCore from "./internal/cell-core.js";
|
|
11
|
+
import {CellMeasurements} from "./internal/common.js";
|
|
11
12
|
|
|
12
13
|
import type {CellProps, TypographyText} from "../util/types.js";
|
|
13
14
|
|
|
@@ -55,8 +56,11 @@ type DetailCellProps = {|
|
|
|
55
56
|
|};
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
|
-
* This is a variant of
|
|
59
|
-
* the cell title.
|
|
59
|
+
* This is a variant of CompactCell that allows adding subtitles, before and
|
|
60
|
+
* after the cell title. They typically represent an item that can be
|
|
61
|
+
* clicked/tapped to view more complex details. They vary in height depending on
|
|
62
|
+
* the presence or absence of subtitles, and they allow for a wide range of
|
|
63
|
+
* functionality depending on which accessories are active.
|
|
60
64
|
*
|
|
61
65
|
* ### Usage
|
|
62
66
|
*
|
|
@@ -76,11 +80,11 @@ function DetailCell(props: DetailCellProps): React.Node {
|
|
|
76
80
|
const {title, subtitle1, subtitle2, ...coreProps} = props;
|
|
77
81
|
|
|
78
82
|
return (
|
|
79
|
-
<CellCore {...coreProps}>
|
|
83
|
+
<CellCore {...coreProps} innerStyle={styles.innerWrapper}>
|
|
80
84
|
<Subtitle subtitle={subtitle1} disabled={coreProps.disabled} />
|
|
81
85
|
{subtitle1 && <Strut size={Spacing.xxxxSmall_2} />}
|
|
82
86
|
{typeof title === "string" ? (
|
|
83
|
-
<
|
|
87
|
+
<LabelMedium>{title}</LabelMedium>
|
|
84
88
|
) : (
|
|
85
89
|
title
|
|
86
90
|
)}
|
|
@@ -95,6 +99,11 @@ const styles = StyleSheet.create({
|
|
|
95
99
|
subtitle: {
|
|
96
100
|
color: Color.offBlack64,
|
|
97
101
|
},
|
|
102
|
+
|
|
103
|
+
// This is to override the default padding of the CellCore innerWrapper.
|
|
104
|
+
innerWrapper: {
|
|
105
|
+
padding: `${CellMeasurements.detailCellPadding.paddingVertical}px ${CellMeasurements.detailCellPadding.paddingHorizontal}px`,
|
|
106
|
+
},
|
|
98
107
|
});
|
|
99
108
|
|
|
100
109
|
export default DetailCell;
|
|
@@ -74,7 +74,10 @@ describe("CellCore", () => {
|
|
|
74
74
|
);
|
|
75
75
|
|
|
76
76
|
// Assert
|
|
77
|
-
expect(screen.getByRole("button")).
|
|
77
|
+
expect(screen.getByRole("button")).toHaveAttribute(
|
|
78
|
+
"aria-disabled",
|
|
79
|
+
"true",
|
|
80
|
+
);
|
|
78
81
|
});
|
|
79
82
|
|
|
80
83
|
it("should add aria-current if active is set", () => {
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {StyleSheet} from "aphrodite";
|
|
4
4
|
|
|
5
|
+
import type {StyleType} from "@khanacademy/wonder-blocks-core";
|
|
6
|
+
|
|
5
7
|
import Clickable from "@khanacademy/wonder-blocks-clickable";
|
|
6
8
|
import {View} from "@khanacademy/wonder-blocks-core";
|
|
7
9
|
import Color, {fade} from "@khanacademy/wonder-blocks-color";
|
|
@@ -94,11 +96,19 @@ type CellCoreProps = {|
|
|
|
94
96
|
* The content of the cell.
|
|
95
97
|
*/
|
|
96
98
|
children: React.Node,
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The optional styles applied to the inner wrapper.
|
|
102
|
+
*
|
|
103
|
+
* Note: This is not intended to be used externally, only used directly
|
|
104
|
+
* within the package scope.
|
|
105
|
+
*/
|
|
106
|
+
innerStyle?: StyleType,
|
|
97
107
|
|};
|
|
98
108
|
|
|
99
109
|
/**
|
|
100
110
|
* CellCore is the base cell wrapper. It's used as the skeleton/layout that is
|
|
101
|
-
* used by
|
|
111
|
+
* used by CompactCell and DetailCell (and any other variants).
|
|
102
112
|
*
|
|
103
113
|
* Both variants share how they render their accessories, and the main
|
|
104
114
|
* responsibility of this component is to render the contents that are passed in
|
|
@@ -118,6 +128,7 @@ const CellCore = (props: CellCoreProps): React.Node => {
|
|
|
118
128
|
style,
|
|
119
129
|
testId,
|
|
120
130
|
"aria-label": ariaLabel,
|
|
131
|
+
innerStyle,
|
|
121
132
|
} = props;
|
|
122
133
|
|
|
123
134
|
const renderCell = (eventState?: ClickableState): React.Node => {
|
|
@@ -130,14 +141,15 @@ const CellCore = (props: CellCoreProps): React.Node => {
|
|
|
130
141
|
// focused applied to the main wrapper to make the border
|
|
131
142
|
// outline part of the wrapper
|
|
132
143
|
eventState?.focused && styles.focused,
|
|
133
|
-
// custom styles
|
|
134
|
-
style,
|
|
135
144
|
]}
|
|
136
145
|
aria-current={active ? "true" : undefined}
|
|
137
146
|
>
|
|
138
147
|
<View
|
|
139
148
|
style={[
|
|
140
149
|
styles.innerWrapper,
|
|
150
|
+
innerStyle,
|
|
151
|
+
// custom styles
|
|
152
|
+
style,
|
|
141
153
|
horizontalRuleStyles,
|
|
142
154
|
disabled && styles.disabled,
|
|
143
155
|
active && styles.active,
|
|
@@ -273,6 +285,9 @@ const styles = StyleSheet.create({
|
|
|
273
285
|
|
|
274
286
|
disabled: {
|
|
275
287
|
color: Color.offBlack32,
|
|
288
|
+
":hover": {
|
|
289
|
+
cursor: "not-allowed",
|
|
290
|
+
},
|
|
276
291
|
},
|
|
277
292
|
|
|
278
293
|
accessoryActive: {
|
|
@@ -18,6 +18,14 @@ export const CellMeasurements = {
|
|
|
18
18
|
paddingHorizontal: Spacing.medium_16,
|
|
19
19
|
},
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* The DetailCell wrapper's gap.
|
|
23
|
+
*/
|
|
24
|
+
detailCellPadding: {
|
|
25
|
+
paddingVertical: Spacing.small_12,
|
|
26
|
+
paddingHorizontal: Spacing.medium_16,
|
|
27
|
+
},
|
|
28
|
+
|
|
21
29
|
/**
|
|
22
30
|
* The extra vertical spacing added to the title/content wrapper.
|
|
23
31
|
*/
|
package/src/index.js
CHANGED