@khanacademy/wonder-blocks-cell 2.0.1 → 2.2.0

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,27 @@
1
1
  # @khanacademy/wonder-blocks-cell
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 35b9ef9c: Add target prop to cell.
8
+
9
+ ## 2.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 9819c13f: Add href prop for client-side navigation
14
+
15
+ ## 2.0.2
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [246a921d]
20
+ - @khanacademy/wonder-blocks-core@4.3.0
21
+ - @khanacademy/wonder-blocks-clickable@2.2.5
22
+ - @khanacademy/wonder-blocks-layout@1.4.8
23
+ - @khanacademy/wonder-blocks-typography@1.1.30
24
+
3
25
  ## 2.0.1
4
26
 
5
27
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -134,6 +134,7 @@ const CellCore = props => {
134
134
  active,
135
135
  children,
136
136
  disabled,
137
+ href,
137
138
  horizontalRule = "inset",
138
139
  leftAccessory = undefined,
139
140
  leftAccessoryStyle = undefined,
@@ -143,7 +144,8 @@ const CellCore = props => {
143
144
  style,
144
145
  testId,
145
146
  "aria-label": ariaLabel,
146
- innerStyle
147
+ innerStyle,
148
+ target
147
149
  } = props;
148
150
 
149
151
  const renderCell = eventState => {
@@ -176,12 +178,14 @@ const CellCore = props => {
176
178
  }; // Pressable cell.
177
179
 
178
180
 
179
- if (onClick) {
181
+ if (onClick || href) {
180
182
  return /*#__PURE__*/React.createElement(Clickable, {
181
183
  disabled: disabled,
182
184
  onClick: onClick,
185
+ href: href,
183
186
  hideDefaultFocusRing: true,
184
- "aria-label": ariaLabel ? ariaLabel : undefined
187
+ "aria-label": ariaLabel ? ariaLabel : undefined,
188
+ target: target
185
189
  }, eventState => renderCell(eventState));
186
190
  } // No click event attached, so just render the cell as-is.
187
191
 
package/dist/index.js CHANGED
@@ -299,6 +299,7 @@ const CellCore = props => {
299
299
  active,
300
300
  children,
301
301
  disabled,
302
+ href,
302
303
  horizontalRule = "inset",
303
304
  leftAccessory = undefined,
304
305
  leftAccessoryStyle = undefined,
@@ -308,7 +309,8 @@ const CellCore = props => {
308
309
  style,
309
310
  testId,
310
311
  "aria-label": ariaLabel,
311
- innerStyle
312
+ innerStyle,
313
+ target
312
314
  } = props;
313
315
 
314
316
  const renderCell = eventState => {
@@ -341,12 +343,14 @@ const CellCore = props => {
341
343
  }; // Pressable cell.
342
344
 
343
345
 
344
- if (onClick) {
346
+ if (onClick || href) {
345
347
  return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2___default.a, {
346
348
  disabled: disabled,
347
349
  onClick: onClick,
350
+ href: href,
348
351
  hideDefaultFocusRing: true,
349
- "aria-label": ariaLabel ? ariaLabel : undefined
352
+ "aria-label": ariaLabel ? ariaLabel : undefined,
353
+ target: target
350
354
  }, eventState => renderCell(eventState));
351
355
  } // No click event attached, so just render the cell as-is.
352
356
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-cell",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
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.4",
17
+ "@khanacademy/wonder-blocks-clickable": "^2.2.5",
18
18
  "@khanacademy/wonder-blocks-color": "^1.1.20",
19
- "@khanacademy/wonder-blocks-core": "^4.2.1",
20
- "@khanacademy/wonder-blocks-layout": "^1.4.7",
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.29"
22
+ "@khanacademy/wonder-blocks-typography": "^1.1.30"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "aphrodite": "^1.2.5",
@@ -27,7 +27,7 @@ export const AccessoryMappings = {
27
27
  </View>
28
28
  ): React.Element<typeof View>),
29
29
  withImage: ((
30
- <img src="/avatar.png" alt="ItemAvatar" width={48} height={48} />
30
+ <img src="./avatar.png" alt="ItemAvatar" width={48} height={48} />
31
31
  ): React$Element<"img">),
32
32
  };
33
33
 
@@ -121,6 +121,17 @@ export default {
121
121
  },
122
122
  },
123
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
+ },
124
135
  onClick: {
125
136
  action: "clicked",
126
137
  description: `Called when the cell is clicked.
@@ -1,6 +1,7 @@
1
1
  // @flow
2
2
  import * as React from "react";
3
3
  import {StyleSheet} from "aphrodite";
4
+ import {MemoryRouter, Route, Switch} from "react-router-dom";
4
5
 
5
6
  import {View} from "@khanacademy/wonder-blocks-core";
6
7
  import Color from "@khanacademy/wonder-blocks-color";
@@ -145,10 +146,61 @@ ClickableDetailCell.parameters = {
145
146
  },
146
147
  };
147
148
 
149
+ export const DetailCellNavigation: StoryComponentType = () => (
150
+ <MemoryRouter>
151
+ <View>
152
+ <DetailCell
153
+ title="Data"
154
+ subtitle2="Subtitle for article item"
155
+ leftAccessory={<Icon icon={icons.contentVideo} size="medium" />}
156
+ rightAccessory={<Icon icon={icons.caretRight} />}
157
+ href="/math/algebra"
158
+ aria-label="Press to navigate to the article"
159
+ />
160
+ <DetailCell
161
+ title="Geometry"
162
+ subtitle2="Subtitle for article item"
163
+ leftAccessory={<Icon icon={icons.contentVideo} size="medium" />}
164
+ rightAccessory={<Icon icon={icons.caretRight} />}
165
+ href="/math/geometry"
166
+ aria-label="Press to navigate to the article"
167
+ horizontalRule="none"
168
+ />
169
+ </View>
170
+
171
+ <View style={styles.navigation}>
172
+ <Switch>
173
+ <Route path="/math/algebra">Navigates to /math/algebra</Route>
174
+ <Route path="/math/geometry">Navigates to /math/geometry</Route>
175
+ <Route path="*">See navigation changes here</Route>
176
+ </Switch>
177
+ </View>
178
+ </MemoryRouter>
179
+ );
180
+
181
+ DetailCellNavigation.storyName = "Client-side navigation with DetailCell";
182
+
183
+ DetailCellNavigation.parameters = {
184
+ chromatic: {
185
+ // This only includes interactions with the clickable cell, so no need
186
+ // to capture screenshots.
187
+ disableSnapshot: true,
188
+ },
189
+ docs: {
190
+ storyDescription:
191
+ "Cells accept an `href` prop to be able to navigate to a different URL. Note that this will use client-side navigation if the Cell component is within a React-Router environment.",
192
+ },
193
+ };
194
+
148
195
  const styles = StyleSheet.create({
149
196
  example: {
150
197
  backgroundColor: Color.offWhite,
151
198
  padding: Spacing.large_24,
152
199
  width: 376,
153
200
  },
201
+ navigation: {
202
+ border: `1px dashed ${Color.lightBlue}`,
203
+ marginTop: Spacing.large_24,
204
+ padding: Spacing.large_24,
205
+ },
154
206
  });
@@ -47,6 +47,20 @@ describe("CellCore", () => {
47
47
  expect(screen.getByRole("button")).toBeInTheDocument();
48
48
  });
49
49
 
50
+ it("should add an anchor if href is set", () => {
51
+ // Arrange
52
+
53
+ // Act
54
+ render(
55
+ <CellCore href="/math">
56
+ <div>cell core content</div>
57
+ </CellCore>,
58
+ );
59
+
60
+ // Assert
61
+ expect(screen.getByRole("link")).toHaveAttribute("href", "/math");
62
+ });
63
+
50
64
  it("should add aria-label to the button", () => {
51
65
  // Arrange
52
66
 
@@ -119,6 +119,7 @@ const CellCore = (props: CellCoreProps): React.Node => {
119
119
  active,
120
120
  children,
121
121
  disabled,
122
+ href,
122
123
  horizontalRule = "inset",
123
124
  leftAccessory = undefined,
124
125
  leftAccessoryStyle = undefined,
@@ -129,6 +130,7 @@ const CellCore = (props: CellCoreProps): React.Node => {
129
130
  testId,
130
131
  "aria-label": ariaLabel,
131
132
  innerStyle,
133
+ target,
132
134
  } = props;
133
135
 
134
136
  const renderCell = (eventState?: ClickableState): React.Node => {
@@ -191,13 +193,15 @@ const CellCore = (props: CellCoreProps): React.Node => {
191
193
  };
192
194
 
193
195
  // Pressable cell.
194
- if (onClick) {
196
+ if (onClick || href) {
195
197
  return (
196
198
  <Clickable
197
199
  disabled={disabled}
198
200
  onClick={onClick}
201
+ href={href}
199
202
  hideDefaultFocusRing={true}
200
203
  aria-label={ariaLabel ? ariaLabel : undefined}
204
+ target={target}
201
205
  >
202
206
  {(eventState) => renderCell(eventState)}
203
207
  </Clickable>
package/src/util/types.js CHANGED
@@ -126,4 +126,18 @@ export type CellProps = {|
126
126
  * Used to announce the cell's content to screen readers.
127
127
  */
128
128
  "aria-label"?: string,
129
+
130
+ /**
131
+ * Optinal href which Cell should direct to, uses client-side routing
132
+ * by default if react-router is present.
133
+ */
134
+ href?: string,
135
+
136
+ /**
137
+ * A target destination window for a link to open in. Should only be used
138
+ * when `href` is specified.
139
+ *
140
+ * TODO(WB-1262): only allow this prop when `href` is also set.t
141
+ */
142
+ target?: "_blank",
129
143
  |};