@fluentui/react-tooltip 9.2.4 → 9.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. package/.swcrc +30 -0
  2. package/CHANGELOG.json +64 -1
  3. package/CHANGELOG.md +19 -2
  4. package/lib/Tooltip.js.map +1 -1
  5. package/lib/components/Tooltip/Tooltip.js +1 -0
  6. package/lib/components/Tooltip/Tooltip.js.map +1 -1
  7. package/lib/components/Tooltip/Tooltip.types.js +1 -1
  8. package/lib/components/Tooltip/Tooltip.types.js.map +1 -1
  9. package/lib/components/Tooltip/index.js.map +1 -1
  10. package/lib/components/Tooltip/private/constants.js +1 -2
  11. package/lib/components/Tooltip/private/constants.js.map +1 -1
  12. package/lib/components/Tooltip/renderTooltip.js +1 -3
  13. package/lib/components/Tooltip/renderTooltip.js.map +1 -1
  14. package/lib/components/Tooltip/useTooltip.js +7 -7
  15. package/lib/components/Tooltip/useTooltip.js.map +1 -1
  16. package/lib/components/Tooltip/useTooltipStyles.js.map +1 -1
  17. package/lib/index.js.map +1 -1
  18. package/lib-commonjs/Tooltip.js +5 -4
  19. package/lib-commonjs/Tooltip.js.map +1 -1
  20. package/lib-commonjs/components/Tooltip/Tooltip.js +20 -21
  21. package/lib-commonjs/components/Tooltip/Tooltip.js.map +1 -1
  22. package/lib-commonjs/components/Tooltip/Tooltip.types.js +5 -2
  23. package/lib-commonjs/components/Tooltip/Tooltip.types.js.map +1 -1
  24. package/lib-commonjs/components/Tooltip/index.js +9 -8
  25. package/lib-commonjs/components/Tooltip/index.js.map +1 -1
  26. package/lib-commonjs/components/Tooltip/private/constants.js +17 -16
  27. package/lib-commonjs/components/Tooltip/private/constants.js.map +1 -1
  28. package/lib-commonjs/components/Tooltip/renderTooltip.js +19 -24
  29. package/lib-commonjs/components/Tooltip/renderTooltip.js.map +1 -1
  30. package/lib-commonjs/components/Tooltip/useTooltip.js +191 -194
  31. package/lib-commonjs/components/Tooltip/useTooltip.js.map +1 -1
  32. package/lib-commonjs/components/Tooltip/useTooltipStyles.js +200 -92
  33. package/lib-commonjs/components/Tooltip/useTooltipStyles.js.map +1 -1
  34. package/lib-commonjs/index.js +16 -33
  35. package/lib-commonjs/index.js.map +1 -1
  36. package/package.json +11 -10
  37. package/lib-amd/Tooltip.js +0 -6
  38. package/lib-amd/Tooltip.js.map +0 -1
  39. package/lib-amd/components/Tooltip/Tooltip.js +0 -20
  40. package/lib-amd/components/Tooltip/Tooltip.js.map +0 -1
  41. package/lib-amd/components/Tooltip/Tooltip.types.js +0 -5
  42. package/lib-amd/components/Tooltip/Tooltip.types.js.map +0 -1
  43. package/lib-amd/components/Tooltip/index.js +0 -10
  44. package/lib-amd/components/Tooltip/index.js.map +0 -1
  45. package/lib-amd/components/Tooltip/private/constants.js +0 -18
  46. package/lib-amd/components/Tooltip/private/constants.js.map +0 -1
  47. package/lib-amd/components/Tooltip/renderTooltip.js +0 -19
  48. package/lib-amd/components/Tooltip/renderTooltip.js.map +0 -1
  49. package/lib-amd/components/Tooltip/useTooltip.js +0 -158
  50. package/lib-amd/components/Tooltip/useTooltip.js.map +0 -1
  51. package/lib-amd/components/Tooltip/useTooltipStyles.js +0 -36
  52. package/lib-amd/components/Tooltip/useTooltipStyles.js.map +0 -1
  53. package/lib-amd/index.js +0 -11
  54. package/lib-amd/index.js.map +0 -1
@@ -1,158 +0,0 @@
1
- define(["require", "exports", "tslib", "react", "@fluentui/react-positioning", "@fluentui/react-shared-contexts", "@fluentui/react-utilities", "./private/constants", "@fluentui/keyboard-keys"], function (require, exports, tslib_1, React, react_positioning_1, react_shared_contexts_1, react_utilities_1, constants_1, keyboard_keys_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.useTooltip_unstable = void 0;
5
- /**
6
- * Create the state required to render Tooltip.
7
- *
8
- * The returned state can be modified with hooks such as useTooltipStyles_unstable,
9
- * before being passed to renderTooltip_unstable.
10
- *
11
- * @param props - props from this instance of Tooltip
12
- */
13
- var useTooltip_unstable = function (props) {
14
- var _a, _b, _c, _d;
15
- var context = react_shared_contexts_1.useTooltipVisibility_unstable();
16
- var isServerSideRender = react_utilities_1.useIsSSR();
17
- var targetDocument = react_shared_contexts_1.useFluent_unstable().targetDocument;
18
- var _e = react_utilities_1.useTimeout(), setDelayTimeout = _e[0], clearDelayTimeout = _e[1];
19
- var _f = props.appearance, appearance = _f === void 0 ? 'normal' : _f, children = props.children, content = props.content, _g = props.withArrow, withArrow = _g === void 0 ? false : _g, _h = props.positioning, positioning = _h === void 0 ? 'above' : _h, onVisibleChange = props.onVisibleChange, relationship = props.relationship, _j = props.showDelay, showDelay = _j === void 0 ? 250 : _j, _k = props.hideDelay, hideDelay = _k === void 0 ? 250 : _k, mountNode = props.mountNode;
20
- var _l = react_utilities_1.useControllableState({ state: props.visible, initialState: false }), visible = _l[0], setVisibleInternal = _l[1];
21
- var setVisible = React.useCallback(function (newVisible, ev) {
22
- clearDelayTimeout();
23
- setVisibleInternal(function (oldVisible) {
24
- if (newVisible !== oldVisible) {
25
- onVisibleChange === null || onVisibleChange === void 0 ? void 0 : onVisibleChange(ev, { visible: newVisible });
26
- }
27
- return newVisible;
28
- });
29
- }, [clearDelayTimeout, setVisibleInternal, onVisibleChange]);
30
- var state = {
31
- withArrow: withArrow,
32
- positioning: positioning,
33
- showDelay: showDelay,
34
- hideDelay: hideDelay,
35
- relationship: relationship,
36
- visible: visible,
37
- shouldRenderTooltip: visible,
38
- appearance: appearance,
39
- mountNode: mountNode,
40
- // Slots
41
- components: {
42
- content: 'div',
43
- },
44
- content: react_utilities_1.resolveShorthand(content, {
45
- defaultProps: {
46
- role: 'tooltip',
47
- },
48
- required: true,
49
- }),
50
- };
51
- state.content.id = react_utilities_1.useId('tooltip-', state.content.id);
52
- var positioningOptions = tslib_1.__assign({ enabled: state.visible, arrowPadding: 2 * constants_1.tooltipBorderRadius, position: 'above', align: 'center', offset: 4 }, react_positioning_1.resolvePositioningShorthand(state.positioning));
53
- if (state.withArrow) {
54
- positioningOptions.offset = react_positioning_1.mergeArrowOffset(positioningOptions.offset, constants_1.arrowHeight);
55
- }
56
- var _m = react_positioning_1.usePositioning(positioningOptions), targetRef = _m.targetRef, containerRef = _m.containerRef, arrowRef = _m.arrowRef;
57
- state.content.ref = react_utilities_1.useMergedRefs(state.content.ref, containerRef);
58
- state.arrowRef = arrowRef;
59
- // When this tooltip is visible, hide any other tooltips, and register it
60
- // as the visibleTooltip with the TooltipContext.
61
- // Also add a listener on document to hide the tooltip if Escape is pressed
62
- react_utilities_1.useIsomorphicLayoutEffect(function () {
63
- var _a;
64
- if (visible) {
65
- var thisTooltip_1 = { hide: function () { return setVisible(false); } };
66
- (_a = context.visibleTooltip) === null || _a === void 0 ? void 0 : _a.hide();
67
- context.visibleTooltip = thisTooltip_1;
68
- var onDocumentKeyDown_1 = function (ev) {
69
- if (ev.key === keyboard_keys_1.Escape) {
70
- thisTooltip_1.hide();
71
- // stop propagation to avoid conflicting with other elements that listen for `Escape`
72
- // e,g: Dialog, Popover, Menu
73
- ev.stopPropagation();
74
- }
75
- };
76
- targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.addEventListener('keydown', onDocumentKeyDown_1, {
77
- // As this event is added at targeted document,
78
- // we need to capture the event to be sure keydown handling from tooltip happens first
79
- capture: true,
80
- });
81
- return function () {
82
- if (context.visibleTooltip === thisTooltip_1) {
83
- context.visibleTooltip = undefined;
84
- }
85
- targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.removeEventListener('keydown', onDocumentKeyDown_1, { capture: true });
86
- };
87
- }
88
- }, [context, targetDocument, visible, setVisible]);
89
- // The focused element gets a blur event when the document loses focus
90
- // (e.g. switching tabs in the browser), but we don't want to show the
91
- // tooltip again when the document gets focus back. Handle this case by
92
- // checking if the blurred element is still the document's activeElement.
93
- // See https://github.com/microsoft/fluentui/issues/13541
94
- var ignoreNextFocusEventRef = React.useRef(false);
95
- // Listener for onPointerEnter and onFocus on the trigger element
96
- var onEnterTrigger = React.useCallback(function (ev) {
97
- if (ev.type === 'focus' && ignoreNextFocusEventRef.current) {
98
- ignoreNextFocusEventRef.current = false;
99
- return;
100
- }
101
- // Show immediately if another tooltip is already visible
102
- var delay = context.visibleTooltip ? 0 : state.showDelay;
103
- setDelayTimeout(function () {
104
- setVisible(true, ev);
105
- }, delay);
106
- ev.persist(); // Persist the event since the setVisible call will happen asynchronously
107
- }, [setDelayTimeout, setVisible, state.showDelay, context]);
108
- // Listener for onPointerLeave and onBlur on the trigger element
109
- var onLeaveTrigger = React.useCallback(function (ev) {
110
- var delay = state.hideDelay;
111
- if (ev.type === 'blur') {
112
- // Hide immediately when losing focus
113
- delay = 0;
114
- ignoreNextFocusEventRef.current = (targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) === ev.target;
115
- }
116
- setDelayTimeout(function () {
117
- setVisible(false, ev);
118
- }, delay);
119
- ev.persist(); // Persist the event since the setVisible call will happen asynchronously
120
- }, [setDelayTimeout, setVisible, state.hideDelay, targetDocument]);
121
- // Cancel the hide timer when the mouse or focus enters the tooltip, and restart it when the mouse or focus leaves.
122
- // This keeps the tooltip visible when the mouse is moved over it, or it has focus within.
123
- state.content.onPointerEnter = react_utilities_1.mergeCallbacks(state.content.onPointerEnter, clearDelayTimeout);
124
- state.content.onPointerLeave = react_utilities_1.mergeCallbacks(state.content.onPointerLeave, onLeaveTrigger);
125
- state.content.onFocus = react_utilities_1.mergeCallbacks(state.content.onFocus, clearDelayTimeout);
126
- state.content.onBlur = react_utilities_1.mergeCallbacks(state.content.onBlur, onLeaveTrigger);
127
- var child = react_utilities_1.getTriggerChild(children);
128
- var triggerAriaProps = {};
129
- if (relationship === 'label') {
130
- // aria-label only works if the content is a string. Otherwise, need to use aria-labelledby.
131
- if (typeof state.content.children === 'string') {
132
- triggerAriaProps['aria-label'] = state.content.children;
133
- }
134
- else {
135
- triggerAriaProps['aria-labelledby'] = state.content.id;
136
- // Always render the tooltip even if hidden, so that aria-labelledby refers to a valid element
137
- state.shouldRenderTooltip = true;
138
- }
139
- }
140
- else if (relationship === 'description') {
141
- triggerAriaProps['aria-describedby'] = state.content.id;
142
- // Always render the tooltip even if hidden, so that aria-describedby refers to a valid element
143
- state.shouldRenderTooltip = true;
144
- }
145
- // Don't render the Tooltip in SSR to avoid hydration errors
146
- if (isServerSideRender) {
147
- state.shouldRenderTooltip = false;
148
- }
149
- var childTargetRef = react_utilities_1.useMergedRefs(child === null || child === void 0 ? void 0 : child.ref, targetRef);
150
- // Apply the trigger props to the child, either by calling the render function, or cloning with the new props
151
- state.children = react_utilities_1.applyTriggerPropsToChildren(children, tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, triggerAriaProps), child === null || child === void 0 ? void 0 : child.props), {
152
- // If the target prop is not provided, attach targetRef to the trigger element's ref prop
153
- ref: positioningOptions.target === undefined ? childTargetRef : child === null || child === void 0 ? void 0 : child.ref, onPointerEnter: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks((_a = child === null || child === void 0 ? void 0 : child.props) === null || _a === void 0 ? void 0 : _a.onPointerEnter, onEnterTrigger)), onPointerLeave: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks((_b = child === null || child === void 0 ? void 0 : child.props) === null || _b === void 0 ? void 0 : _b.onPointerLeave, onLeaveTrigger)), onFocus: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks((_c = child === null || child === void 0 ? void 0 : child.props) === null || _c === void 0 ? void 0 : _c.onFocus, onEnterTrigger)), onBlur: react_utilities_1.useEventCallback(react_utilities_1.mergeCallbacks((_d = child === null || child === void 0 ? void 0 : child.props) === null || _d === void 0 ? void 0 : _d.onBlur, onLeaveTrigger)) }));
154
- return state;
155
- };
156
- exports.useTooltip_unstable = useTooltip_unstable;
157
- });
158
- //# sourceMappingURL=useTooltip.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTooltip.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/useTooltip.tsx"],"names":[],"mappings":";;;;IAuBA;;;;;;;OAOG;IACI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K,CAAE,KAAK;YACf,yFAAyF;YACzF,GAAG,EAAE,kBAAkB,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,GAAG,EAC1E,cAAc,EAAE,kCAAgB,CAAC,gCAAc,CAAC,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,0CAAE,cAAc,EAAE,cAAc,CAAC,CAAC,EAC9F,cAAc,EAAE,kCAAgB,CAAC,gCAAc,CAAC,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,0CAAE,cAAc,EAAE,cAAc,CAAC,CAAC,EAC9F,OAAO,EAAE,kCAAgB,CAAC,gCAAc,CAAC,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,0CAAE,OAAO,EAAE,cAAc,CAAC,CAAC,EAChF,MAAM,EAAE,kCAAgB,CAAC,gCAAc,CAAC,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,KAAK,0CAAE,MAAM,EAAE,cAAc,CAAC,CAAC,IAC9E,CAAC;QAEH,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IApNW,QAAA,mBAAmB,uBAoN9B","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"]}
@@ -1,36 +0,0 @@
1
- define(["require", "exports", "tslib", "@griffel/react", "@fluentui/react-positioning", "@fluentui/react-theme", "./private/constants"], function (require, exports, tslib_1, react_1, react_positioning_1, react_theme_1, constants_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.useTooltipStyles_unstable = exports.tooltipClassNames = void 0;
5
- exports.tooltipClassNames = {
6
- content: 'fui-Tooltip__content',
7
- };
8
- /**
9
- * Styles for the tooltip
10
- */
11
- var useStyles = react_1.makeStyles({
12
- root: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({ display: 'none', boxSizing: 'border-box', maxWidth: '240px', cursor: 'default', fontFamily: react_theme_1.tokens.fontFamilyBase, fontSize: react_theme_1.tokens.fontSizeBase200, lineHeight: react_theme_1.tokens.lineHeightBase200 }, react_1.shorthands.borderRadius(react_theme_1.tokens.borderRadiusMedium)), react_1.shorthands.border('1px', 'solid', react_theme_1.tokens.colorTransparentStroke)), react_1.shorthands.padding('4px', '11px', '6px', '11px')), { backgroundColor: react_theme_1.tokens.colorNeutralBackground1, color: react_theme_1.tokens.colorNeutralForeground1,
13
- // TODO need to add versions of tokens.alias.shadow.shadow8, etc. that work with filter
14
- filter: "drop-shadow(0 0 2px " + react_theme_1.tokens.colorNeutralShadowAmbient + ") " +
15
- ("drop-shadow(0 4px 8px " + react_theme_1.tokens.colorNeutralShadowKey + ")") }),
16
- visible: {
17
- display: 'block',
18
- },
19
- inverted: {
20
- backgroundColor: react_theme_1.tokens.colorNeutralBackgroundStatic,
21
- color: react_theme_1.tokens.colorNeutralForegroundStaticInverted,
22
- },
23
- arrow: react_positioning_1.createArrowStyles({ arrowHeight: constants_1.arrowHeight }),
24
- });
25
- /**
26
- * Apply styling to the Tooltip slots based on the state
27
- */
28
- var useTooltipStyles_unstable = function (state) {
29
- var styles = useStyles();
30
- state.content.className = react_1.mergeClasses(exports.tooltipClassNames.content, styles.root, state.appearance === 'inverted' && styles.inverted, state.visible && styles.visible, state.content.className);
31
- state.arrowClassName = styles.arrow;
32
- return state;
33
- };
34
- exports.useTooltipStyles_unstable = useTooltipStyles_unstable;
35
- });
36
- //# sourceMappingURL=useTooltipStyles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTooltipStyles.js","sourceRoot":"","sources":["../../../../../../../../../packages/react-components/react-tooltip/src/components/Tooltip/useTooltipStyles.ts"],"names":[],"mappings":";;;;IAOa,QAAA,iBAAiB,GAAiC;QAC7D,OAAO,EAAE,sBAAsB;KAChC,CAAC;IAEF;;OAEG;IACH,IAAM,SAAS,GAAG,kBAAU,CAAC;QAC3B,IAAI,wEACF,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,YAAY,EACvB,QAAQ,EAAE,OAAO,EACjB,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,oBAAM,CAAC,cAAc,EACjC,QAAQ,EAAE,oBAAM,CAAC,eAAe,EAChC,UAAU,EAAE,oBAAM,CAAC,iBAAiB,IAEjC,kBAAU,CAAC,YAAY,CAAC,oBAAM,CAAC,kBAAkB,CAAC,GAClD,kBAAU,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,oBAAM,CAAC,sBAAsB,CAAC,GAChE,kBAAU,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,KACnD,eAAe,EAAE,oBAAM,CAAC,uBAAuB,EAC/C,KAAK,EAAE,oBAAM,CAAC,uBAAuB;YAErC,uFAAuF;YACvF,MAAM,EACJ,yBAAuB,oBAAM,CAAC,yBAAyB,OAAI;iBAC3D,2BAAyB,oBAAM,CAAC,qBAAqB,MAAG,CAAA,GAC3D;QAED,OAAO,EAAE;YACP,OAAO,EAAE,OAAO;SACjB;QAED,QAAQ,EAAE;YACR,eAAe,EAAE,oBAAM,CAAC,4BAA4B;YACpD,KAAK,EAAE,oBAAM,CAAC,oCAAoC;SACnD;QAED,KAAK,EAAE,qCAAiB,CAAC,EAAE,WAAW,yBAAA,EAAE,CAAC;KAC1C,CAAC,CAAC;IAEH;;OAEG;IACI,IAAM,yBAAyB,GAAG,UAAC,KAAmB;QAC3D,IAAM,MAAM,GAAG,SAAS,EAAE,CAAC;QAE3B,KAAK,CAAC,OAAO,CAAC,SAAS,GAAG,oBAAY,CACpC,yBAAiB,CAAC,OAAO,EACzB,MAAM,CAAC,IAAI,EACX,KAAK,CAAC,UAAU,KAAK,UAAU,IAAI,MAAM,CAAC,QAAQ,EAClD,KAAK,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,EAC/B,KAAK,CAAC,OAAO,CAAC,SAAS,CACxB,CAAC;QAEF,KAAK,CAAC,cAAc,GAAG,MAAM,CAAC,KAAK,CAAC;QAEpC,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAdW,QAAA,yBAAyB,6BAcpC","sourcesContent":["import { shorthands, makeStyles, mergeClasses } from '@griffel/react';\nimport { createArrowStyles } from '@fluentui/react-positioning';\nimport { tokens } from '@fluentui/react-theme';\nimport { arrowHeight } from './private/constants';\nimport type { TooltipSlots, TooltipState } from './Tooltip.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\n\nexport const tooltipClassNames: SlotClassNames<TooltipSlots> = {\n content: 'fui-Tooltip__content',\n};\n\n/**\n * Styles for the tooltip\n */\nconst useStyles = makeStyles({\n root: {\n display: 'none',\n boxSizing: 'border-box',\n maxWidth: '240px',\n cursor: 'default',\n fontFamily: tokens.fontFamilyBase,\n fontSize: tokens.fontSizeBase200,\n lineHeight: tokens.lineHeightBase200,\n\n ...shorthands.borderRadius(tokens.borderRadiusMedium),\n ...shorthands.border('1px', 'solid', tokens.colorTransparentStroke),\n ...shorthands.padding('4px', '11px', '6px', '11px'), // '5px 12px 7px 12px' minus the border width '1px'\n backgroundColor: tokens.colorNeutralBackground1,\n color: tokens.colorNeutralForeground1,\n\n // TODO need to add versions of tokens.alias.shadow.shadow8, etc. that work with filter\n filter:\n `drop-shadow(0 0 2px ${tokens.colorNeutralShadowAmbient}) ` +\n `drop-shadow(0 4px 8px ${tokens.colorNeutralShadowKey})`,\n },\n\n visible: {\n display: 'block',\n },\n\n inverted: {\n backgroundColor: tokens.colorNeutralBackgroundStatic,\n color: tokens.colorNeutralForegroundStaticInverted,\n },\n\n arrow: createArrowStyles({ arrowHeight }),\n});\n\n/**\n * Apply styling to the Tooltip slots based on the state\n */\nexport const useTooltipStyles_unstable = (state: TooltipState): TooltipState => {\n const styles = useStyles();\n\n state.content.className = mergeClasses(\n tooltipClassNames.content,\n styles.root,\n state.appearance === 'inverted' && styles.inverted,\n state.visible && styles.visible,\n state.content.className,\n );\n\n state.arrowClassName = styles.arrow;\n\n return state;\n};\n"]}
package/lib-amd/index.js DELETED
@@ -1,11 +0,0 @@
1
- define(["require", "exports", "./Tooltip"], function (require, exports, Tooltip_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.useTooltip_unstable = exports.useTooltipStyles_unstable = exports.tooltipClassNames = exports.renderTooltip_unstable = exports.Tooltip = void 0;
5
- Object.defineProperty(exports, "Tooltip", { enumerable: true, get: function () { return Tooltip_1.Tooltip; } });
6
- Object.defineProperty(exports, "renderTooltip_unstable", { enumerable: true, get: function () { return Tooltip_1.renderTooltip_unstable; } });
7
- Object.defineProperty(exports, "tooltipClassNames", { enumerable: true, get: function () { return Tooltip_1.tooltipClassNames; } });
8
- Object.defineProperty(exports, "useTooltipStyles_unstable", { enumerable: true, get: function () { return Tooltip_1.useTooltipStyles_unstable; } });
9
- Object.defineProperty(exports, "useTooltip_unstable", { enumerable: true, get: function () { return Tooltip_1.useTooltip_unstable; } });
10
- });
11
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/react-tooltip/src/index.ts"],"names":[],"mappings":";;;;IACE,kGAAA,OAAO,OAAA;IACP,iHAAA,sBAAsB,OAAA;IACtB,4GAAA,iBAAiB,OAAA;IACjB,oHAAA,yBAAyB,OAAA;IACzB,8GAAA,mBAAmB,OAAA","sourcesContent":["export {\n Tooltip,\n renderTooltip_unstable,\n tooltipClassNames,\n useTooltipStyles_unstable,\n useTooltip_unstable,\n} from './Tooltip';\nexport type {\n OnVisibleChangeData,\n TooltipProps,\n TooltipSlots,\n TooltipState,\n TooltipChildProps as TooltipTriggerProps,\n} from './Tooltip';\n"]}