@khanacademy/wonder-blocks-tooltip 1.4.6 → 1.4.8

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 (53) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/components/tooltip-anchor.d.ts +85 -0
  3. package/dist/components/tooltip-anchor.js.flow +98 -0
  4. package/dist/components/tooltip-bubble.d.ts +36 -0
  5. package/dist/components/tooltip-bubble.js.flow +72 -0
  6. package/dist/components/tooltip-content.d.ts +33 -0
  7. package/dist/components/tooltip-content.js.flow +44 -0
  8. package/dist/components/tooltip-popper.d.ts +32 -0
  9. package/dist/components/tooltip-popper.js.flow +39 -0
  10. package/dist/components/tooltip-tail.d.ts +57 -0
  11. package/dist/components/tooltip-tail.js.flow +77 -0
  12. package/dist/components/tooltip.d.ts +150 -0
  13. package/dist/components/tooltip.js.flow +159 -0
  14. package/dist/es/index.js +220 -273
  15. package/dist/index.d.ts +8 -0
  16. package/dist/index.js +234 -288
  17. package/dist/index.js.flow +20 -2
  18. package/dist/util/active-tracker.d.ts +61 -0
  19. package/dist/util/active-tracker.js.flow +71 -0
  20. package/dist/util/constants.d.ts +6 -0
  21. package/dist/util/constants.js.flow +13 -0
  22. package/dist/util/ref-tracker.d.ts +16 -0
  23. package/dist/util/ref-tracker.js.flow +16 -0
  24. package/dist/util/types.d.ts +11 -0
  25. package/dist/util/types.js.flow +36 -0
  26. package/package.json +9 -9
  27. package/src/components/__tests__/{tooltip-anchor.test.js → tooltip-anchor.test.tsx} +30 -40
  28. package/src/components/__tests__/{tooltip-bubble.test.js → tooltip-bubble.test.tsx} +4 -4
  29. package/src/components/__tests__/{tooltip-popper.test.js → tooltip-popper.test.tsx} +15 -12
  30. package/src/components/__tests__/{tooltip-tail.test.js → tooltip-tail.test.tsx} +5 -4
  31. package/src/components/__tests__/{tooltip.integration.test.js → tooltip.integration.test.tsx} +0 -1
  32. package/src/components/__tests__/{tooltip.test.js → tooltip.test.tsx} +10 -8
  33. package/src/components/{tooltip-anchor.js → tooltip-anchor.tsx} +26 -27
  34. package/src/components/{tooltip-bubble.js → tooltip-bubble.tsx} +18 -30
  35. package/src/components/{tooltip-content.js → tooltip-content.tsx} +8 -10
  36. package/src/components/{tooltip-popper.js → tooltip-popper.tsx} +14 -14
  37. package/src/components/{tooltip-tail.js → tooltip-tail.tsx} +28 -32
  38. package/src/components/{tooltip.js → tooltip.tsx} +35 -39
  39. package/src/{index.js → index.ts} +0 -1
  40. package/src/util/__tests__/{active-tracker.test.js → active-tracker.test.ts} +0 -1
  41. package/src/util/__tests__/{ref-tracker.test.js → ref-tracker.test.tsx} +13 -7
  42. package/src/util/{active-tracker.js → active-tracker.ts} +1 -2
  43. package/src/util/{constants.js → constants.ts} +0 -1
  44. package/src/util/{ref-tracker.js → ref-tracker.ts} +14 -7
  45. package/src/util/types.ts +32 -0
  46. package/tsconfig.json +16 -0
  47. package/tsconfig.tsbuildinfo +1 -0
  48. package/src/components/__docs__/tooltip-content.stories.js +0 -89
  49. package/src/components/__docs__/tooltip.argtypes.js +0 -15
  50. package/src/components/__docs__/tooltip.stories.js +0 -335
  51. package/src/util/types.js +0 -29
  52. /package/src/util/__tests__/__snapshots__/{active-tracker.test.js.snap → active-tracker.test.ts.snap} +0 -0
  53. /package/src/util/__tests__/__snapshots__/{ref-tracker.test.js.snap → ref-tracker.test.tsx.snap} +0 -0
@@ -1,89 +0,0 @@
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";
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
- };
@@ -1,15 +0,0 @@
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
- };
@@ -1,335 +0,0 @@
1
- // @flow
2
- import * as React from "react";
3
- import {StyleSheet} from "aphrodite";
4
-
5
- import {within, userEvent} from "@storybook/testing-library";
6
- import {expect} from "@storybook/jest";
7
-
8
- import Button from "@khanacademy/wonder-blocks-button";
9
- import Color from "@khanacademy/wonder-blocks-color";
10
- import {View} from "@khanacademy/wonder-blocks-core";
11
- import {TextField} from "@khanacademy/wonder-blocks-form";
12
- import IconButton from "@khanacademy/wonder-blocks-icon-button";
13
- import {icons} from "@khanacademy/wonder-blocks-icon";
14
- import {OnePaneDialog, ModalLauncher} from "@khanacademy/wonder-blocks-modal";
15
- import Spacing from "@khanacademy/wonder-blocks-spacing";
16
- import Tooltip from "@khanacademy/wonder-blocks-tooltip";
17
- import {Body} from "@khanacademy/wonder-blocks-typography";
18
-
19
- import type {StoryComponentType} from "@storybook/react";
20
- import TooltipArgtypes from "./tooltip.argtypes";
21
-
22
- import ComponentInfo from "../../../../../.storybook/components/component-info";
23
- import {name, version} from "../../../package.json";
24
-
25
- export default {
26
- title: "Tooltip / Tooltip",
27
- component: Tooltip,
28
- argTypes: TooltipArgtypes,
29
- args: {
30
- forceAnchorFocusivity: true,
31
- placement: "top",
32
- },
33
- parameters: {
34
- componentSubtitle: ((
35
- <ComponentInfo name={name} version={version} />
36
- ): any),
37
- },
38
- decorators: [
39
- (Story: any): React.Node => (
40
- <View style={styles.storyCanvas}>{Story()}</View>
41
- ),
42
- ],
43
- };
44
-
45
- const Template = (args) => <Tooltip {...args} />;
46
-
47
- /**
48
- * Default example (interactive).
49
- */
50
- export const Default: StoryComponentType = Template.bind({});
51
-
52
- Default.args = {
53
- content: "This is a text tooltip on the top",
54
- children: "some text",
55
- };
56
-
57
- Default.play = async ({canvasElement}) => {
58
- // Arrange
59
- // NOTE: Using `body` here to work with React Portals.
60
- const canvas = within(canvasElement.ownerDocument.body);
61
-
62
- // Act
63
- // Triggers the hover state
64
- const text = await canvas.findByText("some text");
65
- await userEvent.hover(text);
66
-
67
- // Assert
68
- await expect(
69
- await canvas.findByText("This is a text tooltip on the top"),
70
- ).toBeInTheDocument();
71
- };
72
-
73
- /**
74
- * Complex anchor & title tooltip
75
- */
76
- export const ComplexAnchorAndTitle: StoryComponentType = Template.bind({});
77
-
78
- ComplexAnchorAndTitle.args = {
79
- forceAnchorFocusivity: false,
80
- placement: "bottom",
81
- id: "my-a11y-tooltip",
82
- title: "This tooltip has a title",
83
- content: "I'm at the bottom!",
84
- children: (
85
- <View>
86
- Some text
87
- <TextField
88
- aria-describedby="my-a11y-tooltip"
89
- id=""
90
- onChange={() => {}}
91
- value=""
92
- />
93
- </View>
94
- ),
95
- };
96
-
97
- ComplexAnchorAndTitle.play = async ({canvasElement}) => {
98
- // Arrange
99
- // NOTE: Using `body` here to work with React Portals.
100
- const canvas = within(canvasElement.ownerDocument.body);
101
-
102
- // Act
103
- // Triggers the hover state
104
- const text = await canvas.findByText("Some text");
105
- await userEvent.hover(text);
106
-
107
- // Assert
108
- await expect(
109
- await canvas.findByText("This tooltip has a title"),
110
- ).toBeInTheDocument();
111
- };
112
-
113
- ComplexAnchorAndTitle.parameters = {
114
- docs: {
115
- description: {
116
- 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).",
117
- },
118
- },
119
- };
120
-
121
- /**
122
- * Anchor in scrollable parent & placement bottom
123
- */
124
- export const AnchorInScrollableParent: StoryComponentType = () => (
125
- <View style={styles.scrollbox}>
126
- <View style={styles.hostbox}>
127
- <Body>
128
- This is a big long piece of text with a
129
- <Tooltip
130
- content="This tooltip will disappear when scrolled out of bounds"
131
- placement="bottom"
132
- >
133
- [tooltip]
134
- </Tooltip>{" "}
135
- in the middle.
136
- </Body>
137
- </View>
138
- </View>
139
- );
140
-
141
- AnchorInScrollableParent.parameters = {
142
- // Disable Chromatic because it only shows the trigger element.
143
- chromatic: {
144
- disableSnapshot: true,
145
- },
146
- docs: {
147
- description: {
148
- 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.",
149
- },
150
- },
151
- };
152
-
153
- /**
154
- * Tooltip in a modal
155
- */
156
- export const TooltipInModal: StoryComponentType = () => {
157
- const scrollyContent = (
158
- <View style={styles.scrollbox}>
159
- <View style={styles.hostbox}>
160
- <Tooltip content="I'm on the left!" placement="left">
161
- tooltip
162
- </Tooltip>
163
- </View>
164
- </View>
165
- );
166
-
167
- const modal = (
168
- <OnePaneDialog
169
- title="My modal"
170
- footer="Still my modal"
171
- content={<View style={styles.modalbox}>{scrollyContent}</View>}
172
- />
173
- );
174
-
175
- return (
176
- <ModalLauncher modal={modal}>
177
- {({openModal}) => <Button onClick={openModal}>Click here!</Button>}
178
- </ModalLauncher>
179
- );
180
- };
181
-
182
- TooltipInModal.parameters = {
183
- // Disable Chromatic because it initially renders the modal offscreen.
184
- chromatic: {
185
- disableSnapshot: true,
186
- },
187
- docs: {
188
- description: {
189
- story: "This checks that the tooltip works how we want inside a modal. Click the button to take a look.",
190
- },
191
- },
192
- };
193
-
194
- /**
195
- * Tooltips side-by-side
196
- */
197
- export const SideBySide: StoryComponentType = () => (
198
- <View style={styles.row}>
199
- <Tooltip content="Tooltip A" placement="bottom">
200
- <View style={styles.block}>A</View>
201
- </Tooltip>
202
- <Tooltip content="Tooltip B" placement="bottom">
203
- <View style={styles.block}>B</View>
204
- </Tooltip>
205
- <Tooltip content="Tooltip C" placement="bottom">
206
- <View style={styles.block}>C</View>
207
- </Tooltip>
208
- <Tooltip content="Tooltip D" placement="bottom">
209
- <View style={styles.block}>D</View>
210
- </Tooltip>
211
- </View>
212
- );
213
-
214
- SideBySide.storyName = "Side-by-side";
215
-
216
- SideBySide.parameters = {
217
- // Disable Chromatic because it only shows the trigger element.
218
- chromatic: {
219
- disableSnapshot: true,
220
- },
221
- docs: {
222
- description: {
223
- 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.",
224
- },
225
- },
226
- };
227
-
228
- /**
229
- * Tooltips on buttons
230
- */
231
- export const TooltipOnButtons: StoryComponentType = () => {
232
- return (
233
- <View style={[styles.centered, styles.row]}>
234
- <Tooltip content={"This is a tooltip on a button."}>
235
- <Button disabled={false}>Example 1</Button>
236
- </Tooltip>
237
- <Tooltip
238
- content="This is a tooltip on a disabled button."
239
- placement="bottom"
240
- >
241
- <Button disabled={true}>Example 2</Button>
242
- </Tooltip>
243
- <Tooltip content="Short and stout">
244
- <IconButton
245
- icon={icons.search}
246
- aria-label="search"
247
- onClick={() => {}}
248
- />
249
- </Tooltip>
250
- </View>
251
- );
252
- };
253
-
254
- TooltipOnButtons.parameters = {
255
- chromatic: {
256
- disableSnapshot: true,
257
- },
258
- docs: {
259
- description: {
260
- story: "This example shows tooltips on different types of buttons.",
261
- },
262
- },
263
- };
264
-
265
- /**
266
- * Opening a tooltip programatically (Controlled)
267
- */
268
- export const Controlled: StoryComponentType = () => {
269
- const [opened, setOpened] = React.useState(true);
270
- const buttonText = `Click to ${opened ? "close" : "open"} tooltip`;
271
-
272
- return (
273
- <View style={[styles.centered, styles.row]}>
274
- <Tooltip
275
- content="You opened the tooltip with a button"
276
- opened={opened}
277
- >
278
- tooltip
279
- </Tooltip>
280
- <Button onClick={() => setOpened(!opened)}>{buttonText}</Button>
281
- </View>
282
- );
283
- };
284
-
285
- Controlled.parameters = {
286
- docs: {
287
- description: {
288
- story: `Sometimes you'll want to trigger a tooltip programmatically.
289
- This can be done by setting the \`opened\` prop to \`true\`. In
290
- this situation the \`Tooltip\` is a controlled component. The
291
- parent is responsible for managing the opening/closing of the
292
- tooltip when using this prop. This means that you'll also have
293
- to update \`opened\` to \`false\` in response to the
294
- \`onClose\` callback being triggered.`,
295
- },
296
- },
297
- };
298
-
299
- const styles = StyleSheet.create({
300
- storyCanvas: {
301
- // NOTE: This is needed for Chromatic to include the tooltip bubble.
302
- minHeight: 280,
303
- padding: Spacing.xxxLarge_64,
304
- justifyContent: "center",
305
- textAlign: "center",
306
- },
307
- row: {
308
- flexDirection: "row",
309
- },
310
- centered: {
311
- alignItems: "center",
312
- justifyContent: "center",
313
- gap: Spacing.medium_16,
314
- padding: Spacing.xxLarge_48,
315
- },
316
- scrollbox: {
317
- height: 100,
318
- overflow: "auto",
319
- border: "1px solid black",
320
- margin: Spacing.small_12,
321
- },
322
- hostbox: {
323
- minHeight: "200vh",
324
- },
325
- modalbox: {
326
- height: "200vh",
327
- },
328
- block: {
329
- border: `solid 1px ${Color.lightBlue}`,
330
- width: Spacing.xLarge_32,
331
- height: Spacing.xLarge_32,
332
- alignItems: "center",
333
- justifyContent: "center",
334
- },
335
- });
package/src/util/types.js DELETED
@@ -1,29 +0,0 @@
1
- // @flow
2
- import * as React from "react";
3
-
4
- export type getRefFn = (?(React.Component<any> | Element)) => void;
5
-
6
- export type Offset = {|
7
- bottom: ?string,
8
- top: ?string,
9
- left: ?string,
10
- right: ?string,
11
- transform: ?string,
12
- |};
13
-
14
- export type Placement =
15
- | "auto"
16
- | "auto-start"
17
- | "auto-end"
18
- | "top"
19
- | "top-start"
20
- | "top-end"
21
- | "bottom"
22
- | "bottom-start"
23
- | "bottom-end"
24
- | "right"
25
- | "right-start"
26
- | "right-end"
27
- | "left"
28
- | "left-start"
29
- | "left-end";