@fluentui/react-tooltip 9.0.0-nightly.f81b28ceb3.1 → 9.0.0-rc.4
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.json +457 -24
- package/CHANGELOG.md +113 -14
- package/MIGRATION.md +51 -43
- package/Spec.md +201 -337
- package/dist/react-tooltip.d.ts +40 -48
- package/lib/Tooltip.js.map +1 -1
- package/lib/components/Tooltip/Tooltip.d.ts +3 -2
- package/lib/components/Tooltip/Tooltip.js +9 -9
- package/lib/components/Tooltip/Tooltip.js.map +1 -1
- package/lib/components/Tooltip/Tooltip.types.d.ts +32 -39
- package/lib/components/Tooltip/Tooltip.types.js.map +1 -1
- package/lib/components/Tooltip/index.d.ts +1 -1
- package/lib/components/Tooltip/index.js +1 -1
- package/lib/components/Tooltip/index.js.map +1 -1
- package/lib/components/Tooltip/private/constants.d.ts +12 -0
- package/lib/components/Tooltip/private/constants.js +14 -0
- package/lib/components/Tooltip/private/constants.js.map +1 -0
- package/lib/components/Tooltip/renderTooltip.d.ts +1 -1
- package/lib/components/Tooltip/renderTooltip.js +8 -8
- package/lib/components/Tooltip/renderTooltip.js.map +1 -1
- package/lib/components/Tooltip/useTooltip.d.ts +3 -6
- package/lib/components/Tooltip/useTooltip.js +96 -127
- package/lib/components/Tooltip/useTooltip.js.map +1 -1
- package/lib/components/Tooltip/useTooltipStyles.d.ts +2 -1
- package/lib/components/Tooltip/useTooltipStyles.js +50 -23
- package/lib/components/Tooltip/useTooltipStyles.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib-commonjs/Tooltip.js +1 -1
- package/lib-commonjs/Tooltip.js.map +1 -1
- package/lib-commonjs/components/Tooltip/Tooltip.d.ts +3 -2
- package/lib-commonjs/components/Tooltip/Tooltip.js +11 -10
- package/lib-commonjs/components/Tooltip/Tooltip.js.map +1 -1
- package/lib-commonjs/components/Tooltip/Tooltip.types.d.ts +32 -39
- package/lib-commonjs/components/Tooltip/Tooltip.types.js.map +1 -1
- package/lib-commonjs/components/Tooltip/index.d.ts +1 -1
- package/lib-commonjs/components/Tooltip/index.js +2 -10
- package/lib-commonjs/components/Tooltip/index.js.map +1 -1
- package/lib-commonjs/components/Tooltip/private/constants.d.ts +12 -0
- package/lib-commonjs/components/Tooltip/private/constants.js +21 -0
- package/lib-commonjs/components/Tooltip/private/constants.js.map +1 -0
- package/lib-commonjs/components/Tooltip/renderTooltip.d.ts +1 -1
- package/lib-commonjs/components/Tooltip/renderTooltip.js +13 -14
- package/lib-commonjs/components/Tooltip/renderTooltip.js.map +1 -1
- package/lib-commonjs/components/Tooltip/useTooltip.d.ts +3 -6
- package/lib-commonjs/components/Tooltip/useTooltip.js +104 -135
- package/lib-commonjs/components/Tooltip/useTooltip.js.map +1 -1
- package/lib-commonjs/components/Tooltip/useTooltipStyles.d.ts +2 -1
- package/lib-commonjs/components/Tooltip/useTooltipStyles.js +56 -26
- package/lib-commonjs/components/Tooltip/useTooltipStyles.js.map +1 -1
- package/lib-commonjs/index.js +1 -1
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +12 -14
- package/lib/common/isConformant.d.ts +0 -4
- package/lib/common/isConformant.js +0 -11
- package/lib/common/isConformant.js.map +0 -1
- package/lib-commonjs/common/isConformant.d.ts +0 -4
- package/lib-commonjs/common/isConformant.js +0 -22
- package/lib-commonjs/common/isConformant.js.map +0 -1
@@ -1,41 +1,37 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import type { PositioningShorthand } from '@fluentui/react-positioning';
|
3
|
-
import type { ComponentProps, ComponentState,
|
3
|
+
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
|
4
4
|
/**
|
5
5
|
* Slot properties for Tooltip
|
6
6
|
*/
|
7
7
|
export declare type TooltipSlots = {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
* Alternatively, children can be a render function that takes the props and adds
|
13
|
-
* them to the appropriate elements.
|
14
|
-
*/
|
15
|
-
children?: (React.ReactElement<React.HTMLAttributes<HTMLElement>> & {
|
16
|
-
ref?: React.Ref<unknown>;
|
17
|
-
}) | ((props: TooltipTriggerProps) => React.ReactNode) | null;
|
18
|
-
};
|
8
|
+
/**
|
9
|
+
* The text or JSX content of the tooltip.
|
10
|
+
*/
|
11
|
+
content: NonNullable<Slot<'div'>>;
|
19
12
|
};
|
20
13
|
/**
|
21
14
|
* Properties and state for Tooltip
|
22
15
|
*/
|
23
|
-
|
24
|
-
/**
|
25
|
-
* A tooltip can appear with the default appearance or inverted.
|
26
|
-
* When not specified, the default appearance is used.
|
27
|
-
*/
|
28
|
-
appearance?: 'inverted';
|
16
|
+
declare type TooltipCommons = {
|
29
17
|
/**
|
30
|
-
*
|
18
|
+
* (Required) Specifies whether this tooltip is acting as the description or label of its trigger element.
|
19
|
+
*
|
20
|
+
* * `label` - The tooltip sets the trigger's aria-label or aria-labelledby attribute. This is useful for buttons
|
21
|
+
* displaying only an icon, for example.
|
22
|
+
* * `description` - The tooltip sets the trigger's aria-description or aria-describedby attribute.
|
23
|
+
* * `inaccessible` - No aria attributes are set on the trigger. This makes the tooltip's content inaccessible to
|
24
|
+
* screen readers, and should only be used if the tooltip's text is available by some other means.
|
31
25
|
*/
|
32
|
-
|
26
|
+
relationship: 'label' | 'description' | 'inaccessible';
|
33
27
|
/**
|
34
|
-
*
|
28
|
+
* The tooltip's visual appearance.
|
29
|
+
* * `normal` - Uses the theme's background and text colors.
|
30
|
+
* * `inverted` - Higher contrast variant that uses the theme's inverted colors.
|
35
31
|
*
|
36
|
-
* @defaultvalue
|
32
|
+
* @defaultvalue normal
|
37
33
|
*/
|
38
|
-
|
34
|
+
appearance?: 'normal' | 'inverted';
|
39
35
|
/**
|
40
36
|
* Render an arrow pointing to the target element
|
41
37
|
*
|
@@ -61,16 +57,6 @@ export declare type TooltipCommons = {
|
|
61
57
|
* Notification when the visibility of the tooltip is changing
|
62
58
|
*/
|
63
59
|
onVisibleChange?: (event: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement> | undefined, data: OnVisibleChangeData) => void;
|
64
|
-
/**
|
65
|
-
* Specifies which aria attribute to set on the trigger element.
|
66
|
-
* * `label` - Set aria-label to the tooltip's content. Requires content to be a string; if not, uses `labelledby`.
|
67
|
-
* * `labelledby` - Set aria-labelledby to the tooltip's id. The id is generated if not provided.
|
68
|
-
* * `describedby` - Set aria-describedby to the tooltip's id. The id is generated if not provided.
|
69
|
-
* * null - Do not set any aria attributes on the trigger element.
|
70
|
-
*
|
71
|
-
* @defaultvalue label
|
72
|
-
*/
|
73
|
-
triggerAriaAttribute: 'label' | 'labelledby' | 'describedby' | null;
|
74
60
|
/**
|
75
61
|
* Delay before the tooltip is shown, in milliseconds.
|
76
62
|
*
|
@@ -99,18 +85,24 @@ export declare type OnVisibleChangeData = {
|
|
99
85
|
/**
|
100
86
|
* Properties for Tooltip
|
101
87
|
*/
|
102
|
-
export declare type TooltipProps = ComponentProps<TooltipSlots> & Partial<Omit<TooltipCommons, '
|
88
|
+
export declare type TooltipProps = ComponentProps<TooltipSlots> & Partial<Omit<TooltipCommons, 'relationship'>> & Pick<TooltipCommons, 'relationship'> & {
|
89
|
+
/**
|
90
|
+
* The tooltip can have a single JSX child, or a render function that accepts TooltipTriggerProps.
|
91
|
+
*
|
92
|
+
* If no child is provided, the tooltip's target must be set with the `positioning` prop, and its
|
93
|
+
* visibility must be controlled with the `visible` prop.
|
94
|
+
*/
|
95
|
+
children?: (React.ReactElement & {
|
96
|
+
ref?: React.Ref<unknown>;
|
97
|
+
}) | ((props: TooltipTriggerProps) => React.ReactElement | null) | null;
|
98
|
+
};
|
103
99
|
/**
|
104
100
|
* State used in rendering Tooltip
|
105
101
|
*/
|
106
102
|
export declare type TooltipState = ComponentState<TooltipSlots> & TooltipCommons & {
|
103
|
+
children?: React.ReactElement | null;
|
107
104
|
/**
|
108
105
|
* Whether the tooltip should be rendered to the DOM.
|
109
|
-
*
|
110
|
-
* Normally the tooltip will only be rendered when visible. However, if
|
111
|
-
* triggerAriaAttribute is labelledby or describedby, the tooltip will
|
112
|
-
* always be rendered even when hidden so that those aria attributes
|
113
|
-
* to always refer to a valid DOM element.
|
114
106
|
*/
|
115
107
|
shouldRenderTooltip?: boolean;
|
116
108
|
/**
|
@@ -122,3 +114,4 @@ export declare type TooltipState = ComponentState<TooltipSlots> & TooltipCommons
|
|
122
114
|
*/
|
123
115
|
arrowClassName?: string;
|
124
116
|
};
|
117
|
+
export {};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":""}
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
|
@@ -3,9 +3,8 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.useTooltipStyles = void 0;
|
7
6
|
|
8
|
-
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
9
8
|
|
10
9
|
tslib_1.__exportStar(require("./Tooltip"), exports);
|
11
10
|
|
@@ -15,12 +14,5 @@ tslib_1.__exportStar(require("./renderTooltip"), exports);
|
|
15
14
|
|
16
15
|
tslib_1.__exportStar(require("./useTooltip"), exports);
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
Object.defineProperty(exports, "useTooltipStyles", {
|
21
|
-
enumerable: true,
|
22
|
-
get: function () {
|
23
|
-
return useTooltipStyles_1.useTooltipStyles;
|
24
|
-
}
|
25
|
-
});
|
17
|
+
tslib_1.__exportStar(require("./useTooltipStyles"), exports);
|
26
18
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["components/Tooltip/index.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,WAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,iBAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,cAAA,CAAA,EAAA,OAAA;;AACA,OAAA,CAAA,YAAA,CAAA,OAAA,CAAA,oBAAA,CAAA,EAAA,OAAA","sourcesContent":["export * from './Tooltip';\nexport * from './Tooltip.types';\nexport * from './renderTooltip';\nexport * from './useTooltip';\nexport * from './useTooltipStyles';\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/**
|
2
|
+
* The height of the tooltip's arrow in pixels.
|
3
|
+
*/
|
4
|
+
export declare const arrowHeight = 6;
|
5
|
+
/**
|
6
|
+
* The default value of the tooltip's border radius (borderRadiusMedium).
|
7
|
+
*
|
8
|
+
* Unfortunately, Popper requires it to be specified as a variable instead of using CSS.
|
9
|
+
* While we could use getComputedStyle, that adds a performance penalty for something that
|
10
|
+
* will likely never change.
|
11
|
+
*/
|
12
|
+
export declare const tooltipBorderRadius = 4;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.tooltipBorderRadius = exports.arrowHeight = void 0;
|
7
|
+
/**
|
8
|
+
* The height of the tooltip's arrow in pixels.
|
9
|
+
*/
|
10
|
+
|
11
|
+
exports.arrowHeight = 6;
|
12
|
+
/**
|
13
|
+
* The default value of the tooltip's border radius (borderRadiusMedium).
|
14
|
+
*
|
15
|
+
* Unfortunately, Popper requires it to be specified as a variable instead of using CSS.
|
16
|
+
* While we could use getComputedStyle, that adds a performance penalty for something that
|
17
|
+
* will likely never change.
|
18
|
+
*/
|
19
|
+
|
20
|
+
exports.tooltipBorderRadius = 4;
|
21
|
+
//# sourceMappingURL=constants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["components/Tooltip/private/constants.ts"],"names":[],"mappings":";;;;;;AAAA;;AAEG;;AACU,OAAA,CAAA,WAAA,GAAc,CAAd;AAEb;;;;;;AAMG;;AACU,OAAA,CAAA,mBAAA,GAAsB,CAAtB","sourcesContent":["/**\n * The height of the tooltip's arrow in pixels.\n */\nexport const arrowHeight = 6;\n\n/**\n * The default value of the tooltip's border radius (borderRadiusMedium).\n *\n * Unfortunately, Popper requires it to be specified as a variable instead of using CSS.\n * While we could use getComputedStyle, that adds a performance penalty for something that\n * will likely never change.\n */\nexport const tooltipBorderRadius = 4;\n"],"sourceRoot":"../src/"}
|
@@ -3,30 +3,29 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.renderTooltip_unstable = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
9
|
|
10
|
-
|
10
|
+
const react_portal_1 = /*#__PURE__*/require("@fluentui/react-portal");
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
var react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
12
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
15
13
|
/**
|
16
14
|
* Render the final JSX of Tooltip
|
17
15
|
*/
|
18
16
|
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
return React.createElement(React.Fragment, null, state.
|
18
|
+
const renderTooltip_unstable = state => {
|
19
|
+
const {
|
20
|
+
slots,
|
21
|
+
slotProps
|
22
|
+
} = react_utilities_1.getSlots(state);
|
23
|
+
return React.createElement(React.Fragment, null, state.children, state.shouldRenderTooltip && React.createElement(react_portal_1.Portal, null, React.createElement(slots.content, { ...slotProps.content
|
24
|
+
}, state.withArrow && React.createElement("div", {
|
26
25
|
ref: state.arrowRef,
|
27
26
|
className: state.arrowClassName
|
28
|
-
}), state.content)));
|
27
|
+
}), state.content.children)));
|
29
28
|
};
|
30
29
|
|
31
|
-
exports.
|
30
|
+
exports.renderTooltip_unstable = renderTooltip_unstable;
|
32
31
|
//# sourceMappingURL=renderTooltip.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["
|
1
|
+
{"version":3,"sources":["components/Tooltip/renderTooltip.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,cAAA,gBAAA,OAAA,CAAA,wBAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;AAGA;;AAEG;;;AACI,MAAM,sBAAsB,GAAI,KAAD,IAAwB;AAC5D,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,iBAAA,CAAA,QAAA,CAAuB,KAAvB,CAA7B;AAEA,SACE,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA,EACG,KAAK,CAAC,QADT,EAEG,KAAK,CAAC,mBAAN,IACC,KAAA,CAAA,aAAA,CAAC,cAAA,CAAA,MAAD,EAAO,IAAP,EACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,OAAP,EAAc,EAAA,GAAK,SAAS,CAAC;AAAf,GAAd,EACG,KAAK,CAAC,SAAN,IAAmB,KAAA,CAAA,aAAA,CAAA,KAAA,EAAA;AAAK,IAAA,GAAG,EAAE,KAAK,CAAC,QAAhB;AAA0B,IAAA,SAAS,EAAE,KAAK,CAAC;AAA3C,GAAA,CADtB,EAEG,KAAK,CAAC,OAAN,CAAc,QAFjB,CADF,CAHJ,CADF;AAaD,CAhBM;;AAAM,OAAA,CAAA,sBAAA,GAAsB,sBAAtB","sourcesContent":["import * as React from 'react';\nimport { Portal } from '@fluentui/react-portal';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { TooltipSlots, TooltipState } from './Tooltip.types';\n\n/**\n * Render the final JSX of Tooltip\n */\nexport const renderTooltip_unstable = (state: TooltipState) => {\n const { slots, slotProps } = getSlots<TooltipSlots>(state);\n\n return (\n <>\n {state.children}\n {state.shouldRenderTooltip && (\n <Portal>\n <slots.content {...slotProps.content}>\n {state.withArrow && <div ref={state.arrowRef} className={state.arrowClassName} />}\n {state.content.children}\n </slots.content>\n </Portal>\n )}\n </>\n );\n};\n"],"sourceRoot":"../src/"}
|
@@ -1,13 +1,10 @@
|
|
1
|
-
import * as React from 'react';
|
2
1
|
import type { TooltipProps, TooltipState } from './Tooltip.types';
|
3
2
|
/**
|
4
3
|
* Create the state required to render Tooltip.
|
5
4
|
*
|
6
|
-
* The returned state can be modified with hooks such as
|
7
|
-
* before being passed to
|
5
|
+
* The returned state can be modified with hooks such as useTooltipStyles_unstable,
|
6
|
+
* before being passed to renderTooltip_unstable.
|
8
7
|
*
|
9
8
|
* @param props - props from this instance of Tooltip
|
10
|
-
* @param ref - reference to root HTMLElement of Tooltip
|
11
|
-
* @param defaultProps - (optional) default prop values provided by the implementing type
|
12
9
|
*/
|
13
|
-
export declare const
|
10
|
+
export declare const useTooltip_unstable: (props: TooltipProps) => TooltipState;
|
@@ -3,67 +3,54 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.useTooltip_unstable = void 0;
|
7
7
|
|
8
|
-
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
9
|
|
10
|
-
|
10
|
+
const react_positioning_1 = /*#__PURE__*/require("@fluentui/react-positioning");
|
11
11
|
|
12
|
-
|
12
|
+
const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
var react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities"); // Style values that are required for popper to properly position the tooltip
|
17
|
-
|
18
|
-
|
19
|
-
var tooltipBorderRadius = 4; // Update the root's borderRadius in useTooltipStyles.ts if this changes
|
20
|
-
|
21
|
-
var arrowHeight = 6; // Update the arrow's width/height in useTooltipStyles.ts if this changes
|
14
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
22
15
|
|
16
|
+
const constants_1 = /*#__PURE__*/require("./private/constants");
|
23
17
|
/**
|
24
18
|
* Create the state required to render Tooltip.
|
25
19
|
*
|
26
|
-
* The returned state can be modified with hooks such as
|
27
|
-
* before being passed to
|
20
|
+
* The returned state can be modified with hooks such as useTooltipStyles_unstable,
|
21
|
+
* before being passed to renderTooltip_unstable.
|
28
22
|
*
|
29
23
|
* @param props - props from this instance of Tooltip
|
30
|
-
* @param ref - reference to root HTMLElement of Tooltip
|
31
|
-
* @param defaultProps - (optional) default prop values provided by the implementing type
|
32
24
|
*/
|
33
25
|
|
34
|
-
|
26
|
+
|
27
|
+
const useTooltip_unstable = props => {
|
35
28
|
var _a, _b, _c, _d;
|
36
29
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
hideDelay = _h === void 0 ? 250 : _h;
|
56
|
-
|
57
|
-
var _j = react_utilities_1.useControllableState({
|
30
|
+
const context = React.useContext(react_shared_contexts_1.TooltipContext);
|
31
|
+
const isServerSideRender = react_utilities_1.useIsSSR();
|
32
|
+
const {
|
33
|
+
targetDocument
|
34
|
+
} = react_shared_contexts_1.useFluent();
|
35
|
+
const [setDelayTimeout, clearDelayTimeout] = react_utilities_1.useTimeout();
|
36
|
+
const {
|
37
|
+
appearance,
|
38
|
+
children,
|
39
|
+
content,
|
40
|
+
withArrow,
|
41
|
+
positioning,
|
42
|
+
onVisibleChange,
|
43
|
+
relationship,
|
44
|
+
showDelay = 250,
|
45
|
+
hideDelay = 250
|
46
|
+
} = props;
|
47
|
+
const [visible, setVisibleInternal] = react_utilities_1.useControllableState({
|
58
48
|
state: props.visible,
|
59
49
|
initialState: false
|
60
|
-
})
|
61
|
-
|
62
|
-
setVisibleInternal = _j[1];
|
63
|
-
|
64
|
-
var setVisible = React.useCallback(function (newVisible, ev) {
|
50
|
+
});
|
51
|
+
const setVisible = React.useCallback((newVisible, ev) => {
|
65
52
|
clearDelayTimeout();
|
66
|
-
setVisibleInternal(
|
53
|
+
setVisibleInternal(oldVisible => {
|
67
54
|
if (newVisible !== oldVisible) {
|
68
55
|
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev, {
|
69
56
|
visible: newVisible
|
@@ -73,76 +60,73 @@ var useTooltip = function (props, ref) {
|
|
73
60
|
return newVisible;
|
74
61
|
});
|
75
62
|
}, [clearDelayTimeout, setVisibleInternal, onVisibleChange]);
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
triggerAriaAttribute: triggerAriaAttribute,
|
84
|
-
visible: visible,
|
63
|
+
const state = {
|
64
|
+
withArrow,
|
65
|
+
positioning,
|
66
|
+
showDelay,
|
67
|
+
hideDelay,
|
68
|
+
relationship,
|
69
|
+
visible,
|
85
70
|
shouldRenderTooltip: visible,
|
86
|
-
appearance
|
71
|
+
appearance,
|
87
72
|
// Slots
|
88
73
|
components: {
|
89
|
-
|
74
|
+
content: 'div'
|
90
75
|
},
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
})
|
76
|
+
content: react_utilities_1.resolveShorthand(content, {
|
77
|
+
defaultProps: {
|
78
|
+
role: 'tooltip'
|
79
|
+
},
|
80
|
+
required: true
|
81
|
+
})
|
97
82
|
};
|
98
|
-
|
99
|
-
|
83
|
+
state.content.id = react_utilities_1.useId('tooltip-', state.content.id);
|
84
|
+
const popperOptions = {
|
100
85
|
enabled: state.visible,
|
101
|
-
arrowPadding: 2 * tooltipBorderRadius,
|
86
|
+
arrowPadding: 2 * constants_1.tooltipBorderRadius,
|
102
87
|
position: 'above',
|
103
88
|
align: 'center',
|
104
|
-
offset: [0, 4]
|
105
|
-
|
89
|
+
offset: [0, 4],
|
90
|
+
...react_positioning_1.resolvePositioningShorthand(state.positioning)
|
91
|
+
};
|
106
92
|
|
107
93
|
if (state.withArrow) {
|
108
|
-
popperOptions.offset = react_positioning_1.mergeArrowOffset(popperOptions.offset, arrowHeight);
|
94
|
+
popperOptions.offset = react_positioning_1.mergeArrowOffset(popperOptions.offset, constants_1.arrowHeight);
|
109
95
|
}
|
110
96
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
state.
|
97
|
+
const {
|
98
|
+
targetRef,
|
99
|
+
containerRef,
|
100
|
+
arrowRef
|
101
|
+
} = react_positioning_1.usePopper(popperOptions);
|
102
|
+
state.content.ref = react_utilities_1.useMergedRefs(state.content.ref, containerRef);
|
117
103
|
state.arrowRef = arrowRef; // When this tooltip is visible, hide any other tooltips, and register it
|
118
104
|
// as the visibleTooltip with the TooltipContext.
|
119
105
|
// Also add a listener on document to hide the tooltip if Escape is pressed
|
120
106
|
|
121
|
-
react_utilities_1.useIsomorphicLayoutEffect(
|
107
|
+
react_utilities_1.useIsomorphicLayoutEffect(() => {
|
122
108
|
var _a;
|
123
109
|
|
124
110
|
if (visible) {
|
125
|
-
|
126
|
-
hide:
|
127
|
-
return setVisible(false);
|
128
|
-
}
|
111
|
+
const thisTooltip = {
|
112
|
+
hide: () => setVisible(false)
|
129
113
|
};
|
130
114
|
(_a = context.visibleTooltip) === null || _a === void 0 ? void 0 : _a.hide();
|
131
|
-
context.visibleTooltip =
|
115
|
+
context.visibleTooltip = thisTooltip;
|
132
116
|
|
133
|
-
|
117
|
+
const onDocumentKeyDown = ev => {
|
134
118
|
if (ev.key === 'Escape' || ev.key === 'Esc') {
|
135
|
-
|
119
|
+
thisTooltip.hide();
|
136
120
|
}
|
137
121
|
};
|
138
122
|
|
139
|
-
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('keydown',
|
140
|
-
return
|
141
|
-
if (context.visibleTooltip ===
|
123
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('keydown', onDocumentKeyDown);
|
124
|
+
return () => {
|
125
|
+
if (context.visibleTooltip === thisTooltip) {
|
142
126
|
context.visibleTooltip = undefined;
|
143
127
|
}
|
144
128
|
|
145
|
-
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('keydown',
|
129
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('keydown', onDocumentKeyDown);
|
146
130
|
};
|
147
131
|
}
|
148
132
|
}, [context, targetDocument, visible, setVisible]); // The focused element gets a blur event when the document loses focus
|
@@ -151,24 +135,24 @@ var useTooltip = function (props, ref) {
|
|
151
135
|
// checking if the blurred element is still the document's activeElement.
|
152
136
|
// See https://github.com/microsoft/fluentui/issues/13541
|
153
137
|
|
154
|
-
|
138
|
+
const ignoreNextFocusEventRef = React.useRef(false); // Listener for onPointerEnter and onFocus on the trigger element
|
155
139
|
|
156
|
-
|
140
|
+
const onEnterTrigger = React.useCallback(ev => {
|
157
141
|
if (ev.type === 'focus' && ignoreNextFocusEventRef.current) {
|
158
142
|
ignoreNextFocusEventRef.current = false;
|
159
143
|
return;
|
160
144
|
} // Show immediately if another tooltip is already visible
|
161
145
|
|
162
146
|
|
163
|
-
|
164
|
-
setDelayTimeout(
|
147
|
+
const delay = context.visibleTooltip ? 0 : state.showDelay;
|
148
|
+
setDelayTimeout(() => {
|
165
149
|
setVisible(true, ev);
|
166
150
|
}, delay);
|
167
151
|
ev.persist(); // Persist the event since the setVisible call will happen asynchronously
|
168
152
|
}, [setDelayTimeout, setVisible, state.showDelay, context]); // Listener for onPointerLeave and onBlur on the trigger element
|
169
153
|
|
170
|
-
|
171
|
-
|
154
|
+
const onLeaveTrigger = React.useCallback(ev => {
|
155
|
+
let delay = state.hideDelay;
|
172
156
|
|
173
157
|
if (ev.type === 'blur') {
|
174
158
|
// Hide immediately when losing focus
|
@@ -176,63 +160,48 @@ var useTooltip = function (props, ref) {
|
|
176
160
|
ignoreNextFocusEventRef.current = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) === ev.target;
|
177
161
|
}
|
178
162
|
|
179
|
-
setDelayTimeout(
|
163
|
+
setDelayTimeout(() => {
|
180
164
|
setVisible(false, ev);
|
181
165
|
}, delay);
|
182
166
|
ev.persist(); // Persist the event since the setVisible call will happen asynchronously
|
183
167
|
}, [setDelayTimeout, setVisible, state.hideDelay, targetDocument]); // Cancel the hide timer when the pointer enters the tooltip, and restart it when the mouse leaves.
|
184
168
|
// This keeps the tooltip visible when the pointer is moved over it.
|
185
169
|
|
186
|
-
state.
|
187
|
-
state.
|
188
|
-
|
170
|
+
state.content.onPointerEnter = react_utilities_1.useMergedEventCallbacks(state.content.onPointerEnter, clearDelayTimeout);
|
171
|
+
state.content.onPointerLeave = react_utilities_1.useMergedEventCallbacks(state.content.onPointerLeave, onLeaveTrigger);
|
172
|
+
const child = React.isValidElement(children) ? react_utilities_1.getTriggerChild(children) : undefined;
|
173
|
+
const triggerAriaProps = {};
|
189
174
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
175
|
+
if (relationship === 'label') {
|
176
|
+
// aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.
|
177
|
+
if (typeof state.content.children === 'string') {
|
178
|
+
triggerAriaProps['aria-label'] = state.content.children;
|
179
|
+
} else if (!isServerSideRender) {
|
180
|
+
triggerAriaProps['aria-labelledby'] = state.content.id; // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element
|
196
181
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
}
|
182
|
+
state.shouldRenderTooltip = true;
|
183
|
+
}
|
184
|
+
} else if (relationship === 'description') {
|
185
|
+
if (!isServerSideRender) {
|
186
|
+
triggerAriaProps['aria-describedby'] = state.content.id; // Always render the tooltip even if hidden, so that aria-describedby refers to a valid element
|
203
187
|
|
204
|
-
|
205
|
-
// aria-label only works if the content is a string. Otherwise, need to use labelledby.
|
206
|
-
if (typeof state.content === 'string') {
|
207
|
-
triggerProps['aria-label'] = state.content;
|
208
|
-
} else {
|
209
|
-
state.triggerAriaAttribute = 'labelledby';
|
188
|
+
state.shouldRenderTooltip = true;
|
210
189
|
}
|
211
190
|
}
|
212
191
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
192
|
+
const childTargetRef = react_utilities_1.useMergedRefs(child === null || child === void 0 ? void 0 : child.ref, targetRef); // Apply the trigger props to the child, either by calling the render function, or cloning with the new props
|
193
|
+
|
194
|
+
state.children = react_utilities_1.applyTriggerPropsToChildren(children, { ...triggerAriaProps,
|
195
|
+
...(child === null || child === void 0 ? void 0 : child.props),
|
196
|
+
// If the target prop is not provided, attach targetRef to the trigger element's ref prop
|
197
|
+
ref: popperOptions.target === undefined ? childTargetRef : child === null || child === void 0 ? void 0 : child.ref,
|
198
|
+
onPointerEnter: react_utilities_1.useMergedEventCallbacks((_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.onPointerEnter, onEnterTrigger),
|
199
|
+
onPointerLeave: react_utilities_1.useMergedEventCallbacks((_b = child === null || child === void 0 ? void 0 : child.props) === null || _b === void 0 ? void 0 : _b.onPointerLeave, onLeaveTrigger),
|
200
|
+
onFocus: react_utilities_1.useMergedEventCallbacks((_c = child === null || child === void 0 ? void 0 : child.props) === null || _c === void 0 ? void 0 : _c.onFocus, onEnterTrigger),
|
201
|
+
onBlur: react_utilities_1.useMergedEventCallbacks((_d = child === null || child === void 0 ? void 0 : child.props) === null || _d === void 0 ? void 0 : _d.onBlur, onLeaveTrigger)
|
202
|
+
});
|
224
203
|
return state;
|
225
204
|
};
|
226
205
|
|
227
|
-
exports.
|
228
|
-
/**
|
229
|
-
* Combine up to two event callbacks into a single function that calls them in order
|
230
|
-
*/
|
231
|
-
|
232
|
-
var useMergedCallbacks = function (callback1, callback2) {
|
233
|
-
return React.useCallback(function (ev) {
|
234
|
-
callback1 === null || callback1 === void 0 ? void 0 : callback1(ev);
|
235
|
-
callback2 === null || callback2 === void 0 ? void 0 : callback2(ev);
|
236
|
-
}, [callback1, callback2]);
|
237
|
-
};
|
206
|
+
exports.useTooltip_unstable = useTooltip_unstable;
|
238
207
|
//# sourceMappingURL=useTooltip.js.map
|