@fluentui/react-tooltip 0.0.0-nightly65dd5f749420211213.1 → 0.0.0-nightly695230dc7220220301.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 (46) hide show
  1. package/CHANGELOG.json +261 -24
  2. package/CHANGELOG.md +70 -14
  3. package/MIGRATION.md +51 -43
  4. package/Spec.md +201 -337
  5. package/dist/react-tooltip.d.ts +38 -48
  6. package/lib/Tooltip.js.map +1 -1
  7. package/lib/components/Tooltip/Tooltip.d.ts +3 -2
  8. package/lib/components/Tooltip/Tooltip.js +9 -9
  9. package/lib/components/Tooltip/Tooltip.js.map +1 -1
  10. package/lib/components/Tooltip/Tooltip.types.d.ts +32 -39
  11. package/lib/components/Tooltip/Tooltip.types.js.map +1 -1
  12. package/lib/components/Tooltip/index.js.map +1 -1
  13. package/lib/components/Tooltip/private/constants.d.ts +12 -0
  14. package/lib/components/Tooltip/private/constants.js +14 -0
  15. package/lib/components/Tooltip/private/constants.js.map +1 -0
  16. package/lib/components/Tooltip/renderTooltip.d.ts +1 -1
  17. package/lib/components/Tooltip/renderTooltip.js +4 -4
  18. package/lib/components/Tooltip/renderTooltip.js.map +1 -1
  19. package/lib/components/Tooltip/useTooltip.d.ts +3 -6
  20. package/lib/components/Tooltip/useTooltip.js +44 -65
  21. package/lib/components/Tooltip/useTooltip.js.map +1 -1
  22. package/lib/components/Tooltip/useTooltipStyles.d.ts +1 -1
  23. package/lib/components/Tooltip/useTooltipStyles.js +38 -25
  24. package/lib/components/Tooltip/useTooltipStyles.js.map +1 -1
  25. package/lib/index.js.map +1 -1
  26. package/lib-commonjs/Tooltip.js.map +1 -1
  27. package/lib-commonjs/components/Tooltip/Tooltip.d.ts +3 -2
  28. package/lib-commonjs/components/Tooltip/Tooltip.js +8 -7
  29. package/lib-commonjs/components/Tooltip/Tooltip.js.map +1 -1
  30. package/lib-commonjs/components/Tooltip/Tooltip.types.d.ts +32 -39
  31. package/lib-commonjs/components/Tooltip/Tooltip.types.js.map +1 -1
  32. package/lib-commonjs/components/Tooltip/index.js.map +1 -1
  33. package/lib-commonjs/components/Tooltip/private/constants.d.ts +12 -0
  34. package/lib-commonjs/components/Tooltip/private/constants.js +21 -0
  35. package/lib-commonjs/components/Tooltip/private/constants.js.map +1 -0
  36. package/lib-commonjs/components/Tooltip/renderTooltip.d.ts +1 -1
  37. package/lib-commonjs/components/Tooltip/renderTooltip.js +6 -6
  38. package/lib-commonjs/components/Tooltip/renderTooltip.js.map +1 -1
  39. package/lib-commonjs/components/Tooltip/useTooltip.d.ts +3 -6
  40. package/lib-commonjs/components/Tooltip/useTooltip.js +49 -69
  41. package/lib-commonjs/components/Tooltip/useTooltip.js.map +1 -1
  42. package/lib-commonjs/components/Tooltip/useTooltipStyles.d.ts +1 -1
  43. package/lib-commonjs/components/Tooltip/useTooltipStyles.js +43 -28
  44. package/lib-commonjs/components/Tooltip/useTooltipStyles.js.map +1 -1
  45. package/lib-commonjs/index.js.map +1 -1
  46. package/package.json +9 -11
@@ -1,9 +1,9 @@
1
1
  import type { ComponentProps } from '@fluentui/react-utilities';
2
2
  import type { ComponentState } from '@fluentui/react-utilities';
3
- import type { ForwardRefComponent } from '@fluentui/react-utilities';
4
- import type { IntrinsicShorthandProps } from '@fluentui/react-utilities';
3
+ import type { FluentTriggerComponent } from '@fluentui/react-utilities';
5
4
  import type { PositioningShorthand } from '@fluentui/react-positioning';
6
5
  import * as React_2 from 'react';
6
+ import type { Slot } from '@fluentui/react-utilities';
7
7
 
8
8
  /**
9
9
  * Data for the Tooltip's onVisibleChange event.
@@ -15,34 +15,37 @@ export declare type OnVisibleChangeData = {
15
15
  /**
16
16
  * Render the final JSX of Tooltip
17
17
  */
18
- export declare const renderTooltip: (state: TooltipState) => JSX.Element;
18
+ export declare const renderTooltip_unstable: (state: TooltipState) => JSX.Element;
19
19
 
20
20
  /**
21
21
  * A tooltip provides light weight contextual information on top of its target element.
22
22
  */
23
- export declare const Tooltip: ForwardRefComponent<TooltipProps>;
23
+ export declare const Tooltip: React_2.FC<TooltipProps> & FluentTriggerComponent;
24
24
 
25
25
  export declare const tooltipClassName = "fui-Tooltip";
26
26
 
27
27
  /**
28
28
  * Properties and state for Tooltip
29
29
  */
30
- export declare type TooltipCommons = {
30
+ declare type TooltipCommons = {
31
31
  /**
32
- * A tooltip can appear with the default appearance or inverted.
33
- * When not specified, the default appearance is used.
34
- */
35
- appearance?: 'inverted';
36
- /**
37
- * The content displayed inside the tooltip.
32
+ * (Required) Specifies whether this tooltip is acting as the description or label of its trigger element.
33
+ *
34
+ * * `label` - The tooltip sets the trigger's aria-label or aria-labelledby attribute. This is useful for buttons
35
+ * displaying only an icon, for example.
36
+ * * `description` - The tooltip sets the trigger's aria-description or aria-describedby attribute.
37
+ * * `inaccessible` - No aria attributes are set on the trigger. This makes the tooltip's content inaccessible to
38
+ * screen readers, and should only be used if the tooltip's text is available by some other means.
38
39
  */
39
- content: React_2.ReactNode;
40
+ relationship: 'label' | 'description' | 'inaccessible';
40
41
  /**
41
- * Color variant with inverted colors
42
+ * The tooltip's visual appearance.
43
+ * * `normal` - Uses the theme's background and text colors.
44
+ * * `inverted` - Higher contrast variant that uses the theme's inverted colors.
42
45
  *
43
- * @defaultvalue false
46
+ * @defaultvalue normal
44
47
  */
45
- inverted?: boolean;
48
+ appearance?: 'normal' | 'inverted';
46
49
  /**
47
50
  * Render an arrow pointing to the target element
48
51
  *
@@ -68,16 +71,6 @@ export declare type TooltipCommons = {
68
71
  * Notification when the visibility of the tooltip is changing
69
72
  */
70
73
  onVisibleChange?: (event: React_2.PointerEvent<HTMLElement> | React_2.FocusEvent<HTMLElement> | undefined, data: OnVisibleChangeData) => void;
71
- /**
72
- * Specifies which aria attribute to set on the trigger element.
73
- * * `label` - Set aria-label to the tooltip's content. Requires content to be a string; if not, uses `labelledby`.
74
- * * `labelledby` - Set aria-labelledby to the tooltip's id. The id is generated if not provided.
75
- * * `describedby` - Set aria-describedby to the tooltip's id. The id is generated if not provided.
76
- * * null - Do not set any aria attributes on the trigger element.
77
- *
78
- * @defaultvalue label
79
- */
80
- triggerAriaAttribute: 'label' | 'labelledby' | 'describedby' | null;
81
74
  /**
82
75
  * Delay before the tooltip is shown, in milliseconds.
83
76
  *
@@ -95,36 +88,35 @@ export declare type TooltipCommons = {
95
88
  /**
96
89
  * Properties for Tooltip
97
90
  */
98
- export declare type TooltipProps = ComponentProps<TooltipSlots> & Partial<Omit<TooltipCommons, 'content'>> & Pick<TooltipCommons, 'content'>;
91
+ export declare type TooltipProps = ComponentProps<TooltipSlots> & Partial<Omit<TooltipCommons, 'relationship'>> & Pick<TooltipCommons, 'relationship'> & {
92
+ /**
93
+ * The tooltip can have a single JSX child, or a render function that accepts TooltipTriggerProps.
94
+ *
95
+ * If no child is provided, the tooltip's target must be set with the `positioning` prop, and its
96
+ * visibility must be controlled with the `visible` prop.
97
+ */
98
+ children?: (React_2.ReactElement & {
99
+ ref?: React_2.Ref<unknown>;
100
+ }) | ((props: TooltipTriggerProps) => React_2.ReactElement | null) | null;
101
+ };
99
102
 
100
103
  /**
101
104
  * Slot properties for Tooltip
102
105
  */
103
106
  export declare type TooltipSlots = {
104
- root: Omit<IntrinsicShorthandProps<'div'>, 'children'> & {
105
- /**
106
- * The child is the element that triggers the Tooltip. It will have additional properties added,
107
- * including events and aria properties.
108
- * Alternatively, children can be a render function that takes the props and adds
109
- * them to the appropriate elements.
110
- */
111
- children?: (React_2.ReactElement<React_2.HTMLAttributes<HTMLElement>> & {
112
- ref?: React_2.Ref<unknown>;
113
- }) | ((props: TooltipTriggerProps) => React_2.ReactNode) | null;
114
- };
107
+ /**
108
+ * The text or JSX content of the tooltip.
109
+ */
110
+ content: NonNullable<Slot<'div'>>;
115
111
  };
116
112
 
117
113
  /**
118
114
  * State used in rendering Tooltip
119
115
  */
120
116
  export declare type TooltipState = ComponentState<TooltipSlots> & TooltipCommons & {
117
+ children?: React_2.ReactElement | null;
121
118
  /**
122
119
  * Whether the tooltip should be rendered to the DOM.
123
- *
124
- * Normally the tooltip will only be rendered when visible. However, if
125
- * triggerAriaAttribute is labelledby or describedby, the tooltip will
126
- * always be rendered even when hidden so that those aria attributes
127
- * to always refer to a valid DOM element.
128
120
  */
129
121
  shouldRenderTooltip?: boolean;
130
122
  /**
@@ -147,18 +139,16 @@ export declare type TooltipTriggerProps = {
147
139
  /**
148
140
  * Create the state required to render Tooltip.
149
141
  *
150
- * The returned state can be modified with hooks such as useTooltipStyles,
151
- * before being passed to renderTooltip.
142
+ * The returned state can be modified with hooks such as useTooltipStyles_unstable,
143
+ * before being passed to renderTooltip_unstable.
152
144
  *
153
145
  * @param props - props from this instance of Tooltip
154
- * @param ref - reference to root HTMLElement of Tooltip
155
- * @param defaultProps - (optional) default prop values provided by the implementing type
156
146
  */
157
- export declare const useTooltip: (props: TooltipProps, ref: React_2.Ref<HTMLDivElement>) => TooltipState;
147
+ export declare const useTooltip_unstable: (props: TooltipProps) => TooltipState;
158
148
 
159
149
  /**
160
150
  * Apply styling to the Tooltip slots based on the state
161
151
  */
162
- export declare const useTooltipStyles: (state: TooltipState) => TooltipState;
152
+ export declare const useTooltipStyles_unstable: (state: TooltipState) => TooltipState;
163
153
 
164
154
  export { }
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","sourceRoot":"","sources":["../src/Tooltip.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC"}
1
+ {"version":3,"file":"Tooltip.js","sourceRoot":"../src/","sources":["Tooltip.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC","sourcesContent":["export * from './components/Tooltip/index';\n"]}
@@ -1,6 +1,7 @@
1
+ import * as React from 'react';
1
2
  import type { TooltipProps } from './Tooltip.types';
2
- import type { ForwardRefComponent } from '@fluentui/react-utilities';
3
+ import type { FluentTriggerComponent } from '@fluentui/react-utilities';
3
4
  /**
4
5
  * A tooltip provides light weight contextual information on top of its target element.
5
6
  */
6
- export declare const Tooltip: ForwardRefComponent<TooltipProps>;
7
+ export declare const Tooltip: React.FC<TooltipProps> & FluentTriggerComponent;
@@ -1,15 +1,15 @@
1
- import * as React from 'react';
2
- import { useTooltip } from './useTooltip';
3
- import { renderTooltip } from './renderTooltip';
4
- import { useTooltipStyles } from './useTooltipStyles';
1
+ import { useTooltip_unstable } from './useTooltip';
2
+ import { renderTooltip_unstable } from './renderTooltip';
3
+ import { useTooltipStyles_unstable } from './useTooltipStyles';
5
4
  /**
6
5
  * A tooltip provides light weight contextual information on top of its target element.
7
6
  */
8
7
 
9
- export const Tooltip = /*#__PURE__*/React.forwardRef((props, ref) => {
10
- const state = useTooltip(props, ref);
11
- useTooltipStyles(state);
12
- return renderTooltip(state);
13
- });
8
+ export const Tooltip = props => {
9
+ const state = useTooltip_unstable(props);
10
+ useTooltipStyles_unstable(state);
11
+ return renderTooltip_unstable(state);
12
+ };
14
13
  Tooltip.displayName = 'Tooltip';
14
+ Tooltip.isFluentTriggerComponent = true;
15
15
  //# sourceMappingURL=Tooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Tooltip/Tooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,UAAT,QAA2B,cAA3B;AACA,SAAS,aAAT,QAA8B,iBAA9B;AACA,SAAS,gBAAT,QAAiC,oBAAjC;AAIA;;AAEG;;AACH,OAAO,MAAM,OAAO,gBAAsC,KAAK,CAAC,UAAN,CAAiB,CAAC,KAAD,EAAQ,GAAR,KAAe;AACxF,QAAM,KAAK,GAAG,UAAU,CAAC,KAAD,EAAQ,GAAR,CAAxB;AAEA,EAAA,gBAAgB,CAAC,KAAD,CAAhB;AACA,SAAO,aAAa,CAAC,KAAD,CAApB;AACD,CALyD,CAAnD;AAOP,OAAO,CAAC,WAAR,GAAsB,SAAtB","sourceRoot":""}
1
+ {"version":3,"sources":["components/Tooltip/Tooltip.tsx"],"names":[],"mappings":"AACA,SAAS,mBAAT,QAAoC,cAApC;AACA,SAAS,sBAAT,QAAuC,iBAAvC;AACA,SAAS,yBAAT,QAA0C,oBAA1C;AAIA;;AAEG;;AACH,OAAO,MAAM,OAAO,GAAoD,KAAK,IAAG;AAC9E,QAAM,KAAK,GAAG,mBAAmB,CAAC,KAAD,CAAjC;AAEA,EAAA,yBAAyB,CAAC,KAAD,CAAzB;AACA,SAAO,sBAAsB,CAAC,KAAD,CAA7B;AACD,CALM;AAOP,OAAO,CAAC,WAAR,GAAsB,SAAtB;AACA,OAAO,CAAC,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/"}
@@ -1,41 +1,37 @@
1
1
  import * as React from 'react';
2
2
  import type { PositioningShorthand } from '@fluentui/react-positioning';
3
- import type { ComponentProps, ComponentState, IntrinsicShorthandProps } from '@fluentui/react-utilities';
3
+ import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
4
4
  /**
5
5
  * Slot properties for Tooltip
6
6
  */
7
7
  export declare type TooltipSlots = {
8
- root: Omit<IntrinsicShorthandProps<'div'>, 'children'> & {
9
- /**
10
- * The child is the element that triggers the Tooltip. It will have additional properties added,
11
- * including events and aria properties.
12
- * Alternatively, children can be a render function that takes the props and adds
13
- * them to the appropriate elements.
14
- */
15
- children?: (React.ReactElement<React.HTMLAttributes<HTMLElement>> & {
16
- ref?: React.Ref<unknown>;
17
- }) | ((props: TooltipTriggerProps) => React.ReactNode) | null;
18
- };
8
+ /**
9
+ * The text or JSX content of the tooltip.
10
+ */
11
+ content: NonNullable<Slot<'div'>>;
19
12
  };
20
13
  /**
21
14
  * Properties and state for Tooltip
22
15
  */
23
- export declare type TooltipCommons = {
24
- /**
25
- * A tooltip can appear with the default appearance or inverted.
26
- * When not specified, the default appearance is used.
27
- */
28
- appearance?: 'inverted';
16
+ declare type TooltipCommons = {
29
17
  /**
30
- * The content displayed inside the tooltip.
18
+ * (Required) Specifies whether this tooltip is acting as the description or label of its trigger element.
19
+ *
20
+ * * `label` - The tooltip sets the trigger's aria-label or aria-labelledby attribute. This is useful for buttons
21
+ * displaying only an icon, for example.
22
+ * * `description` - The tooltip sets the trigger's aria-description or aria-describedby attribute.
23
+ * * `inaccessible` - No aria attributes are set on the trigger. This makes the tooltip's content inaccessible to
24
+ * screen readers, and should only be used if the tooltip's text is available by some other means.
31
25
  */
32
- content: React.ReactNode;
26
+ relationship: 'label' | 'description' | 'inaccessible';
33
27
  /**
34
- * Color variant with inverted colors
28
+ * The tooltip's visual appearance.
29
+ * * `normal` - Uses the theme's background and text colors.
30
+ * * `inverted` - Higher contrast variant that uses the theme's inverted colors.
35
31
  *
36
- * @defaultvalue false
32
+ * @defaultvalue normal
37
33
  */
38
- inverted?: boolean;
34
+ appearance?: 'normal' | 'inverted';
39
35
  /**
40
36
  * Render an arrow pointing to the target element
41
37
  *
@@ -61,16 +57,6 @@ export declare type TooltipCommons = {
61
57
  * Notification when the visibility of the tooltip is changing
62
58
  */
63
59
  onVisibleChange?: (event: React.PointerEvent<HTMLElement> | React.FocusEvent<HTMLElement> | undefined, data: OnVisibleChangeData) => void;
64
- /**
65
- * Specifies which aria attribute to set on the trigger element.
66
- * * `label` - Set aria-label to the tooltip's content. Requires content to be a string; if not, uses `labelledby`.
67
- * * `labelledby` - Set aria-labelledby to the tooltip's id. The id is generated if not provided.
68
- * * `describedby` - Set aria-describedby to the tooltip's id. The id is generated if not provided.
69
- * * null - Do not set any aria attributes on the trigger element.
70
- *
71
- * @defaultvalue label
72
- */
73
- triggerAriaAttribute: 'label' | 'labelledby' | 'describedby' | null;
74
60
  /**
75
61
  * Delay before the tooltip is shown, in milliseconds.
76
62
  *
@@ -99,18 +85,24 @@ export declare type OnVisibleChangeData = {
99
85
  /**
100
86
  * Properties for Tooltip
101
87
  */
102
- export declare type TooltipProps = ComponentProps<TooltipSlots> & Partial<Omit<TooltipCommons, 'content'>> & Pick<TooltipCommons, 'content'>;
88
+ export declare type TooltipProps = ComponentProps<TooltipSlots> & Partial<Omit<TooltipCommons, 'relationship'>> & Pick<TooltipCommons, 'relationship'> & {
89
+ /**
90
+ * The tooltip can have a single JSX child, or a render function that accepts TooltipTriggerProps.
91
+ *
92
+ * If no child is provided, the tooltip's target must be set with the `positioning` prop, and its
93
+ * visibility must be controlled with the `visible` prop.
94
+ */
95
+ children?: (React.ReactElement & {
96
+ ref?: React.Ref<unknown>;
97
+ }) | ((props: TooltipTriggerProps) => React.ReactElement | null) | null;
98
+ };
103
99
  /**
104
100
  * State used in rendering Tooltip
105
101
  */
106
102
  export declare type TooltipState = ComponentState<TooltipSlots> & TooltipCommons & {
103
+ children?: React.ReactElement | null;
107
104
  /**
108
105
  * Whether the tooltip should be rendered to the DOM.
109
- *
110
- * Normally the tooltip will only be rendered when visible. However, if
111
- * triggerAriaAttribute is labelledby or describedby, the tooltip will
112
- * always be rendered even when hidden so that those aria attributes
113
- * to always refer to a valid DOM element.
114
106
  */
115
107
  shouldRenderTooltip?: boolean;
116
108
  /**
@@ -122,3 +114,4 @@ export declare type TooltipState = ComponentState<TooltipSlots> & TooltipCommons
122
114
  */
123
115
  arrowClassName?: string;
124
116
  };
117
+ export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.types.js","sourceRoot":"","sources":["../../../src/components/Tooltip/Tooltip.types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"Tooltip.types.js","sourceRoot":"../src/","sources":["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 } from '@fluentui/react-utilities';\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 * Properties and state for Tooltip\n */\ntype TooltipCommons = {\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 * 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 * @defaultvalue normal\n */\n appearance?: 'normal' | 'inverted';\n\n /**\n * Render an arrow pointing to the target element\n *\n * @defaultvalue false\n */\n withArrow?: boolean;\n\n /**\n * Configure the positioning of the tooltip\n *\n * @defaultvalue above\n */\n positioning?: PositioningShorthand;\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 visible?: boolean;\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 * Delay before the tooltip is shown, in milliseconds.\n *\n * @defaultvalue 250\n */\n showDelay: number;\n\n /**\n * Delay before the tooltip is hidden, in milliseconds.\n *\n * @defaultvalue 250\n */\n hideDelay: number;\n};\n\n/**\n * The properties that are added to the trigger of the Tooltip\n */\nexport type TooltipTriggerProps = {\n ref?: React.Ref<never>;\n} & Pick<\n React.HTMLAttributes<HTMLElement>,\n 'onPointerEnter' | 'onPointerLeave' | 'onFocus' | 'onBlur' | 'aria-describedby' | 'aria-labelledby' | 'aria-label'\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 Partial<Omit<TooltipCommons, 'relationship'>> &\n Pick<TooltipCommons, 'relationship'> & {\n /**\n * The tooltip can have a single JSX child, or a render function that accepts TooltipTriggerProps.\n *\n * If no child is provided, the tooltip's target must be set with the `positioning` prop, and its\n * visibility must be controlled with the `visible` prop.\n */\n children?:\n | (React.ReactElement & { ref?: React.Ref<unknown> })\n | ((props: TooltipTriggerProps) => React.ReactElement | null)\n | null;\n };\n\n/**\n * State used in rendering Tooltip\n */\nexport type TooltipState = ComponentState<TooltipSlots> &\n TooltipCommons & {\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 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["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"]}
@@ -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,14 @@
1
+ /**
2
+ * The height of the tooltip's arrow in pixels.
3
+ */
4
+ export 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
+
13
+ export const tooltipBorderRadius = 4;
14
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["components/Tooltip/private/constants.ts"],"names":[],"mappings":"AAAA;;AAEG;AACH,OAAO,MAAM,WAAW,GAAG,CAApB;AAEP;;;;;;AAMG;;AACH,OAAO,MAAM,mBAAmB,GAAG,CAA5B","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/"}
@@ -2,4 +2,4 @@ import type { TooltipState } from './Tooltip.types';
2
2
  /**
3
3
  * Render the final JSX of Tooltip
4
4
  */
5
- export declare const renderTooltip: (state: TooltipState) => JSX.Element;
5
+ export declare const renderTooltip_unstable: (state: TooltipState) => JSX.Element;
@@ -5,15 +5,15 @@ import { getSlots } from '@fluentui/react-utilities';
5
5
  * Render the final JSX of Tooltip
6
6
  */
7
7
 
8
- export const renderTooltip = state => {
8
+ export const renderTooltip_unstable = state => {
9
9
  const {
10
10
  slots,
11
11
  slotProps
12
- } = getSlots(state, ['root']);
13
- return /*#__PURE__*/React.createElement(React.Fragment, null, state.root.children, state.shouldRenderTooltip && /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
12
+ } = getSlots(state);
13
+ return /*#__PURE__*/React.createElement(React.Fragment, null, state.children, state.shouldRenderTooltip && /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(slots.content, { ...slotProps.content
14
14
  }, state.withArrow && /*#__PURE__*/React.createElement("div", {
15
15
  ref: state.arrowRef,
16
16
  className: state.arrowClassName
17
- }), state.content)));
17
+ }), state.content.children)));
18
18
  };
19
19
  //# sourceMappingURL=renderTooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Tooltip/renderTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,MAAT,QAAuB,wBAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,aAAa,GAAI,KAAD,IAAwB;AACnD,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,QAAQ,CAAe,KAAf,EAAsB,CAAC,MAAD,CAAtB,CAArC;AAEA,sBACE,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA,EACG,KAAK,CAAC,IAAN,CAAW,QADd,EAEG,KAAK,CAAC,mBAAN,iBACC,KAAA,CAAA,aAAA,CAAC,MAAD,EAAO,IAAP,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;AAAf,GAAX,EACG,KAAK,CAAC,SAAN,iBAAmB,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,OAFT,CADF,CAHJ,CADF;AAaD,CAhBM","sourceRoot":""}
1
+ {"version":3,"sources":["components/Tooltip/renderTooltip.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,MAAT,QAAuB,wBAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAGA;;AAEG;;AACH,OAAO,MAAM,sBAAsB,GAAI,KAAD,IAAwB;AAC5D,QAAM;AAAE,IAAA,KAAF;AAAS,IAAA;AAAT,MAAuB,QAAQ,CAAe,KAAf,CAArC;AAEA,sBACE,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA,EACG,KAAK,CAAC,QADT,EAEG,KAAK,CAAC,mBAAN,iBACC,KAAA,CAAA,aAAA,CAAC,MAAD,EAAO,IAAP,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,OAAP,EAAc,EAAA,GAAK,SAAS,CAAC;AAAf,GAAd,EACG,KAAK,CAAC,SAAN,iBAAmB,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","sourcesContent":["import * as React from 'react';\nimport { Portal } from '@fluentui/react-portal';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { TooltipSlots, TooltipState } from './Tooltip.types';\n\n/**\n * Render the final JSX of Tooltip\n */\nexport const renderTooltip_unstable = (state: TooltipState) => {\n const { slots, slotProps } = getSlots<TooltipSlots>(state);\n\n return (\n <>\n {state.children}\n {state.shouldRenderTooltip && (\n <Portal>\n <slots.content {...slotProps.content}>\n {state.withArrow && <div ref={state.arrowRef} className={state.arrowClassName} />}\n {state.content.children}\n </slots.content>\n </Portal>\n )}\n </>\n );\n};\n"],"sourceRoot":"../src/"}
@@ -1,13 +1,10 @@
1
- import * as React from 'react';
2
1
  import type { TooltipProps, TooltipState } from './Tooltip.types';
3
2
  /**
4
3
  * Create the state required to render Tooltip.
5
4
  *
6
- * The returned state can be modified with hooks such as useTooltipStyles,
7
- * before being passed to renderTooltip.
5
+ * The returned state can be modified with hooks such as useTooltipStyles_unstable,
6
+ * before being passed to renderTooltip_unstable.
8
7
  *
9
8
  * @param props - props from this instance of Tooltip
10
- * @param ref - reference to root HTMLElement of Tooltip
11
- * @param defaultProps - (optional) default prop values provided by the implementing type
12
9
  */
13
- export declare const useTooltip: (props: TooltipProps, ref: React.Ref<HTMLDivElement>) => TooltipState;
10
+ export declare const useTooltip_unstable: (props: TooltipProps) => TooltipState;
@@ -1,24 +1,18 @@
1
1
  import * as React from 'react';
2
2
  import { mergeArrowOffset, resolvePositioningShorthand, usePopper } from '@fluentui/react-positioning';
3
3
  import { TooltipContext, useFluent } from '@fluentui/react-shared-contexts';
4
- import { applyTriggerPropsToChildren, getNativeElementProps, useControllableState, useId, useIsomorphicLayoutEffect, useIsSSR, useMergedRefs, useTimeout } from '@fluentui/react-utilities'; // Style values that are required for popper to properly position the tooltip
5
-
6
- const tooltipBorderRadius = 4; // Update the root's borderRadius in useTooltipStyles.ts if this changes
7
-
8
- const arrowHeight = 6; // Update the arrow's width/height in useTooltipStyles.ts if this changes
9
-
4
+ import { applyTriggerPropsToChildren, resolveShorthand, useControllableState, useMergedEventCallbacks, useId, useIsomorphicLayoutEffect, useIsSSR, useMergedRefs, useTimeout, getTriggerChild } from '@fluentui/react-utilities';
5
+ import { arrowHeight, tooltipBorderRadius } from './private/constants';
10
6
  /**
11
7
  * Create the state required to render Tooltip.
12
8
  *
13
- * The returned state can be modified with hooks such as useTooltipStyles,
14
- * before being passed to renderTooltip.
9
+ * The returned state can be modified with hooks such as useTooltipStyles_unstable,
10
+ * before being passed to renderTooltip_unstable.
15
11
  *
16
12
  * @param props - props from this instance of Tooltip
17
- * @param ref - reference to root HTMLElement of Tooltip
18
- * @param defaultProps - (optional) default prop values provided by the implementing type
19
13
  */
20
14
 
21
- export const useTooltip = (props, ref) => {
15
+ export const useTooltip_unstable = props => {
22
16
  var _a, _b, _c, _d;
23
17
 
24
18
  const context = React.useContext(TooltipContext);
@@ -28,12 +22,13 @@ export const useTooltip = (props, ref) => {
28
22
  } = useFluent();
29
23
  const [setDelayTimeout, clearDelayTimeout] = useTimeout();
30
24
  const {
25
+ appearance,
26
+ children,
31
27
  content,
32
- inverted,
33
28
  withArrow,
34
29
  positioning,
35
30
  onVisibleChange,
36
- triggerAriaAttribute = 'label',
31
+ relationship,
37
32
  showDelay = 250,
38
33
  hideDelay = 250
39
34
  } = props;
@@ -54,27 +49,26 @@ export const useTooltip = (props, ref) => {
54
49
  });
55
50
  }, [clearDelayTimeout, setVisibleInternal, onVisibleChange]);
56
51
  const state = {
57
- content,
58
- inverted,
59
52
  withArrow,
60
53
  positioning,
61
54
  showDelay,
62
55
  hideDelay,
63
- triggerAriaAttribute,
56
+ relationship,
64
57
  visible,
65
58
  shouldRenderTooltip: visible,
66
- appearance: props.appearance,
59
+ appearance,
67
60
  // Slots
68
61
  components: {
69
- root: 'div'
62
+ content: 'div'
70
63
  },
71
- root: getNativeElementProps('div', {
72
- role: 'tooltip',
73
- ...props,
74
- ref,
75
- id: useId('tooltip-', props.id)
64
+ content: resolveShorthand(content, {
65
+ defaultProps: {
66
+ role: 'tooltip'
67
+ },
68
+ required: true
76
69
  })
77
70
  };
71
+ state.content.id = useId('tooltip-', state.content.id);
78
72
  const popperOptions = {
79
73
  enabled: state.visible,
80
74
  arrowPadding: 2 * tooltipBorderRadius,
@@ -93,7 +87,7 @@ export const useTooltip = (props, ref) => {
93
87
  containerRef,
94
88
  arrowRef
95
89
  } = usePopper(popperOptions);
96
- state.root.ref = useMergedRefs(state.root.ref, containerRef);
90
+ state.content.ref = useMergedRefs(state.content.ref, containerRef);
97
91
  state.arrowRef = arrowRef; // When this tooltip is visible, hide any other tooltips, and register it
98
92
  // as the visibleTooltip with the TooltipContext.
99
93
  // Also add a listener on document to hide the tooltip if Escape is pressed
@@ -161,54 +155,39 @@ export const useTooltip = (props, ref) => {
161
155
  }, [setDelayTimeout, setVisible, state.hideDelay, targetDocument]); // Cancel the hide timer when the pointer enters the tooltip, and restart it when the mouse leaves.
162
156
  // This keeps the tooltip visible when the pointer is moved over it.
163
157
 
164
- state.root.onPointerEnter = useMergedCallbacks(state.root.onPointerEnter, clearDelayTimeout);
165
- state.root.onPointerLeave = useMergedCallbacks(state.root.onPointerLeave, onLeaveTrigger);
166
- const child = /*#__PURE__*/React.isValidElement(state.root.children) ? state.root.children : undefined; // The props to add to the trigger element (child)
158
+ state.content.onPointerEnter = useMergedEventCallbacks(state.content.onPointerEnter, clearDelayTimeout);
159
+ state.content.onPointerLeave = useMergedEventCallbacks(state.content.onPointerLeave, onLeaveTrigger);
160
+ const child = /*#__PURE__*/React.isValidElement(children) ? getTriggerChild(children) : undefined;
161
+ const triggerAriaProps = {};
167
162
 
168
- const triggerProps = {
169
- onPointerEnter: useMergedCallbacks((_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.onPointerEnter, onEnterTrigger),
170
- onPointerLeave: useMergedCallbacks((_b = child === null || child === void 0 ? void 0 : child.props) === null || _b === void 0 ? void 0 : _b.onPointerLeave, onLeaveTrigger),
171
- onFocus: useMergedCallbacks((_c = child === null || child === void 0 ? void 0 : child.props) === null || _c === void 0 ? void 0 : _c.onFocus, onEnterTrigger),
172
- onBlur: useMergedCallbacks((_d = child === null || child === void 0 ? void 0 : child.props) === null || _d === void 0 ? void 0 : _d.onBlur, onLeaveTrigger)
173
- }; // If the target prop is not provided, attach targetRef to the trigger element's ref prop
163
+ if (relationship === 'label') {
164
+ // aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.
165
+ if (typeof state.content.children === 'string') {
166
+ triggerAriaProps['aria-label'] = state.content.children;
167
+ } else if (!isServerSideRender) {
168
+ triggerAriaProps['aria-labelledby'] = state.content.id; // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element
174
169
 
175
- const childWithRef = child;
176
- const childTargetRef = useMergedRefs(childWithRef === null || childWithRef === void 0 ? void 0 : childWithRef.ref, targetRef);
177
-
178
- if (popperOptions.target === undefined) {
179
- triggerProps.ref = childTargetRef;
180
- }
170
+ state.shouldRenderTooltip = true;
171
+ }
172
+ } else if (relationship === 'description') {
173
+ if (!isServerSideRender) {
174
+ triggerAriaProps['aria-describedby'] = state.content.id; // Always render the tooltip even if hidden, so that aria-describedby refers to a valid element
181
175
 
182
- if (state.triggerAriaAttribute === 'label') {
183
- // aria-label only works if the content is a string. Otherwise, need to use labelledby.
184
- if (typeof state.content === 'string') {
185
- triggerProps['aria-label'] = state.content;
186
- } else {
187
- state.triggerAriaAttribute = 'labelledby';
176
+ state.shouldRenderTooltip = true;
188
177
  }
189
178
  }
190
179
 
191
- if (state.triggerAriaAttribute === 'labelledby' && !isServerSideRender) {
192
- triggerProps['aria-labelledby'] = state.root.id; // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element
180
+ const childTargetRef = 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
181
 
194
- state.shouldRenderTooltip = true;
195
- } else if (state.triggerAriaAttribute === 'describedby' && !isServerSideRender) {
196
- triggerProps['aria-describedby'] = state.root.id;
197
- state.shouldRenderTooltip = true;
198
- } // Apply the trigger props to the child, either by calling the render function, or cloning with the new props
199
-
200
-
201
- state.root.children = applyTriggerPropsToChildren(state.root.children, triggerProps);
182
+ state.children = applyTriggerPropsToChildren(children, { ...triggerAriaProps,
183
+ ...(child === null || child === void 0 ? void 0 : child.props),
184
+ // If the target prop is not provided, attach targetRef to the trigger element's ref prop
185
+ ref: popperOptions.target === undefined ? childTargetRef : child === null || child === void 0 ? void 0 : child.ref,
186
+ onPointerEnter: useMergedEventCallbacks((_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.onPointerEnter, onEnterTrigger),
187
+ onPointerLeave: useMergedEventCallbacks((_b = child === null || child === void 0 ? void 0 : child.props) === null || _b === void 0 ? void 0 : _b.onPointerLeave, onLeaveTrigger),
188
+ onFocus: useMergedEventCallbacks((_c = child === null || child === void 0 ? void 0 : child.props) === null || _c === void 0 ? void 0 : _c.onFocus, onEnterTrigger),
189
+ onBlur: useMergedEventCallbacks((_d = child === null || child === void 0 ? void 0 : child.props) === null || _d === void 0 ? void 0 : _d.onBlur, onLeaveTrigger)
190
+ });
202
191
  return state;
203
192
  };
204
- /**
205
- * Combine up to two event callbacks into a single function that calls them in order
206
- */
207
-
208
- const useMergedCallbacks = (callback1, callback2) => {
209
- return React.useCallback(ev => {
210
- callback1 === null || callback1 === void 0 ? void 0 : callback1(ev);
211
- callback2 === null || callback2 === void 0 ? void 0 : callback2(ev);
212
- }, [callback1, callback2]);
213
- };
214
193
  //# sourceMappingURL=useTooltip.js.map