@khanacademy/wonder-blocks-tooltip 1.3.21 → 1.3.23
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 +13 -0
- package/dist/index.js +35 -0
- package/docs.md +3 -10
- package/package.json +2 -2
- package/src/components/__docs__/tooltip-content.stories.js +89 -0
- package/src/components/__docs__/tooltip.argtypes.js +15 -0
- package/src/components/__docs__/tooltip.stories.js +245 -0
- package/src/components/tooltip-content.js +10 -0
- package/src/components/tooltip.js +24 -0
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +0 -2684
- package/src/__tests__/generated-snapshot.test.js +0 -475
- package/src/components/tooltip-bubble.md +0 -92
- package/src/components/tooltip-content.md +0 -34
- package/src/components/tooltip-tail.md +0 -143
- package/src/components/tooltip.md +0 -194
- package/src/components/tooltip.stories.js +0 -111
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
The `TooltipTail` renders the tail, including appropriate padding from the anchor location and corners of the tooltip bubble (so as space out the bubble corners).
|
|
2
|
-
|
|
3
|
-
Each example is shown next to a bar that indicates the padding either side of the tail and the tail width itself. The bar also indicates how far away from the anchor element the tail will render.
|
|
4
|
-
|
|
5
|
-
### Placement top
|
|
6
|
-
|
|
7
|
-
```jsx
|
|
8
|
-
import {StyleSheet} from "aphrodite";
|
|
9
|
-
import {View} from "@khanacademy/wonder-blocks-core";
|
|
10
|
-
import {Spring} from "@khanacademy/wonder-blocks-layout";
|
|
11
|
-
import Spacing from "@khanacademy/wonder-blocks-spacing";
|
|
12
|
-
|
|
13
|
-
const styles = StyleSheet.create({
|
|
14
|
-
guideContainer: {
|
|
15
|
-
flexDirection: "row",
|
|
16
|
-
height: Spacing.xxxSmall_4,
|
|
17
|
-
},
|
|
18
|
-
padding: {
|
|
19
|
-
backgroundColor: "bisque",
|
|
20
|
-
width: Spacing.xSmall_8,
|
|
21
|
-
},
|
|
22
|
-
tail: {
|
|
23
|
-
backgroundColor: "green",
|
|
24
|
-
width: Spacing.large_24,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
<View>
|
|
29
|
-
<TooltipTail placement="top" />
|
|
30
|
-
<View style={styles.guideContainer}>
|
|
31
|
-
<View key="padleft" style={styles.padding} />
|
|
32
|
-
<View key="tail" style={styles.tail} />
|
|
33
|
-
<View key="padright" style={styles.padding} />
|
|
34
|
-
<Spring key="spring" />
|
|
35
|
-
</View>
|
|
36
|
-
</View>
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Placement right
|
|
40
|
-
|
|
41
|
-
```jsx
|
|
42
|
-
import {StyleSheet} from "aphrodite";
|
|
43
|
-
import {View} from "@khanacademy/wonder-blocks-core";
|
|
44
|
-
import {Spring} from "@khanacademy/wonder-blocks-layout";
|
|
45
|
-
import Spacing from "@khanacademy/wonder-blocks-spacing";
|
|
46
|
-
|
|
47
|
-
const styles = StyleSheet.create({
|
|
48
|
-
exampleContainer: {
|
|
49
|
-
flexDirection: "row",
|
|
50
|
-
},
|
|
51
|
-
guideContainer: {
|
|
52
|
-
width: Spacing.xxxSmall_4,
|
|
53
|
-
},
|
|
54
|
-
padding: {
|
|
55
|
-
backgroundColor: "bisque",
|
|
56
|
-
height: Spacing.xSmall_8,
|
|
57
|
-
},
|
|
58
|
-
tail: {
|
|
59
|
-
backgroundColor: "green",
|
|
60
|
-
height: Spacing.large_24,
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
<View style={styles.exampleContainer}>
|
|
65
|
-
<View style={styles.guideContainer}>
|
|
66
|
-
<View key="padleft" style={styles.padding} />
|
|
67
|
-
<View key="tail" style={styles.tail} />
|
|
68
|
-
<View key="padright" style={styles.padding} />
|
|
69
|
-
<Spring key="spring" />
|
|
70
|
-
</View>
|
|
71
|
-
<TooltipTail placement="right" />
|
|
72
|
-
</View>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### Placement bottom
|
|
76
|
-
|
|
77
|
-
```jsx
|
|
78
|
-
import {StyleSheet} from "aphrodite";
|
|
79
|
-
import {View} from "@khanacademy/wonder-blocks-core";
|
|
80
|
-
import {Spring} from "@khanacademy/wonder-blocks-layout";
|
|
81
|
-
import Spacing from "@khanacademy/wonder-blocks-spacing";
|
|
82
|
-
|
|
83
|
-
const styles = StyleSheet.create({
|
|
84
|
-
guideContainer: {
|
|
85
|
-
flexDirection: "row",
|
|
86
|
-
height: Spacing.xxxSmall_4,
|
|
87
|
-
},
|
|
88
|
-
padding: {
|
|
89
|
-
backgroundColor: "bisque",
|
|
90
|
-
width: Spacing.xSmall_8,
|
|
91
|
-
},
|
|
92
|
-
tail: {
|
|
93
|
-
backgroundColor: "green",
|
|
94
|
-
width: Spacing.large_24,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
<View>
|
|
99
|
-
<View style={styles.guideContainer}>
|
|
100
|
-
<View key="padleft" style={styles.padding} />
|
|
101
|
-
<View key="tail" style={styles.tail} />
|
|
102
|
-
<View key="padright" style={styles.padding} />
|
|
103
|
-
<Spring key="spring" />
|
|
104
|
-
</View>
|
|
105
|
-
<TooltipTail placement="bottom" />
|
|
106
|
-
</View>
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Placement left
|
|
110
|
-
|
|
111
|
-
```jsx
|
|
112
|
-
import {StyleSheet} from "aphrodite";
|
|
113
|
-
import {View} from "@khanacademy/wonder-blocks-core";
|
|
114
|
-
import {Spring} from "@khanacademy/wonder-blocks-layout";
|
|
115
|
-
import Spacing from "@khanacademy/wonder-blocks-spacing";
|
|
116
|
-
|
|
117
|
-
const styles = StyleSheet.create({
|
|
118
|
-
exampleContainer: {
|
|
119
|
-
flexDirection: "row",
|
|
120
|
-
},
|
|
121
|
-
guideContainer: {
|
|
122
|
-
width: Spacing.xxxSmall_4,
|
|
123
|
-
},
|
|
124
|
-
padding: {
|
|
125
|
-
backgroundColor: "bisque",
|
|
126
|
-
height: Spacing.xSmall_8,
|
|
127
|
-
},
|
|
128
|
-
tail: {
|
|
129
|
-
backgroundColor: "green",
|
|
130
|
-
height: Spacing.large_24,
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
<View style={styles.exampleContainer}>
|
|
135
|
-
<TooltipTail placement="left" />
|
|
136
|
-
<View style={styles.guideContainer}>
|
|
137
|
-
<View key="padleft" style={styles.padding} />
|
|
138
|
-
<View key="tail" style={styles.tail} />
|
|
139
|
-
<View key="padright" style={styles.padding} />
|
|
140
|
-
<Spring key="spring" />
|
|
141
|
-
</View>
|
|
142
|
-
</View>
|
|
143
|
-
```
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
### Text anchor & text tooltip & placement right
|
|
2
|
-
|
|
3
|
-
```js
|
|
4
|
-
import Tooltip from "@khanacademy/wonder-blocks-tooltip";
|
|
5
|
-
|
|
6
|
-
<Tooltip content="This is a text tooltip on the right" placement="right">
|
|
7
|
-
Some text
|
|
8
|
-
</Tooltip>
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
### Complex anchor & title tooltip & placement default (top)
|
|
12
|
-
|
|
13
|
-
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).
|
|
14
|
-
|
|
15
|
-
```js
|
|
16
|
-
import {View} from "@khanacademy/wonder-blocks-core";
|
|
17
|
-
import Tooltip from "@khanacademy/wonder-blocks-tooltip";
|
|
18
|
-
|
|
19
|
-
<Tooltip
|
|
20
|
-
id="my-a11y-tooltip"
|
|
21
|
-
forceAnchorFocusivity={false}
|
|
22
|
-
title="This tooltip has a title"
|
|
23
|
-
content="I'm at the top!"
|
|
24
|
-
>
|
|
25
|
-
<View>
|
|
26
|
-
Some text
|
|
27
|
-
<input aria-describedby="my-a11y-tooltip" />
|
|
28
|
-
</View>
|
|
29
|
-
</Tooltip>
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Substring anchor in scrollable parent & placement bottom
|
|
33
|
-
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.
|
|
34
|
-
|
|
35
|
-
```js
|
|
36
|
-
import {StyleSheet} from "aphrodite";
|
|
37
|
-
|
|
38
|
-
import {View} from "@khanacademy/wonder-blocks-core";
|
|
39
|
-
import {Body} from "@khanacademy/wonder-blocks-typography";
|
|
40
|
-
import Tooltip from "@khanacademy/wonder-blocks-tooltip";
|
|
41
|
-
|
|
42
|
-
const styles = StyleSheet.create({
|
|
43
|
-
scrollbox: {
|
|
44
|
-
height: 100,
|
|
45
|
-
overflow: "auto",
|
|
46
|
-
border: "1px solid black",
|
|
47
|
-
margin: 10,
|
|
48
|
-
},
|
|
49
|
-
hostbox: {
|
|
50
|
-
minHeight: "200vh",
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
<View>
|
|
55
|
-
<View style={styles.scrollbox}>
|
|
56
|
-
<View style={styles.hostbox}>
|
|
57
|
-
<Body>
|
|
58
|
-
This is a big long piece of text with a
|
|
59
|
-
<Tooltip content="This tooltip will disappear when scrolled out of bounds" placement="bottom">
|
|
60
|
-
[tooltip]
|
|
61
|
-
</Tooltip>
|
|
62
|
-
<span> </span>in the middle.
|
|
63
|
-
</Body>
|
|
64
|
-
</View>
|
|
65
|
-
</View>
|
|
66
|
-
</View>
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
### Tooltip in a modal & placement left
|
|
70
|
-
This checks that the tooltip works how we want inside a modal. Click the button to take a look.
|
|
71
|
-
|
|
72
|
-
```js
|
|
73
|
-
import {StyleSheet} from "aphrodite";
|
|
74
|
-
|
|
75
|
-
import {View, Text} from "@khanacademy/wonder-blocks-core";
|
|
76
|
-
import {OnePaneDialog, ModalLauncher} from "@khanacademy/wonder-blocks-modal";
|
|
77
|
-
import Button from "@khanacademy/wonder-blocks-button";
|
|
78
|
-
import Tooltip from "@khanacademy/wonder-blocks-tooltip";
|
|
79
|
-
|
|
80
|
-
const styles = StyleSheet.create({
|
|
81
|
-
scrollbox: {
|
|
82
|
-
height: 100,
|
|
83
|
-
overflow: "auto",
|
|
84
|
-
border: "1px solid black",
|
|
85
|
-
margin: 10,
|
|
86
|
-
},
|
|
87
|
-
hostbox: {
|
|
88
|
-
minHeight: "200vh",
|
|
89
|
-
},
|
|
90
|
-
modalbox: {
|
|
91
|
-
height: "200vh",
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
const scrollyContent = (
|
|
96
|
-
<View style={styles.scrollbox}>
|
|
97
|
-
<View style={styles.hostbox}>
|
|
98
|
-
<Tooltip content="I'm on the left!" placement="left">
|
|
99
|
-
tooltip
|
|
100
|
-
</Tooltip>
|
|
101
|
-
</View>
|
|
102
|
-
</View>
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
const modalContent = (
|
|
106
|
-
<View style={styles.modalbox}>
|
|
107
|
-
{scrollyContent}
|
|
108
|
-
</View>
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
const modal = (
|
|
112
|
-
<OnePaneDialog
|
|
113
|
-
title="My modal"
|
|
114
|
-
footer="Still my modal"
|
|
115
|
-
content={modalContent} />
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
<ModalLauncher modal={modal}>
|
|
119
|
-
{({openModal}) => <Button onClick={openModal}>Click here!</Button>}
|
|
120
|
-
</ModalLauncher>
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### Tooltips side-by-side
|
|
124
|
-
|
|
125
|
-
```js
|
|
126
|
-
import {StyleSheet} from "aphrodite";
|
|
127
|
-
|
|
128
|
-
import {View} from "@khanacademy/wonder-blocks-core";
|
|
129
|
-
import {LabelSmall} from "@khanacademy/wonder-blocks-typography";
|
|
130
|
-
import Tooltip from "@khanacademy/wonder-blocks-tooltip";
|
|
131
|
-
|
|
132
|
-
const styles = StyleSheet.create({
|
|
133
|
-
"block": {
|
|
134
|
-
border: "solid 1px steelblue",
|
|
135
|
-
width: 32,
|
|
136
|
-
height: 32,
|
|
137
|
-
alignItems: "center",
|
|
138
|
-
justifyContent: "center",
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
<View>
|
|
143
|
-
<LabelSmall>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.</LabelSmall>
|
|
144
|
-
|
|
145
|
-
<View style={{flexDirection: "row"}}>
|
|
146
|
-
<Tooltip content="Tooltip A" placement="bottom">
|
|
147
|
-
<View style={styles.block}>A</View>
|
|
148
|
-
</Tooltip>
|
|
149
|
-
<Tooltip content="Tooltip B" placement="bottom">
|
|
150
|
-
<View style={styles.block}>B</View>
|
|
151
|
-
</Tooltip>
|
|
152
|
-
<Tooltip content="Tooltip C" placement="bottom">
|
|
153
|
-
<View style={styles.block}>C</View>
|
|
154
|
-
</Tooltip>
|
|
155
|
-
<Tooltip content="Tooltip D" placement="bottom">
|
|
156
|
-
<View style={styles.block}>D</View>
|
|
157
|
-
</Tooltip>
|
|
158
|
-
</View>
|
|
159
|
-
</View>
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
### Tooltips on buttons
|
|
163
|
-
|
|
164
|
-
```js
|
|
165
|
-
import {StyleSheet} from "aphrodite";
|
|
166
|
-
|
|
167
|
-
import Button from "@khanacademy/wonder-blocks-button";
|
|
168
|
-
import IconButton from "@khanacademy/wonder-blocks-icon-button";
|
|
169
|
-
import {icons} from "@khanacademy/wonder-blocks-icon";
|
|
170
|
-
import {View} from "@khanacademy/wonder-blocks-core";
|
|
171
|
-
import {Strut} from "@khanacademy/wonder-blocks-layout";
|
|
172
|
-
import Tooltip from "@khanacademy/wonder-blocks-tooltip";
|
|
173
|
-
|
|
174
|
-
const styles = {
|
|
175
|
-
container: {
|
|
176
|
-
flexDirection: "row",
|
|
177
|
-
alignItems: "center",
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
<View style={styles.container}>
|
|
182
|
-
<Tooltip content="I'm a little tooltip">
|
|
183
|
-
<Button>Click me!</Button>
|
|
184
|
-
</Tooltip>
|
|
185
|
-
<Strut size={16} />
|
|
186
|
-
<Tooltip content="Short and stout">
|
|
187
|
-
<IconButton
|
|
188
|
-
icon={icons.search}
|
|
189
|
-
aria-label="search"
|
|
190
|
-
onClick={(e) => console.log("hello")}
|
|
191
|
-
/>
|
|
192
|
-
</Tooltip>
|
|
193
|
-
</View>
|
|
194
|
-
```
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import {StyleSheet} from "aphrodite";
|
|
4
|
-
import {View} from "@khanacademy/wonder-blocks-core";
|
|
5
|
-
import Button from "@khanacademy/wonder-blocks-button";
|
|
6
|
-
import {TextField} from "@khanacademy/wonder-blocks-form";
|
|
7
|
-
import {Strut} from "@khanacademy/wonder-blocks-layout";
|
|
8
|
-
import Spacing from "@khanacademy/wonder-blocks-spacing";
|
|
9
|
-
import Tooltip from "@khanacademy/wonder-blocks-tooltip";
|
|
10
|
-
|
|
11
|
-
import type {Placement} from "@khanacademy/wonder-blocks-tooltip";
|
|
12
|
-
import type {StoryComponentType} from "@storybook/react";
|
|
13
|
-
|
|
14
|
-
export default {
|
|
15
|
-
title: "Floating/Tooltip",
|
|
16
|
-
parameters: {
|
|
17
|
-
// TODO(WB-1170): Reassess this after investigating more about Chromatic
|
|
18
|
-
// flakyness.
|
|
19
|
-
chromatic: {
|
|
20
|
-
disableSnapshot: true,
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const BaseTooltipExample = ({placement}: {|placement: Placement|}) => {
|
|
26
|
-
const inputRef = React.useRef(null);
|
|
27
|
-
React.useEffect(() => {
|
|
28
|
-
if (inputRef.current) {
|
|
29
|
-
inputRef.current.focus();
|
|
30
|
-
}
|
|
31
|
-
}, []);
|
|
32
|
-
|
|
33
|
-
return (
|
|
34
|
-
<View style={styles.centered}>
|
|
35
|
-
<View>
|
|
36
|
-
<Tooltip
|
|
37
|
-
content={`This is a text tooltip on the ${placement}`}
|
|
38
|
-
placement={placement}
|
|
39
|
-
>
|
|
40
|
-
<TextField
|
|
41
|
-
id="tf-1"
|
|
42
|
-
type="text"
|
|
43
|
-
value=""
|
|
44
|
-
placeholder="Text"
|
|
45
|
-
onChange={() => {}}
|
|
46
|
-
ref={inputRef}
|
|
47
|
-
/>
|
|
48
|
-
</Tooltip>
|
|
49
|
-
</View>
|
|
50
|
-
</View>
|
|
51
|
-
);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const TooltipOnButtons: StoryComponentType = () => {
|
|
55
|
-
return (
|
|
56
|
-
<View style={styles.centered}>
|
|
57
|
-
<View>
|
|
58
|
-
<Tooltip content={"This is a tooltip on a button."}>
|
|
59
|
-
<Button disabled={false}>Example 1</Button>
|
|
60
|
-
</Tooltip>
|
|
61
|
-
<Strut size={Spacing.medium_16} />
|
|
62
|
-
<Tooltip
|
|
63
|
-
content="This is a tooltip on a disabled button."
|
|
64
|
-
placement="bottom"
|
|
65
|
-
>
|
|
66
|
-
<Button disabled={true}>Example 2</Button>
|
|
67
|
-
</Tooltip>
|
|
68
|
-
</View>
|
|
69
|
-
</View>
|
|
70
|
-
);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
TooltipOnButtons.parameters = {
|
|
74
|
-
chromatic: {
|
|
75
|
-
disableSnapshot: true,
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
export const TooltipRight: StoryComponentType = () => (
|
|
80
|
-
<BaseTooltipExample placement="right" />
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
export const TooltipLeft: StoryComponentType = () => (
|
|
84
|
-
<BaseTooltipExample placement="left" />
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
export const TooltipTop: StoryComponentType = () => (
|
|
88
|
-
<BaseTooltipExample placement="top" />
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
export const TooltipBottom: StoryComponentType = () => (
|
|
92
|
-
<BaseTooltipExample placement="bottom" />
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
const styles = StyleSheet.create({
|
|
96
|
-
row: {
|
|
97
|
-
flexDirection: "row",
|
|
98
|
-
},
|
|
99
|
-
fullBleed: {
|
|
100
|
-
width: "100%",
|
|
101
|
-
},
|
|
102
|
-
wrapper: {
|
|
103
|
-
height: "800px",
|
|
104
|
-
width: "1200px",
|
|
105
|
-
},
|
|
106
|
-
centered: {
|
|
107
|
-
alignItems: "center",
|
|
108
|
-
justifyContent: "center",
|
|
109
|
-
height: `calc(100vh - 16px)`,
|
|
110
|
-
},
|
|
111
|
-
});
|