@khanacademy/wonder-blocks-tooltip 1.3.21 → 1.3.22

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,12 @@
1
1
  # @khanacademy/wonder-blocks-tooltip
2
2
 
3
+ ## 1.3.22
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [13cdc7fe]
8
+ - @khanacademy/wonder-blocks-modal@3.0.0
9
+
3
10
  ## 1.3.21
4
11
 
5
12
  ### Patch Changes
package/dist/index.js CHANGED
@@ -540,6 +540,16 @@ const styles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
540
540
  /**
541
541
  * This component is used to provide the content that is to be rendered in the
542
542
  * tooltip bubble.
543
+ *
544
+ * ### Usage
545
+ *
546
+ * ```jsx
547
+ * import {TooltipContent} from "@khanacademy/wonder-blocks-tooltip";
548
+ *
549
+ * <TooltipContent title="Title text!">
550
+ * Some content in my tooltip.
551
+ * </TooltipContent>
552
+ * ```
543
553
  */
544
554
  class TooltipContent extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
545
555
  _renderTitle() {
@@ -800,6 +810,31 @@ class RefTracker {
800
810
 
801
811
 
802
812
 
813
+
814
+ /**
815
+ * Use a tooltip to help describe an on screen object.
816
+ *
817
+ * Tooltips:
818
+ * - contain text
819
+ * - (optional) contain small graphic elements to complement the text
820
+ * - appear on hover or focus (for non-assistive tech keyboard users)
821
+ * - must have a tail that points to a parent object
822
+ * - DO NOT include actions
823
+ *
824
+ * For more rich content see Popovers, for taking action on an object, see
825
+ * Snackbars (proposed).
826
+ *
827
+ * ### Usage
828
+ *
829
+ * ```jsx
830
+ * import Tooltip from "@khanacademy/wonder-blocks-tooltip";
831
+ *
832
+ * <Tooltip content="This is a text tooltip">
833
+ * Tooltip anchor
834
+ * </Tooltip>
835
+ * ```
836
+ *
837
+ */
803
838
  class Tooltip extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
804
839
  constructor(...args) {
805
840
  super(...args);
package/docs.md CHANGED
@@ -1,11 +1,4 @@
1
- Use a tooltip to help describe an on screen object.
1
+ Documentation for `@khanacademy/wonder-blocks-tooltip` is now in Storybook.
2
2
 
3
- Tooltips:
4
-
5
- - contain text
6
- - (optional) contain small graphic elements to complement the text
7
- - appear on hover or focus (for non-assistive tech keyboard users)
8
- - must have a tail that points to a parent object
9
- - DO NOT include actions
10
-
11
- For more rich content see Popovers, for taking action on an object, see Snackbars (proposed).
3
+ Visit the [Storybook
4
+ Tooltip](https://khan.github.io/wonder-blocks/?path=/docs/tooltip) docs on GitHub Pages.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-tooltip",
3
- "version": "1.3.21",
3
+ "version": "1.3.22",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -19,7 +19,7 @@
19
19
  "@khanacademy/wonder-blocks-color": "^1.2.0",
20
20
  "@khanacademy/wonder-blocks-core": "^4.5.0",
21
21
  "@khanacademy/wonder-blocks-layout": "^1.4.12",
22
- "@khanacademy/wonder-blocks-modal": "^2.3.11",
22
+ "@khanacademy/wonder-blocks-modal": "^3.0.0",
23
23
  "@khanacademy/wonder-blocks-spacing": "^3.0.5",
24
24
  "@khanacademy/wonder-blocks-typography": "^1.1.34"
25
25
  },
@@ -0,0 +1,89 @@
1
+ // @flow
2
+ import * as React from "react";
3
+ import {TooltipContent} from "@khanacademy/wonder-blocks-tooltip";
4
+ import {Body, LabelSmall} from "@khanacademy/wonder-blocks-typography";
5
+
6
+ import type {StoryComponentType} from "@storybook/react";
7
+
8
+ import ComponentInfo from "../../../../../.storybook/components/component-info.js";
9
+ import {name, version} from "../../../package.json";
10
+
11
+ export default {
12
+ title: "Tooltip / TooltipContent",
13
+ component: TooltipContent,
14
+ parameters: {
15
+ componentSubtitle: ((
16
+ <ComponentInfo name={name} version={version} />
17
+ ): any),
18
+ },
19
+ };
20
+
21
+ const Template = (args) => <TooltipContent {...args} />;
22
+
23
+ /**
24
+ * Default example (interactive).
25
+ */
26
+ export const Default: StoryComponentType = Template.bind({});
27
+
28
+ Default.args = {
29
+ title: "A Tooltip with a title",
30
+ children: "some text",
31
+ };
32
+
33
+ /**
34
+ * Only text content
35
+ */
36
+ export const OnlyTextContent: StoryComponentType = Template.bind({});
37
+
38
+ OnlyTextContent.args = {
39
+ children: "Only the content",
40
+ };
41
+
42
+ OnlyTextContent.parameters = {
43
+ docs: {
44
+ description: {
45
+ story: "This shows the default which is text rendered using `LabelMedium`.",
46
+ },
47
+ },
48
+ };
49
+
50
+ /**
51
+ * Titled content
52
+ */
53
+ export const TitledContent: StoryComponentType = Template.bind({});
54
+
55
+ TitledContent.args = {
56
+ title: "This tooltip has a title",
57
+ children: "Some content in my tooltip",
58
+ };
59
+
60
+ TitledContent.parameters = {
61
+ docs: {
62
+ description: {
63
+ story: "This shows the default with a title; the title is rendered using `HeadingSmall`.",
64
+ },
65
+ },
66
+ };
67
+
68
+ /**
69
+ * Custom title and custom content
70
+ */
71
+ export const CustomContent: StoryComponentType = Template.bind({});
72
+
73
+ CustomContent.args = {
74
+ title: <Body>Body text title!</Body>,
75
+ children: (
76
+ <>
77
+ <Body>Body text content!</Body>
78
+ <LabelSmall>And LabelSmall!</LabelSmall>
79
+ </>
80
+ ),
81
+ };
82
+
83
+ CustomContent.parameters = {
84
+ docs: {
85
+ description: {
86
+ story: "This shows how we can customize both the title and the content.",
87
+ },
88
+ },
89
+ };
@@ -0,0 +1,15 @@
1
+ // @flow
2
+
3
+ export default {
4
+ placement: {
5
+ control: {
6
+ type: "select",
7
+ options: ["top", "bottom", "right", "left"],
8
+ },
9
+ },
10
+ title: {
11
+ control: {
12
+ type: "text",
13
+ },
14
+ },
15
+ };
@@ -0,0 +1,245 @@
1
+ // @flow
2
+ import * as React from "react";
3
+ import {StyleSheet} from "aphrodite";
4
+ import Button from "@khanacademy/wonder-blocks-button";
5
+ import Color from "@khanacademy/wonder-blocks-color";
6
+ import {View} from "@khanacademy/wonder-blocks-core";
7
+ import {TextField} from "@khanacademy/wonder-blocks-form";
8
+ import IconButton from "@khanacademy/wonder-blocks-icon-button";
9
+ import {icons} from "@khanacademy/wonder-blocks-icon";
10
+ import {OnePaneDialog, ModalLauncher} from "@khanacademy/wonder-blocks-modal";
11
+ import Spacing from "@khanacademy/wonder-blocks-spacing";
12
+ import Tooltip from "@khanacademy/wonder-blocks-tooltip";
13
+ import {Body} from "@khanacademy/wonder-blocks-typography";
14
+
15
+ import type {StoryComponentType} from "@storybook/react";
16
+ import TooltipArgtypes from "./tooltip.argtypes.js";
17
+
18
+ import ComponentInfo from "../../../../../.storybook/components/component-info.js";
19
+ import {name, version} from "../../../package.json";
20
+
21
+ export default {
22
+ title: "Tooltip / Tooltip",
23
+ component: Tooltip,
24
+ argTypes: TooltipArgtypes,
25
+ args: {
26
+ forceAnchorFocusivity: true,
27
+ placement: "top",
28
+ },
29
+ parameters: {
30
+ // TODO(WB-1170): Reassess this after investigating more about Chromatic
31
+ // flakyness.
32
+ chromatic: {
33
+ disableSnapshot: true,
34
+ },
35
+ componentSubtitle: ((
36
+ <ComponentInfo name={name} version={version} />
37
+ ): any),
38
+ },
39
+ };
40
+
41
+ const Template = (args) => <Tooltip {...args} />;
42
+
43
+ /**
44
+ * Default example (interactive).
45
+ */
46
+ export const Default: StoryComponentType = Template.bind({});
47
+
48
+ Default.args = {
49
+ content: "This is a text tooltip on the top",
50
+ children: "some text",
51
+ };
52
+
53
+ /**
54
+ * Complex anchor & title tooltip
55
+ */
56
+ export const ComplexAnchorAndTitle: StoryComponentType = Template.bind({});
57
+
58
+ ComplexAnchorAndTitle.args = {
59
+ forceAnchorFocusivity: false,
60
+ id: "my-a11y-tooltip",
61
+ title: "This tooltip has a title",
62
+ content: "I'm at the top!",
63
+ children: (
64
+ <View>
65
+ Some text
66
+ <TextField
67
+ aria-describedby="my-a11y-tooltip"
68
+ id=""
69
+ onChange={() => {}}
70
+ value=""
71
+ />
72
+ </View>
73
+ ),
74
+ };
75
+
76
+ ComplexAnchorAndTitle.parameters = {
77
+ docs: {
78
+ description: {
79
+ story: "In this example, we're no longer forcing the anchor root to be focusable, since the text input can take focus. However, that needs a custom accessibility implementation too (for that, we should use `UniqueIDProvider`, but we'll cheat here and give our own identifier).",
80
+ },
81
+ },
82
+ };
83
+
84
+ /**
85
+ * Anchor in scrollable parent & placement bottom
86
+ */
87
+ export const AnchorInScrollableParent: StoryComponentType = () => (
88
+ <View style={styles.scrollbox}>
89
+ <View style={styles.hostbox}>
90
+ <Body>
91
+ This is a big long piece of text with a
92
+ <Tooltip
93
+ content="This tooltip will disappear when scrolled out of bounds"
94
+ placement="bottom"
95
+ >
96
+ [tooltip]
97
+ </Tooltip>{" "}
98
+ in the middle.
99
+ </Body>
100
+ </View>
101
+ </View>
102
+ );
103
+
104
+ AnchorInScrollableParent.parameters = {
105
+ docs: {
106
+ description: {
107
+ story: "In this example, we have the anchor in a scrollable parent. Notice how, when the anchor is focused but scrolled out of bounds, the tooltip disappears.",
108
+ },
109
+ },
110
+ };
111
+
112
+ /**
113
+ * Tooltip in a modal
114
+ */
115
+ export const TooltipInModal: StoryComponentType = () => {
116
+ const scrollyContent = (
117
+ <View style={styles.scrollbox}>
118
+ <View style={styles.hostbox}>
119
+ <Tooltip content="I'm on the left!" placement="left">
120
+ tooltip
121
+ </Tooltip>
122
+ </View>
123
+ </View>
124
+ );
125
+
126
+ const modal = (
127
+ <OnePaneDialog
128
+ title="My modal"
129
+ footer="Still my modal"
130
+ content={<View style={styles.modalbox}>{scrollyContent}</View>}
131
+ />
132
+ );
133
+
134
+ return (
135
+ <ModalLauncher modal={modal}>
136
+ {({openModal}) => <Button onClick={openModal}>Click here!</Button>}
137
+ </ModalLauncher>
138
+ );
139
+ };
140
+
141
+ TooltipInModal.parameters = {
142
+ docs: {
143
+ description: {
144
+ story: "This checks that the tooltip works how we want inside a modal. Click the button to take a look.",
145
+ },
146
+ },
147
+ };
148
+
149
+ /**
150
+ * Tooltips side-by-side
151
+ */
152
+ export const SideBySide: StoryComponentType = () => (
153
+ <View style={styles.row}>
154
+ <Tooltip content="Tooltip A" placement="bottom">
155
+ <View style={styles.block}>A</View>
156
+ </Tooltip>
157
+ <Tooltip content="Tooltip B" placement="bottom">
158
+ <View style={styles.block}>B</View>
159
+ </Tooltip>
160
+ <Tooltip content="Tooltip C" placement="bottom">
161
+ <View style={styles.block}>C</View>
162
+ </Tooltip>
163
+ <Tooltip content="Tooltip D" placement="bottom">
164
+ <View style={styles.block}>D</View>
165
+ </Tooltip>
166
+ </View>
167
+ );
168
+
169
+ SideBySide.storyName = "Side-by-side";
170
+
171
+ SideBySide.parameters = {
172
+ docs: {
173
+ description: {
174
+ story: "Here, we can see that the first tooltip shown has an initial delay before it appears, as does the last tooltip shown, yet when moving between tooltipped items, the transition from one to another is instantaneous.",
175
+ },
176
+ },
177
+ };
178
+
179
+ /**
180
+ * Tooltips on buttons
181
+ */
182
+ export const TooltipOnButtons: StoryComponentType = () => {
183
+ return (
184
+ <View style={[styles.centered, styles.row]}>
185
+ <Tooltip content={"This is a tooltip on a button."}>
186
+ <Button disabled={false}>Example 1</Button>
187
+ </Tooltip>
188
+ <Tooltip
189
+ content="This is a tooltip on a disabled button."
190
+ placement="bottom"
191
+ >
192
+ <Button disabled={true}>Example 2</Button>
193
+ </Tooltip>
194
+ <Tooltip content="Short and stout">
195
+ <IconButton
196
+ icon={icons.search}
197
+ aria-label="search"
198
+ onClick={() => {}}
199
+ />
200
+ </Tooltip>
201
+ </View>
202
+ );
203
+ };
204
+
205
+ TooltipOnButtons.parameters = {
206
+ chromatic: {
207
+ disableSnapshot: true,
208
+ },
209
+ docs: {
210
+ description: {
211
+ story: "This example shows tooltips on different types of buttons.",
212
+ },
213
+ },
214
+ };
215
+
216
+ const styles = StyleSheet.create({
217
+ row: {
218
+ flexDirection: "row",
219
+ },
220
+ centered: {
221
+ alignItems: "center",
222
+ justifyContent: "center",
223
+ gap: Spacing.medium_16,
224
+ padding: Spacing.xxLarge_48,
225
+ },
226
+ scrollbox: {
227
+ height: 100,
228
+ overflow: "auto",
229
+ border: "1px solid black",
230
+ margin: Spacing.small_12,
231
+ },
232
+ hostbox: {
233
+ minHeight: "200vh",
234
+ },
235
+ modalbox: {
236
+ height: "200vh",
237
+ },
238
+ block: {
239
+ border: `solid 1px ${Color.lightBlue}`,
240
+ width: Spacing.xLarge_32,
241
+ height: Spacing.xLarge_32,
242
+ alignItems: "center",
243
+ justifyContent: "center",
244
+ },
245
+ });
@@ -28,6 +28,16 @@ type Props = {|
28
28
  /**
29
29
  * This component is used to provide the content that is to be rendered in the
30
30
  * tooltip bubble.
31
+ *
32
+ * ### Usage
33
+ *
34
+ * ```jsx
35
+ * import {TooltipContent} from "@khanacademy/wonder-blocks-tooltip";
36
+ *
37
+ * <TooltipContent title="Title text!">
38
+ * Some content in my tooltip.
39
+ * </TooltipContent>
40
+ * ```
31
41
  */
32
42
  export default class TooltipContent extends React.Component<Props> {
33
43
  _renderTitle(): React.Node {
@@ -122,6 +122,30 @@ type DefaultProps = {|
122
122
  placement: $PropertyType<Props, "placement">,
123
123
  |};
124
124
 
125
+ /**
126
+ * Use a tooltip to help describe an on screen object.
127
+ *
128
+ * Tooltips:
129
+ * - contain text
130
+ * - (optional) contain small graphic elements to complement the text
131
+ * - appear on hover or focus (for non-assistive tech keyboard users)
132
+ * - must have a tail that points to a parent object
133
+ * - DO NOT include actions
134
+ *
135
+ * For more rich content see Popovers, for taking action on an object, see
136
+ * Snackbars (proposed).
137
+ *
138
+ * ### Usage
139
+ *
140
+ * ```jsx
141
+ * import Tooltip from "@khanacademy/wonder-blocks-tooltip";
142
+ *
143
+ * <Tooltip content="This is a text tooltip">
144
+ * Tooltip anchor
145
+ * </Tooltip>
146
+ * ```
147
+ *
148
+ */
125
149
  export default class Tooltip extends React.Component<Props, State> {
126
150
  static defaultProps: DefaultProps = {
127
151
  forceAnchorFocusivity: true,