@fluentui/react-tooltip 0.0.0-nightly-20230317-0436.1 → 0.0.0-nightly-20230317-1454.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.
Files changed (40) hide show
  1. package/.swcrc +39 -0
  2. package/CHANGELOG.json +17 -17
  3. package/CHANGELOG.md +11 -11
  4. package/lib/Tooltip.js +1 -1
  5. package/lib/Tooltip.js.map +1 -1
  6. package/lib/components/Tooltip/Tooltip.js +6 -5
  7. package/lib/components/Tooltip/Tooltip.js.map +1 -1
  8. package/lib/components/Tooltip/Tooltip.types.js +1 -1
  9. package/lib/components/Tooltip/Tooltip.types.js.map +1 -1
  10. package/lib/components/Tooltip/index.js +5 -5
  11. package/lib/components/Tooltip/index.js.map +1 -1
  12. package/lib/components/Tooltip/private/constants.js +1 -2
  13. package/lib/components/Tooltip/private/constants.js.map +1 -1
  14. package/lib/components/Tooltip/renderTooltip.js +4 -6
  15. package/lib/components/Tooltip/renderTooltip.js.map +1 -1
  16. package/lib/components/Tooltip/useTooltip.js +33 -35
  17. package/lib/components/Tooltip/useTooltip.js.map +1 -1
  18. package/lib/components/Tooltip/useTooltipStyles.js +6 -6
  19. package/lib/components/Tooltip/useTooltipStyles.js.map +1 -1
  20. package/lib/index.js +1 -1
  21. package/lib/index.js.map +1 -1
  22. package/lib-commonjs/Tooltip.js +5 -4
  23. package/lib-commonjs/Tooltip.js.map +1 -1
  24. package/lib-commonjs/components/Tooltip/Tooltip.js +20 -21
  25. package/lib-commonjs/components/Tooltip/Tooltip.js.map +1 -1
  26. package/lib-commonjs/components/Tooltip/Tooltip.types.js +5 -2
  27. package/lib-commonjs/components/Tooltip/Tooltip.types.js.map +1 -1
  28. package/lib-commonjs/components/Tooltip/index.js +9 -8
  29. package/lib-commonjs/components/Tooltip/index.js.map +1 -1
  30. package/lib-commonjs/components/Tooltip/private/constants.js +17 -16
  31. package/lib-commonjs/components/Tooltip/private/constants.js.map +1 -1
  32. package/lib-commonjs/components/Tooltip/renderTooltip.js +19 -24
  33. package/lib-commonjs/components/Tooltip/renderTooltip.js.map +1 -1
  34. package/lib-commonjs/components/Tooltip/useTooltip.js +189 -194
  35. package/lib-commonjs/components/Tooltip/useTooltip.js.map +1 -1
  36. package/lib-commonjs/components/Tooltip/useTooltipStyles.js +200 -92
  37. package/lib-commonjs/components/Tooltip/useTooltipStyles.js.map +1 -1
  38. package/lib-commonjs/index.js +16 -33
  39. package/lib-commonjs/index.js.map +1 -1
  40. package/package.json +10 -10
package/.swcrc ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/swcrc",
3
+ "env": {
4
+ "targets": {
5
+ "chrome": "84",
6
+ "edge": "84",
7
+ "firefox": "75",
8
+ "opera": "73",
9
+ "safari": "14.1"
10
+ },
11
+ "bugfixes": true
12
+ },
13
+ "exclude": [
14
+ "/testing",
15
+ "/**/*.cy.ts",
16
+ "/**/*.cy.tsx",
17
+ "/**/*.spec.ts",
18
+ "/**/*.spec.tsx",
19
+ "/**/*.test.ts",
20
+ "/**/*.test.tsx"
21
+ ],
22
+ "jsc": {
23
+ "parser": {
24
+ "syntax": "typescript",
25
+ "tsx": true,
26
+ "decorators": false,
27
+ "dynamicImport": false
28
+ },
29
+ "externalHelpers": true,
30
+ "transform": {
31
+ "react": {
32
+ "runtime": "classic",
33
+ "useSpread": true
34
+ }
35
+ }
36
+ },
37
+ "minify": false,
38
+ "sourceMaps": true
39
+ }
package/CHANGELOG.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@fluentui/react-tooltip",
3
3
  "entries": [
4
4
  {
5
- "date": "Fri, 17 Mar 2023 04:44:04 GMT",
6
- "tag": "@fluentui/react-tooltip_v0.0.0-nightly-20230317-0436.1",
7
- "version": "0.0.0-nightly-20230317-0436.1",
5
+ "date": "Fri, 17 Mar 2023 15:00:08 GMT",
6
+ "tag": "@fluentui/react-tooltip_v0.0.0-nightly-20230317-1454.1",
7
+ "version": "0.0.0-nightly-20230317-1454.1",
8
8
  "comments": {
9
9
  "prerelease": [
10
10
  {
@@ -16,44 +16,44 @@
16
16
  {
17
17
  "author": "beachball",
18
18
  "package": "@fluentui/react-tooltip",
19
- "comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly-20230317-0436.1",
20
- "commit": "83781b613de20e14968f5f85d52f6836ee4c899f"
19
+ "comment": "Bump @fluentui/keyboard-keys to v0.0.0-nightly-20230317-1454.1",
20
+ "commit": "636275472966fa37b1efc14ac2e70ad32bd39b86"
21
21
  },
22
22
  {
23
23
  "author": "beachball",
24
24
  "package": "@fluentui/react-tooltip",
25
- "comment": "Bump @fluentui/react-portal to v0.0.0-nightly-20230317-0436.1",
26
- "commit": "83781b613de20e14968f5f85d52f6836ee4c899f"
25
+ "comment": "Bump @fluentui/react-portal to v0.0.0-nightly-20230317-1454.1",
26
+ "commit": "636275472966fa37b1efc14ac2e70ad32bd39b86"
27
27
  },
28
28
  {
29
29
  "author": "beachball",
30
30
  "package": "@fluentui/react-tooltip",
31
- "comment": "Bump @fluentui/react-positioning to v0.0.0-nightly-20230317-0436.1",
32
- "commit": "83781b613de20e14968f5f85d52f6836ee4c899f"
31
+ "comment": "Bump @fluentui/react-positioning to v0.0.0-nightly-20230317-1454.1",
32
+ "commit": "636275472966fa37b1efc14ac2e70ad32bd39b86"
33
33
  },
34
34
  {
35
35
  "author": "beachball",
36
36
  "package": "@fluentui/react-tooltip",
37
- "comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230317-0436.1",
38
- "commit": "83781b613de20e14968f5f85d52f6836ee4c899f"
37
+ "comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230317-1454.1",
38
+ "commit": "636275472966fa37b1efc14ac2e70ad32bd39b86"
39
39
  },
40
40
  {
41
41
  "author": "beachball",
42
42
  "package": "@fluentui/react-tooltip",
43
- "comment": "Bump @fluentui/react-theme to v0.0.0-nightly-20230317-0436.1",
44
- "commit": "83781b613de20e14968f5f85d52f6836ee4c899f"
43
+ "comment": "Bump @fluentui/react-theme to v0.0.0-nightly-20230317-1454.1",
44
+ "commit": "636275472966fa37b1efc14ac2e70ad32bd39b86"
45
45
  },
46
46
  {
47
47
  "author": "beachball",
48
48
  "package": "@fluentui/react-tooltip",
49
- "comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230317-0436.1",
50
- "commit": "83781b613de20e14968f5f85d52f6836ee4c899f"
49
+ "comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230317-1454.1",
50
+ "commit": "636275472966fa37b1efc14ac2e70ad32bd39b86"
51
51
  },
52
52
  {
53
53
  "author": "beachball",
54
54
  "package": "@fluentui/react-tooltip",
55
- "comment": "Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20230317-0436.1",
56
- "commit": "83781b613de20e14968f5f85d52f6836ee4c899f"
55
+ "comment": "Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20230317-1454.1",
56
+ "commit": "636275472966fa37b1efc14ac2e70ad32bd39b86"
57
57
  }
58
58
  ]
59
59
  }
package/CHANGELOG.md CHANGED
@@ -1,24 +1,24 @@
1
1
  # Change Log - @fluentui/react-tooltip
2
2
 
3
- This log was last generated on Fri, 17 Mar 2023 04:44:04 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 17 Mar 2023 15:00:08 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightly-20230317-0436.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-tooltip_v0.0.0-nightly-20230317-0436.1)
7
+ ## [0.0.0-nightly-20230317-1454.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-tooltip_v0.0.0-nightly-20230317-1454.1)
8
8
 
9
- Fri, 17 Mar 2023 04:44:04 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tooltip_v9.2.4..@fluentui/react-tooltip_v0.0.0-nightly-20230317-0436.1)
9
+ Fri, 17 Mar 2023 15:00:08 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-tooltip_v9.2.4..@fluentui/react-tooltip_v0.0.0-nightly-20230317-1454.1)
11
11
 
12
12
  ### Changes
13
13
 
14
14
  - Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
15
- - Bump @fluentui/keyboard-keys to v0.0.0-nightly-20230317-0436.1 ([commit](https://github.com/microsoft/fluentui/commit/83781b613de20e14968f5f85d52f6836ee4c899f) by beachball)
16
- - Bump @fluentui/react-portal to v0.0.0-nightly-20230317-0436.1 ([commit](https://github.com/microsoft/fluentui/commit/83781b613de20e14968f5f85d52f6836ee4c899f) by beachball)
17
- - Bump @fluentui/react-positioning to v0.0.0-nightly-20230317-0436.1 ([commit](https://github.com/microsoft/fluentui/commit/83781b613de20e14968f5f85d52f6836ee4c899f) by beachball)
18
- - Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230317-0436.1 ([commit](https://github.com/microsoft/fluentui/commit/83781b613de20e14968f5f85d52f6836ee4c899f) by beachball)
19
- - Bump @fluentui/react-theme to v0.0.0-nightly-20230317-0436.1 ([commit](https://github.com/microsoft/fluentui/commit/83781b613de20e14968f5f85d52f6836ee4c899f) by beachball)
20
- - Bump @fluentui/react-utilities to v0.0.0-nightly-20230317-0436.1 ([commit](https://github.com/microsoft/fluentui/commit/83781b613de20e14968f5f85d52f6836ee4c899f) by beachball)
21
- - Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20230317-0436.1 ([commit](https://github.com/microsoft/fluentui/commit/83781b613de20e14968f5f85d52f6836ee4c899f) by beachball)
15
+ - Bump @fluentui/keyboard-keys to v0.0.0-nightly-20230317-1454.1 ([commit](https://github.com/microsoft/fluentui/commit/636275472966fa37b1efc14ac2e70ad32bd39b86) by beachball)
16
+ - Bump @fluentui/react-portal to v0.0.0-nightly-20230317-1454.1 ([commit](https://github.com/microsoft/fluentui/commit/636275472966fa37b1efc14ac2e70ad32bd39b86) by beachball)
17
+ - Bump @fluentui/react-positioning to v0.0.0-nightly-20230317-1454.1 ([commit](https://github.com/microsoft/fluentui/commit/636275472966fa37b1efc14ac2e70ad32bd39b86) by beachball)
18
+ - Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230317-1454.1 ([commit](https://github.com/microsoft/fluentui/commit/636275472966fa37b1efc14ac2e70ad32bd39b86) by beachball)
19
+ - Bump @fluentui/react-theme to v0.0.0-nightly-20230317-1454.1 ([commit](https://github.com/microsoft/fluentui/commit/636275472966fa37b1efc14ac2e70ad32bd39b86) by beachball)
20
+ - Bump @fluentui/react-utilities to v0.0.0-nightly-20230317-1454.1 ([commit](https://github.com/microsoft/fluentui/commit/636275472966fa37b1efc14ac2e70ad32bd39b86) by beachball)
21
+ - Bump @fluentui/react-conformance-griffel to v0.0.0-nightly-20230317-1454.1 ([commit](https://github.com/microsoft/fluentui/commit/636275472966fa37b1efc14ac2e70ad32bd39b86) by beachball)
22
22
 
23
23
  ## [9.2.4](https://github.com/microsoft/fluentui/tree/@fluentui/react-tooltip_v9.2.4)
24
24
 
package/lib/Tooltip.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from './components/Tooltip/index';
1
+ export * from "./components/Tooltip/index";
2
2
  //# sourceMappingURL=Tooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-tooltip/src/Tooltip.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC","sourcesContent":["export * from './components/Tooltip/index';\n"]}
1
+ {"version":3,"names":[],"sources":["../src/Tooltip.ts"],"sourcesContent":["export * from './components/Tooltip/index';\n"],"mappings":"AAAA,cAAc"}
@@ -1,7 +1,8 @@
1
- import { useTooltip_unstable } from './useTooltip';
2
- import { renderTooltip_unstable } from './renderTooltip';
3
- import { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts';
4
- import { useTooltipStyles_unstable } from './useTooltipStyles';
1
+ import * as React from "react";
2
+ import { useTooltip_unstable } from "./useTooltip";
3
+ import { renderTooltip_unstable } from "./renderTooltip";
4
+ import { useCustomStyleHooks_unstable } from "@fluentui/react-shared-contexts";
5
+ import { useTooltipStyles_unstable } from "./useTooltipStyles";
5
6
  /**
6
7
  * A tooltip provides light weight contextual information on top of its target element.
7
8
  */
@@ -14,7 +15,7 @@ export const Tooltip = props => {
14
15
  useCustomStyles(state);
15
16
  return renderTooltip_unstable(state);
16
17
  };
17
- Tooltip.displayName = 'Tooltip';
18
+ Tooltip.displayName = "Tooltip";
18
19
  // type casting here is required to ensure internal type FluentTriggerComponent is not leaked
19
20
  Tooltip.isFluentTriggerComponent = true;
20
21
  //# sourceMappingURL=Tooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useTooltip_unstable","renderTooltip_unstable","useCustomStyleHooks_unstable","useTooltipStyles_unstable","Tooltip","props","state","useCustomStyles","displayName","isFluentTriggerComponent"],"sources":["../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useTooltip_unstable } from './useTooltip';\nimport { renderTooltip_unstable } from './renderTooltip';\nimport { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts';\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> = props => {\n const state = useTooltip_unstable(props);\n\n useTooltipStyles_unstable(state);\n\n const { useTooltipStyles_unstable: useCustomStyles } = useCustomStyleHooks_unstable();\n useCustomStyles(state);\n\n return renderTooltip_unstable(state);\n};\n\nTooltip.displayName = 'Tooltip';\n// type casting here is required to ensure internal type FluentTriggerComponent is not leaked\n(Tooltip as FluentTriggerComponent).isFluentTriggerComponent = true;\n"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,cAAc;AAClD,SAASC,sBAAsB,QAAQ,iBAAiB;AACxD,SAASC,4BAA4B,QAAQ,iCAAiC;AAC9E,SAASC,yBAAyB,QAAQ,oBAAoB;AAI9D;;;AAGA,OAAO,MAAMC,OAAO,GAA2BC,KAAK,IAAG;EACrD,MAAMC,KAAK,GAAGN,mBAAmB,CAACK,KAAK,CAAC;EAExCF,yBAAyB,CAACG,KAAK,CAAC;EAEhC,MAAM;IAAEH,yBAAyB,EAAEI;EAAe,CAAE,GAAGL,4BAA4B,EAAE;EACrFK,eAAe,CAACD,KAAK,CAAC;EAEtB,OAAOL,sBAAsB,CAACK,KAAK,CAAC;AACtC,CAAC;AAEDF,OAAO,CAACI,WAAW,GAAG,SAAS;AAC/B;AACCJ,OAAkC,CAACK,wBAAwB,GAAG,IAAI"}
1
+ {"version":3,"names":["React","useTooltip_unstable","renderTooltip_unstable","useCustomStyleHooks_unstable","useTooltipStyles_unstable","Tooltip","props","state","useCustomStyles","displayName","isFluentTriggerComponent"],"sources":["../../../src/components/Tooltip/Tooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { useTooltip_unstable } from './useTooltip';\nimport { renderTooltip_unstable } from './renderTooltip';\nimport { useCustomStyleHooks_unstable } from '@fluentui/react-shared-contexts';\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> = props => {\n const state = useTooltip_unstable(props);\n\n useTooltipStyles_unstable(state);\n\n const { useTooltipStyles_unstable: useCustomStyles } = useCustomStyleHooks_unstable();\n useCustomStyles(state);\n\n return renderTooltip_unstable(state);\n};\n\nTooltip.displayName = 'Tooltip';\n// type casting here is required to ensure internal type FluentTriggerComponent is not leaked\n(Tooltip as FluentTriggerComponent).isFluentTriggerComponent = true;\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,mBAAmB,QAAQ;AACpC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,4BAA4B,QAAQ;AAC7C,SAASC,yBAAyB,QAAQ;AAI1C;;;AAGA,OAAO,MAAMC,OAAA,GAAkCC,KAAA,IAAS;EACtD,MAAMC,KAAA,GAAQN,mBAAA,CAAoBK,KAAA;EAElCF,yBAAA,CAA0BG,KAAA;EAE1B,MAAM;IAAEH,yBAAA,EAA2BI;EAAe,CAAE,GAAGL,4BAAA;EACvDK,eAAA,CAAgBD,KAAA;EAEhB,OAAOL,sBAAA,CAAuBK,KAAA;AAChC;AAEAF,OAAA,CAAQI,WAAW,GAAG;AACtB;AACCJ,OAAA,CAAmCK,wBAAwB,GAAG,IAAI"}
@@ -1,2 +1,2 @@
1
- export {};
1
+ import * as React from "react";
2
2
  //# sourceMappingURL=Tooltip.types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.types.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/Tooltip.types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\nimport type { PositioningShorthand } from '@fluentui/react-positioning';\nimport type { ComponentProps, ComponentState, Slot, TriggerProps } from '@fluentui/react-utilities';\nimport type { PortalProps } from '@fluentui/react-portal';\n\n/**\n * Slot properties for Tooltip\n */\nexport type TooltipSlots = {\n /**\n * The text or JSX content of the tooltip.\n */\n content: NonNullable<Slot<'div'>>;\n};\n\n/**\n * The properties that are added to the child of the Tooltip\n */\nexport type TooltipChildProps = {\n ref?: React.Ref<unknown>;\n} & Pick<\n React.HTMLAttributes<HTMLElement>,\n 'aria-describedby' | 'aria-label' | 'aria-labelledby' | 'onBlur' | 'onFocus' | 'onPointerEnter' | 'onPointerLeave'\n>;\n\n/**\n * Data for the Tooltip's onVisibleChange event.\n */\nexport type OnVisibleChangeData = {\n visible: boolean;\n};\n\n/**\n * Properties for Tooltip\n */\nexport type TooltipProps = ComponentProps<TooltipSlots> &\n TriggerProps<TooltipChildProps> &\n Pick<PortalProps, 'mountNode'> & {\n /**\n * The tooltip's visual appearance.\n * * `normal` - Uses the theme's background and text colors.\n * * `inverted` - Higher contrast variant that uses the theme's inverted colors.\n *\n * @default normal\n */\n appearance?: 'normal' | 'inverted';\n /**\n * Delay before the tooltip is hidden, in milliseconds.\n *\n * @default 250\n */\n hideDelay?: number;\n\n /**\n * Notification when the visibility of the tooltip is changing\n */\n onVisibleChange?: (\n event: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement> | undefined,\n data: OnVisibleChangeData,\n ) => void;\n\n /**\n * Configure the positioning of the tooltip\n *\n * @default above\n */\n positioning?: PositioningShorthand;\n\n /**\n * (Required) Specifies whether this tooltip is acting as the description or label of its trigger element.\n *\n * * `label` - The tooltip sets the trigger's aria-label or aria-labelledby attribute. This is useful for buttons\n * displaying only an icon, for example.\n * * `description` - The tooltip sets the trigger's aria-description or aria-describedby attribute.\n * * `inaccessible` - No aria attributes are set on the trigger. This makes the tooltip's content inaccessible to\n * screen readers, and should only be used if the tooltip's text is available by some other means.\n */\n relationship: 'label' | 'description' | 'inaccessible';\n\n /**\n * Delay before the tooltip is shown, in milliseconds.\n *\n * @default 250\n */\n showDelay?: number;\n\n /**\n * Control the tooltip's visibility programatically.\n *\n * This can be used in conjunction with onVisibleChange to modify the tooltip's show and hide behavior.\n *\n * If not provided, the visibility will be controlled by the tooltip itself, based on hover and focus events on the\n * trigger (child) element.\n *\n * @default false\n */\n visible?: boolean;\n\n /**\n * Render an arrow pointing to the target element\n *\n * @default false\n */\n withArrow?: boolean;\n };\n\n/**\n * State used in rendering Tooltip\n */\nexport type TooltipState = ComponentState<TooltipSlots> &\n Pick<TooltipProps, 'mountNode' | 'relationship'> &\n Required<Pick<TooltipProps, 'appearance' | 'hideDelay' | 'positioning' | 'showDelay' | 'visible' | 'withArrow'>> & {\n children?: React.ReactElement | null;\n\n /**\n * Whether the tooltip should be rendered to the DOM.\n */\n shouldRenderTooltip?: boolean;\n\n /**\n * Ref to the arrow element\n */\n arrowRef?: React.Ref<HTMLDivElement>;\n\n /**\n * CSS class for the arrow element\n */\n arrowClassName?: string;\n };\n"]}
1
+ {"version":3,"names":["React"],"sources":["../../../src/components/Tooltip/Tooltip.types.ts"],"sourcesContent":["import * as React from 'react';\nimport type { PositioningShorthand } from '@fluentui/react-positioning';\nimport type { ComponentProps, ComponentState, Slot, TriggerProps } from '@fluentui/react-utilities';\nimport type { PortalProps } from '@fluentui/react-portal';\n\n/**\n * Slot properties for Tooltip\n */\nexport type TooltipSlots = {\n /**\n * The text or JSX content of the tooltip.\n */\n content: NonNullable<Slot<'div'>>;\n};\n\n/**\n * The properties that are added to the child of the Tooltip\n */\nexport type TooltipChildProps = {\n ref?: React.Ref<unknown>;\n} & Pick<\n React.HTMLAttributes<HTMLElement>,\n 'aria-describedby' | 'aria-label' | 'aria-labelledby' | 'onBlur' | 'onFocus' | 'onPointerEnter' | 'onPointerLeave'\n>;\n\n/**\n * Data for the Tooltip's onVisibleChange event.\n */\nexport type OnVisibleChangeData = {\n visible: boolean;\n};\n\n/**\n * Properties for Tooltip\n */\nexport type TooltipProps = ComponentProps<TooltipSlots> &\n TriggerProps<TooltipChildProps> &\n Pick<PortalProps, 'mountNode'> & {\n /**\n * The tooltip's visual appearance.\n * * `normal` - Uses the theme's background and text colors.\n * * `inverted` - Higher contrast variant that uses the theme's inverted colors.\n *\n * @default normal\n */\n appearance?: 'normal' | 'inverted';\n /**\n * Delay before the tooltip is hidden, in milliseconds.\n *\n * @default 250\n */\n hideDelay?: number;\n\n /**\n * Notification when the visibility of the tooltip is changing\n */\n onVisibleChange?: (\n event: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement> | undefined,\n data: OnVisibleChangeData,\n ) => void;\n\n /**\n * Configure the positioning of the tooltip\n *\n * @default above\n */\n positioning?: PositioningShorthand;\n\n /**\n * (Required) Specifies whether this tooltip is acting as the description or label of its trigger element.\n *\n * * `label` - The tooltip sets the trigger's aria-label or aria-labelledby attribute. This is useful for buttons\n * displaying only an icon, for example.\n * * `description` - The tooltip sets the trigger's aria-description or aria-describedby attribute.\n * * `inaccessible` - No aria attributes are set on the trigger. This makes the tooltip's content inaccessible to\n * screen readers, and should only be used if the tooltip's text is available by some other means.\n */\n relationship: 'label' | 'description' | 'inaccessible';\n\n /**\n * Delay before the tooltip is shown, in milliseconds.\n *\n * @default 250\n */\n showDelay?: number;\n\n /**\n * Control the tooltip's visibility programatically.\n *\n * This can be used in conjunction with onVisibleChange to modify the tooltip's show and hide behavior.\n *\n * If not provided, the visibility will be controlled by the tooltip itself, based on hover and focus events on the\n * trigger (child) element.\n *\n * @default false\n */\n visible?: boolean;\n\n /**\n * Render an arrow pointing to the target element\n *\n * @default false\n */\n withArrow?: boolean;\n };\n\n/**\n * State used in rendering Tooltip\n */\nexport type TooltipState = ComponentState<TooltipSlots> &\n Pick<TooltipProps, 'mountNode' | 'relationship'> &\n Required<Pick<TooltipProps, 'appearance' | 'hideDelay' | 'positioning' | 'showDelay' | 'visible' | 'withArrow'>> & {\n children?: React.ReactElement | null;\n\n /**\n * Whether the tooltip should be rendered to the DOM.\n */\n shouldRenderTooltip?: boolean;\n\n /**\n * Ref to the arrow element\n */\n arrowRef?: React.Ref<HTMLDivElement>;\n\n /**\n * CSS class for the arrow element\n */\n arrowClassName?: string;\n };\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW"}
@@ -1,6 +1,6 @@
1
- export * from './Tooltip';
2
- export * from './Tooltip.types';
3
- export * from './renderTooltip';
4
- export * from './useTooltip';
5
- export * from './useTooltipStyles';
1
+ export * from "./Tooltip";
2
+ export * from "./Tooltip.types";
3
+ export * from "./renderTooltip";
4
+ export * from "./useTooltip";
5
+ export * from "./useTooltipStyles";
6
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC","sourcesContent":["export * from './Tooltip';\nexport * from './Tooltip.types';\nexport * from './renderTooltip';\nexport * from './useTooltip';\nexport * from './useTooltipStyles';\n"]}
1
+ {"version":3,"names":[],"sources":["../../../src/components/Tooltip/index.ts"],"sourcesContent":["export * from './Tooltip';\nexport * from './Tooltip.types';\nexport * from './renderTooltip';\nexport * from './useTooltip';\nexport * from './useTooltipStyles';\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc"}
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * The height of the tooltip's arrow in pixels.
3
- */
4
- export const arrowHeight = 6;
3
+ */export const arrowHeight = 6;
5
4
  /**
6
5
  * The default value of the tooltip's border radius (borderRadiusMedium).
7
6
  *
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/private/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AAE7B;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC","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"]}
1
+ {"version":3,"names":["arrowHeight","tooltipBorderRadius"],"sources":["../../../../src/components/Tooltip/private/constants.ts"],"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"],"mappings":"AAAA;;GAGA,OAAO,MAAMA,WAAA,GAAc;AAE3B;;;;;;;AAOA,OAAO,MAAMC,mBAAA,GAAsB"}
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
2
- import { Portal } from '@fluentui/react-portal';
3
- import { getSlots } from '@fluentui/react-utilities';
1
+ import * as React from "react";
2
+ import { Portal } from "@fluentui/react-portal";
3
+ import { getSlots } from "@fluentui/react-utilities";
4
4
  /**
5
5
  * Render the final JSX of Tooltip
6
6
  */
@@ -11,9 +11,7 @@ export const renderTooltip_unstable = state => {
11
11
  } = getSlots(state);
12
12
  return /*#__PURE__*/React.createElement(React.Fragment, null, state.children, state.shouldRenderTooltip && /*#__PURE__*/React.createElement(Portal, {
13
13
  mountNode: state.mountNode
14
- }, /*#__PURE__*/React.createElement(slots.content, {
15
- ...slotProps.content
16
- }, state.withArrow && /*#__PURE__*/React.createElement("div", {
14
+ }, /*#__PURE__*/React.createElement(slots.content, slotProps.content, state.withArrow && /*#__PURE__*/React.createElement("div", {
17
15
  ref: state.arrowRef,
18
16
  className: state.arrowClassName
19
17
  }), state.content.children)));
@@ -1 +1 @@
1
- {"version":3,"names":["React","Portal","getSlots","renderTooltip_unstable","state","slots","slotProps","createElement","Fragment","children","shouldRenderTooltip","mountNode","content","withArrow","ref","arrowRef","className","arrowClassName"],"sources":["../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/renderTooltip.tsx"],"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 mountNode={state.mountNode}>\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"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,MAAM,QAAQ,wBAAwB;AAC/C,SAASC,QAAQ,QAAQ,2BAA2B;AAGpD;;;AAGA,OAAO,MAAMC,sBAAsB,GAAIC,KAAmB,IAAI;EAC5D,MAAM;IAAEC,KAAK;IAAEC;EAAS,CAAE,GAAGJ,QAAQ,CAAeE,KAAK,CAAC;EAE1D,oBACEJ,KAAA,CAAAO,aAAA,CAAAP,KAAA,CAAAQ,QAAA,QACGJ,KAAK,CAACK,QAAQ,EACdL,KAAK,CAACM,mBAAmB,iBACxBV,KAAA,CAAAO,aAAA,CAACN,MAAM;IAACU,SAAS,EAAEP,KAAK,CAACO;EAAS,gBAChCX,KAAA,CAAAO,aAAA,CAACF,KAAK,CAACO,OAAO;IAAA,GAAKN,SAAS,CAACM;EAAO,GACjCR,KAAK,CAACS,SAAS,iBAAIb,KAAA,CAAAO,aAAA;IAAKO,GAAG,EAAEV,KAAK,CAACW,QAAQ;IAAEC,SAAS,EAAEZ,KAAK,CAACa;EAAc,EAAI,EAChFb,KAAK,CAACQ,OAAO,CAACH,QAAQ,CACT,CAEnB,CACA;AAEP,CAAC"}
1
+ {"version":3,"names":["React","Portal","getSlots","renderTooltip_unstable","state","slots","slotProps","createElement","Fragment","children","shouldRenderTooltip","mountNode","content","withArrow","ref","arrowRef","className","arrowClassName"],"sources":["../../../src/components/Tooltip/renderTooltip.tsx"],"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 mountNode={state.mountNode}>\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"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,MAAM,QAAQ;AACvB,SAASC,QAAQ,QAAQ;AAGzB;;;AAGA,OAAO,MAAMC,sBAAA,GAA0BC,KAAA,IAAwB;EAC7D,MAAM;IAAEC,KAAA;IAAOC;EAAS,CAAE,GAAGJ,QAAA,CAAuBE,KAAA;EAEpD,oBACEJ,KAAA,CAAAO,aAAA,CAAAP,KAAA,CAAAQ,QAAA,QACGJ,KAAA,CAAMK,QAAQ,EACdL,KAAA,CAAMM,mBAAmB,iBACxBV,KAAA,CAAAO,aAAA,CAACN,MAAA;IAAOU,SAAA,EAAWP,KAAA,CAAMO;kBACvBX,KAAA,CAAAO,aAAA,CAACF,KAAA,CAAMO,OAAO,EAAKN,SAAA,CAAUM,OAAO,EACjCR,KAAA,CAAMS,SAAS,iBAAIb,KAAA,CAAAO,aAAA,CAAC;IAAIO,GAAA,EAAKV,KAAA,CAAMW,QAAQ;IAAEC,SAAA,EAAWZ,KAAA,CAAMa;MAC9Db,KAAA,CAAMQ,OAAO,CAACH,QAAQ;AAMnC"}
@@ -1,9 +1,9 @@
1
- import * as React from 'react';
2
- import { mergeArrowOffset, resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';
3
- import { useTooltipVisibility_unstable as useTooltipVisibility, useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
4
- import { applyTriggerPropsToChildren, resolveShorthand, useControllableState, useId, useIsomorphicLayoutEffect, useIsSSR, useMergedRefs, useTimeout, getTriggerChild, mergeCallbacks, useEventCallback } from '@fluentui/react-utilities';
5
- import { arrowHeight, tooltipBorderRadius } from './private/constants';
6
- import { Escape } from '@fluentui/keyboard-keys';
1
+ import * as React from "react";
2
+ import { mergeArrowOffset, resolvePositioningShorthand, usePositioning } from "@fluentui/react-positioning";
3
+ import { useTooltipVisibility_unstable as useTooltipVisibility, useFluent_unstable as useFluent } from "@fluentui/react-shared-contexts";
4
+ import { applyTriggerPropsToChildren, resolveShorthand, useControllableState, useId, useIsomorphicLayoutEffect, useIsSSR, useMergedRefs, useTimeout, getTriggerChild, mergeCallbacks, useEventCallback } from "@fluentui/react-utilities";
5
+ import { arrowHeight, tooltipBorderRadius } from "./private/constants";
6
+ import { Escape } from "@fluentui/keyboard-keys";
7
7
  /**
8
8
  * Create the state required to render Tooltip.
9
9
  *
@@ -13,7 +13,6 @@ import { Escape } from '@fluentui/keyboard-keys';
13
13
  * @param props - props from this instance of Tooltip
14
14
  */
15
15
  export const useTooltip_unstable = props => {
16
- var _a, _b, _c, _d;
17
16
  const context = useTooltipVisibility();
18
17
  const isServerSideRender = useIsSSR();
19
18
  const {
@@ -21,11 +20,11 @@ export const useTooltip_unstable = props => {
21
20
  } = useFluent();
22
21
  const [setDelayTimeout, clearDelayTimeout] = useTimeout();
23
22
  const {
24
- appearance = 'normal',
23
+ appearance = "normal",
25
24
  children,
26
25
  content,
27
26
  withArrow = false,
28
- positioning = 'above',
27
+ positioning = "above",
29
28
  onVisibleChange,
30
29
  relationship,
31
30
  showDelay = 250,
@@ -40,7 +39,7 @@ export const useTooltip_unstable = props => {
40
39
  clearDelayTimeout();
41
40
  setVisibleInternal(oldVisible => {
42
41
  if (newVisible !== oldVisible) {
43
- onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev, {
42
+ onVisibleChange?.(ev, {
44
43
  visible: newVisible
45
44
  });
46
45
  }
@@ -59,21 +58,21 @@ export const useTooltip_unstable = props => {
59
58
  mountNode,
60
59
  // Slots
61
60
  components: {
62
- content: 'div'
61
+ content: "div"
63
62
  },
64
63
  content: resolveShorthand(content, {
65
64
  defaultProps: {
66
- role: 'tooltip'
65
+ role: "tooltip"
67
66
  },
68
67
  required: true
69
68
  })
70
69
  };
71
- state.content.id = useId('tooltip-', state.content.id);
70
+ state.content.id = useId("tooltip-", state.content.id);
72
71
  const positioningOptions = {
73
72
  enabled: state.visible,
74
73
  arrowPadding: 2 * tooltipBorderRadius,
75
- position: 'above',
76
- align: 'center',
74
+ position: "above",
75
+ align: "center",
77
76
  offset: 4,
78
77
  ...resolvePositioningShorthand(state.positioning)
79
78
  };
@@ -91,12 +90,11 @@ export const useTooltip_unstable = props => {
91
90
  // as the visibleTooltip with the TooltipContext.
92
91
  // Also add a listener on document to hide the tooltip if Escape is pressed
93
92
  useIsomorphicLayoutEffect(() => {
94
- var _a;
95
93
  if (visible) {
96
94
  const thisTooltip = {
97
95
  hide: () => setVisible(false)
98
96
  };
99
- (_a = context.visibleTooltip) === null || _a === void 0 ? void 0 : _a.hide();
97
+ context.visibleTooltip?.hide();
100
98
  context.visibleTooltip = thisTooltip;
101
99
  const onDocumentKeyDown = ev => {
102
100
  if (ev.key === Escape) {
@@ -106,7 +104,7 @@ export const useTooltip_unstable = props => {
106
104
  ev.stopPropagation();
107
105
  }
108
106
  };
109
- targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('keydown', onDocumentKeyDown, {
107
+ targetDocument?.addEventListener("keydown", onDocumentKeyDown, {
110
108
  // As this event is added at targeted document,
111
109
  // we need to capture the event to be sure keydown handling from tooltip happens first
112
110
  capture: true
@@ -115,7 +113,7 @@ export const useTooltip_unstable = props => {
115
113
  if (context.visibleTooltip === thisTooltip) {
116
114
  context.visibleTooltip = undefined;
117
115
  }
118
- targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('keydown', onDocumentKeyDown, {
116
+ targetDocument?.removeEventListener("keydown", onDocumentKeyDown, {
119
117
  capture: true
120
118
  });
121
119
  };
@@ -129,7 +127,7 @@ export const useTooltip_unstable = props => {
129
127
  const ignoreNextFocusEventRef = React.useRef(false);
130
128
  // Listener for onPointerEnter and onFocus on the trigger element
131
129
  const onEnterTrigger = React.useCallback(ev => {
132
- if (ev.type === 'focus' && ignoreNextFocusEventRef.current) {
130
+ if (ev.type === "focus" && ignoreNextFocusEventRef.current) {
133
131
  ignoreNextFocusEventRef.current = false;
134
132
  return;
135
133
  }
@@ -143,10 +141,10 @@ export const useTooltip_unstable = props => {
143
141
  // Listener for onPointerLeave and onBlur on the trigger element
144
142
  const onLeaveTrigger = React.useCallback(ev => {
145
143
  let delay = state.hideDelay;
146
- if (ev.type === 'blur') {
144
+ if (ev.type === "blur") {
147
145
  // Hide immediately when losing focus
148
146
  delay = 0;
149
- ignoreNextFocusEventRef.current = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) === ev.target;
147
+ ignoreNextFocusEventRef.current = targetDocument?.activeElement === ev.target;
150
148
  }
151
149
  setDelayTimeout(() => {
152
150
  setVisible(false, ev);
@@ -161,17 +159,17 @@ export const useTooltip_unstable = props => {
161
159
  state.content.onBlur = mergeCallbacks(state.content.onBlur, onLeaveTrigger);
162
160
  const child = getTriggerChild(children);
163
161
  const triggerAriaProps = {};
164
- if (relationship === 'label') {
162
+ if (relationship === "label") {
165
163
  // aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.
166
- if (typeof state.content.children === 'string') {
167
- triggerAriaProps['aria-label'] = state.content.children;
164
+ if (typeof state.content.children === "string") {
165
+ triggerAriaProps["aria-label"] = state.content.children;
168
166
  } else {
169
- triggerAriaProps['aria-labelledby'] = state.content.id;
167
+ triggerAriaProps["aria-labelledby"] = state.content.id;
170
168
  // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element
171
169
  state.shouldRenderTooltip = true;
172
170
  }
173
- } else if (relationship === 'description') {
174
- triggerAriaProps['aria-describedby'] = state.content.id;
171
+ } else if (relationship === "description") {
172
+ triggerAriaProps["aria-describedby"] = state.content.id;
175
173
  // Always render the tooltip even if hidden, so that aria-describedby refers to a valid element
176
174
  state.shouldRenderTooltip = true;
177
175
  }
@@ -179,17 +177,17 @@ export const useTooltip_unstable = props => {
179
177
  if (isServerSideRender) {
180
178
  state.shouldRenderTooltip = false;
181
179
  }
182
- const childTargetRef = useMergedRefs(child === null || child === void 0 ? void 0 : child.ref, targetRef);
180
+ const childTargetRef = useMergedRefs(child?.ref, targetRef);
183
181
  // Apply the trigger props to the child, either by calling the render function, or cloning with the new props
184
182
  state.children = applyTriggerPropsToChildren(children, {
185
183
  ...triggerAriaProps,
186
- ...(child === null || child === void 0 ? void 0 : child.props),
184
+ ...child?.props,
187
185
  // If the target prop is not provided, attach targetRef to the trigger element's ref prop
188
- ref: positioningOptions.target === undefined ? childTargetRef : child === null || child === void 0 ? void 0 : child.ref,
189
- onPointerEnter: useEventCallback(mergeCallbacks((_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.onPointerEnter, onEnterTrigger)),
190
- onPointerLeave: useEventCallback(mergeCallbacks((_b = child === null || child === void 0 ? void 0 : child.props) === null || _b === void 0 ? void 0 : _b.onPointerLeave, onLeaveTrigger)),
191
- onFocus: useEventCallback(mergeCallbacks((_c = child === null || child === void 0 ? void 0 : child.props) === null || _c === void 0 ? void 0 : _c.onFocus, onEnterTrigger)),
192
- onBlur: useEventCallback(mergeCallbacks((_d = child === null || child === void 0 ? void 0 : child.props) === null || _d === void 0 ? void 0 : _d.onBlur, onLeaveTrigger))
186
+ ref: positioningOptions.target === undefined ? childTargetRef : child?.ref,
187
+ onPointerEnter: useEventCallback(mergeCallbacks(child?.props?.onPointerEnter, onEnterTrigger)),
188
+ onPointerLeave: useEventCallback(mergeCallbacks(child?.props?.onPointerLeave, onLeaveTrigger)),
189
+ onFocus: useEventCallback(mergeCallbacks(child?.props?.onFocus, onEnterTrigger)),
190
+ onBlur: useEventCallback(mergeCallbacks(child?.props?.onBlur, onLeaveTrigger))
193
191
  });
194
192
  return state;
195
193
  };
@@ -1 +1 @@
1
- {"version":3,"names":["React","mergeArrowOffset","resolvePositioningShorthand","usePositioning","useTooltipVisibility_unstable","useTooltipVisibility","useFluent_unstable","useFluent","applyTriggerPropsToChildren","resolveShorthand","useControllableState","useId","useIsomorphicLayoutEffect","useIsSSR","useMergedRefs","useTimeout","getTriggerChild","mergeCallbacks","useEventCallback","arrowHeight","tooltipBorderRadius","Escape","useTooltip_unstable","props","context","isServerSideRender","targetDocument","setDelayTimeout","clearDelayTimeout","appearance","children","content","withArrow","positioning","onVisibleChange","relationship","showDelay","hideDelay","mountNode","visible","setVisibleInternal","state","initialState","setVisible","useCallback","newVisible","ev","oldVisible","shouldRenderTooltip","components","defaultProps","role","required","id","positioningOptions","enabled","arrowPadding","position","align","offset","targetRef","containerRef","arrowRef","ref","thisTooltip","hide","_a","visibleTooltip","onDocumentKeyDown","key","stopPropagation","addEventListener","capture","undefined","removeEventListener","ignoreNextFocusEventRef","useRef","onEnterTrigger","type","current","delay","persist","onLeaveTrigger","activeElement","target","onPointerEnter","onPointerLeave","onFocus","onBlur","child","triggerAriaProps","childTargetRef","_b","_c","_d"],"sources":["../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/useTooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { mergeArrowOffset, resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport {\n useTooltipVisibility_unstable as useTooltipVisibility,\n useFluent_unstable as useFluent,\n} from '@fluentui/react-shared-contexts';\nimport {\n applyTriggerPropsToChildren,\n resolveShorthand,\n useControllableState,\n useId,\n useIsomorphicLayoutEffect,\n useIsSSR,\n useMergedRefs,\n useTimeout,\n getTriggerChild,\n mergeCallbacks,\n useEventCallback,\n} from '@fluentui/react-utilities';\nimport type { TooltipProps, TooltipState, TooltipChildProps } from './Tooltip.types';\nimport { arrowHeight, tooltipBorderRadius } from './private/constants';\nimport { Escape } from '@fluentui/keyboard-keys';\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 = useTooltipVisibility();\n const isServerSideRender = useIsSSR();\n const { targetDocument } = useFluent();\n const [setDelayTimeout, clearDelayTimeout] = useTimeout();\n\n const {\n appearance = 'normal',\n children,\n content,\n withArrow = false,\n positioning = 'above',\n onVisibleChange,\n relationship,\n showDelay = 250,\n hideDelay = 250,\n mountNode,\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 mountNode,\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 positioningOptions = {\n enabled: state.visible,\n arrowPadding: 2 * tooltipBorderRadius,\n position: 'above' as const,\n align: 'center' as const,\n offset: 4,\n ...resolvePositioningShorthand(state.positioning),\n };\n\n if (state.withArrow) {\n positioningOptions.offset = mergeArrowOffset(positioningOptions.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 } = usePositioning(positioningOptions);\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) {\n thisTooltip.hide();\n // stop propagation to avoid conflicting with other elements that listen for `Escape`\n // e,g: Dialog, Popover, Menu\n ev.stopPropagation();\n }\n };\n\n targetDocument?.addEventListener('keydown', onDocumentKeyDown, {\n // As this event is added at targeted document,\n // we need to capture the event to be sure keydown handling from tooltip happens first\n capture: true,\n });\n\n return () => {\n if (context.visibleTooltip === thisTooltip) {\n context.visibleTooltip = undefined;\n }\n\n targetDocument?.removeEventListener('keydown', onDocumentKeyDown, { capture: true });\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 mouse or focus enters the tooltip, and restart it when the mouse or focus leaves.\n // This keeps the tooltip visible when the mouse is moved over it, or it has focus within.\n state.content.onPointerEnter = mergeCallbacks(state.content.onPointerEnter, clearDelayTimeout);\n state.content.onPointerLeave = mergeCallbacks(state.content.onPointerLeave, onLeaveTrigger);\n state.content.onFocus = mergeCallbacks(state.content.onFocus, clearDelayTimeout);\n state.content.onBlur = mergeCallbacks(state.content.onBlur, onLeaveTrigger);\n\n const child = getTriggerChild(children);\n\n const triggerAriaProps: Pick<TooltipChildProps, '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 {\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 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 // Don't render the Tooltip in SSR to avoid hydration errors\n if (isServerSideRender) {\n state.shouldRenderTooltip = false;\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(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: positioningOptions.target === undefined ? childTargetRef : child?.ref,\n onPointerEnter: useEventCallback(mergeCallbacks(child?.props?.onPointerEnter, onEnterTrigger)),\n onPointerLeave: useEventCallback(mergeCallbacks(child?.props?.onPointerLeave, onLeaveTrigger)),\n onFocus: useEventCallback(mergeCallbacks(child?.props?.onFocus, onEnterTrigger)),\n onBlur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f;IACAwC,GAAG,EAAET,kBAAkB,CAAC8B,MAAM,KAAKX,SAAS,GAAGkB,cAAc,GAAGF,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAE1B,GAAG;IAC1EsB,cAAc,EAAEnE,gBAAgB,CAACD,cAAc,CAAC,CAAAiD,EAAA,GAAAuB,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAElE,KAAK,cAAA2C,EAAA,uBAAAA,EAAA,CAAEmB,cAAc,EAAER,cAAc,CAAC,CAAC;IAC9FS,cAAc,EAAEpE,gBAAgB,CAACD,cAAc,CAAC,CAAA2E,EAAA,GAAAH,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAElE,KAAK,cAAAqE,EAAA,uBAAAA,EAAA,CAAEN,cAAc,EAAEJ,cAAc,CAAC,CAAC;IAC9FK,OAAO,EAAErE,gBAAgB,CAACD,cAAc,CAAC,CAAA4E,EAAA,GAAAJ,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAElE,KAAK,cAAAsE,EAAA,uBAAAA,EAAA,CAAEN,OAAO,EAAEV,cAAc,CAAC,CAAC;IAChFW,MAAM,EAAEtE,gBAAgB,CAACD,cAAc,CAAC,CAAA6E,EAAA,GAAAL,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAElE,KAAK,cAAAuE,EAAA,uBAAAA,EAAA,CAAEN,MAAM,EAAEN,cAAc,CAAC;GAC9E,CAAC;EAEF,OAAOzC,KAAK;AACd,CAAC"}
1
+ {"version":3,"names":["React","mergeArrowOffset","resolvePositioningShorthand","usePositioning","useTooltipVisibility_unstable","useTooltipVisibility","useFluent_unstable","useFluent","applyTriggerPropsToChildren","resolveShorthand","useControllableState","useId","useIsomorphicLayoutEffect","useIsSSR","useMergedRefs","useTimeout","getTriggerChild","mergeCallbacks","useEventCallback","arrowHeight","tooltipBorderRadius","Escape","useTooltip_unstable","props","context","isServerSideRender","targetDocument","setDelayTimeout","clearDelayTimeout","appearance","children","content","withArrow","positioning","onVisibleChange","relationship","showDelay","hideDelay","mountNode","visible","setVisibleInternal","state","initialState","setVisible","useCallback","newVisible","ev","oldVisible","shouldRenderTooltip","components","defaultProps","role","required","id","positioningOptions","enabled","arrowPadding","position","align","offset","targetRef","containerRef","arrowRef","ref","thisTooltip","hide","visibleTooltip","onDocumentKeyDown","key","stopPropagation","addEventListener","capture","undefined","removeEventListener","ignoreNextFocusEventRef","useRef","onEnterTrigger","type","current","delay","persist","onLeaveTrigger","activeElement","target","onPointerEnter","onPointerLeave","onFocus","onBlur","child","triggerAriaProps","childTargetRef"],"sources":["../../../src/components/Tooltip/useTooltip.tsx"],"sourcesContent":["import * as React from 'react';\nimport { mergeArrowOffset, resolvePositioningShorthand, usePositioning } from '@fluentui/react-positioning';\nimport {\n useTooltipVisibility_unstable as useTooltipVisibility,\n useFluent_unstable as useFluent,\n} from '@fluentui/react-shared-contexts';\nimport {\n applyTriggerPropsToChildren,\n resolveShorthand,\n useControllableState,\n useId,\n useIsomorphicLayoutEffect,\n useIsSSR,\n useMergedRefs,\n useTimeout,\n getTriggerChild,\n mergeCallbacks,\n useEventCallback,\n} from '@fluentui/react-utilities';\nimport type { TooltipProps, TooltipState, TooltipChildProps } from './Tooltip.types';\nimport { arrowHeight, tooltipBorderRadius } from './private/constants';\nimport { Escape } from '@fluentui/keyboard-keys';\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 = useTooltipVisibility();\n const isServerSideRender = useIsSSR();\n const { targetDocument } = useFluent();\n const [setDelayTimeout, clearDelayTimeout] = useTimeout();\n\n const {\n appearance = 'normal',\n children,\n content,\n withArrow = false,\n positioning = 'above',\n onVisibleChange,\n relationship,\n showDelay = 250,\n hideDelay = 250,\n mountNode,\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 mountNode,\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 positioningOptions = {\n enabled: state.visible,\n arrowPadding: 2 * tooltipBorderRadius,\n position: 'above' as const,\n align: 'center' as const,\n offset: 4,\n ...resolvePositioningShorthand(state.positioning),\n };\n\n if (state.withArrow) {\n positioningOptions.offset = mergeArrowOffset(positioningOptions.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 } = usePositioning(positioningOptions);\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) {\n thisTooltip.hide();\n // stop propagation to avoid conflicting with other elements that listen for `Escape`\n // e,g: Dialog, Popover, Menu\n ev.stopPropagation();\n }\n };\n\n targetDocument?.addEventListener('keydown', onDocumentKeyDown, {\n // As this event is added at targeted document,\n // we need to capture the event to be sure keydown handling from tooltip happens first\n capture: true,\n });\n\n return () => {\n if (context.visibleTooltip === thisTooltip) {\n context.visibleTooltip = undefined;\n }\n\n targetDocument?.removeEventListener('keydown', onDocumentKeyDown, { capture: true });\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 mouse or focus enters the tooltip, and restart it when the mouse or focus leaves.\n // This keeps the tooltip visible when the mouse is moved over it, or it has focus within.\n state.content.onPointerEnter = mergeCallbacks(state.content.onPointerEnter, clearDelayTimeout);\n state.content.onPointerLeave = mergeCallbacks(state.content.onPointerLeave, onLeaveTrigger);\n state.content.onFocus = mergeCallbacks(state.content.onFocus, clearDelayTimeout);\n state.content.onBlur = mergeCallbacks(state.content.onBlur, onLeaveTrigger);\n\n const child = getTriggerChild(children);\n\n const triggerAriaProps: Pick<TooltipChildProps, '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 {\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 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 // Don't render the Tooltip in SSR to avoid hydration errors\n if (isServerSideRender) {\n state.shouldRenderTooltip = false;\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(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: positioningOptions.target === undefined ? childTargetRef : child?.ref,\n onPointerEnter: useEventCallback(mergeCallbacks(child?.props?.onPointerEnter, onEnterTrigger)),\n onPointerLeave: useEventCallback(mergeCallbacks(child?.props?.onPointerLeave, onLeaveTrigger)),\n onFocus: useEventCallback(mergeCallbacks(child?.props?.onFocus, onEnterTrigger)),\n onBlur: useEventCallback(mergeCallbacks(child?.props?.onBlur, onLeaveTrigger)),\n });\n\n return state;\n};\n"],"mappings":"AAAA,YAAYA,KAAA,MAAW;AACvB,SAASC,gBAAgB,EAAEC,2BAA2B,EAAEC,cAAc,QAAQ;AAC9E,SACEC,6BAAA,IAAiCC,oBAAoB,EACrDC,kBAAA,IAAsBC,SAAS,QAC1B;AACP,SACEC,2BA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CAAC,mBAAmB,GAAGhD,KAAA,CAAMV,OAAO,CAACsB,EAAE;IACvD;IACAZ,KAAA,CAAMO,mBAAmB,GAAG,IAAI;EAClC;EAEA;EACA,IAAIvB,kBAAA,EAAoB;IACtBgB,KAAA,CAAMO,mBAAmB,GAAG,KAAK;EACnC;EAEA,MAAM0C,cAAA,GAAiB5E,aAAA,CAAc0E,KAAA,EAAOzB,GAAA,EAAKH,SAAA;EAEjD;EACAnB,KAAA,CAAMX,QAAQ,GAAGtB,2BAAA,CAA4BsB,QAAA,EAAU;IACrD,GAAG2D,gBAAgB;IACnB,GAAGD,KAAA,EAAOjE,KAAK;IACf;IACAwC,GAAA,EAAKT,kBAAA,CAAmB6B,MAAM,KAAKX,SAAA,GAAYkB,cAAA,GAAiBF,KAAA,EAAOzB,GAAG;IAC1EqB,cAAA,EAAgBlE,gBAAA,CAAiBD,cAAA,CAAeuE,KAAA,EAAOjE,KAAA,EAAO6D,cAAA,EAAgBR,cAAA;IAC9ES,cAAA,EAAgBnE,gBAAA,CAAiBD,cAAA,CAAeuE,KAAA,EAAOjE,KAAA,EAAO8D,cAAA,EAAgBJ,cAAA;IAC9EK,OAAA,EAASpE,gBAAA,CAAiBD,cAAA,CAAeuE,KAAA,EAAOjE,KAAA,EAAO+D,OAAA,EAASV,cAAA;IAChEW,MAAA,EAAQrE,gBAAA,CAAiBD,cAAA,CAAeuE,KAAA,EAAOjE,KAAA,EAAOgE,MAAA,EAAQN,cAAA;EAChE;EAEA,OAAOxC,KAAA;AACT"}
@@ -1,9 +1,9 @@
1
- import { shorthands, __styles, mergeClasses } from '@griffel/react';
2
- import { createArrowStyles } from '@fluentui/react-positioning';
3
- import { tokens } from '@fluentui/react-theme';
4
- import { arrowHeight } from './private/constants';
1
+ import { shorthands, __styles, mergeClasses } from "@griffel/react";
2
+ import { createArrowStyles } from "@fluentui/react-positioning";
3
+ import { tokens } from "@fluentui/react-theme";
4
+ import { arrowHeight } from "./private/constants";
5
5
  export const tooltipClassNames = {
6
- content: 'fui-Tooltip__content'
6
+ content: "fui-Tooltip__content"
7
7
  };
8
8
  /**
9
9
  * Styles for the tooltip
@@ -87,7 +87,7 @@ const useStyles = /*#__PURE__*/__styles({
87
87
  */
88
88
  export const useTooltipStyles_unstable = state => {
89
89
  const styles = useStyles();
90
- state.content.className = mergeClasses(tooltipClassNames.content, styles.root, state.appearance === 'inverted' && styles.inverted, state.visible && styles.visible, state.content.className);
90
+ state.content.className = mergeClasses(tooltipClassNames.content, styles.root, state.appearance === "inverted" && styles.inverted, state.visible && styles.visible, state.content.className);
91
91
  state.arrowClassName = styles.arrow;
92
92
  return state;
93
93
  };