@khanacademy/wonder-blocks-clickable 2.2.5 → 2.3.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.
@@ -33,13 +33,13 @@ type CommonProps = {|
33
33
  onClick?: (e: SyntheticEvent<>) => mixed,
34
34
 
35
35
  /**
36
- * Optinal href which Clickable should direct to, uses client-side routing
36
+ * Optional href which Clickable should direct to, uses client-side routing
37
37
  * by default if react-router is present
38
38
  */
39
39
  href?: string,
40
40
 
41
41
  /**
42
- * Styles to apply to the Clickable compoenent
42
+ * Styles to apply to the Clickable component
43
43
  */
44
44
  style?: StyleType,
45
45
 
@@ -111,6 +111,8 @@ type Props =
111
111
 
112
112
  /**
113
113
  * A target destination window for a link to open in.
114
+ *
115
+ * TODO(WB-1262): only allow this prop when `href` is also set.t
114
116
  */
115
117
  target?: "_blank",
116
118
  |}
@@ -143,6 +145,8 @@ type Props =
143
145
 
144
146
  /**
145
147
  * A target destination window for a link to open in.
148
+ *
149
+ * TODO(WB-1262): only allow this prop when `href` is also set.t
146
150
  */
147
151
  target?: "_blank",
148
152
  |}
@@ -182,11 +186,20 @@ const StyledLink = addStyle<typeof Link>(Link);
182
186
  /**
183
187
  * A component to turn any custom component into a clickable one.
184
188
  *
185
- * Works by wrapping ClickableBehavior around the child element and styling the
186
- * child appropriately and encapsulates routing logic which can be customized.
187
- * Expects a function which returns an element as it's child.
189
+ * Works by wrapping `ClickableBehavior` around the child element and styling
190
+ * the child appropriately and encapsulates routing logic which can be
191
+ * customized. Expects a function which returns an element as its child.
192
+ *
193
+ * Clickable allows your components to:
194
+ *
195
+ * - Handle mouse / touch / keyboard events
196
+ * - Match the standard behavior of the given role
197
+ * - Apply custom styles based on pressed / focused / hovered state
198
+ * - Perform Client Side Navigation when href is passed and the component is a
199
+ * descendent of a react-router Router.
200
+ *
201
+ * ### Usage
188
202
  *
189
- * Example usage:
190
203
  * ```jsx
191
204
  * <Clickable onClick={() => alert("You clicked me!")}>
192
205
  * {({hovered, focused, pressed}) =>
@@ -289,6 +302,7 @@ export default class Clickable extends React.Component<Props> {
289
302
  !hideDefaultFocusRing &&
290
303
  state.focused &&
291
304
  (light ? styles.focusedLight : styles.focused),
305
+ disabled && styles.disabled,
292
306
  style,
293
307
  ];
294
308
 
@@ -383,9 +397,21 @@ const styles = StyleSheet.create({
383
397
  cursor: "pointer",
384
398
  },
385
399
  focused: {
386
- outline: `solid 2px ${Color.blue}`,
400
+ ":focus": {
401
+ outline: `solid 2px ${Color.blue}`,
402
+ },
387
403
  },
388
404
  focusedLight: {
389
405
  outline: `solid 2px ${Color.white}`,
390
406
  },
407
+ disabled: {
408
+ color: Color.offBlack32,
409
+ cursor: "not-allowed",
410
+ ":focus": {
411
+ outline: "none",
412
+ },
413
+ ":focus-visible": {
414
+ outline: `solid 2px ${Color.blue}`,
415
+ },
416
+ },
391
417
  });
@@ -1,127 +0,0 @@
1
- // @flow
2
- import * as React from "react";
3
-
4
- import {StyleSheet} from "aphrodite";
5
- import Clickable from "@khanacademy/wonder-blocks-clickable";
6
- import {View} from "@khanacademy/wonder-blocks-core";
7
- import Color from "@khanacademy/wonder-blocks-color";
8
- import {Strut} from "@khanacademy/wonder-blocks-layout";
9
- import Spacing from "@khanacademy/wonder-blocks-spacing";
10
- import {Body} from "@khanacademy/wonder-blocks-typography";
11
-
12
- import type {StoryComponentType} from "@storybook/react";
13
-
14
- export default {
15
- title: "Navigation/Clickable",
16
- };
17
-
18
- export const Basic: StoryComponentType = () => (
19
- <View>
20
- <View style={styles.centerText}>
21
- <Clickable
22
- href="https://www.khanacademy.org/about/tos"
23
- skipClientNav={true}
24
- >
25
- {({hovered, focused, pressed}) => (
26
- <View
27
- style={[
28
- hovered && styles.hovered,
29
- pressed && styles.pressed,
30
- ]}
31
- >
32
- <Body>This text is clickable!</Body>
33
- </View>
34
- )}
35
- </Clickable>
36
- </View>
37
- <Strut size={Spacing.xLarge_32} />
38
- <View style={[styles.centerText, styles.dark]}>
39
- <Clickable
40
- href="https://www.khanacademy.org/about/tos"
41
- skipClientNav={true}
42
- light={true}
43
- >
44
- {({hovered, focused, pressed}) => (
45
- <View
46
- style={[
47
- hovered && styles.hovered,
48
- pressed && styles.pressed,
49
- ]}
50
- >
51
- <Body>This text is clickable!</Body>
52
- </View>
53
- )}
54
- </Clickable>
55
- </View>
56
- </View>
57
- );
58
-
59
- export const KeyboardNavigation: StoryComponentType = () => (
60
- <View>
61
- <Clickable
62
- href="https://www.khanacademy.org/about/tos"
63
- skipClientNav={true}
64
- >
65
- {({hovered, focused, pressed}) => (
66
- <View
67
- style={[
68
- hovered && styles.hovered,
69
- focused && styles.focused,
70
- pressed && styles.pressed,
71
- ]}
72
- >
73
- <Body>This text should navigate using the keyboard</Body>
74
- </View>
75
- )}
76
- </Clickable>
77
- </View>
78
- );
79
-
80
- KeyboardNavigation.parameters = {
81
- chromatic: {
82
- // we don't need screenshots because this story only tests behavior.
83
- disableSnapshot: true,
84
- },
85
- };
86
-
87
- export const KeyboardNavigationTab: StoryComponentType = () => (
88
- <View>
89
- <Clickable role="tab" aria-controls="panel-1" id="tab-1">
90
- {({hovered, focused, pressed}) => (
91
- <View
92
- style={[
93
- hovered && styles.hovered,
94
- focused && styles.focused,
95
- pressed && styles.pressed,
96
- ]}
97
- >
98
- <Body>Open School Info</Body>
99
- </View>
100
- )}
101
- </Clickable>
102
- <View id="panel-1" role="tabpanel" tabindex="0" aria-labelledby="tab-1">
103
- This is the information for the school.
104
- </View>
105
- </View>
106
- );
107
-
108
- const styles = StyleSheet.create({
109
- hovered: {
110
- textDecoration: "underline",
111
- backgroundColor: Color.teal,
112
- },
113
- pressed: {
114
- color: Color.blue,
115
- },
116
- focused: {
117
- outline: `solid 4px ${Color.lightBlue}`,
118
- },
119
- centerText: {
120
- textAlign: "center",
121
- },
122
- dark: {
123
- backgroundColor: Color.darkBlue,
124
- color: Color.white,
125
- padding: Spacing.xSmall_8,
126
- },
127
- });