@khanacademy/wonder-blocks-tooltip 1.4.6 → 1.4.7
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 +29 -0
- package/dist/components/tooltip-anchor.d.ts +85 -0
- package/dist/components/tooltip-anchor.js.flow +98 -0
- package/dist/components/tooltip-bubble.d.ts +36 -0
- package/dist/components/tooltip-bubble.js.flow +72 -0
- package/dist/components/tooltip-content.d.ts +33 -0
- package/dist/components/tooltip-content.js.flow +44 -0
- package/dist/components/tooltip-popper.d.ts +32 -0
- package/dist/components/tooltip-popper.js.flow +39 -0
- package/dist/components/tooltip-tail.d.ts +57 -0
- package/dist/components/tooltip-tail.js.flow +77 -0
- package/dist/components/tooltip.d.ts +150 -0
- package/dist/components/tooltip.js.flow +159 -0
- package/dist/es/index.js +220 -273
- package/dist/index.d.ts +8 -0
- package/dist/index.js +234 -288
- package/dist/index.js.flow +20 -2
- package/dist/util/active-tracker.d.ts +61 -0
- package/dist/util/active-tracker.js.flow +71 -0
- package/dist/util/constants.d.ts +6 -0
- package/dist/util/constants.js.flow +13 -0
- package/dist/util/ref-tracker.d.ts +16 -0
- package/dist/util/ref-tracker.js.flow +16 -0
- package/dist/util/types.d.ts +11 -0
- package/dist/util/types.js.flow +36 -0
- package/package.json +9 -9
- package/src/components/__tests__/{tooltip-anchor.test.js → tooltip-anchor.test.tsx} +30 -40
- package/src/components/__tests__/{tooltip-bubble.test.js → tooltip-bubble.test.tsx} +4 -4
- package/src/components/__tests__/{tooltip-popper.test.js → tooltip-popper.test.tsx} +15 -12
- package/src/components/__tests__/{tooltip-tail.test.js → tooltip-tail.test.tsx} +5 -4
- package/src/components/__tests__/{tooltip.integration.test.js → tooltip.integration.test.tsx} +0 -1
- package/src/components/__tests__/{tooltip.test.js → tooltip.test.tsx} +10 -8
- package/src/components/{tooltip-anchor.js → tooltip-anchor.tsx} +26 -27
- package/src/components/{tooltip-bubble.js → tooltip-bubble.tsx} +18 -30
- package/src/components/{tooltip-content.js → tooltip-content.tsx} +8 -10
- package/src/components/{tooltip-popper.js → tooltip-popper.tsx} +14 -14
- package/src/components/{tooltip-tail.js → tooltip-tail.tsx} +28 -32
- package/src/components/{tooltip.js → tooltip.tsx} +35 -39
- package/src/{index.js → index.ts} +0 -1
- package/src/util/__tests__/{active-tracker.test.js → active-tracker.test.ts} +0 -1
- package/src/util/__tests__/{ref-tracker.test.js → ref-tracker.test.tsx} +13 -7
- package/src/util/{active-tracker.js → active-tracker.ts} +1 -2
- package/src/util/{constants.js → constants.ts} +0 -1
- package/src/util/{ref-tracker.js → ref-tracker.ts} +14 -7
- package/src/util/types.ts +32 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/components/__docs__/tooltip-content.stories.js +0 -89
- package/src/components/__docs__/tooltip.argtypes.js +0 -15
- package/src/components/__docs__/tooltip.stories.js +0 -335
- package/src/util/types.js +0 -29
- /package/src/util/__tests__/__snapshots__/{active-tracker.test.js.snap → active-tracker.test.ts.snap} +0 -0
- /package/src/util/__tests__/__snapshots__/{ref-tracker.test.js.snap → ref-tracker.test.tsx.snap} +0 -0
package/dist/index.js.flow
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for index
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Placement } from "./util/types";
|
|
9
|
+
import type { PopperElementProps } from "./components/tooltip-bubble";
|
|
10
|
+
import Tooltip from "./components/tooltip";
|
|
11
|
+
import TooltipContent from "./components/tooltip-content";
|
|
12
|
+
import TooltipPopper from "./components/tooltip-popper";
|
|
13
|
+
import TooltipTail from "./components/tooltip-tail";
|
|
14
|
+
declare export {
|
|
15
|
+
Tooltip as default,
|
|
16
|
+
TooltipContent,
|
|
17
|
+
TooltipPopper,
|
|
18
|
+
TooltipTail,
|
|
19
|
+
};
|
|
20
|
+
export type { Placement, PopperElementProps };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This interface should be implemented by types that are interested in the
|
|
3
|
+
* notifications of active state being stolen. Generally, this would also be
|
|
4
|
+
* subscribers that may also steal active state, but not necessarily.
|
|
5
|
+
*
|
|
6
|
+
* Once implemented, the type must call subscribe on a tracker to begin
|
|
7
|
+
* receiving notifications.
|
|
8
|
+
*/
|
|
9
|
+
export interface IActiveTrackerSubscriber {
|
|
10
|
+
/**
|
|
11
|
+
* Notification raised when something steals the active state from a
|
|
12
|
+
* subscribed tracker.
|
|
13
|
+
*/
|
|
14
|
+
activeStateStolen: () => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* This class is used to track the concept of active state (though technically
|
|
18
|
+
* that could be any boolean state). The tracker has a variety of subscribers
|
|
19
|
+
* that receive notifications of state theft and can steal the state.
|
|
20
|
+
*
|
|
21
|
+
* For the tooltip, this enables us to have a single tooltip active at any one
|
|
22
|
+
* time. The tracker allows tooltip anchors to coordinate which of them is
|
|
23
|
+
* active, and to ensure that if a different one becomes active, all the others
|
|
24
|
+
* know that they aren't.
|
|
25
|
+
*
|
|
26
|
+
* - When notified that the state has been stolen, subscribers can immediately
|
|
27
|
+
* reflect that theft (in the case of a tooltip, they would hide themselves).
|
|
28
|
+
* - The thief does not get notified if they were the one who stole the state
|
|
29
|
+
* since they should already know that they did that (this avoids having to have
|
|
30
|
+
* checks for reentrancy, for example).
|
|
31
|
+
* - When the subscriber that owns the state no longer needs it, it can
|
|
32
|
+
* voluntarily give it up.
|
|
33
|
+
* - If the state is stolen while a subscriber owns the
|
|
34
|
+
* state, that subscriber does not give up the state, as it doesn't have it
|
|
35
|
+
* anymore (it was stolen).
|
|
36
|
+
*/
|
|
37
|
+
export default class ActiveTracker {
|
|
38
|
+
_subscribers: Array<IActiveTrackerSubscriber>;
|
|
39
|
+
_active: boolean;
|
|
40
|
+
_getIndex(who: IActiveTrackerSubscriber): number;
|
|
41
|
+
/**
|
|
42
|
+
* Called when a tooltip anchor becomes active so that it can tell all other
|
|
43
|
+
* anchors that they are no longer the active tooltip. Returns true if
|
|
44
|
+
* the there was a steal of active state from another anchor; otherwise, if
|
|
45
|
+
* no other anchor had been active, returns false.
|
|
46
|
+
*/
|
|
47
|
+
steal(who: IActiveTrackerSubscriber): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Called if a tooltip doesn't want to be active anymore.
|
|
50
|
+
* Should not be called when being told the active spot was stolen by
|
|
51
|
+
* another anchor, only when the anchor is unhovered and unfocused and they
|
|
52
|
+
* were active.
|
|
53
|
+
*/
|
|
54
|
+
giveup(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Subscribes a tooltip anchor to the tracker so that it can be notified of
|
|
57
|
+
* steals. Returns a method that can be used to unsubscribe the anchor from
|
|
58
|
+
* notifications.
|
|
59
|
+
*/
|
|
60
|
+
subscribe(who: IActiveTrackerSubscriber): () => void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for active-tracker
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This interface should be implemented by types that are interested in the
|
|
10
|
+
* notifications of active state being stolen. Generally, this would also be
|
|
11
|
+
* subscribers that may also steal active state, but not necessarily.
|
|
12
|
+
*
|
|
13
|
+
* Once implemented, the type must call subscribe on a tracker to begin
|
|
14
|
+
* receiving notifications.
|
|
15
|
+
*/
|
|
16
|
+
export interface IActiveTrackerSubscriber {
|
|
17
|
+
/**
|
|
18
|
+
* Notification raised when something steals the active state from a
|
|
19
|
+
* subscribed tracker.
|
|
20
|
+
*/
|
|
21
|
+
activeStateStolen: () => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* This class is used to track the concept of active state (though technically
|
|
25
|
+
* that could be any boolean state). The tracker has a variety of subscribers
|
|
26
|
+
* that receive notifications of state theft and can steal the state.
|
|
27
|
+
*
|
|
28
|
+
* For the tooltip, this enables us to have a single tooltip active at any one
|
|
29
|
+
* time. The tracker allows tooltip anchors to coordinate which of them is
|
|
30
|
+
* active, and to ensure that if a different one becomes active, all the others
|
|
31
|
+
* know that they aren't.
|
|
32
|
+
*
|
|
33
|
+
* - When notified that the state has been stolen, subscribers can immediately
|
|
34
|
+
* reflect that theft (in the case of a tooltip, they would hide themselves).
|
|
35
|
+
* - The thief does not get notified if they were the one who stole the state
|
|
36
|
+
* since they should already know that they did that (this avoids having to have
|
|
37
|
+
* checks for reentrancy, for example).
|
|
38
|
+
* - When the subscriber that owns the state no longer needs it, it can
|
|
39
|
+
* voluntarily give it up.
|
|
40
|
+
* - If the state is stolen while a subscriber owns the
|
|
41
|
+
* state, that subscriber does not give up the state, as it doesn't have it
|
|
42
|
+
* anymore (it was stolen).
|
|
43
|
+
*/
|
|
44
|
+
declare export default class ActiveTracker {
|
|
45
|
+
_subscribers: Array<IActiveTrackerSubscriber>;
|
|
46
|
+
_active: boolean;
|
|
47
|
+
_getIndex(who: IActiveTrackerSubscriber): number;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Called when a tooltip anchor becomes active so that it can tell all other
|
|
51
|
+
* anchors that they are no longer the active tooltip. Returns true if
|
|
52
|
+
* the there was a steal of active state from another anchor; otherwise, if
|
|
53
|
+
* no other anchor had been active, returns false.
|
|
54
|
+
*/
|
|
55
|
+
steal(who: IActiveTrackerSubscriber): boolean;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Called if a tooltip doesn't want to be active anymore.
|
|
59
|
+
* Should not be called when being told the active spot was stolen by
|
|
60
|
+
* another anchor, only when the anchor is unhovered and unfocused and they
|
|
61
|
+
* were active.
|
|
62
|
+
*/
|
|
63
|
+
giveup(): void;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Subscribes a tooltip anchor to the tracker so that it can be notified of
|
|
67
|
+
* steals. Returns a method that can be used to unsubscribe the anchor from
|
|
68
|
+
* notifications.
|
|
69
|
+
*/
|
|
70
|
+
subscribe(who: IActiveTrackerSubscriber): () => void;
|
|
71
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for constants
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The attribute used to identify a tooltip portal.
|
|
10
|
+
*/
|
|
11
|
+
declare export var TooltipPortalAttributeName: "data-tooltip-portal";
|
|
12
|
+
declare export var TooltipAppearanceDelay: 100;
|
|
13
|
+
declare export var TooltipDisappearanceDelay: 75;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a little helper that we can use to wrap the react-popper reference
|
|
3
|
+
* update methods so that we can convert a regular React ref into a DOM node
|
|
4
|
+
* as react-popper expects, and also ensure we only update react-popper
|
|
5
|
+
* on actual changes, and not just renders of the same thing.
|
|
6
|
+
*/
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import type { PopperChildrenProps } from "react-popper";
|
|
9
|
+
type PopperRef = PopperChildrenProps["ref"];
|
|
10
|
+
export default class RefTracker {
|
|
11
|
+
_lastRef: HTMLElement | null | undefined;
|
|
12
|
+
_targetFn: (arg1?: HTMLElement | null | undefined) => void | null | undefined;
|
|
13
|
+
updateRef: (ref?: React.Component<any> | Element | null | undefined) => void;
|
|
14
|
+
setCallback: (targetFn?: PopperRef | null | undefined) => void;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for ref-tracker
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { PopperChildrenProps } from "react-popper";
|
|
10
|
+
declare type PopperRef = $PropertyType<PopperChildrenProps, "ref">;
|
|
11
|
+
declare export default class RefTracker {
|
|
12
|
+
_lastRef: HTMLElement | null | void;
|
|
13
|
+
_targetFn: (arg1?: HTMLElement | null | void) => void | null | void;
|
|
14
|
+
updateRef: (ref?: React.Component<any> | Element | null | void) => void;
|
|
15
|
+
setCallback: (targetFn?: PopperRef | null | void) => void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { CSSProperties } from "aphrodite";
|
|
3
|
+
export type getRefFn = (arg1?: React.Component<any> | Element | null | undefined) => void;
|
|
4
|
+
export type Offset = {
|
|
5
|
+
bottom: CSSProperties["bottom"];
|
|
6
|
+
top: CSSProperties["top"];
|
|
7
|
+
left: CSSProperties["left"];
|
|
8
|
+
right: CSSProperties["right"];
|
|
9
|
+
transform: CSSProperties["transform"];
|
|
10
|
+
};
|
|
11
|
+
export type Placement = "auto" | "auto-start" | "auto-end" | "top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "right" | "right-start" | "right-end" | "left" | "left-start" | "left-end";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for types
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { CSSProperties } from "aphrodite";
|
|
10
|
+
export type getRefFn = (
|
|
11
|
+
arg1?: React.Component<any> | Element | null | void
|
|
12
|
+
) => void;
|
|
13
|
+
export type Offset = {
|
|
14
|
+
bottom: $PropertyType<CSSProperties, "bottom">,
|
|
15
|
+
top: $PropertyType<CSSProperties, "top">,
|
|
16
|
+
left: $PropertyType<CSSProperties, "left">,
|
|
17
|
+
right: $PropertyType<CSSProperties, "right">,
|
|
18
|
+
transform: $PropertyType<CSSProperties, "transform">,
|
|
19
|
+
...
|
|
20
|
+
};
|
|
21
|
+
export type Placement =
|
|
22
|
+
| "auto"
|
|
23
|
+
| "auto-start"
|
|
24
|
+
| "auto-end"
|
|
25
|
+
| "top"
|
|
26
|
+
| "top-start"
|
|
27
|
+
| "top-end"
|
|
28
|
+
| "bottom"
|
|
29
|
+
| "bottom-start"
|
|
30
|
+
| "bottom-end"
|
|
31
|
+
| "right"
|
|
32
|
+
| "right-start"
|
|
33
|
+
| "right-end"
|
|
34
|
+
| "left"
|
|
35
|
+
| "left-start"
|
|
36
|
+
| "left-end";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-tooltip",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.7",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"module": "dist/es/index.js",
|
|
11
|
-
"
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
14
|
},
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
|
-
"@khanacademy/wonder-blocks-color": "^1.2.
|
|
20
|
-
"@khanacademy/wonder-blocks-core": "^4.
|
|
21
|
-
"@khanacademy/wonder-blocks-layout": "^1.4.
|
|
22
|
-
"@khanacademy/wonder-blocks-modal": "^3.0.
|
|
23
|
-
"@khanacademy/wonder-blocks-spacing": "^3.0.
|
|
24
|
-
"@khanacademy/wonder-blocks-typography": "^1.1.
|
|
19
|
+
"@khanacademy/wonder-blocks-color": "^1.2.2",
|
|
20
|
+
"@khanacademy/wonder-blocks-core": "^4.8.0",
|
|
21
|
+
"@khanacademy/wonder-blocks-layout": "^1.4.17",
|
|
22
|
+
"@khanacademy/wonder-blocks-modal": "^3.0.8",
|
|
23
|
+
"@khanacademy/wonder-blocks-spacing": "^3.0.6",
|
|
24
|
+
"@khanacademy/wonder-blocks-typography": "^1.1.39"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@popperjs/core": "^2.10.1",
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"react-popper": "^2.0.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"wb-dev-build-settings": "^0.7.
|
|
34
|
+
"wb-dev-build-settings": "^0.7.2"
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {View} from "@khanacademy/wonder-blocks-core";
|
|
4
3
|
import {render, screen} from "@testing-library/react";
|
|
@@ -14,14 +13,14 @@ jest.mock("../../util/active-tracker");
|
|
|
14
13
|
|
|
15
14
|
describe("TooltipAnchor", () => {
|
|
16
15
|
beforeEach(async () => {
|
|
17
|
-
//
|
|
16
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mockReset' does not exist on type '{ <K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ... 1 more ... | undefined): void; }'.
|
|
18
17
|
if (typeof document.addEventListener.mockReset === "function") {
|
|
19
|
-
//
|
|
18
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mockRestore' does not exist on type '{ <K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ... 1 more ... | undefined): void; }'.
|
|
20
19
|
document.addEventListener.mockRestore();
|
|
21
20
|
}
|
|
22
|
-
//
|
|
21
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mockReset' does not exist on type '{ <K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ... 1 more ... | undefined): void; }'.
|
|
23
22
|
if (typeof document.removeEventListener.mockReset === "function") {
|
|
24
|
-
//
|
|
23
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mockRestore' does not exist on type '{ <K extends keyof DocumentEventMap>(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions | undefined): void; (type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ... 1 more ... | undefined): void; }'.
|
|
25
24
|
document.removeEventListener.mockRestore();
|
|
26
25
|
}
|
|
27
26
|
jest.clearAllTimers();
|
|
@@ -32,8 +31,7 @@ describe("TooltipAnchor", () => {
|
|
|
32
31
|
);
|
|
33
32
|
// We know there's one global instance of this import, so let's
|
|
34
33
|
// reset it.
|
|
35
|
-
//
|
|
36
|
-
// $FlowFixMe[prop-missing]
|
|
34
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mock' does not exist on type 'typeof ActiveTracker'.
|
|
37
35
|
const mockTracker = ActiveTracker.mock.instances[0];
|
|
38
36
|
mockTracker.steal.mockClear();
|
|
39
37
|
mockTracker.giveup.mockClear();
|
|
@@ -250,8 +248,7 @@ describe("TooltipAnchor", () => {
|
|
|
250
248
|
const timeoutSpy = jest.spyOn(global, "setTimeout");
|
|
251
249
|
// Let's tell the tooltip it isn't stealing and therefore it should
|
|
252
250
|
// be using a delay to show the tooltip.
|
|
253
|
-
//
|
|
254
|
-
// $FlowFixMe[prop-missing]
|
|
251
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mock' does not exist on type 'typeof ActiveTracker'.
|
|
255
252
|
const mockTracker = ActiveTracker.mock.instances[0];
|
|
256
253
|
mockTracker.steal.mockImplementationOnce(() => false);
|
|
257
254
|
|
|
@@ -260,7 +257,7 @@ describe("TooltipAnchor", () => {
|
|
|
260
257
|
render(
|
|
261
258
|
<TooltipAnchor
|
|
262
259
|
anchorRef={jest.fn()}
|
|
263
|
-
onActiveChanged={(active) => {
|
|
260
|
+
onActiveChanged={(active: any) => {
|
|
264
261
|
activeState = active;
|
|
265
262
|
}}
|
|
266
263
|
>
|
|
@@ -290,8 +287,7 @@ describe("TooltipAnchor", () => {
|
|
|
290
287
|
);
|
|
291
288
|
// Let's tell the tooltip it is stealing and therefore it should
|
|
292
289
|
// not be using a delay to show the tooltip.
|
|
293
|
-
//
|
|
294
|
-
// $FlowFixMe[prop-missing]
|
|
290
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mock' does not exist on type 'typeof ActiveTracker'.
|
|
295
291
|
const mockTracker = ActiveTracker.mock.instances[0];
|
|
296
292
|
mockTracker.steal.mockImplementationOnce(() => true);
|
|
297
293
|
|
|
@@ -300,7 +296,7 @@ describe("TooltipAnchor", () => {
|
|
|
300
296
|
render(
|
|
301
297
|
<TooltipAnchor
|
|
302
298
|
anchorRef={jest.fn()}
|
|
303
|
-
onActiveChanged={(active) => {
|
|
299
|
+
onActiveChanged={(active: any) => {
|
|
304
300
|
activeState = active;
|
|
305
301
|
}}
|
|
306
302
|
>
|
|
@@ -326,7 +322,7 @@ describe("TooltipAnchor", () => {
|
|
|
326
322
|
render(
|
|
327
323
|
<TooltipAnchor
|
|
328
324
|
anchorRef={jest.fn()}
|
|
329
|
-
onActiveChanged={(active) => {
|
|
325
|
+
onActiveChanged={(active: any) => {
|
|
330
326
|
activeState = active;
|
|
331
327
|
}}
|
|
332
328
|
>
|
|
@@ -362,15 +358,14 @@ describe("TooltipAnchor", () => {
|
|
|
362
358
|
const {default: ActiveTracker} = await import(
|
|
363
359
|
"../../util/active-tracker"
|
|
364
360
|
);
|
|
365
|
-
//
|
|
366
|
-
// $FlowFixMe[prop-missing]
|
|
361
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mock' does not exist on type 'typeof ActiveTracker'.
|
|
367
362
|
const mockTracker = ActiveTracker.mock.instances[0];
|
|
368
363
|
|
|
369
364
|
let activeState = false;
|
|
370
365
|
render(
|
|
371
366
|
<TooltipAnchor
|
|
372
367
|
anchorRef={jest.fn()}
|
|
373
|
-
onActiveChanged={(active) => {
|
|
368
|
+
onActiveChanged={(active: any) => {
|
|
374
369
|
activeState = active;
|
|
375
370
|
}}
|
|
376
371
|
>
|
|
@@ -408,7 +403,7 @@ describe("TooltipAnchor", () => {
|
|
|
408
403
|
render(
|
|
409
404
|
<TooltipAnchor
|
|
410
405
|
anchorRef={jest.fn()}
|
|
411
|
-
onActiveChanged={(active) => {
|
|
406
|
+
onActiveChanged={(active: any) => {
|
|
412
407
|
activeState = active;
|
|
413
408
|
}}
|
|
414
409
|
>
|
|
@@ -440,15 +435,14 @@ describe("TooltipAnchor", () => {
|
|
|
440
435
|
const {default: ActiveTracker} = await import(
|
|
441
436
|
"../../util/active-tracker"
|
|
442
437
|
);
|
|
443
|
-
//
|
|
444
|
-
// $FlowFixMe[prop-missing]
|
|
438
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mock' does not exist on type 'typeof ActiveTracker'.
|
|
445
439
|
const mockTracker = ActiveTracker.mock.instances[0];
|
|
446
440
|
// Arrange
|
|
447
441
|
let activeState = false;
|
|
448
442
|
render(
|
|
449
443
|
<TooltipAnchor
|
|
450
444
|
anchorRef={jest.fn()}
|
|
451
|
-
onActiveChanged={(active) => {
|
|
445
|
+
onActiveChanged={(active: any) => {
|
|
452
446
|
activeState = active;
|
|
453
447
|
}}
|
|
454
448
|
>
|
|
@@ -479,7 +473,7 @@ describe("TooltipAnchor", () => {
|
|
|
479
473
|
render(
|
|
480
474
|
<TooltipAnchor
|
|
481
475
|
anchorRef={jest.fn()}
|
|
482
|
-
onActiveChanged={(active) => {
|
|
476
|
+
onActiveChanged={(active: any) => {
|
|
483
477
|
activeState = active;
|
|
484
478
|
}}
|
|
485
479
|
>
|
|
@@ -517,8 +511,7 @@ describe("TooltipAnchor", () => {
|
|
|
517
511
|
);
|
|
518
512
|
// Let's tell the tooltip it isn't stealing and therefore it should
|
|
519
513
|
// be using a delay to show the tooltip.
|
|
520
|
-
//
|
|
521
|
-
// $FlowFixMe[prop-missing]
|
|
514
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mock' does not exist on type 'typeof ActiveTracker'.
|
|
522
515
|
const mockTracker = ActiveTracker.mock.instances[0];
|
|
523
516
|
mockTracker.steal.mockImplementationOnce(() => false);
|
|
524
517
|
|
|
@@ -527,7 +520,7 @@ describe("TooltipAnchor", () => {
|
|
|
527
520
|
render(
|
|
528
521
|
<TooltipAnchor
|
|
529
522
|
anchorRef={jest.fn()}
|
|
530
|
-
onActiveChanged={(active) => {
|
|
523
|
+
onActiveChanged={(active: any) => {
|
|
531
524
|
activeState = active;
|
|
532
525
|
}}
|
|
533
526
|
>
|
|
@@ -556,8 +549,7 @@ describe("TooltipAnchor", () => {
|
|
|
556
549
|
);
|
|
557
550
|
// Let's tell the tooltip it is stealing and therefore it should
|
|
558
551
|
// not be using a delay to show the tooltip.
|
|
559
|
-
//
|
|
560
|
-
// $FlowFixMe[prop-missing]
|
|
552
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mock' does not exist on type 'typeof ActiveTracker'.
|
|
561
553
|
const mockTracker = ActiveTracker.mock.instances[0];
|
|
562
554
|
mockTracker.steal.mockImplementationOnce(() => true);
|
|
563
555
|
|
|
@@ -566,7 +558,7 @@ describe("TooltipAnchor", () => {
|
|
|
566
558
|
render(
|
|
567
559
|
<TooltipAnchor
|
|
568
560
|
anchorRef={jest.fn()}
|
|
569
|
-
onActiveChanged={(active) => {
|
|
561
|
+
onActiveChanged={(active: any) => {
|
|
570
562
|
activeState = active;
|
|
571
563
|
}}
|
|
572
564
|
>
|
|
@@ -591,7 +583,7 @@ describe("TooltipAnchor", () => {
|
|
|
591
583
|
render(
|
|
592
584
|
<TooltipAnchor
|
|
593
585
|
anchorRef={jest.fn()}
|
|
594
|
-
onActiveChanged={(active) => {
|
|
586
|
+
onActiveChanged={(active: any) => {
|
|
595
587
|
activeState = active;
|
|
596
588
|
}}
|
|
597
589
|
>
|
|
@@ -626,15 +618,14 @@ describe("TooltipAnchor", () => {
|
|
|
626
618
|
const {default: ActiveTracker} = await import(
|
|
627
619
|
"../../util/active-tracker"
|
|
628
620
|
);
|
|
629
|
-
//
|
|
630
|
-
// $FlowFixMe[prop-missing]
|
|
621
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mock' does not exist on type 'typeof ActiveTracker'.
|
|
631
622
|
const mockTracker = ActiveTracker.mock.instances[0];
|
|
632
623
|
let activeState = false;
|
|
633
624
|
|
|
634
625
|
render(
|
|
635
626
|
<TooltipAnchor
|
|
636
627
|
anchorRef={jest.fn()}
|
|
637
|
-
onActiveChanged={(active) => {
|
|
628
|
+
onActiveChanged={(active: any) => {
|
|
638
629
|
activeState = active;
|
|
639
630
|
}}
|
|
640
631
|
>
|
|
@@ -671,7 +662,7 @@ describe("TooltipAnchor", () => {
|
|
|
671
662
|
render(
|
|
672
663
|
<TooltipAnchor
|
|
673
664
|
anchorRef={jest.fn()}
|
|
674
|
-
onActiveChanged={(active) => {
|
|
665
|
+
onActiveChanged={(active: any) => {
|
|
675
666
|
activeState = active;
|
|
676
667
|
}}
|
|
677
668
|
>
|
|
@@ -701,15 +692,14 @@ describe("TooltipAnchor", () => {
|
|
|
701
692
|
const {default: ActiveTracker} = await import(
|
|
702
693
|
"../../util/active-tracker"
|
|
703
694
|
);
|
|
704
|
-
//
|
|
705
|
-
// $FlowFixMe[prop-missing]
|
|
695
|
+
// @ts-expect-error [FEI-5019] - TS2339 - Property 'mock' does not exist on type 'typeof ActiveTracker'.
|
|
706
696
|
const mockTracker = ActiveTracker.mock.instances[0];
|
|
707
697
|
// Arrange
|
|
708
698
|
let activeState = false;
|
|
709
699
|
render(
|
|
710
700
|
<TooltipAnchor
|
|
711
701
|
anchorRef={jest.fn()}
|
|
712
|
-
onActiveChanged={(active) => {
|
|
702
|
+
onActiveChanged={(active: any) => {
|
|
713
703
|
activeState = active;
|
|
714
704
|
}}
|
|
715
705
|
>
|
|
@@ -738,7 +728,7 @@ describe("TooltipAnchor", () => {
|
|
|
738
728
|
render(
|
|
739
729
|
<TooltipAnchor
|
|
740
730
|
anchorRef={jest.fn()}
|
|
741
|
-
onActiveChanged={(active) => {
|
|
731
|
+
onActiveChanged={(active: any) => {
|
|
742
732
|
activeState = active;
|
|
743
733
|
}}
|
|
744
734
|
>
|
|
@@ -883,7 +873,7 @@ describe("TooltipAnchor", () => {
|
|
|
883
873
|
render(
|
|
884
874
|
<TooltipAnchor
|
|
885
875
|
anchorRef={jest.fn()}
|
|
886
|
-
onActiveChanged={(active) => {
|
|
876
|
+
onActiveChanged={(active: any) => {
|
|
887
877
|
activeState = active;
|
|
888
878
|
}}
|
|
889
879
|
>
|
|
@@ -927,9 +917,9 @@ describe("TooltipAnchor", () => {
|
|
|
927
917
|
TooltipAppearanceDelay,
|
|
928
918
|
);
|
|
929
919
|
jest.runOnlyPendingTimers();
|
|
930
|
-
const event: KeyboardEvent =
|
|
920
|
+
const event: KeyboardEvent = document.createEvent("Event") as any;
|
|
931
921
|
const spyOnStopPropagation = jest.spyOn(event, "stopPropagation");
|
|
932
|
-
//
|
|
922
|
+
// @ts-expect-error [FEI-5019] - TS2540 - Cannot assign to 'key' because it is a read-only property.
|
|
933
923
|
event.key = "Escape";
|
|
934
924
|
event.initEvent("keyup", true, true);
|
|
935
925
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import {render, screen} from "@testing-library/react";
|
|
4
3
|
|
|
5
4
|
import {View} from "@khanacademy/wonder-blocks-core";
|
|
6
5
|
|
|
7
6
|
import TooltipBubble from "../tooltip-bubble";
|
|
8
|
-
import
|
|
7
|
+
import TooltipContent from "../tooltip-content";
|
|
9
8
|
|
|
10
9
|
describe("TooltipBubble", () => {
|
|
11
10
|
// A little helper method to make the actual test more readable.
|
|
@@ -28,15 +27,16 @@ describe("TooltipBubble", () => {
|
|
|
28
27
|
|
|
29
28
|
// Do some casting to pretend this is `TooltipContent`. That way we are
|
|
30
29
|
// isolating behaviors a bit more.
|
|
31
|
-
const fakeContent = (
|
|
30
|
+
const fakeContent = (
|
|
32
31
|
<View id="content">Some content</View>
|
|
33
|
-
)
|
|
32
|
+
) as React.ReactElement<React.ComponentProps<typeof TooltipContent>>;
|
|
34
33
|
|
|
35
34
|
// Act
|
|
36
35
|
render(
|
|
37
36
|
<View>
|
|
38
37
|
<TooltipBubble
|
|
39
38
|
id="bubble"
|
|
39
|
+
// @ts-expect-error [FEI-5019] - TS2769 - No overload matches this call.
|
|
40
40
|
placement={props.placement}
|
|
41
41
|
tailOffset={props.tailOffset}
|
|
42
42
|
updateBubbleRef={jest.fn()}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import * as React from "react";
|
|
3
2
|
import * as ReactDOM from "react-dom";
|
|
4
3
|
import {render} from "@testing-library/react";
|
|
5
4
|
|
|
6
5
|
import {View} from "@khanacademy/wonder-blocks-core";
|
|
7
6
|
|
|
8
|
-
import
|
|
7
|
+
import TooltipBubble from "../tooltip-bubble";
|
|
9
8
|
import TooltipPopper from "../tooltip-popper";
|
|
10
9
|
|
|
11
|
-
type State = {
|
|
10
|
+
type State = {
|
|
11
|
+
ref: HTMLElement | null | undefined;
|
|
12
|
+
};
|
|
12
13
|
/**
|
|
13
14
|
* A little wrapper for the TooltipPopper so that we can provide an anchor
|
|
14
15
|
* element reference and test that the children get rendered.
|
|
@@ -18,25 +19,27 @@ class TestHarness extends React.Component<any, State> {
|
|
|
18
19
|
ref: null,
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
updateRef(ref) {
|
|
22
|
+
updateRef(ref: any) {
|
|
22
23
|
const actualRef = ref && ReactDOM.findDOMNode(ref);
|
|
23
24
|
if (actualRef && this.state.ref !== actualRef) {
|
|
24
|
-
this.setState({ref:
|
|
25
|
+
this.setState({ref: actualRef as HTMLElement | null | undefined});
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
render(): React.
|
|
29
|
-
const fakeBubble = (
|
|
30
|
-
<View ref={(ref) => this.props.resultRef(ref)}>
|
|
31
|
-
|
|
29
|
+
render(): React.ReactElement {
|
|
30
|
+
const fakeBubble = (
|
|
31
|
+
<View ref={(ref: any) => this.props.resultRef(ref)}>
|
|
32
|
+
Fake bubble
|
|
33
|
+
</View>
|
|
34
|
+
) as React.ReactElement<React.ComponentProps<typeof TooltipBubble>>;
|
|
32
35
|
return (
|
|
33
36
|
<View>
|
|
34
|
-
<View ref={(ref) => this.updateRef(ref)}>Anchor</View>
|
|
37
|
+
<View ref={(ref: any) => this.updateRef(ref)}>Anchor</View>
|
|
35
38
|
<TooltipPopper
|
|
36
39
|
placement={this.props.placement}
|
|
37
40
|
anchorElement={this.state.ref}
|
|
38
41
|
>
|
|
39
|
-
{(props) => fakeBubble}
|
|
42
|
+
{(props: any) => fakeBubble}
|
|
40
43
|
</TooltipPopper>
|
|
41
44
|
</View>
|
|
42
45
|
);
|
|
@@ -51,7 +54,7 @@ describe("TooltipPopper", () => {
|
|
|
51
54
|
// and use other things to test the overall placement things.
|
|
52
55
|
test("ensure component renders", async () => {
|
|
53
56
|
// Arrange
|
|
54
|
-
const ref = await new Promise((resolve, reject) => {
|
|
57
|
+
const ref = await new Promise((resolve: any, reject: any) => {
|
|
55
58
|
const nodes = (
|
|
56
59
|
<View>
|
|
57
60
|
<TestHarness placement="bottom" resultRef={resolve} />
|