@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.
Files changed (53) hide show
  1. package/CHANGELOG.md +29 -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
@@ -0,0 +1,150 @@
1
+ /**
2
+ * The Tooltip component provides the means to anchor some additional
3
+ * information to some content. The additional information is shown in a
4
+ * callout that hovers above the page content. This additional information is
5
+ * invoked by hovering over the anchored content, or focusing all or part of the
6
+ * anchored content.
7
+ *
8
+ * This component is structured as follows:
9
+ *
10
+ * Tooltip (this component)
11
+ * - TooltipAnchor (provides hover/focus behaviors on anchored content)
12
+ * - TooltipPortalMounter (creates portal into which the callout is rendered)
13
+ * --------------------------- [PORTAL BOUNDARY] ------------------------------
14
+ * - TooltipPopper (provides positioning for the callout using react-popper)
15
+ * - TooltipBubble (renders the callout borders, background and shadow)
16
+ * - TooltipContent (renders the callout content; the actual information)
17
+ * - TooltipTail (renders the callout tail and shadow that points from the
18
+ * callout to the anchor content)
19
+ */
20
+ import * as React from "react";
21
+ import { IIdentifierFactory } from "@khanacademy/wonder-blocks-core";
22
+ import type { Typography } from "@khanacademy/wonder-blocks-typography";
23
+ import type { AriaProps } from "@khanacademy/wonder-blocks-core";
24
+ import TooltipContent from "./tooltip-content";
25
+ import type { Placement } from "../util/types";
26
+ type Props = AriaProps & {
27
+ /**
28
+ * The content for anchoring the tooltip.
29
+ * This component will be used to position the tooltip.
30
+ */
31
+ children: React.ReactElement<any> | string;
32
+ /**
33
+ * The title of the tooltip.
34
+ * Optional.
35
+ */
36
+ title?: string | React.ReactElement<React.ComponentProps<Typography>>;
37
+ /**
38
+ * The content to render in the tooltip.
39
+ */
40
+ content: string | React.ReactElement<React.ComponentProps<typeof TooltipContent>>;
41
+ /**
42
+ * The unique identifier to give to the tooltip. Provide this in cases where
43
+ * you want to override the default accessibility solution. This identifier
44
+ * will be applied to the tooltip bubble content.
45
+ *
46
+ * By providing this identifier, the children that this tooltip anchors to
47
+ * will not be automatically given the aria-desribedby attribute. Instead,
48
+ * the accessibility solution is the responsibility of the caller.
49
+ *
50
+ * If this is not provided, the aria-describedby attribute will be added
51
+ * to the children with a unique identifier pointing to the tooltip bubble
52
+ * content.
53
+ */
54
+ id?: string;
55
+ /**
56
+ * When true, if a tabindex attribute is not already present on the element
57
+ * wrapped by the anchor, the element will be given tabindex=0 to make it
58
+ * keyboard focusable; otherwise, does not attempt to change the ability to
59
+ * focus the anchor element.
60
+ *
61
+ * Defaults to true.
62
+ *
63
+ * One might set this to false in circumstances where the wrapped component
64
+ * already can receive focus or contains an element that can.
65
+ * Use good judgement when overriding this value, the tooltip content should
66
+ * be accessible via keyboard in all circumstances where the tooltip would
67
+ * appear using the mouse, so verify those use-cases.
68
+ *
69
+ * Also, note that the aria-describedby attribute is attached to the root
70
+ * anchor element, so you may need to implement an additional accessibility
71
+ * solution when overriding anchor focusivity.
72
+ */
73
+ forceAnchorFocusivity?: boolean;
74
+ /**
75
+ * Where the tooltip should appear in relation to the anchor element.
76
+ * Defaults to "top".
77
+ */
78
+ placement: Placement;
79
+ /**
80
+ * Renders the tooltip when true, renders nothing when false.
81
+ *
82
+ * Using this prop makes the component behave as a controlled component. The
83
+ * parent is responsible for managing the opening/closing of the tooltip
84
+ * when using this prop.
85
+ */
86
+ opened?: boolean;
87
+ /**
88
+ * Test ID used for e2e testing.
89
+ */
90
+ testId?: string;
91
+ };
92
+ type State = {
93
+ /**
94
+ * Whether the tooltip is open by hovering/focusing on the anchor element.
95
+ */
96
+ active: boolean;
97
+ /**
98
+ * Whether the tooltip is open by hovering on the tooltip bubble.
99
+ */
100
+ activeBubble: boolean;
101
+ /**
102
+ * The element that activates the tooltip.
103
+ */
104
+ anchorElement: HTMLElement | null | undefined;
105
+ };
106
+ type DefaultProps = {
107
+ forceAnchorFocusivity: Props["forceAnchorFocusivity"];
108
+ placement: Props["placement"];
109
+ };
110
+ /**
111
+ * Use a tooltip to help describe an on screen object.
112
+ *
113
+ * Tooltips:
114
+ * - contain text
115
+ * - (optional) contain small graphic elements to complement the text
116
+ * - appear on hover or focus (for non-assistive tech keyboard users)
117
+ * - must have a tail that points to a parent object
118
+ * - DO NOT include actions
119
+ *
120
+ * For more rich content see Popovers, for taking action on an object, see
121
+ * Snackbars (proposed).
122
+ *
123
+ * ### Usage
124
+ *
125
+ * ```jsx
126
+ * import Tooltip from "@khanacademy/wonder-blocks-tooltip";
127
+ *
128
+ * <Tooltip content="This is a text tooltip">
129
+ * Tooltip anchor
130
+ * </Tooltip>
131
+ * ```
132
+ *
133
+ */
134
+ export default class Tooltip extends React.Component<Props, State> {
135
+ static defaultProps: DefaultProps;
136
+ /**
137
+ * Used to sync the `opened` state when Tooltip acts as a controlled
138
+ * component
139
+ */
140
+ static getDerivedStateFromProps(props: Props, state: State): Partial<State> | null;
141
+ state: State;
142
+ static ariaContentId: string;
143
+ _updateAnchorElement(ref?: Element | null): void;
144
+ _renderBubbleContent(): React.ReactElement<React.ComponentProps<typeof TooltipContent>>;
145
+ _renderPopper(ids?: IIdentifierFactory): React.ReactNode;
146
+ _getHost(): Element | null | undefined;
147
+ _renderTooltipAnchor(ids?: IIdentifierFactory): React.ReactNode;
148
+ render(): React.ReactElement;
149
+ }
150
+ export {};
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Flowtype definitions for tooltip
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 { IIdentifierFactory } from "@khanacademy/wonder-blocks-core";
10
+ import type { Typography } from "@khanacademy/wonder-blocks-typography";
11
+ import type { AriaProps } from "@khanacademy/wonder-blocks-core";
12
+ import TooltipContent from "./tooltip-content";
13
+ import type { Placement } from "../util/types";
14
+ declare type Props = {
15
+ ...AriaProps,
16
+ ...{
17
+ /**
18
+ * The content for anchoring the tooltip.
19
+ * This component will be used to position the tooltip.
20
+ */
21
+ children: React.Element<any> | string,
22
+
23
+ /**
24
+ * The title of the tooltip.
25
+ * Optional.
26
+ */
27
+ title?: string | React.Element<React.ComponentProps<Typography>>,
28
+
29
+ /**
30
+ * The content to render in the tooltip.
31
+ */
32
+ content:
33
+ | string
34
+ | React.Element<React.ComponentProps<typeof TooltipContent>>,
35
+
36
+ /**
37
+ * The unique identifier to give to the tooltip. Provide this in cases where
38
+ * you want to override the default accessibility solution. This identifier
39
+ * will be applied to the tooltip bubble content.
40
+ *
41
+ * By providing this identifier, the children that this tooltip anchors to
42
+ * will not be automatically given the aria-desribedby attribute. Instead,
43
+ * the accessibility solution is the responsibility of the caller.
44
+ *
45
+ * If this is not provided, the aria-describedby attribute will be added
46
+ * to the children with a unique identifier pointing to the tooltip bubble
47
+ * content.
48
+ */
49
+ id?: string,
50
+
51
+ /**
52
+ * When true, if a tabindex attribute is not already present on the element
53
+ * wrapped by the anchor, the element will be given tabindex=0 to make it
54
+ * keyboard focusable; otherwise, does not attempt to change the ability to
55
+ * focus the anchor element.
56
+ *
57
+ * Defaults to true.
58
+ *
59
+ * One might set this to false in circumstances where the wrapped component
60
+ * already can receive focus or contains an element that can.
61
+ * Use good judgement when overriding this value, the tooltip content should
62
+ * be accessible via keyboard in all circumstances where the tooltip would
63
+ * appear using the mouse, so verify those use-cases.
64
+ *
65
+ * Also, note that the aria-describedby attribute is attached to the root
66
+ * anchor element, so you may need to implement an additional accessibility
67
+ * solution when overriding anchor focusivity.
68
+ */
69
+ forceAnchorFocusivity?: boolean,
70
+
71
+ /**
72
+ * Where the tooltip should appear in relation to the anchor element.
73
+ * Defaults to "top".
74
+ */
75
+ placement: Placement,
76
+
77
+ /**
78
+ * Renders the tooltip when true, renders nothing when false.
79
+ *
80
+ * Using this prop makes the component behave as a controlled component. The
81
+ * parent is responsible for managing the opening/closing of the tooltip
82
+ * when using this prop.
83
+ */
84
+ opened?: boolean,
85
+
86
+ /**
87
+ * Test ID used for e2e testing.
88
+ */
89
+ testId?: string,
90
+ ...
91
+ },
92
+ };
93
+ declare type State = {
94
+ /**
95
+ * Whether the tooltip is open by hovering/focusing on the anchor element.
96
+ */
97
+ active: boolean,
98
+
99
+ /**
100
+ * Whether the tooltip is open by hovering on the tooltip bubble.
101
+ */
102
+ activeBubble: boolean,
103
+
104
+ /**
105
+ * The element that activates the tooltip.
106
+ */
107
+ anchorElement: HTMLElement | null | void,
108
+ ...
109
+ };
110
+ declare type DefaultProps = {
111
+ forceAnchorFocusivity: $PropertyType<Props, "forceAnchorFocusivity">,
112
+ placement: $PropertyType<Props, "placement">,
113
+ ...
114
+ };
115
+ /**
116
+ * Use a tooltip to help describe an on screen object.
117
+ *
118
+ * Tooltips:
119
+ * - contain text
120
+ * - (optional) contain small graphic elements to complement the text
121
+ * - appear on hover or focus (for non-assistive tech keyboard users)
122
+ * - must have a tail that points to a parent object
123
+ * - DO NOT include actions
124
+ *
125
+ * For more rich content see Popovers, for taking action on an object, see
126
+ * Snackbars (proposed).
127
+ *
128
+ * ### Usage
129
+ *
130
+ * ```jsx
131
+ * import Tooltip from "@khanacademy/wonder-blocks-tooltip";
132
+ *
133
+ * <Tooltip content="This is a text tooltip">
134
+ * Tooltip anchor
135
+ * </Tooltip>
136
+ * ```
137
+ */
138
+ declare export default class Tooltip mixins React.Component<Props, State> {
139
+ static defaultProps: DefaultProps;
140
+
141
+ /**
142
+ * Used to sync the `opened` state when Tooltip acts as a controlled
143
+ * component
144
+ */
145
+ static getDerivedStateFromProps(
146
+ props: Props,
147
+ state: State
148
+ ): $Rest<State, { ... }> | null;
149
+ state: State;
150
+ static ariaContentId: string;
151
+ _updateAnchorElement(ref?: Element | null): void;
152
+ _renderBubbleContent(): React.Element<
153
+ React.ComponentProps<typeof TooltipContent>
154
+ >;
155
+ _renderPopper(ids?: IIdentifierFactory): React.Node;
156
+ _getHost(): Element | null | void;
157
+ _renderTooltipAnchor(ids?: IIdentifierFactory): React.Node;
158
+ render(): React.Element<>;
159
+ }