@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
@@ -1,189 +0,0 @@
1
- // @flow
2
- import * as React from "react";
3
- import {View} from "@khanacademy/wonder-blocks-core";
4
- import Icon, {icons} from "@khanacademy/wonder-blocks-icon";
5
- import {LabelSmall, LabelXSmall} from "@khanacademy/wonder-blocks-typography";
6
-
7
- /**
8
- * Some pre-defined accessory examples to use in our stories.
9
- */
10
- export const AccessoryMappings = {
11
- withContentArticle: ((
12
- <Icon icon={icons.contentArticle} size="medium" />
13
- ): React.Element<typeof Icon>),
14
- withContentVideo: ((
15
- <Icon icon={icons.contentVideo} size="medium" />
16
- ): React.Element<typeof Icon>),
17
- withCaret: (<Icon icon={icons.caretRight} size="medium" />: React.Element<
18
- typeof Icon,
19
- >),
20
- withText: (<LabelSmall>26.3 GB</LabelSmall>: React.Element<
21
- typeof LabelSmall,
22
- >),
23
- withIconText: ((
24
- <View style={{alignItems: "center"}}>
25
- <Icon icon={icons.info} size="small" />
26
- <LabelXSmall>Info</LabelXSmall>
27
- </View>
28
- ): React.Element<typeof View>),
29
- withImage: ((
30
- <img src="./avatar.png" alt="ItemAvatar" width={48} height={48} />
31
- ): React$Element<"img">),
32
- };
33
-
34
- export default {
35
- title: {
36
- description:
37
- "The title / main content of the cell. You can either provide a string or a Typography component. If a string is provided, typography defaults to `LabelLarge`.",
38
- type: {required: true},
39
- table: {
40
- type: {
41
- summary: "TypographyText",
42
- detail: "string | React.Element<Typography>",
43
- },
44
- },
45
- },
46
- leftAccessory: {
47
- description: `If provided, this adds a left accessory to the cell. Left Accessories can be defined using WB components such as Icon, IconButton, or it can even be used for a custom node/component if needed. What ever is passed in will occupy the "LeftAccessory” area of the Cell.`,
48
- control: {type: "select"},
49
- options: (Object.keys(AccessoryMappings): Array<React.Node>),
50
- mapping: AccessoryMappings,
51
- table: {
52
- category: "Layout",
53
- type: {
54
- summary: "React.Node",
55
- detail: "By default it uses a free width and its default alignment is center (for both vertical and horizontal).",
56
- },
57
- },
58
- },
59
- leftAccessoryStyle: {
60
- description: `Optional custom styles applied to the leftAccessory wrapper. For example, it can be used to set a custom minWidth or a custom alignment.`,
61
- table: {
62
- category: "Styling",
63
- type: {
64
- summary: "AccessoryStyle",
65
- detail: "NOTE: leftAccessoryStyle can only be used if leftAccessory is set.",
66
- },
67
- },
68
- },
69
- rightAccessory: {
70
- description: `If provided, this adds a right accessory to the cell. Right Accessories can be defined using WB components such as Icon, IconButton, or it can even be used for a custom node/component if needed. What ever is passed in will occupy the “RightAccessory” area of the Cell.`,
71
- control: {type: "select"},
72
- options: (Object.keys(AccessoryMappings): Array<React.Node>),
73
- mapping: AccessoryMappings,
74
- table: {
75
- category: "Layout",
76
- type: {
77
- summary: "React.Node",
78
- detail: "By default it uses a free width and its default alignment is center (for both vertical and horizontal).",
79
- },
80
- },
81
- },
82
- rightAccessoryStyle: {
83
- description: `Optional custom styles applied to the rightAccessory wrapper. For example, it can be used to set a custom minWidth or a custom alignment.`,
84
- table: {
85
- category: "Styling",
86
- type: {
87
- summary: "AccessoryStyle",
88
- detail: "NOTE: rightAccessoryStyle can only be used if rightAccessory is set.",
89
- },
90
- },
91
- },
92
- horizontalRule: {
93
- description:
94
- "Adds a horizontal rule at the bottom of the cell that can be used to separate cells within groups such as lists. Defaults to `inset`.",
95
- defaultValue: "inset",
96
- options: ["inset", "full-width", "none"],
97
- control: {type: "select"},
98
- table: {
99
- category: "Layout",
100
- type: {
101
- summary: "inset | full-width | none",
102
- },
103
- },
104
- },
105
- style: {
106
- description: "Optional custom styles.",
107
- control: {type: "object"},
108
- table: {
109
- category: "Styling",
110
- type: {
111
- summary: "StyleType",
112
- },
113
- },
114
- },
115
- testId: {
116
- description: "Test ID used for e2e testing.",
117
- control: {type: "text"},
118
- table: {
119
- type: {
120
- summary: "string",
121
- },
122
- },
123
- },
124
- href: {
125
- description:
126
- "Optional href which Cell should direct to, uses client-side routing by default if react-router is present.",
127
- control: {type: "text"},
128
- table: {
129
- category: "Navigation",
130
- type: {
131
- summary: "string",
132
- },
133
- },
134
- },
135
- onClick: {
136
- action: "clicked",
137
- description: `Called when the cell is clicked.
138
- If not provided, the Cell can’t be hovered and/or pressed (highlighted on
139
- hover).
140
- `,
141
- table: {
142
- category: "Events",
143
- type: {
144
- summary: "(e: SyntheticEvent<>) => mixed",
145
- },
146
- },
147
- },
148
- disabled: {
149
- description: "Whether the cell is disabled.",
150
- control: {
151
- type: "boolean",
152
- },
153
- defaultValue: false,
154
- table: {
155
- type: {
156
- summary: "boolean",
157
- },
158
- },
159
- },
160
- active: {
161
- description: "Whether the cell is active (or currently selected).",
162
- control: {
163
- type: "boolean",
164
- },
165
- defaultValue: false,
166
- table: {
167
- type: {
168
- summary: "boolean",
169
- },
170
- },
171
- },
172
- /**
173
- * Accessibility
174
- */
175
- ariaLabel: {
176
- name: "aria-label",
177
- control: {
178
- type: "string",
179
- },
180
- description: "Used to announce the cell's content to screen readers.",
181
- table: {
182
- category: "Accessibility",
183
- type: {
184
- summary: "string",
185
- detail: `aria-label should be specially used when the cell is pressable so screen readers can announce the link when the user is focused on it.`,
186
- },
187
- },
188
- },
189
- };
@@ -1,305 +0,0 @@
1
- // @flow
2
- import * as React from "react";
3
- import {StyleSheet} from "aphrodite";
4
-
5
- import {View} from "@khanacademy/wonder-blocks-core";
6
- import Color from "@khanacademy/wonder-blocks-color";
7
- import {Strut} from "@khanacademy/wonder-blocks-layout";
8
- import Spacing from "@khanacademy/wonder-blocks-spacing";
9
- import Icon, {icons} from "@khanacademy/wonder-blocks-icon";
10
-
11
- import type {StoryComponentType} from "@storybook/react";
12
-
13
- import type {IconAsset} from "@khanacademy/wonder-blocks-icon";
14
-
15
- import ComponentInfo from "../../../../../.storybook/components/component-info.js";
16
- import {name, version} from "../../../package.json";
17
- import CompactCellArgTypes, {
18
- AccessoryMappings,
19
- } from "./compact-cell.argtypes.js";
20
-
21
- import CompactCell from "../compact-cell.js";
22
-
23
- export default {
24
- title: "Cell / CompactCell",
25
- component: CompactCell,
26
- argTypes: CompactCellArgTypes,
27
- parameters: {
28
- componentSubtitle: ((
29
- <ComponentInfo name={name} version={version} />
30
- ): any),
31
- docs: {
32
- description: {
33
- component: null,
34
- },
35
- source: {
36
- // See https://github.com/storybookjs/storybook/issues/12596
37
- excludeDecorators: true,
38
- },
39
- },
40
- },
41
- decorators: [
42
- (Story: any): React.Node => (
43
- <View style={styles.example}>{Story()}</View>
44
- ),
45
- ],
46
- };
47
-
48
- /**
49
- * Default CompactCell example. It will be rendered as the first/default story and
50
- * it can be interacted with the controls panel in the Browser.
51
- */
52
- const Template = (args) => <CompactCell {...args} />;
53
-
54
- export const DefaultCompactCell: StoryComponentType = Template.bind({});
55
-
56
- DefaultCompactCell.args = {
57
- title: "Basic Cell",
58
- rightAccessory: <Icon icon={icons.caretRight} />,
59
- };
60
-
61
- DefaultCompactCell.parameters = {
62
- chromatic: {
63
- // We have screenshots of other stories that cover other variants.
64
- disableSnapshot: true,
65
- },
66
- };
67
-
68
- /**
69
- * Only including an accessory on the left.
70
- */
71
- export const CompactCellLeft: StoryComponentType = () => (
72
- <CompactCell
73
- title="Intro to rational & irrational numbers"
74
- leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
75
- />
76
- );
77
-
78
- CompactCellLeft.parameters = {
79
- docs: {
80
- storyDescription:
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.",
82
- },
83
- };
84
-
85
- /**
86
- * Only including an accessory on the right.
87
- */
88
- export const CompactCellRight: StoryComponentType = (args) => (
89
- <CompactCell
90
- title="Intro to rational & irrational numbers"
91
- rightAccessory={<Icon icon={icons.caretRight} size="medium" />}
92
- />
93
- );
94
-
95
- CompactCellRight.parameters = {
96
- docs: {
97
- storyDescription:
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`.",
99
- },
100
- };
101
-
102
- /**
103
- * Adding multiline title to verify that the cell's height is correct.
104
- */
105
- export const CompactCellWithDifferentHeights: StoryComponentType = (args) => (
106
- <>
107
- <CompactCell
108
- title="Single line with short accessory."
109
- rightAccessory={AccessoryMappings.withCaret}
110
- />
111
- <Strut size={Spacing.xSmall_8} />
112
- <CompactCell
113
- title="Single line with tall accessory."
114
- rightAccessory={AccessoryMappings.withIconText}
115
- />
116
- <Strut size={Spacing.xSmall_8} />
117
- <CompactCell
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."
119
- rightAccessory={AccessoryMappings.withIconText}
120
- />
121
- </>
122
- );
123
-
124
- CompactCellWithDifferentHeights.parameters = {
125
- docs: {
126
- storyDescription:
127
- "Cells should keep a consistent height no matter the content passed in the title prop. It should also respect a `minHeight` of 48px",
128
- },
129
- };
130
-
131
- /**
132
- * A CompactCell example adding both accessories (left and right)
133
- */
134
- const calendarIcon: IconAsset = {
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`,
136
- };
137
-
138
- export const CompactCellBoth: StoryComponentType = () => (
139
- <CompactCell
140
- title="Intro to rational & irrational numbers"
141
- leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
142
- rightAccessory={
143
- <Icon icon={calendarIcon} size="medium" color={Color.blue} />
144
- }
145
- />
146
- );
147
-
148
- CompactCellBoth.storyName = "CompactCell with both accessories";
149
-
150
- CompactCellBoth.parameters = {
151
- docs: {
152
- storyDescription:
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.",
154
- },
155
- };
156
-
157
- export const CompactCellAccessoryStyles: StoryComponentType = () => (
158
- <CompactCell
159
- title="CompactCell with custom accessory styles"
160
- leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
161
- leftAccessoryStyle={{
162
- minWidth: Spacing.xxLarge_48,
163
- alignSelf: "flex-start",
164
- alignItems: "flex-start",
165
- }}
166
- rightAccessory={<Icon icon={icons.caretRight} size="small" />}
167
- rightAccessoryStyle={{
168
- minWidth: Spacing.large_24,
169
- alignSelf: "flex-end",
170
- alignItems: "flex-end",
171
- }}
172
- />
173
- );
174
-
175
- CompactCellAccessoryStyles.storyName =
176
- "CompactCell accessories with custom styles";
177
-
178
- CompactCellAccessoryStyles.parameters = {
179
- docs: {
180
- storyDescription:
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
- },
183
- };
184
-
185
- /**
186
- * Defining horizontal rule variants
187
- */
188
- export const CompactCellHorizontalRules: StoryComponentType = () => (
189
- <>
190
- <CompactCell
191
- title="This is a basic cell with an 'inset' horizontal rule"
192
- leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
193
- horizontalRule="inset"
194
- />
195
- <CompactCell
196
- title="This is a basic cell with a 'full-width' horizontal rule"
197
- leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
198
- horizontalRule="full-width"
199
- />
200
- <CompactCell
201
- title="This is a basic cell without a horizontal rule"
202
- leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
203
- horizontalRule="none"
204
- />
205
- </>
206
- );
207
-
208
- CompactCellHorizontalRules.storyName = "Defining horizontal rule variants";
209
-
210
- CompactCellHorizontalRules.parameters = {
211
- docs: {
212
- storyDescription:
213
- "Cell components can use the `horizontalRule` prop to use a set of predefined variants that we can use to match our needs.",
214
- },
215
- };
216
-
217
- export const CompactCellWithCustomStyles: StoryComponentType = () => (
218
- <CompactCell
219
- title="CompactCell with a darkBlue background"
220
- leftAccessory={<Icon icon={icons.contentArticle} size="medium" />}
221
- rightAccessory={<Icon icon={calendarIcon} color={Color.white} />}
222
- style={{
223
- background: Color.darkBlue,
224
- color: Color.white,
225
- }}
226
- onClick={() => {}}
227
- />
228
- );
229
-
230
- CompactCellWithCustomStyles.parameters = {
231
- docs: {
232
- storyDescription:
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.",
234
- },
235
- };
236
-
237
- /*
238
- * CompactCell with onClick set
239
-
240
- */
241
-
242
- export const ClickableCompactCell: StoryComponentType = () => (
243
- <CompactCell
244
- title="Intro to rational & irrational numbers"
245
- rightAccessory={<Icon icon={icons.caretRight} />}
246
- onClick={() => {}}
247
- aria-label="Press to navigate to the article"
248
- />
249
- );
250
-
251
- ClickableCompactCell.parameters = {
252
- chromatic: {
253
- // This only includes interactions with the clickable cell, so no need
254
- // to capture screenshots.
255
- disableSnapshot: true,
256
- },
257
- docs: {
258
- storyDescription:
259
- "Cell components can also also be clickable. This is done by passing a `onClick` prop to the component.",
260
- },
261
- };
262
-
263
- export const CompactCellActive: StoryComponentType = () => (
264
- <CompactCell
265
- title="Title for article item"
266
- leftAccessory={
267
- <Icon icon={icons.contentVideo} size="medium" color="black" />
268
- }
269
- rightAccessory={<Icon icon={calendarIcon} size="small" />}
270
- active={true}
271
- onClick={() => {}}
272
- />
273
- );
274
-
275
- CompactCellActive.parameters = {
276
- docs: {
277
- storyDescription:
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.",
279
- },
280
- };
281
-
282
- export const CompactCellDisabled: StoryComponentType = () => (
283
- <CompactCell
284
- title="Title for article item"
285
- leftAccessory={AccessoryMappings.withImage}
286
- rightAccessory={<Icon icon={calendarIcon} size="small" />}
287
- disabled={true}
288
- onClick={() => {}}
289
- />
290
- );
291
-
292
- CompactCellDisabled.parameters = {
293
- docs: {
294
- storyDescription:
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.",
296
- },
297
- };
298
-
299
- const styles = StyleSheet.create({
300
- example: {
301
- backgroundColor: Color.offWhite,
302
- padding: Spacing.large_24,
303
- width: 320 + Spacing.xxLarge_48,
304
- },
305
- });
@@ -1,28 +0,0 @@
1
- // @flow
2
- import CompactCellArgTypes from "./compact-cell.argtypes.js";
3
-
4
- export default {
5
- ...CompactCellArgTypes,
6
- subtitle1: {
7
- control: {
8
- type: "text",
9
- },
10
- table: {
11
- category: "Layout",
12
- type: {
13
- detail: "string | React.Element<Typography>",
14
- },
15
- },
16
- },
17
- subtitle2: {
18
- control: {
19
- type: "text",
20
- },
21
- table: {
22
- category: "Layout",
23
- type: {
24
- detail: "string | React.Element<Typography>",
25
- },
26
- },
27
- },
28
- };