@fluentui/react-tooltip 0.0.0-nightly-20220302-0405.1
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 +3319 -0
- package/CHANGELOG.md +1147 -0
- package/LICENSE +15 -0
- package/MIGRATION.md +68 -0
- package/README.md +5 -0
- package/Spec.md +374 -0
- package/dist/react-tooltip.d.ts +154 -0
- package/lib/Tooltip.d.ts +1 -0
- package/lib/Tooltip.js +2 -0
- package/lib/Tooltip.js.map +1 -0
- package/lib/components/Tooltip/Tooltip.d.ts +7 -0
- package/lib/components/Tooltip/Tooltip.js +15 -0
- package/lib/components/Tooltip/Tooltip.js.map +1 -0
- package/lib/components/Tooltip/Tooltip.types.d.ts +117 -0
- package/lib/components/Tooltip/Tooltip.types.js +2 -0
- package/lib/components/Tooltip/Tooltip.types.js.map +1 -0
- package/lib/components/Tooltip/index.d.ts +5 -0
- package/lib/components/Tooltip/index.js +6 -0
- package/lib/components/Tooltip/index.js.map +1 -0
- 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 +5 -0
- package/lib/components/Tooltip/renderTooltip.js +19 -0
- package/lib/components/Tooltip/renderTooltip.js.map +1 -0
- package/lib/components/Tooltip/useTooltip.d.ts +10 -0
- package/lib/components/Tooltip/useTooltip.js +193 -0
- package/lib/components/Tooltip/useTooltip.js.map +1 -0
- package/lib/components/Tooltip/useTooltipStyles.d.ts +6 -0
- package/lib/components/Tooltip/useTooltipStyles.js +95 -0
- package/lib/components/Tooltip/useTooltipStyles.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/lib-commonjs/Tooltip.d.ts +1 -0
- package/lib-commonjs/Tooltip.js +10 -0
- package/lib-commonjs/Tooltip.js.map +1 -0
- package/lib-commonjs/components/Tooltip/Tooltip.d.ts +7 -0
- package/lib-commonjs/components/Tooltip/Tooltip.js +27 -0
- package/lib-commonjs/components/Tooltip/Tooltip.js.map +1 -0
- package/lib-commonjs/components/Tooltip/Tooltip.types.d.ts +117 -0
- package/lib-commonjs/components/Tooltip/Tooltip.types.js +6 -0
- package/lib-commonjs/components/Tooltip/Tooltip.types.js.map +1 -0
- package/lib-commonjs/components/Tooltip/index.d.ts +5 -0
- package/lib-commonjs/components/Tooltip/index.js +18 -0
- package/lib-commonjs/components/Tooltip/index.js.map +1 -0
- 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 +5 -0
- package/lib-commonjs/components/Tooltip/renderTooltip.js +31 -0
- package/lib-commonjs/components/Tooltip/renderTooltip.js.map +1 -0
- package/lib-commonjs/components/Tooltip/useTooltip.d.ts +10 -0
- package/lib-commonjs/components/Tooltip/useTooltip.js +207 -0
- package/lib-commonjs/components/Tooltip/useTooltip.js.map +1 -0
- package/lib-commonjs/components/Tooltip/useTooltipStyles.d.ts +6 -0
- package/lib-commonjs/components/Tooltip/useTooltipStyles.js +108 -0
- package/lib-commonjs/components/Tooltip/useTooltipStyles.js.map +1 -0
- package/lib-commonjs/index.d.ts +1 -0
- package/lib-commonjs/index.js +10 -0
- package/lib-commonjs/index.js.map +1 -0
- package/package.json +66 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Tooltip = void 0;
|
7
|
+
|
8
|
+
const useTooltip_1 = /*#__PURE__*/require("./useTooltip");
|
9
|
+
|
10
|
+
const renderTooltip_1 = /*#__PURE__*/require("./renderTooltip");
|
11
|
+
|
12
|
+
const useTooltipStyles_1 = /*#__PURE__*/require("./useTooltipStyles");
|
13
|
+
/**
|
14
|
+
* A tooltip provides light weight contextual information on top of its target element.
|
15
|
+
*/
|
16
|
+
|
17
|
+
|
18
|
+
const Tooltip = props => {
|
19
|
+
const state = useTooltip_1.useTooltip_unstable(props);
|
20
|
+
useTooltipStyles_1.useTooltipStyles_unstable(state);
|
21
|
+
return renderTooltip_1.renderTooltip_unstable(state);
|
22
|
+
};
|
23
|
+
|
24
|
+
exports.Tooltip = Tooltip;
|
25
|
+
exports.Tooltip.displayName = 'Tooltip';
|
26
|
+
exports.Tooltip.isFluentTriggerComponent = true;
|
27
|
+
//# sourceMappingURL=Tooltip.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["components/Tooltip/Tooltip.tsx"],"names":[],"mappings":";;;;;;;AACA,MAAA,YAAA,gBAAA,OAAA,CAAA,cAAA,CAAA;;AACA,MAAA,eAAA,gBAAA,OAAA,CAAA,iBAAA,CAAA;;AACA,MAAA,kBAAA,gBAAA,OAAA,CAAA,oBAAA,CAAA;AAIA;;AAEG;;;AACI,MAAM,OAAO,GAAoD,KAAK,IAAG;AAC9E,QAAM,KAAK,GAAG,YAAA,CAAA,mBAAA,CAAoB,KAApB,CAAd;AAEA,EAAA,kBAAA,CAAA,yBAAA,CAA0B,KAA1B;AACA,SAAO,eAAA,CAAA,sBAAA,CAAuB,KAAvB,CAAP;AACD,CALM;;AAAM,OAAA,CAAA,OAAA,GAAO,OAAP;AAOb,OAAA,CAAA,OAAA,CAAQ,WAAR,GAAsB,SAAtB;AACA,OAAA,CAAA,OAAA,CAAQ,wBAAR,GAAmC,IAAnC","sourcesContent":["import * as React from 'react';\nimport { useTooltip_unstable } from './useTooltip';\nimport { renderTooltip_unstable } from './renderTooltip';\nimport { useTooltipStyles_unstable } from './useTooltipStyles';\nimport type { TooltipProps } from './Tooltip.types';\nimport type { FluentTriggerComponent } from '@fluentui/react-utilities';\n\n/**\n * A tooltip provides light weight contextual information on top of its target element.\n */\nexport const Tooltip: React.FC<TooltipProps> & FluentTriggerComponent = props => {\n const state = useTooltip_unstable(props);\n\n useTooltipStyles_unstable(state);\n return renderTooltip_unstable(state);\n};\n\nTooltip.displayName = 'Tooltip';\nTooltip.isFluentTriggerComponent = true;\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,117 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import type { PositioningShorthand } from '@fluentui/react-positioning';
|
3
|
+
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
|
4
|
+
/**
|
5
|
+
* Slot properties for Tooltip
|
6
|
+
*/
|
7
|
+
export declare type TooltipSlots = {
|
8
|
+
/**
|
9
|
+
* The text or JSX content of the tooltip.
|
10
|
+
*/
|
11
|
+
content: NonNullable<Slot<'div'>>;
|
12
|
+
};
|
13
|
+
/**
|
14
|
+
* Properties and state for Tooltip
|
15
|
+
*/
|
16
|
+
declare type TooltipCommons = {
|
17
|
+
/**
|
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.
|
25
|
+
*/
|
26
|
+
relationship: 'label' | 'description' | 'inaccessible';
|
27
|
+
/**
|
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.
|
31
|
+
*
|
32
|
+
* @defaultvalue normal
|
33
|
+
*/
|
34
|
+
appearance?: 'normal' | 'inverted';
|
35
|
+
/**
|
36
|
+
* Render an arrow pointing to the target element
|
37
|
+
*
|
38
|
+
* @defaultvalue false
|
39
|
+
*/
|
40
|
+
withArrow?: boolean;
|
41
|
+
/**
|
42
|
+
* Configure the positioning of the tooltip
|
43
|
+
*
|
44
|
+
* @defaultvalue above
|
45
|
+
*/
|
46
|
+
positioning?: PositioningShorthand;
|
47
|
+
/**
|
48
|
+
* Control the tooltip's visibility programatically.
|
49
|
+
*
|
50
|
+
* This can be used in conjunction with onVisibleChange to modify the tooltip's show and hide behavior.
|
51
|
+
*
|
52
|
+
* If not provided, the visibility will be controlled by the tooltip itself, based on hover and focus events on the
|
53
|
+
* trigger (child) element.
|
54
|
+
*/
|
55
|
+
visible?: boolean;
|
56
|
+
/**
|
57
|
+
* Notification when the visibility of the tooltip is changing
|
58
|
+
*/
|
59
|
+
onVisibleChange?: (event: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement> | undefined, data: OnVisibleChangeData) => void;
|
60
|
+
/**
|
61
|
+
* Delay before the tooltip is shown, in milliseconds.
|
62
|
+
*
|
63
|
+
* @defaultvalue 250
|
64
|
+
*/
|
65
|
+
showDelay: number;
|
66
|
+
/**
|
67
|
+
* Delay before the tooltip is hidden, in milliseconds.
|
68
|
+
*
|
69
|
+
* @defaultvalue 250
|
70
|
+
*/
|
71
|
+
hideDelay: number;
|
72
|
+
};
|
73
|
+
/**
|
74
|
+
* The properties that are added to the trigger of the Tooltip
|
75
|
+
*/
|
76
|
+
export declare type TooltipTriggerProps = {
|
77
|
+
ref?: React.Ref<never>;
|
78
|
+
} & Pick<React.HTMLAttributes<HTMLElement>, 'onPointerEnter' | 'onPointerLeave' | 'onFocus' | 'onBlur' | 'aria-describedby' | 'aria-labelledby' | 'aria-label'>;
|
79
|
+
/**
|
80
|
+
* Data for the Tooltip's onVisibleChange event.
|
81
|
+
*/
|
82
|
+
export declare type OnVisibleChangeData = {
|
83
|
+
visible: boolean;
|
84
|
+
};
|
85
|
+
/**
|
86
|
+
* Properties for Tooltip
|
87
|
+
*/
|
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
|
+
};
|
99
|
+
/**
|
100
|
+
* State used in rendering Tooltip
|
101
|
+
*/
|
102
|
+
export declare type TooltipState = ComponentState<TooltipSlots> & TooltipCommons & {
|
103
|
+
children?: React.ReactElement | null;
|
104
|
+
/**
|
105
|
+
* Whether the tooltip should be rendered to the DOM.
|
106
|
+
*/
|
107
|
+
shouldRenderTooltip?: boolean;
|
108
|
+
/**
|
109
|
+
* Ref to the arrow element
|
110
|
+
*/
|
111
|
+
arrowRef?: React.Ref<HTMLDivElement>;
|
112
|
+
/**
|
113
|
+
* CSS class for the arrow element
|
114
|
+
*/
|
115
|
+
arrowClassName?: string;
|
116
|
+
};
|
117
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourceRoot":"../src/"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
const tslib_1 = /*#__PURE__*/require("tslib");
|
8
|
+
|
9
|
+
tslib_1.__exportStar(require("./Tooltip"), exports);
|
10
|
+
|
11
|
+
tslib_1.__exportStar(require("./Tooltip.types"), exports);
|
12
|
+
|
13
|
+
tslib_1.__exportStar(require("./renderTooltip"), exports);
|
14
|
+
|
15
|
+
tslib_1.__exportStar(require("./useTooltip"), exports);
|
16
|
+
|
17
|
+
tslib_1.__exportStar(require("./useTooltipStyles"), exports);
|
18
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
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/"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.renderTooltip_unstable = void 0;
|
7
|
+
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
|
+
|
10
|
+
const react_portal_1 = /*#__PURE__*/require("@fluentui/react-portal");
|
11
|
+
|
12
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
13
|
+
/**
|
14
|
+
* Render the final JSX of Tooltip
|
15
|
+
*/
|
16
|
+
|
17
|
+
|
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", {
|
25
|
+
ref: state.arrowRef,
|
26
|
+
className: state.arrowClassName
|
27
|
+
}), state.content.children)));
|
28
|
+
};
|
29
|
+
|
30
|
+
exports.renderTooltip_unstable = renderTooltip_unstable;
|
31
|
+
//# sourceMappingURL=renderTooltip.js.map
|
@@ -0,0 +1 @@
|
|
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/"}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import type { TooltipProps, TooltipState } from './Tooltip.types';
|
2
|
+
/**
|
3
|
+
* Create the state required to render Tooltip.
|
4
|
+
*
|
5
|
+
* The returned state can be modified with hooks such as useTooltipStyles_unstable,
|
6
|
+
* before being passed to renderTooltip_unstable.
|
7
|
+
*
|
8
|
+
* @param props - props from this instance of Tooltip
|
9
|
+
*/
|
10
|
+
export declare const useTooltip_unstable: (props: TooltipProps) => TooltipState;
|
@@ -0,0 +1,207 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useTooltip_unstable = void 0;
|
7
|
+
|
8
|
+
const React = /*#__PURE__*/require("react");
|
9
|
+
|
10
|
+
const react_positioning_1 = /*#__PURE__*/require("@fluentui/react-positioning");
|
11
|
+
|
12
|
+
const react_shared_contexts_1 = /*#__PURE__*/require("@fluentui/react-shared-contexts");
|
13
|
+
|
14
|
+
const react_utilities_1 = /*#__PURE__*/require("@fluentui/react-utilities");
|
15
|
+
|
16
|
+
const constants_1 = /*#__PURE__*/require("./private/constants");
|
17
|
+
/**
|
18
|
+
* Create the state required to render Tooltip.
|
19
|
+
*
|
20
|
+
* The returned state can be modified with hooks such as useTooltipStyles_unstable,
|
21
|
+
* before being passed to renderTooltip_unstable.
|
22
|
+
*
|
23
|
+
* @param props - props from this instance of Tooltip
|
24
|
+
*/
|
25
|
+
|
26
|
+
|
27
|
+
const useTooltip_unstable = props => {
|
28
|
+
var _a, _b, _c, _d;
|
29
|
+
|
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({
|
48
|
+
state: props.visible,
|
49
|
+
initialState: false
|
50
|
+
});
|
51
|
+
const setVisible = React.useCallback((newVisible, ev) => {
|
52
|
+
clearDelayTimeout();
|
53
|
+
setVisibleInternal(oldVisible => {
|
54
|
+
if (newVisible !== oldVisible) {
|
55
|
+
onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev, {
|
56
|
+
visible: newVisible
|
57
|
+
});
|
58
|
+
}
|
59
|
+
|
60
|
+
return newVisible;
|
61
|
+
});
|
62
|
+
}, [clearDelayTimeout, setVisibleInternal, onVisibleChange]);
|
63
|
+
const state = {
|
64
|
+
withArrow,
|
65
|
+
positioning,
|
66
|
+
showDelay,
|
67
|
+
hideDelay,
|
68
|
+
relationship,
|
69
|
+
visible,
|
70
|
+
shouldRenderTooltip: visible,
|
71
|
+
appearance,
|
72
|
+
// Slots
|
73
|
+
components: {
|
74
|
+
content: 'div'
|
75
|
+
},
|
76
|
+
content: react_utilities_1.resolveShorthand(content, {
|
77
|
+
defaultProps: {
|
78
|
+
role: 'tooltip'
|
79
|
+
},
|
80
|
+
required: true
|
81
|
+
})
|
82
|
+
};
|
83
|
+
state.content.id = react_utilities_1.useId('tooltip-', state.content.id);
|
84
|
+
const popperOptions = {
|
85
|
+
enabled: state.visible,
|
86
|
+
arrowPadding: 2 * constants_1.tooltipBorderRadius,
|
87
|
+
position: 'above',
|
88
|
+
align: 'center',
|
89
|
+
offset: [0, 4],
|
90
|
+
...react_positioning_1.resolvePositioningShorthand(state.positioning)
|
91
|
+
};
|
92
|
+
|
93
|
+
if (state.withArrow) {
|
94
|
+
popperOptions.offset = react_positioning_1.mergeArrowOffset(popperOptions.offset, constants_1.arrowHeight);
|
95
|
+
}
|
96
|
+
|
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);
|
103
|
+
state.arrowRef = arrowRef; // When this tooltip is visible, hide any other tooltips, and register it
|
104
|
+
// as the visibleTooltip with the TooltipContext.
|
105
|
+
// Also add a listener on document to hide the tooltip if Escape is pressed
|
106
|
+
|
107
|
+
react_utilities_1.useIsomorphicLayoutEffect(() => {
|
108
|
+
var _a;
|
109
|
+
|
110
|
+
if (visible) {
|
111
|
+
const thisTooltip = {
|
112
|
+
hide: () => setVisible(false)
|
113
|
+
};
|
114
|
+
(_a = context.visibleTooltip) === null || _a === void 0 ? void 0 : _a.hide();
|
115
|
+
context.visibleTooltip = thisTooltip;
|
116
|
+
|
117
|
+
const onDocumentKeyDown = ev => {
|
118
|
+
if (ev.key === 'Escape' || ev.key === 'Esc') {
|
119
|
+
thisTooltip.hide();
|
120
|
+
}
|
121
|
+
};
|
122
|
+
|
123
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('keydown', onDocumentKeyDown);
|
124
|
+
return () => {
|
125
|
+
if (context.visibleTooltip === thisTooltip) {
|
126
|
+
context.visibleTooltip = undefined;
|
127
|
+
}
|
128
|
+
|
129
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('keydown', onDocumentKeyDown);
|
130
|
+
};
|
131
|
+
}
|
132
|
+
}, [context, targetDocument, visible, setVisible]); // The focused element gets a blur event when the document loses focus
|
133
|
+
// (e.g. switching tabs in the browser), but we don't want to show the
|
134
|
+
// tooltip again when the document gets focus back. Handle this case by
|
135
|
+
// checking if the blurred element is still the document's activeElement.
|
136
|
+
// See https://github.com/microsoft/fluentui/issues/13541
|
137
|
+
|
138
|
+
const ignoreNextFocusEventRef = React.useRef(false); // Listener for onPointerEnter and onFocus on the trigger element
|
139
|
+
|
140
|
+
const onEnterTrigger = React.useCallback(ev => {
|
141
|
+
if (ev.type === 'focus' && ignoreNextFocusEventRef.current) {
|
142
|
+
ignoreNextFocusEventRef.current = false;
|
143
|
+
return;
|
144
|
+
} // Show immediately if another tooltip is already visible
|
145
|
+
|
146
|
+
|
147
|
+
const delay = context.visibleTooltip ? 0 : state.showDelay;
|
148
|
+
setDelayTimeout(() => {
|
149
|
+
setVisible(true, ev);
|
150
|
+
}, delay);
|
151
|
+
ev.persist(); // Persist the event since the setVisible call will happen asynchronously
|
152
|
+
}, [setDelayTimeout, setVisible, state.showDelay, context]); // Listener for onPointerLeave and onBlur on the trigger element
|
153
|
+
|
154
|
+
const onLeaveTrigger = React.useCallback(ev => {
|
155
|
+
let delay = state.hideDelay;
|
156
|
+
|
157
|
+
if (ev.type === 'blur') {
|
158
|
+
// Hide immediately when losing focus
|
159
|
+
delay = 0;
|
160
|
+
ignoreNextFocusEventRef.current = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) === ev.target;
|
161
|
+
}
|
162
|
+
|
163
|
+
setDelayTimeout(() => {
|
164
|
+
setVisible(false, ev);
|
165
|
+
}, delay);
|
166
|
+
ev.persist(); // Persist the event since the setVisible call will happen asynchronously
|
167
|
+
}, [setDelayTimeout, setVisible, state.hideDelay, targetDocument]); // Cancel the hide timer when the pointer enters the tooltip, and restart it when the mouse leaves.
|
168
|
+
// This keeps the tooltip visible when the pointer is moved over it.
|
169
|
+
|
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 = {};
|
174
|
+
|
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
|
181
|
+
|
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
|
187
|
+
|
188
|
+
state.shouldRenderTooltip = true;
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
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
|
+
});
|
203
|
+
return state;
|
204
|
+
};
|
205
|
+
|
206
|
+
exports.useTooltip_unstable = useTooltip_unstable;
|
207
|
+
//# sourceMappingURL=useTooltip.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["components/Tooltip/useTooltip.tsx"],"names":[],"mappings":";;;;;;;AAAA,MAAA,KAAA,gBAAA,OAAA,CAAA,OAAA,CAAA;;AACA,MAAA,mBAAA,gBAAA,OAAA,CAAA,6BAAA,CAAA;;AACA,MAAA,uBAAA,gBAAA,OAAA,CAAA,iCAAA,CAAA;;AACA,MAAA,iBAAA,gBAAA,OAAA,CAAA,2BAAA,CAAA;;AAaA,MAAA,WAAA,gBAAA,OAAA,CAAA,qBAAA,CAAA;AAEA;;;;;;;AAOG;;;AACI,MAAM,mBAAmB,GAAI,KAAD,IAAsC;;;AACvE,QAAM,OAAO,GAAG,KAAK,CAAC,UAAN,CAAiB,uBAAA,CAAA,cAAjB,CAAhB;AACA,QAAM,kBAAkB,GAAG,iBAAA,CAAA,QAAA,EAA3B;AACA,QAAM;AAAE,IAAA;AAAF,MAAqB,uBAAA,CAAA,SAAA,EAA3B;AACA,QAAM,CAAC,eAAD,EAAkB,iBAAlB,IAAuC,iBAAA,CAAA,UAAA,EAA7C;AAEA,QAAM;AACJ,IAAA,UADI;AAEJ,IAAA,QAFI;AAGJ,IAAA,OAHI;AAIJ,IAAA,SAJI;AAKJ,IAAA,WALI;AAMJ,IAAA,eANI;AAOJ,IAAA,YAPI;AAQJ,IAAA,SAAS,GAAG,GARR;AASJ,IAAA,SAAS,GAAG;AATR,MAUF,KAVJ;AAYA,QAAM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cAAc,EAAE,iBAAA,CAAA,uBAAA,CAAwB,CAAA,EAAA,GAAA,KAAK,KAAA,IAAL,IAAA,KAAK,KAAA,KAAA,CAAL,GAAK,KAAA,CAAL,GAAA,KAAK,CAAE,KAAP,MAAY,IAAZ,IAAY,EAAA,KAAA,KAAA,CAAZ,GAAY,KAAA,CAAZ,GAAY,EAAA,CAAE,cAAtC,EAAsD,cAAtD,CAN0D;AAO1E,IAAA,OAAO,EAAE,iBAAA,CAAA,uBAAA,CAAwB,CAAA,EAAA,GAAA,KAAK,KAAA,IAAL,IAAA,KAAK,KAAA,KAAA,CAAL,GAAK,KAAA,CAAL,GAAA,KAAK,CAAE,KAAP,MAAY,IAAZ,IAAY,EAAA,KAAA,KAAA,CAAZ,GAAY,KAAA,CAAZ,GAAY,EAAA,CAAE,OAAtC,EAA+C,cAA/C,CAPiE;AAQ1E,IAAA,MAAM,EAAE,iBAAA,CAAA,uBAAA,CAAwB,CAAA,EAAA,GAAA,KAAK,KAAA,IAAL,IAAA,KAAK,KAAA,KAAA,CAAL,GAAK,KAAA,CAAL,GAAA,KAAK,CAAE,KAAP,MAAY,IAAZ,IAAY,EAAA,KAAA,KAAA,CAAZ,GAAY,KAAA,CAAZ,GAAY,EAAA,CAAE,MAAtC,EAA8C,cAA9C;AARkE,GAA3D,CAAjB;AAWA,SAAO,KAAP;AACD,CAvMM;;AAAM,OAAA,CAAA,mBAAA,GAAmB,mBAAnB","sourcesContent":["import * as React from 'react';\nimport { mergeArrowOffset, resolvePositioningShorthand, usePopper } from '@fluentui/react-positioning';\nimport { TooltipContext, useFluent } from '@fluentui/react-shared-contexts';\nimport {\n applyTriggerPropsToChildren,\n resolveShorthand,\n useControllableState,\n useMergedEventCallbacks,\n useId,\n useIsomorphicLayoutEffect,\n useIsSSR,\n useMergedRefs,\n useTimeout,\n getTriggerChild,\n} from '@fluentui/react-utilities';\nimport type { TooltipProps, TooltipState, TooltipTriggerProps } from './Tooltip.types';\nimport { arrowHeight, tooltipBorderRadius } from './private/constants';\n\n/**\n * Create the state required to render Tooltip.\n *\n * The returned state can be modified with hooks such as useTooltipStyles_unstable,\n * before being passed to renderTooltip_unstable.\n *\n * @param props - props from this instance of Tooltip\n */\nexport const useTooltip_unstable = (props: TooltipProps): TooltipState => {\n const context = React.useContext(TooltipContext);\n const isServerSideRender = useIsSSR();\n const { targetDocument } = useFluent();\n const [setDelayTimeout, clearDelayTimeout] = useTimeout();\n\n const {\n appearance,\n children,\n content,\n withArrow,\n positioning,\n onVisibleChange,\n relationship,\n showDelay = 250,\n hideDelay = 250,\n } = props;\n\n const [visible, setVisibleInternal] = useControllableState({ state: props.visible, initialState: false });\n const setVisible = React.useCallback(\n (newVisible: boolean, ev?: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement>) => {\n clearDelayTimeout();\n setVisibleInternal(oldVisible => {\n if (newVisible !== oldVisible) {\n onVisibleChange?.(ev, { visible: newVisible });\n }\n return newVisible;\n });\n },\n [clearDelayTimeout, setVisibleInternal, onVisibleChange],\n );\n\n const state: TooltipState = {\n withArrow,\n positioning,\n showDelay,\n hideDelay,\n relationship,\n visible,\n shouldRenderTooltip: visible,\n appearance,\n\n // Slots\n components: {\n content: 'div',\n },\n content: resolveShorthand(content, {\n defaultProps: {\n role: 'tooltip',\n },\n required: true,\n }),\n };\n\n state.content.id = useId('tooltip-', state.content.id);\n\n const popperOptions = {\n enabled: state.visible,\n arrowPadding: 2 * tooltipBorderRadius,\n position: 'above' as const,\n align: 'center' as const,\n offset: [0, 4] as [number, number],\n ...resolvePositioningShorthand(state.positioning),\n };\n\n if (state.withArrow) {\n popperOptions.offset = mergeArrowOffset(popperOptions.offset, arrowHeight);\n }\n\n const {\n targetRef,\n containerRef,\n arrowRef,\n }: {\n targetRef: React.MutableRefObject<unknown>;\n containerRef: React.MutableRefObject<HTMLDivElement>;\n arrowRef: React.MutableRefObject<HTMLDivElement>;\n } = usePopper(popperOptions);\n\n state.content.ref = useMergedRefs(state.content.ref, containerRef);\n state.arrowRef = arrowRef;\n\n // When this tooltip is visible, hide any other tooltips, and register it\n // as the visibleTooltip with the TooltipContext.\n // Also add a listener on document to hide the tooltip if Escape is pressed\n useIsomorphicLayoutEffect(() => {\n if (visible) {\n const thisTooltip = { hide: () => setVisible(false) };\n\n context.visibleTooltip?.hide();\n context.visibleTooltip = thisTooltip;\n\n const onDocumentKeyDown = (ev: KeyboardEvent) => {\n if (ev.key === 'Escape' || ev.key === 'Esc') {\n thisTooltip.hide();\n }\n };\n\n targetDocument?.addEventListener('keydown', onDocumentKeyDown);\n\n return () => {\n if (context.visibleTooltip === thisTooltip) {\n context.visibleTooltip = undefined;\n }\n\n targetDocument?.removeEventListener('keydown', onDocumentKeyDown);\n };\n }\n }, [context, targetDocument, visible, setVisible]);\n\n // The focused element gets a blur event when the document loses focus\n // (e.g. switching tabs in the browser), but we don't want to show the\n // tooltip again when the document gets focus back. Handle this case by\n // checking if the blurred element is still the document's activeElement.\n // See https://github.com/microsoft/fluentui/issues/13541\n const ignoreNextFocusEventRef = React.useRef(false);\n\n // Listener for onPointerEnter and onFocus on the trigger element\n const onEnterTrigger = React.useCallback(\n (ev: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement>) => {\n if (ev.type === 'focus' && ignoreNextFocusEventRef.current) {\n ignoreNextFocusEventRef.current = false;\n return;\n }\n\n // Show immediately if another tooltip is already visible\n const delay = context.visibleTooltip ? 0 : state.showDelay;\n\n setDelayTimeout(() => {\n setVisible(true, ev);\n }, delay);\n\n ev.persist(); // Persist the event since the setVisible call will happen asynchronously\n },\n [setDelayTimeout, setVisible, state.showDelay, context],\n );\n\n // Listener for onPointerLeave and onBlur on the trigger element\n const onLeaveTrigger = React.useCallback(\n (ev: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement>) => {\n let delay = state.hideDelay;\n\n if (ev.type === 'blur') {\n // Hide immediately when losing focus\n delay = 0;\n\n ignoreNextFocusEventRef.current = targetDocument?.activeElement === ev.target;\n }\n\n setDelayTimeout(() => {\n setVisible(false, ev);\n }, delay);\n\n ev.persist(); // Persist the event since the setVisible call will happen asynchronously\n },\n [setDelayTimeout, setVisible, state.hideDelay, targetDocument],\n );\n\n // Cancel the hide timer when the pointer enters the tooltip, and restart it when the mouse leaves.\n // This keeps the tooltip visible when the pointer is moved over it.\n state.content.onPointerEnter = useMergedEventCallbacks(state.content.onPointerEnter, clearDelayTimeout);\n state.content.onPointerLeave = useMergedEventCallbacks(state.content.onPointerLeave, onLeaveTrigger);\n\n const child = React.isValidElement(children) ? getTriggerChild(children) : undefined;\n\n const triggerAriaProps: Pick<TooltipTriggerProps, 'aria-label' | 'aria-labelledby' | 'aria-describedby'> = {};\n\n if (relationship === 'label') {\n // aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.\n if (typeof state.content.children === 'string') {\n triggerAriaProps['aria-label'] = state.content.children;\n } else if (!isServerSideRender) {\n triggerAriaProps['aria-labelledby'] = state.content.id;\n // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element\n state.shouldRenderTooltip = true;\n }\n } else if (relationship === 'description') {\n if (!isServerSideRender) {\n triggerAriaProps['aria-describedby'] = state.content.id;\n // Always render the tooltip even if hidden, so that aria-describedby refers to a valid element\n state.shouldRenderTooltip = true;\n }\n }\n\n const childTargetRef = useMergedRefs(child?.ref, targetRef);\n\n // Apply the trigger props to the child, either by calling the render function, or cloning with the new props\n state.children = applyTriggerPropsToChildren<TooltipTriggerProps>(children, {\n ...triggerAriaProps,\n ...child?.props,\n // If the target prop is not provided, attach targetRef to the trigger element's ref prop\n ref: popperOptions.target === undefined ? childTargetRef : child?.ref,\n onPointerEnter: useMergedEventCallbacks(child?.props?.onPointerEnter, onEnterTrigger),\n onPointerLeave: useMergedEventCallbacks(child?.props?.onPointerLeave, onLeaveTrigger),\n onFocus: useMergedEventCallbacks(child?.props?.onFocus, onEnterTrigger),\n onBlur: useMergedEventCallbacks(child?.props?.onBlur, onLeaveTrigger),\n });\n\n return state;\n};\n"],"sourceRoot":"../src/"}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.useTooltipStyles_unstable = exports.tooltipClassName = void 0;
|
7
|
+
|
8
|
+
const react_1 = /*#__PURE__*/require("@griffel/react");
|
9
|
+
|
10
|
+
const react_positioning_1 = /*#__PURE__*/require("@fluentui/react-positioning");
|
11
|
+
|
12
|
+
const react_theme_1 = /*#__PURE__*/require("@fluentui/react-theme");
|
13
|
+
|
14
|
+
const constants_1 = /*#__PURE__*/require("./private/constants");
|
15
|
+
|
16
|
+
exports.tooltipClassName = 'fui-Tooltip';
|
17
|
+
/**
|
18
|
+
* Styles for the tooltip
|
19
|
+
*/
|
20
|
+
|
21
|
+
const useStyles = /*#__PURE__*/react_1.__styles({
|
22
|
+
"root": {
|
23
|
+
"mc9l5x": "fjseox",
|
24
|
+
"B7ck84d": "f1ewtqcl",
|
25
|
+
"B2u0y6b": "f132xexn",
|
26
|
+
"Bceei9c": "f158kwzp",
|
27
|
+
"Bahqtrf": "fk6fouc",
|
28
|
+
"Be2twd7": "fy9rknc",
|
29
|
+
"Bg96gwp": "fwrc4pm",
|
30
|
+
"Bbmb7ep": ["f1aa9q02", "f16jpd5f"],
|
31
|
+
"Beyfa6y": ["f16jpd5f", "f1aa9q02"],
|
32
|
+
"B7oj6ja": ["f1jar5jt", "fyu767a"],
|
33
|
+
"Btl43ni": ["fyu767a", "f1jar5jt"],
|
34
|
+
"B4j52fo": "f5ogflp",
|
35
|
+
"Bekrc4i": ["f1hqa2wf", "finvdd3"],
|
36
|
+
"Bn0qgzm": "f1f09k3d",
|
37
|
+
"ibv6hh": ["finvdd3", "f1hqa2wf"],
|
38
|
+
"icvyot": "fzkkow9",
|
39
|
+
"vrafjx": ["fcdblym", "fjik90z"],
|
40
|
+
"oivjwe": "fg706s2",
|
41
|
+
"wvpqe5": ["fjik90z", "fcdblym"],
|
42
|
+
"g2u3we": "fghlq4f",
|
43
|
+
"h3c5rm": ["f1gn591s", "fjscplz"],
|
44
|
+
"B9xav0g": "fb073pr",
|
45
|
+
"zhjwy3": ["fjscplz", "f1gn591s"],
|
46
|
+
"z8tnut": "f10ra9hq",
|
47
|
+
"z189sj": ["fd9xhir", "f1jlaasf"],
|
48
|
+
"Byoj8tv": "f1d7kygh",
|
49
|
+
"uwmqm3": ["f1jlaasf", "fd9xhir"],
|
50
|
+
"De3pzq": "fxugw4r",
|
51
|
+
"sj55zd": "f19n0e5",
|
52
|
+
"Bhu2qc9": "fxeb0a7"
|
53
|
+
},
|
54
|
+
"visible": {
|
55
|
+
"mc9l5x": "ftgm304"
|
56
|
+
},
|
57
|
+
"inverted": {
|
58
|
+
"De3pzq": "f5pduvr",
|
59
|
+
"sj55zd": "fqpbvvt"
|
60
|
+
},
|
61
|
+
"arrow": {
|
62
|
+
"qhf8xq": "f1euv43f",
|
63
|
+
"De3pzq": "f1u2r49w",
|
64
|
+
"Bcdw1i0": "fd7fpy0",
|
65
|
+
"Bj3rh1h": "f1bsuimh",
|
66
|
+
"a9b677": "f1ekdpwm",
|
67
|
+
"Bqenvij": "f83vc9z",
|
68
|
+
"rurcny": "fuzzvh5",
|
69
|
+
"Bex5imi": "fkk33zh",
|
70
|
+
"xx9plb": "fxf9f1y",
|
71
|
+
"Bmqnesq": "f170vdtw",
|
72
|
+
"Bdn98qo": "f103af6e",
|
73
|
+
"Bbc2r3f": "f15umuo5",
|
74
|
+
"B1dvbpk": "f3wpjpt",
|
75
|
+
"D4ky5z": "f1k3tce7",
|
76
|
+
"cqycoz": "f1dkdgqi",
|
77
|
+
"I89eb": "f5ghsz",
|
78
|
+
"k1i1uq": "fyqop9u",
|
79
|
+
"Epwjcz": "f1m5ya7j",
|
80
|
+
"Bp1vogq": "f3sp63x",
|
81
|
+
"px8gyy": ["f5bg3dr", "f1rfdd74"],
|
82
|
+
"h6z6rw": "fzd2j21",
|
83
|
+
"hl6cv3": "f1773hnp",
|
84
|
+
"Bh2vraf": "f1n8855c",
|
85
|
+
"yayu3t": "f1v7783n",
|
86
|
+
"wedwtw": "fsw6im5",
|
87
|
+
"rhl9o9": "fh2hsk5",
|
88
|
+
"Bu8t5uz": "f159pzir",
|
89
|
+
"B6q6orb": "f11yvu4",
|
90
|
+
"Bwwlvwl": "fm1ycve"
|
91
|
+
}
|
92
|
+
}, {
|
93
|
+
"d": [".fjseox{display:none;}", ".f1ewtqcl{box-sizing:border-box;}", ".f132xexn{max-width:240px;}", ".f158kwzp{cursor:default;}", ".fk6fouc{font-family:var(--fontFamilyBase);}", ".fy9rknc{font-size:var(--fontSizeBase200);}", ".fwrc4pm{line-height:var(--lineHeightBase200);}", ".f1aa9q02{border-bottom-right-radius:var(--borderRadiusMedium);}", ".f16jpd5f{border-bottom-left-radius:var(--borderRadiusMedium);}", ".f1jar5jt{border-top-right-radius:var(--borderRadiusMedium);}", ".fyu767a{border-top-left-radius:var(--borderRadiusMedium);}", ".f5ogflp{border-top-width:1px;}", ".f1hqa2wf{border-right-width:1px;}", ".finvdd3{border-left-width:1px;}", ".f1f09k3d{border-bottom-width:1px;}", ".fzkkow9{border-top-style:solid;}", ".fcdblym{border-right-style:solid;}", ".fjik90z{border-left-style:solid;}", ".fg706s2{border-bottom-style:solid;}", ".fghlq4f{border-top-color:var(--colorTransparentStroke);}", ".f1gn591s{border-right-color:var(--colorTransparentStroke);}", ".fjscplz{border-left-color:var(--colorTransparentStroke);}", ".fb073pr{border-bottom-color:var(--colorTransparentStroke);}", ".f10ra9hq{padding-top:4px;}", ".fd9xhir{padding-right:11px;}", ".f1jlaasf{padding-left:11px;}", ".f1d7kygh{padding-bottom:6px;}", ".fxugw4r{background-color:var(--colorNeutralBackground1);}", ".f19n0e5{color:var(--colorNeutralForeground1);}", ".fxeb0a7{-webkit-filter:drop-shadow(0 0 2px var(--colorNeutralShadowAmbient)) drop-shadow(0 4px 8px var(--colorNeutralShadowKey));filter:drop-shadow(0 0 2px var(--colorNeutralShadowAmbient)) drop-shadow(0 4px 8px var(--colorNeutralShadowKey));}", ".ftgm304{display:block;}", ".f5pduvr{background-color:var(--colorNeutralBackgroundInverted);}", ".fqpbvvt{color:var(--colorNeutralForegroundInverted);}", ".f1euv43f{position:absolute;}", ".f1u2r49w{background-color:inherit;}", ".fd7fpy0{visibility:hidden;}", ".f1bsuimh{z-index:-1;}", ".f1ekdpwm{width:8.484px;}", ".f83vc9z{height:8.484px;}", ".fuzzvh5:before{content:\"\";}", ".fkk33zh:before{visibility:visible;}", ".fxf9f1y:before{position:absolute;}", ".f170vdtw:before{box-sizing:border-box;}", ".f103af6e:before{width:inherit;}", ".f15umuo5:before{height:inherit;}", ".f3wpjpt:before{background-color:inherit;}", ".f1k3tce7:before{border-right-width:1px;}", ".f1dkdgqi:before{border-right-style:solid;}", ".f5ghsz:before{border-right-color:var(--colorTransparentStroke);}", ".fyqop9u:before{border-bottom-width:1px;}", ".f1m5ya7j:before{border-bottom-style:solid;}", ".f3sp63x:before{border-bottom-color:var(--colorTransparentStroke);}", ".f5bg3dr:before{border-bottom-right-radius:var(--borderRadiusSmall);}", ".f1rfdd74:before{border-bottom-left-radius:var(--borderRadiusSmall);}", ".fzd2j21:before{-webkit-transform:rotate(var(--angle)) translate(0, 50%) rotate(45deg);-moz-transform:rotate(var(--angle)) translate(0, 50%) rotate(45deg);-ms-transform:rotate(var(--angle)) translate(0, 50%) rotate(45deg);transform:rotate(var(--angle)) translate(0, 50%) rotate(45deg);}", "[data-popper-placement^=\"top\"] .f1773hnp{bottom:-1px;}", "[data-popper-placement^=\"top\"] .f1n8855c{--angle:0;}", "[data-popper-placement^=\"right\"] .f1v7783n{left:-1px;}", "[data-popper-placement^=\"right\"] .fsw6im5{--angle:90deg;}", "[data-popper-placement^=\"bottom\"] .fh2hsk5{top:-1px;}", "[data-popper-placement^=\"bottom\"] .f159pzir{--angle:180deg;}", "[data-popper-placement^=\"left\"] .f11yvu4{right:-1px;}", "[data-popper-placement^=\"left\"] .fm1ycve{--angle:270deg;}"]
|
94
|
+
});
|
95
|
+
/**
|
96
|
+
* Apply styling to the Tooltip slots based on the state
|
97
|
+
*/
|
98
|
+
|
99
|
+
|
100
|
+
const useTooltipStyles_unstable = state => {
|
101
|
+
const styles = useStyles();
|
102
|
+
state.content.className = react_1.mergeClasses(exports.tooltipClassName, styles.root, state.appearance === 'inverted' && styles.inverted, state.visible && styles.visible, state.content.className);
|
103
|
+
state.arrowClassName = styles.arrow;
|
104
|
+
return state;
|
105
|
+
};
|
106
|
+
|
107
|
+
exports.useTooltipStyles_unstable = useTooltipStyles_unstable;
|
108
|
+
//# sourceMappingURL=useTooltipStyles.js.map
|