@khanacademy/wonder-blocks-cell 2.2.14 → 2.2.16

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.
Files changed (33) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/dist/components/compact-cell.d.ts +22 -0
  3. package/dist/components/compact-cell.js.flow +30 -0
  4. package/dist/components/detail-cell.d.ts +39 -0
  5. package/dist/components/detail-cell.js.flow +51 -0
  6. package/dist/components/internal/cell-core.d.ts +26 -0
  7. package/dist/components/internal/cell-core.js.flow +38 -0
  8. package/dist/components/internal/common.d.ts +30 -0
  9. package/dist/components/internal/common.js.flow +45 -0
  10. package/dist/es/index.js +40 -32
  11. package/dist/index.d.ts +3 -0
  12. package/dist/index.js +57 -51
  13. package/dist/index.js.flow +10 -2
  14. package/dist/util/types.d.ts +122 -0
  15. package/dist/util/types.js.flow +148 -0
  16. package/package.json +9 -9
  17. package/src/components/__tests__/{compact-cell.test.js → compact-cell.test.tsx} +1 -2
  18. package/src/components/__tests__/{detail-cell.test.js → detail-cell.test.tsx} +1 -2
  19. package/src/components/{compact-cell.js → compact-cell.tsx} +4 -5
  20. package/src/components/{detail-cell.js → detail-cell.tsx} +20 -18
  21. package/src/components/internal/__tests__/{cell-core.test.js → cell-core.test.tsx} +1 -2
  22. package/src/components/internal/__tests__/{common.test.js → common.test.ts} +1 -3
  23. package/src/components/internal/{cell-core.js → cell-core.tsx} +28 -27
  24. package/src/components/internal/{common.js → common.ts} +2 -3
  25. package/src/index.ts +4 -0
  26. package/src/util/{types.js → types.ts} +25 -39
  27. package/tsconfig.json +17 -0
  28. package/tsconfig.tsbuildinfo +1 -0
  29. package/src/components/__docs__/compact-cell.argtypes.js +0 -189
  30. package/src/components/__docs__/compact-cell.stories.js +0 -305
  31. package/src/components/__docs__/detail-cell.argtypes.js +0 -28
  32. package/src/components/__docs__/detail-cell.stories.js +0 -208
  33. package/src/index.js +0 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,47 @@
1
1
  # @khanacademy/wonder-blocks-cell
2
2
 
3
+ ## 2.2.16
4
+
5
+ ### Patch Changes
6
+
7
+ - d816af08: Update build and test configs use TypeScript
8
+ - 3891f544: Update babel config to include plugins that Storybook needed
9
+ - 0d28bb1c: Configured TypeScript
10
+ - 3d05f764: Fix HOCs and other type errors
11
+ - c2ec4902: Update eslint configuration, fix lint
12
+ - 2983c05b: Include 'types' field in package.json
13
+ - 77ff6a66: Generate Flow types from TypeScript types
14
+ - ec8d4b7f: Fix miscellaneous TypeScript errors
15
+ - Updated dependencies [d816af08]
16
+ - Updated dependencies [3891f544]
17
+ - Updated dependencies [0d28bb1c]
18
+ - Updated dependencies [873f4a14]
19
+ - Updated dependencies [3d05f764]
20
+ - Updated dependencies [c2ec4902]
21
+ - Updated dependencies [2983c05b]
22
+ - Updated dependencies [77ff6a66]
23
+ - Updated dependencies [ec8d4b7f]
24
+ - @khanacademy/wonder-blocks-clickable@2.4.6
25
+ - @khanacademy/wonder-blocks-color@1.2.2
26
+ - @khanacademy/wonder-blocks-core@4.8.0
27
+ - @khanacademy/wonder-blocks-layout@1.4.17
28
+ - @khanacademy/wonder-blocks-spacing@3.0.6
29
+ - @khanacademy/wonder-blocks-typography@1.1.39
30
+
31
+ ## 2.2.15
32
+
33
+ ### Patch Changes
34
+
35
+ - 91cb727c: Remove file extensions from imports
36
+ - Updated dependencies [91cb727c]
37
+ - Updated dependencies [91cb727c]
38
+ - Updated dependencies [91cb727c]
39
+ - @khanacademy/wonder-blocks-clickable@2.4.5
40
+ - @khanacademy/wonder-blocks-color@1.2.1
41
+ - @khanacademy/wonder-blocks-core@4.7.0
42
+ - @khanacademy/wonder-blocks-layout@1.4.16
43
+ - @khanacademy/wonder-blocks-typography@1.1.38
44
+
3
45
  ## 2.2.14
4
46
 
5
47
  ### Patch Changes
@@ -0,0 +1,22 @@
1
+ import * as React from "react";
2
+ import type { CellProps } from "../util/types";
3
+ /**
4
+ * `CompactCell` is the simplest form of the Cell. It is a compacted-height Cell
5
+ * with limited subviews and accessories. Typically they represent additional
6
+ * info or selection lists. It has a minimum height of 48px and a non-bold
7
+ * title. It does not have subtitles or a progress bar, and in general it has
8
+ * less vertical space around text and accessories.
9
+ *
10
+ * ### Usage
11
+ *
12
+ * ```jsx
13
+ * import {CompactCell} from "@khanacademy/wonder-blocks-cell";
14
+ *
15
+ * <CompactCell
16
+ * title="Compact cell"
17
+ * rightAccessory={<Icon icon={icons.caretRight} size="medium" />}
18
+ * />
19
+ * ```
20
+ */
21
+ declare const CompactCell: React.FC<CellProps>;
22
+ export default CompactCell;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Flowtype definitions for compact-cell
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import type { CellProps } from "../util/types";
10
+
11
+ /**
12
+ * `CompactCell` is the simplest form of the Cell. It is a compacted-height Cell
13
+ * with limited subviews and accessories. Typically they represent additional
14
+ * info or selection lists. It has a minimum height of 48px and a non-bold
15
+ * title. It does not have subtitles or a progress bar, and in general it has
16
+ * less vertical space around text and accessories.
17
+ *
18
+ * ### Usage
19
+ *
20
+ * ```jsx
21
+ * import {CompactCell} from "@khanacademy/wonder-blocks-cell";
22
+ *
23
+ * <CompactCell
24
+ * title="Compact cell"
25
+ * rightAccessory={<Icon icon={icons.caretRight} size="medium" />}
26
+ * />
27
+ * ```
28
+ */
29
+ declare var CompactCell: React.FC<CellProps>;
30
+ declare export default typeof CompactCell;
@@ -0,0 +1,39 @@
1
+ import * as React from "react";
2
+ import type { CellProps, TypographyText } from "../util/types";
3
+ type DetailCellProps = CellProps & {
4
+ /**
5
+ * You can either provide a string or a custom node Typography element (or
6
+ * nothing at all). Both a string or a custom node Typography element will
7
+ * occupy the “Subtitle1” area of the Cell.
8
+ */
9
+ subtitle1?: TypographyText;
10
+ /**
11
+ * You can either provide a string or a custom node Typography element (or
12
+ * nothing at all). Both a string or a custom node Typography element will
13
+ * occupy the “Subtitle2” area of the Cell.
14
+ */
15
+ subtitle2?: TypographyText;
16
+ };
17
+ /**
18
+ * This is a variant of CompactCell that allows adding subtitles, before and
19
+ * after the cell title. They typically represent an item that can be
20
+ * clicked/tapped to view more complex details. They vary in height depending on
21
+ * the presence or absence of subtitles, and they allow for a wide range of
22
+ * functionality depending on which accessories are active.
23
+ *
24
+ * ### Usage
25
+ *
26
+ * ```jsx
27
+ * import {DetailCell} from "@khanacademy/wonder-blocks-cell";
28
+ *
29
+ * <DetailCell
30
+ * leftAccessory={<Icon icon={icons.contentVideo} size="medium" />}
31
+ * subtitle1="Subtitle 1"
32
+ * title="Detail cell"
33
+ * subtitle1="Subtitle 2"
34
+ * rightAccessory={<Icon icon={icons.caretRight} size="medium" />}
35
+ * />
36
+ * ```
37
+ */
38
+ declare const DetailCell: React.FC<DetailCellProps>;
39
+ export default DetailCell;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Flowtype definitions for detail-cell
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import type { CellProps, TypographyText } from "../util/types";
10
+ declare type DetailCellProps = {
11
+ ...CellProps,
12
+ ...{
13
+ /**
14
+ * You can either provide a string or a custom node Typography element (or
15
+ * nothing at all). Both a string or a custom node Typography element will
16
+ * occupy the “Subtitle1” area of the Cell.
17
+ */
18
+ subtitle1?: TypographyText,
19
+
20
+ /**
21
+ * You can either provide a string or a custom node Typography element (or
22
+ * nothing at all). Both a string or a custom node Typography element will
23
+ * occupy the “Subtitle2” area of the Cell.
24
+ */
25
+ subtitle2?: TypographyText,
26
+ ...
27
+ },
28
+ };
29
+ /**
30
+ * This is a variant of CompactCell that allows adding subtitles, before and
31
+ * after the cell title. They typically represent an item that can be
32
+ * clicked/tapped to view more complex details. They vary in height depending on
33
+ * the presence or absence of subtitles, and they allow for a wide range of
34
+ * functionality depending on which accessories are active.
35
+ *
36
+ * ### Usage
37
+ *
38
+ * ```jsx
39
+ * import {DetailCell} from "@khanacademy/wonder-blocks-cell";
40
+ *
41
+ * <DetailCell
42
+ * leftAccessory={<Icon icon={icons.contentVideo} size="medium" />}
43
+ * subtitle1="Subtitle 1"
44
+ * title="Detail cell"
45
+ * subtitle1="Subtitle 2"
46
+ * rightAccessory={<Icon icon={icons.caretRight} size="medium" />}
47
+ * />
48
+ * ```
49
+ */
50
+ declare var DetailCell: React.FC<DetailCellProps>;
51
+ declare export default typeof DetailCell;
@@ -0,0 +1,26 @@
1
+ import * as React from "react";
2
+ import type { StyleType } from "@khanacademy/wonder-blocks-core";
3
+ import type { CellProps } from "../../util/types";
4
+ type CellCoreProps = Partial<Omit<CellProps, "title">> & {
5
+ /**
6
+ * The content of the cell.
7
+ */
8
+ children: React.ReactNode;
9
+ /**
10
+ * The optional styles applied to the inner wrapper.
11
+ *
12
+ * Note: This is not intended to be used externally, only used directly
13
+ * within the package scope.
14
+ */
15
+ innerStyle?: StyleType;
16
+ };
17
+ /**
18
+ * CellCore is the base cell wrapper. It's used as the skeleton/layout that is
19
+ * used by CompactCell and DetailCell (and any other variants).
20
+ *
21
+ * Both variants share how they render their accessories, and the main
22
+ * responsibility of this component is to render the contents that are passed in
23
+ * (using the `children` prop).
24
+ */
25
+ declare const CellCore: React.FC<CellCoreProps>;
26
+ export default CellCore;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Flowtype definitions for cell-core
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import type { StyleType } from "@khanacademy/wonder-blocks-core";
10
+ import type { CellProps } from "../../util/types";
11
+ declare type CellCoreProps = {
12
+ ...$Rest<$Diff<CellProps, { title: any }>, { ... }>,
13
+ ...{
14
+ /**
15
+ * The content of the cell.
16
+ */
17
+ children: React.Node,
18
+
19
+ /**
20
+ * The optional styles applied to the inner wrapper.
21
+ *
22
+ * Note: This is not intended to be used externally, only used directly
23
+ * within the package scope.
24
+ */
25
+ innerStyle?: StyleType,
26
+ ...
27
+ },
28
+ };
29
+ /**
30
+ * CellCore is the base cell wrapper. It's used as the skeleton/layout that is
31
+ * used by CompactCell and DetailCell (and any other variants).
32
+ *
33
+ * Both variants share how they render their accessories, and the main
34
+ * responsibility of this component is to render the contents that are passed in
35
+ * (using the `children` prop).
36
+ */
37
+ declare var CellCore: React.FC<CellCoreProps>;
38
+ declare export default typeof CellCore;
@@ -0,0 +1,30 @@
1
+ import type { StyleType } from "@khanacademy/wonder-blocks-core";
2
+ import type { HorizontalRuleVariant } from "../../util/types";
3
+ export declare const CellMeasurements: {
4
+ readonly cellMinHeight: 48;
5
+ /**
6
+ * The cell wrapper's gap.
7
+ */
8
+ readonly cellPadding: {
9
+ readonly paddingVertical: 12;
10
+ readonly paddingHorizontal: 16;
11
+ };
12
+ /**
13
+ * The DetailCell wrapper's gap.
14
+ */
15
+ readonly detailCellPadding: {
16
+ readonly paddingVertical: 16;
17
+ readonly paddingHorizontal: 16;
18
+ };
19
+ /**
20
+ * The horizontal spacing between the left and right accessory.
21
+ */
22
+ readonly accessoryHorizontalSpacing: 16;
23
+ };
24
+ /**
25
+ * Gets the horizontalRule style based on the variant.
26
+ * @param {HorizontalRuleVariant} horizontalRule The variant of the horizontal
27
+ * rule.
28
+ * @returns A styled horizontal rule.
29
+ */
30
+ export declare const getHorizontalRuleStyles: (horizontalRule: HorizontalRuleVariant) => StyleType;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Flowtype definitions for common
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
+ import type { HorizontalRuleVariant } from "../../util/types";
10
+ declare export var CellMeasurements: {
11
+ +cellMinHeight: 48,
12
+
13
+ /**
14
+ * The cell wrapper's gap.
15
+ */
16
+ +cellPadding: {
17
+ +paddingVertical: 12,
18
+ +paddingHorizontal: 16,
19
+ ...
20
+ },
21
+
22
+ /**
23
+ * The DetailCell wrapper's gap.
24
+ */
25
+ +detailCellPadding: {
26
+ +paddingVertical: 16,
27
+ +paddingHorizontal: 16,
28
+ ...
29
+ },
30
+
31
+ /**
32
+ * The horizontal spacing between the left and right accessory.
33
+ */
34
+ +accessoryHorizontalSpacing: 16,
35
+ ...
36
+ };
37
+ /**
38
+ * Gets the horizontalRule style based on the variant.
39
+ * @param {HorizontalRuleVariant} horizontalRule The variant of the horizontal
40
+ * rule.
41
+ * @returns A styled horizontal rule.
42
+ */
43
+ declare export var getHorizontalRuleStyles: (
44
+ horizontalRule: HorizontalRuleVariant
45
+ ) => StyleType;
package/dist/es/index.js CHANGED
@@ -1,7 +1,5 @@
1
- import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
2
1
  import * as React from 'react';
3
2
  import { LabelMedium, LabelSmall } from '@khanacademy/wonder-blocks-typography';
4
- import _extends from '@babel/runtime/helpers/extends';
5
3
  import { StyleSheet } from 'aphrodite';
6
4
  import Clickable from '@khanacademy/wonder-blocks-clickable';
7
5
  import { View } from '@khanacademy/wonder-blocks-core';
@@ -9,6 +7,34 @@ import Color, { fade } from '@khanacademy/wonder-blocks-color';
9
7
  import { Strut } from '@khanacademy/wonder-blocks-layout';
10
8
  import Spacing from '@khanacademy/wonder-blocks-spacing';
11
9
 
10
+ function _objectWithoutPropertiesLoose(source, excluded) {
11
+ if (source == null) return {};
12
+ var target = {};
13
+ var sourceKeys = Object.keys(source);
14
+ var key, i;
15
+ for (i = 0; i < sourceKeys.length; i++) {
16
+ key = sourceKeys[i];
17
+ if (excluded.indexOf(key) >= 0) continue;
18
+ target[key] = source[key];
19
+ }
20
+ return target;
21
+ }
22
+
23
+ function _extends() {
24
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
25
+ for (var i = 1; i < arguments.length; i++) {
26
+ var source = arguments[i];
27
+ for (var key in source) {
28
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
29
+ target[key] = source[key];
30
+ }
31
+ }
32
+ }
33
+ return target;
34
+ };
35
+ return _extends.apply(this, arguments);
36
+ }
37
+
12
38
  const CellMeasurements = {
13
39
  cellMinHeight: Spacing.xxLarge_48,
14
40
  cellPadding: {
@@ -25,10 +51,8 @@ const getHorizontalRuleStyles = horizontalRule => {
25
51
  switch (horizontalRule) {
26
52
  case "inset":
27
53
  return [styles$2.horizontalRule, styles$2.horizontalRuleInset];
28
-
29
54
  case "full-width":
30
55
  return styles$2.horizontalRule;
31
-
32
56
  case "none":
33
57
  return {};
34
58
  }
@@ -61,14 +85,12 @@ const LeftAccessory = ({
61
85
  if (!leftAccessory) {
62
86
  return null;
63
87
  }
64
-
65
88
  return React.createElement(React.Fragment, null, React.createElement(View, {
66
89
  style: [styles$1.accessory, disabled && styles$1.accessoryDisabled, _extends({}, leftAccessoryStyle)]
67
90
  }, leftAccessory), React.createElement(Strut, {
68
91
  size: CellMeasurements.accessoryHorizontalSpacing
69
92
  }));
70
93
  };
71
-
72
94
  const RightAccessory = ({
73
95
  rightAccessory,
74
96
  rightAccessoryStyle,
@@ -78,14 +100,12 @@ const RightAccessory = ({
78
100
  if (!rightAccessory) {
79
101
  return null;
80
102
  }
81
-
82
103
  return React.createElement(React.Fragment, null, React.createElement(Strut, {
83
104
  size: CellMeasurements.accessoryHorizontalSpacing
84
105
  }), React.createElement(View, {
85
106
  style: [styles$1.accessory, styles$1.accessoryRight, disabled && styles$1.accessoryDisabled, _extends({}, rightAccessoryStyle), active && styles$1.accessoryActive]
86
107
  }, rightAccessory));
87
108
  };
88
-
89
109
  const CellCore = props => {
90
110
  const {
91
111
  active,
@@ -104,7 +124,6 @@ const CellCore = props => {
104
124
  innerStyle,
105
125
  target
106
126
  } = props;
107
-
108
127
  const renderCell = eventState => {
109
128
  const horizontalRuleStyles = getHorizontalRuleStyles(horizontalRule);
110
129
  return React.createElement(View, {
@@ -126,7 +145,6 @@ const CellCore = props => {
126
145
  disabled: disabled
127
146
  })));
128
147
  };
129
-
130
148
  if (onClick || href) {
131
149
  return React.createElement(Clickable, {
132
150
  disabled: disabled,
@@ -137,10 +155,8 @@ const CellCore = props => {
137
155
  target: target
138
156
  }, eventState => renderCell(eventState));
139
157
  }
140
-
141
158
  return renderCell();
142
159
  };
143
-
144
160
  const styles$1 = StyleSheet.create({
145
161
  wrapper: {
146
162
  background: Color.white,
@@ -204,18 +220,15 @@ const styles$1 = StyleSheet.create({
204
220
  });
205
221
 
206
222
  const _excluded$1 = ["title"];
207
-
208
- function CompactCell(props) {
223
+ const CompactCell = function CompactCell(props) {
209
224
  const {
210
- title
211
- } = props,
212
- coreProps = _objectWithoutPropertiesLoose(props, _excluded$1);
213
-
225
+ title
226
+ } = props,
227
+ coreProps = _objectWithoutPropertiesLoose(props, _excluded$1);
214
228
  return React.createElement(CellCore, coreProps, typeof title === "string" ? React.createElement(LabelMedium, null, title) : title);
215
- }
229
+ };
216
230
 
217
231
  const _excluded = ["title", "subtitle1", "subtitle2"];
218
-
219
232
  const Subtitle = ({
220
233
  subtitle,
221
234
  disabled
@@ -223,24 +236,20 @@ const Subtitle = ({
223
236
  if (!subtitle) {
224
237
  return null;
225
238
  }
226
-
227
239
  if (typeof subtitle === "string") {
228
240
  return React.createElement(LabelSmall, {
229
241
  style: !disabled && styles.subtitle
230
242
  }, subtitle);
231
243
  }
232
-
233
244
  return subtitle;
234
245
  };
235
-
236
- function DetailCell(props) {
246
+ const DetailCell = function DetailCell(props) {
237
247
  const {
238
- title,
239
- subtitle1,
240
- subtitle2
241
- } = props,
242
- coreProps = _objectWithoutPropertiesLoose(props, _excluded);
243
-
248
+ title,
249
+ subtitle1,
250
+ subtitle2
251
+ } = props,
252
+ coreProps = _objectWithoutPropertiesLoose(props, _excluded);
244
253
  return React.createElement(CellCore, _extends({}, coreProps, {
245
254
  innerStyle: styles.innerWrapper
246
255
  }), React.createElement(Subtitle, {
@@ -254,8 +263,7 @@ function DetailCell(props) {
254
263
  subtitle: subtitle2,
255
264
  disabled: coreProps.disabled
256
265
  }));
257
- }
258
-
266
+ };
259
267
  const styles = StyleSheet.create({
260
268
  subtitle: {
261
269
  color: Color.offBlack64
@@ -0,0 +1,3 @@
1
+ import CompactCell from "./components/compact-cell";
2
+ import DetailCell from "./components/detail-cell";
3
+ export { CompactCell, DetailCell };