@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.
- package/CHANGELOG.md +39 -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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,44 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-tooltip
|
|
2
2
|
|
|
3
|
+
## 1.4.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [779b031d]
|
|
8
|
+
- @khanacademy/wonder-blocks-core@4.9.0
|
|
9
|
+
- @khanacademy/wonder-blocks-layout@1.4.18
|
|
10
|
+
- @khanacademy/wonder-blocks-modal@3.0.9
|
|
11
|
+
- @khanacademy/wonder-blocks-typography@1.1.40
|
|
12
|
+
|
|
13
|
+
## 1.4.7
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- d816af08: Update build and test configs use TypeScript
|
|
18
|
+
- 3891f544: Update babel config to include plugins that Storybook needed
|
|
19
|
+
- 0d28bb1c: Configured TypeScript
|
|
20
|
+
- 3d05f764: Fix HOCs and other type errors
|
|
21
|
+
- c2ec4902: Update eslint configuration, fix lint
|
|
22
|
+
- 2983c05b: Include 'types' field in package.json
|
|
23
|
+
- 77ff6a66: Generate Flow types from TypeScript types
|
|
24
|
+
- 873f4a14: Tweak 'Offset' type to use React.CSSProperties
|
|
25
|
+
- ec8d4b7f: Fix miscellaneous TypeScript errors
|
|
26
|
+
- Updated dependencies [d816af08]
|
|
27
|
+
- Updated dependencies [3891f544]
|
|
28
|
+
- Updated dependencies [0d28bb1c]
|
|
29
|
+
- Updated dependencies [873f4a14]
|
|
30
|
+
- Updated dependencies [3d05f764]
|
|
31
|
+
- Updated dependencies [c2ec4902]
|
|
32
|
+
- Updated dependencies [2983c05b]
|
|
33
|
+
- Updated dependencies [77ff6a66]
|
|
34
|
+
- Updated dependencies [ec8d4b7f]
|
|
35
|
+
- @khanacademy/wonder-blocks-color@1.2.2
|
|
36
|
+
- @khanacademy/wonder-blocks-core@4.8.0
|
|
37
|
+
- @khanacademy/wonder-blocks-layout@1.4.17
|
|
38
|
+
- @khanacademy/wonder-blocks-modal@3.0.8
|
|
39
|
+
- @khanacademy/wonder-blocks-spacing@3.0.6
|
|
40
|
+
- @khanacademy/wonder-blocks-typography@1.1.39
|
|
41
|
+
|
|
3
42
|
## 1.4.6
|
|
4
43
|
|
|
5
44
|
### Patch Changes
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This component turns the given content into an accessible anchor for
|
|
3
|
+
* positioning and displaying tooltips.
|
|
4
|
+
*/
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import type { IIdentifierFactory } from "@khanacademy/wonder-blocks-core";
|
|
7
|
+
import type { IActiveTrackerSubscriber } from "../util/active-tracker";
|
|
8
|
+
type Props = {
|
|
9
|
+
/**
|
|
10
|
+
* The content for anchoring the tooltip.
|
|
11
|
+
* This element will be used to position the tooltip.
|
|
12
|
+
* If a string is passed as children we wrap it in a Text element.
|
|
13
|
+
* We allow children to be a string so that we can add tooltips to
|
|
14
|
+
* words within a large block of text easily.
|
|
15
|
+
*/
|
|
16
|
+
children: React.ReactElement<any> | string;
|
|
17
|
+
/**
|
|
18
|
+
* Callback to be invoked when the anchored content is mounted.
|
|
19
|
+
* This provides a reference to the anchored content, which can then be
|
|
20
|
+
* used for calculating tooltip bubble positioning.
|
|
21
|
+
*/
|
|
22
|
+
anchorRef: (arg1?: Element | null | undefined) => unknown;
|
|
23
|
+
/**
|
|
24
|
+
* When true, if a tabindex attribute is not already present on the element
|
|
25
|
+
* wrapped by the anchor, the element will be given tabindex=0 to make it
|
|
26
|
+
* keyboard focusable; otherwise, does not attempt to change the ability to
|
|
27
|
+
* focus the anchor element.
|
|
28
|
+
*
|
|
29
|
+
* Defaults to true.
|
|
30
|
+
*
|
|
31
|
+
* One might set this to false in circumstances where the wrapped component
|
|
32
|
+
* already can receive focus or contains an element that can.
|
|
33
|
+
* Use good judgement when overriding this value, the tooltip content should
|
|
34
|
+
* be accessible via keyboard in all circumstances where the tooltip would
|
|
35
|
+
* appear using the mouse, so verify those use-cases.
|
|
36
|
+
*/
|
|
37
|
+
forceAnchorFocusivity?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Callback to pass active state back to Tooltip.
|
|
40
|
+
*
|
|
41
|
+
* `active` will be true whenever the anchor is hovered or focused and false
|
|
42
|
+
* otherwise.
|
|
43
|
+
*/
|
|
44
|
+
onActiveChanged: (active: boolean) => unknown;
|
|
45
|
+
/**
|
|
46
|
+
* Optional unique id factory.
|
|
47
|
+
*/
|
|
48
|
+
ids?: IIdentifierFactory;
|
|
49
|
+
};
|
|
50
|
+
type DefaultProps = {
|
|
51
|
+
forceAnchorFocusivity: Props["forceAnchorFocusivity"];
|
|
52
|
+
};
|
|
53
|
+
type State = {
|
|
54
|
+
/** Is the anchor active or not? */
|
|
55
|
+
active: boolean;
|
|
56
|
+
};
|
|
57
|
+
export default class TooltipAnchor extends React.Component<Props, State> implements IActiveTrackerSubscriber {
|
|
58
|
+
_weSetFocusivity: boolean | null | undefined;
|
|
59
|
+
_anchorNode: Element | null | undefined;
|
|
60
|
+
_focused: boolean;
|
|
61
|
+
_hovered: boolean;
|
|
62
|
+
_stolenFromUs: boolean;
|
|
63
|
+
_unsubscribeFromTracker: () => void | null | undefined;
|
|
64
|
+
_timeoutID: number | null | undefined;
|
|
65
|
+
static defaultProps: DefaultProps;
|
|
66
|
+
constructor(props: Props);
|
|
67
|
+
componentDidMount(): void;
|
|
68
|
+
componentDidUpdate(prevProps: Props): void;
|
|
69
|
+
componentWillUnmount(): void;
|
|
70
|
+
static ariaContentId: string;
|
|
71
|
+
activeStateStolen: () => void;
|
|
72
|
+
_updateFocusivity(): void;
|
|
73
|
+
_updateActiveState(hovered: boolean, focused: boolean): void;
|
|
74
|
+
_clearPendingAction(): void;
|
|
75
|
+
_setActiveState(active: boolean, instant?: boolean): void;
|
|
76
|
+
_handleFocusIn: () => void;
|
|
77
|
+
_handleFocusOut: () => void;
|
|
78
|
+
_handleMouseEnter: () => void;
|
|
79
|
+
_handleMouseLeave: () => void;
|
|
80
|
+
_handleKeyUp: (e: KeyboardEvent) => void;
|
|
81
|
+
_renderAnchorableChildren(): React.ReactElement<any>;
|
|
82
|
+
_renderAccessibleChildren(ids: IIdentifierFactory): React.ReactNode;
|
|
83
|
+
render(): React.ReactElement;
|
|
84
|
+
}
|
|
85
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for tooltip-anchor
|
|
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 { IIdentifierFactory } from "@khanacademy/wonder-blocks-core";
|
|
10
|
+
import type { IActiveTrackerSubscriber } from "../util/active-tracker";
|
|
11
|
+
declare type Props = {
|
|
12
|
+
/**
|
|
13
|
+
* The content for anchoring the tooltip.
|
|
14
|
+
* This element will be used to position the tooltip.
|
|
15
|
+
* If a string is passed as children we wrap it in a Text element.
|
|
16
|
+
* We allow children to be a string so that we can add tooltips to
|
|
17
|
+
* words within a large block of text easily.
|
|
18
|
+
*/
|
|
19
|
+
children: React.Element<any> | string,
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Callback to be invoked when the anchored content is mounted.
|
|
23
|
+
* This provides a reference to the anchored content, which can then be
|
|
24
|
+
* used for calculating tooltip bubble positioning.
|
|
25
|
+
*/
|
|
26
|
+
anchorRef: (arg1?: Element | null | void) => mixed,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* When true, if a tabindex attribute is not already present on the element
|
|
30
|
+
* wrapped by the anchor, the element will be given tabindex=0 to make it
|
|
31
|
+
* keyboard focusable; otherwise, does not attempt to change the ability to
|
|
32
|
+
* focus the anchor element.
|
|
33
|
+
*
|
|
34
|
+
* Defaults to true.
|
|
35
|
+
*
|
|
36
|
+
* One might set this to false in circumstances where the wrapped component
|
|
37
|
+
* already can receive focus or contains an element that can.
|
|
38
|
+
* Use good judgement when overriding this value, the tooltip content should
|
|
39
|
+
* be accessible via keyboard in all circumstances where the tooltip would
|
|
40
|
+
* appear using the mouse, so verify those use-cases.
|
|
41
|
+
*/
|
|
42
|
+
forceAnchorFocusivity?: boolean,
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Callback to pass active state back to Tooltip.
|
|
46
|
+
*
|
|
47
|
+
* `active` will be true whenever the anchor is hovered or focused and false
|
|
48
|
+
* otherwise.
|
|
49
|
+
*/
|
|
50
|
+
onActiveChanged: (active: boolean) => mixed,
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Optional unique id factory.
|
|
54
|
+
*/
|
|
55
|
+
ids?: IIdentifierFactory,
|
|
56
|
+
...
|
|
57
|
+
};
|
|
58
|
+
declare type DefaultProps = {
|
|
59
|
+
forceAnchorFocusivity: $PropertyType<Props, "forceAnchorFocusivity">,
|
|
60
|
+
...
|
|
61
|
+
};
|
|
62
|
+
declare type State = {
|
|
63
|
+
/**
|
|
64
|
+
* Is the anchor active or not?
|
|
65
|
+
*/
|
|
66
|
+
active: boolean,
|
|
67
|
+
...
|
|
68
|
+
};
|
|
69
|
+
declare export default class TooltipAnchor
|
|
70
|
+
extends React.Component<Props, State>, IActiveTrackerSubscriber
|
|
71
|
+
{
|
|
72
|
+
_weSetFocusivity: boolean | null | void;
|
|
73
|
+
_anchorNode: Element | null | void;
|
|
74
|
+
_focused: boolean;
|
|
75
|
+
_hovered: boolean;
|
|
76
|
+
_stolenFromUs: boolean;
|
|
77
|
+
_unsubscribeFromTracker: () => void | null | void;
|
|
78
|
+
_timeoutID: number | null | void;
|
|
79
|
+
static defaultProps: DefaultProps;
|
|
80
|
+
constructor(props: Props): this;
|
|
81
|
+
componentDidMount(): void;
|
|
82
|
+
componentDidUpdate(prevProps: Props): void;
|
|
83
|
+
componentWillUnmount(): void;
|
|
84
|
+
static ariaContentId: string;
|
|
85
|
+
activeStateStolen: () => void;
|
|
86
|
+
_updateFocusivity(): void;
|
|
87
|
+
_updateActiveState(hovered: boolean, focused: boolean): void;
|
|
88
|
+
_clearPendingAction(): void;
|
|
89
|
+
_setActiveState(active: boolean, instant?: boolean): void;
|
|
90
|
+
_handleFocusIn: () => void;
|
|
91
|
+
_handleFocusOut: () => void;
|
|
92
|
+
_handleMouseEnter: () => void;
|
|
93
|
+
_handleMouseLeave: () => void;
|
|
94
|
+
_handleKeyUp: (e: KeyboardEvent) => void;
|
|
95
|
+
_renderAnchorableChildren(): React.Element<any>;
|
|
96
|
+
_renderAccessibleChildren(ids: IIdentifierFactory): React.Node;
|
|
97
|
+
render(): React.Element<>;
|
|
98
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
3
|
+
import TooltipContent from "./tooltip-content";
|
|
4
|
+
import type { getRefFn, Offset, Placement } from "../util/types";
|
|
5
|
+
export type PopperElementProps = {
|
|
6
|
+
/** The placement of the bubble with respect to the anchor. */
|
|
7
|
+
placement: Placement;
|
|
8
|
+
/** Whether the bubble is out of bounds or not. */
|
|
9
|
+
isReferenceHidden?: boolean | null | undefined;
|
|
10
|
+
/** A callback for updating the ref of the bubble itself. */
|
|
11
|
+
updateBubbleRef?: getRefFn;
|
|
12
|
+
/** A callback for updating the ref of the bubble's tail. */
|
|
13
|
+
updateTailRef?: getRefFn;
|
|
14
|
+
/** Where the tail is to be rendered. */
|
|
15
|
+
tailOffset?: Offset;
|
|
16
|
+
/** Additional styles to be applied by the bubble. */
|
|
17
|
+
style?: StyleType;
|
|
18
|
+
};
|
|
19
|
+
export type Props = {
|
|
20
|
+
/** The unique identifier for this component. */
|
|
21
|
+
id: string;
|
|
22
|
+
/** The `TooltipContent` element that will be rendered in the bubble. */
|
|
23
|
+
children: React.ReactElement<React.ComponentProps<typeof TooltipContent>>;
|
|
24
|
+
onActiveChanged: (active: boolean) => unknown;
|
|
25
|
+
} & PopperElementProps;
|
|
26
|
+
type State = {
|
|
27
|
+
active: boolean;
|
|
28
|
+
};
|
|
29
|
+
export default class TooltipBubble extends React.Component<Props, State> {
|
|
30
|
+
state: State;
|
|
31
|
+
_setActiveState(active: boolean): void;
|
|
32
|
+
handleMouseEnter: () => void;
|
|
33
|
+
handleMouseLeave: () => void;
|
|
34
|
+
render(): React.ReactElement;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for tooltip-bubble
|
|
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 { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
10
|
+
import TooltipContent from "./tooltip-content";
|
|
11
|
+
import type { getRefFn, Offset, Placement } from "../util/types";
|
|
12
|
+
export type PopperElementProps = {
|
|
13
|
+
/**
|
|
14
|
+
* The placement of the bubble with respect to the anchor.
|
|
15
|
+
*/
|
|
16
|
+
placement: Placement,
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Whether the bubble is out of bounds or not.
|
|
20
|
+
*/
|
|
21
|
+
isReferenceHidden?: boolean | null | void,
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A callback for updating the ref of the bubble itself.
|
|
25
|
+
*/
|
|
26
|
+
updateBubbleRef?: getRefFn,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A callback for updating the ref of the bubble's tail.
|
|
30
|
+
*/
|
|
31
|
+
updateTailRef?: getRefFn,
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Where the tail is to be rendered.
|
|
35
|
+
*/
|
|
36
|
+
tailOffset?: Offset,
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Additional styles to be applied by the bubble.
|
|
40
|
+
*/
|
|
41
|
+
style?: StyleType,
|
|
42
|
+
...
|
|
43
|
+
};
|
|
44
|
+
export type Props = {
|
|
45
|
+
...{
|
|
46
|
+
/**
|
|
47
|
+
* The unique identifier for this component.
|
|
48
|
+
*/
|
|
49
|
+
id: string,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The `TooltipContent` element that will be rendered in the bubble.
|
|
53
|
+
*/
|
|
54
|
+
children: React.Element<React.ComponentProps<typeof TooltipContent>>,
|
|
55
|
+
onActiveChanged: (active: boolean) => mixed,
|
|
56
|
+
...
|
|
57
|
+
},
|
|
58
|
+
...PopperElementProps,
|
|
59
|
+
};
|
|
60
|
+
declare type State = {
|
|
61
|
+
active: boolean,
|
|
62
|
+
...
|
|
63
|
+
};
|
|
64
|
+
declare export default class TooltipBubble
|
|
65
|
+
extends React.Component<Props, State>
|
|
66
|
+
{
|
|
67
|
+
state: State;
|
|
68
|
+
_setActiveState(active: boolean): void;
|
|
69
|
+
handleMouseEnter: () => void;
|
|
70
|
+
handleMouseLeave: () => void;
|
|
71
|
+
render(): React.Element<>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { Typography } from "@khanacademy/wonder-blocks-typography";
|
|
3
|
+
type Props = {
|
|
4
|
+
/**
|
|
5
|
+
* The title for the tooltip content.
|
|
6
|
+
* Optional.
|
|
7
|
+
*/
|
|
8
|
+
title?: string | React.ReactElement<React.ComponentProps<Typography>>;
|
|
9
|
+
/**
|
|
10
|
+
* The main content for a tooltip.
|
|
11
|
+
*/
|
|
12
|
+
children: string | React.ReactElement<React.ComponentProps<Typography>> | Array<React.ReactElement<React.ComponentProps<Typography>>>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* This component is used to provide the content that is to be rendered in the
|
|
16
|
+
* tooltip bubble.
|
|
17
|
+
*
|
|
18
|
+
* ### Usage
|
|
19
|
+
*
|
|
20
|
+
* ```jsx
|
|
21
|
+
* import {TooltipContent} from "@khanacademy/wonder-blocks-tooltip";
|
|
22
|
+
*
|
|
23
|
+
* <TooltipContent title="Title text!">
|
|
24
|
+
* Some content in my tooltip.
|
|
25
|
+
* </TooltipContent>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export default class TooltipContent extends React.Component<Props> {
|
|
29
|
+
_renderTitle(): React.ReactNode;
|
|
30
|
+
_renderChildren(): React.ReactNode;
|
|
31
|
+
render(): React.ReactElement;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for tooltip-content
|
|
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 { Typography } from "@khanacademy/wonder-blocks-typography";
|
|
10
|
+
declare type Props = {
|
|
11
|
+
/**
|
|
12
|
+
* The title for the tooltip content.
|
|
13
|
+
* Optional.
|
|
14
|
+
*/
|
|
15
|
+
title?: string | React.Element<React.ComponentProps<Typography>>,
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The main content for a tooltip.
|
|
19
|
+
*/
|
|
20
|
+
children:
|
|
21
|
+
| string
|
|
22
|
+
| React.Element<React.ComponentProps<Typography>>
|
|
23
|
+
| Array<React.Element<React.ComponentProps<Typography>>>,
|
|
24
|
+
...
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* This component is used to provide the content that is to be rendered in the
|
|
28
|
+
* tooltip bubble.
|
|
29
|
+
*
|
|
30
|
+
* ### Usage
|
|
31
|
+
*
|
|
32
|
+
* ```jsx
|
|
33
|
+
* import {TooltipContent} from "@khanacademy/wonder-blocks-tooltip";
|
|
34
|
+
*
|
|
35
|
+
* <TooltipContent title="Title text!">
|
|
36
|
+
* Some content in my tooltip.
|
|
37
|
+
* </TooltipContent>
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare export default class TooltipContent extends React.Component<Props> {
|
|
41
|
+
_renderTitle(): React.Node;
|
|
42
|
+
_renderChildren(): React.Node;
|
|
43
|
+
render(): React.Element<>;
|
|
44
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This component is a light wrapper for react-popper, allowing us to position
|
|
3
|
+
* and control the tooltip bubble location and visibility as we need.
|
|
4
|
+
*/
|
|
5
|
+
import * as React from "react";
|
|
6
|
+
import type { PopperChildrenProps } from "react-popper";
|
|
7
|
+
import RefTracker from "../util/ref-tracker";
|
|
8
|
+
import type { Placement } from "../util/types";
|
|
9
|
+
import type { PopperElementProps } from "./tooltip-bubble";
|
|
10
|
+
type Props = {
|
|
11
|
+
/**
|
|
12
|
+
* This uses the children-as-a-function approach, mirroring react-popper's
|
|
13
|
+
* implementation.
|
|
14
|
+
*
|
|
15
|
+
* TODO(WB-624): figure out to only allow TooltipBubble and PopoverDialog
|
|
16
|
+
*/
|
|
17
|
+
children: (arg1: PopperElementProps) => React.ReactElement<any>;
|
|
18
|
+
/**
|
|
19
|
+
* The element that anchors the tooltip bubble.
|
|
20
|
+
* This is used to position the bubble.
|
|
21
|
+
*/
|
|
22
|
+
anchorElement: HTMLElement | null | undefined;
|
|
23
|
+
/** Where should the bubble try to go with respect to its anchor. */
|
|
24
|
+
placement: Placement;
|
|
25
|
+
};
|
|
26
|
+
export default class TooltipPopper extends React.Component<Props> {
|
|
27
|
+
_bubbleRefTracker: RefTracker;
|
|
28
|
+
_tailRefTracker: RefTracker;
|
|
29
|
+
_renderPositionedContent(popperProps: PopperChildrenProps): React.ReactNode;
|
|
30
|
+
render(): React.ReactElement;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for tooltip-popper
|
|
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
|
+
import RefTracker from "../util/ref-tracker";
|
|
11
|
+
import type { Placement } from "../util/types";
|
|
12
|
+
import type { PopperElementProps } from "./tooltip-bubble";
|
|
13
|
+
declare type Props = {
|
|
14
|
+
/**
|
|
15
|
+
* This uses the children-as-a-function approach, mirroring react-popper's
|
|
16
|
+
* implementation.
|
|
17
|
+
*
|
|
18
|
+
* TODO(WB-624): figure out to only allow TooltipBubble and PopoverDialog
|
|
19
|
+
*/
|
|
20
|
+
children: (arg1: PopperElementProps) => React.Element<any>,
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The element that anchors the tooltip bubble.
|
|
24
|
+
* This is used to position the bubble.
|
|
25
|
+
*/
|
|
26
|
+
anchorElement: HTMLElement | null | void,
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Where should the bubble try to go with respect to its anchor.
|
|
30
|
+
*/
|
|
31
|
+
placement: Placement,
|
|
32
|
+
...
|
|
33
|
+
};
|
|
34
|
+
declare export default class TooltipPopper extends React.Component<Props> {
|
|
35
|
+
_bubbleRefTracker: RefTracker;
|
|
36
|
+
_tailRefTracker: RefTracker;
|
|
37
|
+
_renderPositionedContent(popperProps: PopperChildrenProps): React.Node;
|
|
38
|
+
render(): React.Element<>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import Colors from "@khanacademy/wonder-blocks-color";
|
|
3
|
+
import type { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
4
|
+
import type { getRefFn, Placement, Offset } from "../util/types";
|
|
5
|
+
export type Props = {
|
|
6
|
+
/**
|
|
7
|
+
* Whether we should use the default white background color or switch to a
|
|
8
|
+
* different bg color.
|
|
9
|
+
*
|
|
10
|
+
* NOTE: Added to support custom popovers
|
|
11
|
+
* @ignore
|
|
12
|
+
*/
|
|
13
|
+
color: keyof typeof Colors;
|
|
14
|
+
/** The offset of the tail indicating where it should be positioned. */
|
|
15
|
+
offset?: Offset;
|
|
16
|
+
/** The placement of the tail with respect to the tooltip anchor. */
|
|
17
|
+
placement: Placement;
|
|
18
|
+
/** A callback to update the ref of the tail element. */
|
|
19
|
+
updateRef?: getRefFn;
|
|
20
|
+
};
|
|
21
|
+
type DefaultProps = {
|
|
22
|
+
color: Props["color"];
|
|
23
|
+
};
|
|
24
|
+
type Dimensions = {
|
|
25
|
+
trimlinePoints: [string, string];
|
|
26
|
+
points: [string, string, string];
|
|
27
|
+
height: number;
|
|
28
|
+
width: number;
|
|
29
|
+
};
|
|
30
|
+
type FilterPosition = {
|
|
31
|
+
y: string;
|
|
32
|
+
x: string;
|
|
33
|
+
offsetShadowX: number;
|
|
34
|
+
};
|
|
35
|
+
export default class TooltipTail extends React.Component<Props> {
|
|
36
|
+
static defaultProps: DefaultProps;
|
|
37
|
+
_calculateDimensionsFromPlacement(): Dimensions;
|
|
38
|
+
_getFilterPositioning(): FilterPosition | null | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Create an SVG filter that applies a blur to an element.
|
|
41
|
+
* We'll apply it to a dark shape outlining the tooltip, which
|
|
42
|
+
* will produce the overall effect of a drop-shadow.
|
|
43
|
+
*
|
|
44
|
+
* Also, scope its ID by side, so that tooltips with other
|
|
45
|
+
* "side" values don't end up using the wrong filter from
|
|
46
|
+
* elsewhere in the document. (The `height` value depends on
|
|
47
|
+
* which way the arrow is turned!)
|
|
48
|
+
*/
|
|
49
|
+
_maybeRenderDropshadow(points: [string, string, string]): React.ReactNode;
|
|
50
|
+
_getFullTailWidth(): number;
|
|
51
|
+
_getFullTailHeight(): number;
|
|
52
|
+
_getContainerStyle(): StyleType;
|
|
53
|
+
_getArrowStyle(): React.CSSProperties;
|
|
54
|
+
_renderArrow(): React.ReactNode;
|
|
55
|
+
render(): React.ReactElement;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for tooltip-tail
|
|
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 Colors from "@khanacademy/wonder-blocks-color";
|
|
10
|
+
import type { StyleType } from "@khanacademy/wonder-blocks-core";
|
|
11
|
+
import type { getRefFn, Placement, Offset } from "../util/types";
|
|
12
|
+
export type Props = {
|
|
13
|
+
/**
|
|
14
|
+
* Whether we should use the default white background color or switch to a
|
|
15
|
+
* different bg color.
|
|
16
|
+
*
|
|
17
|
+
* NOTE: Added to support custom popovers
|
|
18
|
+
* @ignore
|
|
19
|
+
*/
|
|
20
|
+
color: $Keys<typeof Colors>,
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The offset of the tail indicating where it should be positioned.
|
|
24
|
+
*/
|
|
25
|
+
offset?: Offset,
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The placement of the tail with respect to the tooltip anchor.
|
|
29
|
+
*/
|
|
30
|
+
placement: Placement,
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A callback to update the ref of the tail element.
|
|
34
|
+
*/
|
|
35
|
+
updateRef?: getRefFn,
|
|
36
|
+
...
|
|
37
|
+
};
|
|
38
|
+
declare type DefaultProps = {
|
|
39
|
+
color: $PropertyType<Props, "color">,
|
|
40
|
+
...
|
|
41
|
+
};
|
|
42
|
+
declare type Dimensions = {
|
|
43
|
+
trimlinePoints: [string, string],
|
|
44
|
+
points: [string, string, string],
|
|
45
|
+
height: number,
|
|
46
|
+
width: number,
|
|
47
|
+
...
|
|
48
|
+
};
|
|
49
|
+
declare type FilterPosition = {
|
|
50
|
+
y: string,
|
|
51
|
+
x: string,
|
|
52
|
+
offsetShadowX: number,
|
|
53
|
+
...
|
|
54
|
+
};
|
|
55
|
+
declare export default class TooltipTail extends React.Component<Props> {
|
|
56
|
+
static defaultProps: DefaultProps;
|
|
57
|
+
_calculateDimensionsFromPlacement(): Dimensions;
|
|
58
|
+
_getFilterPositioning(): FilterPosition | null | void;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Create an SVG filter that applies a blur to an element.
|
|
62
|
+
* We'll apply it to a dark shape outlining the tooltip, which
|
|
63
|
+
* will produce the overall effect of a drop-shadow.
|
|
64
|
+
*
|
|
65
|
+
* Also, scope its ID by side, so that tooltips with other
|
|
66
|
+
* "side" values don't end up using the wrong filter from
|
|
67
|
+
* elsewhere in the document. (The `height` value depends on
|
|
68
|
+
* which way the arrow is turned!)
|
|
69
|
+
*/
|
|
70
|
+
_maybeRenderDropshadow(points: [string, string, string]): React.Node;
|
|
71
|
+
_getFullTailWidth(): number;
|
|
72
|
+
_getFullTailHeight(): number;
|
|
73
|
+
_getContainerStyle(): StyleType;
|
|
74
|
+
_getArrowStyle(): React.CSSProperties;
|
|
75
|
+
_renderArrow(): React.Node;
|
|
76
|
+
render(): React.Element<>;
|
|
77
|
+
}
|