@elliemae/ds-hooks-headless-tooltip 3.37.0-rc.5

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.
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var DSHooksHeadlessTooltip_exports = {};
30
+ __export(DSHooksHeadlessTooltip_exports, {
31
+ useHeadlessTooltip: () => useHeadlessTooltip
32
+ });
33
+ module.exports = __toCommonJS(DSHooksHeadlessTooltip_exports);
34
+ var React = __toESM(require("react"));
35
+ var import_react = __toESM(require("react"));
36
+ const useGlobalKeyboardListener = (func) => {
37
+ import_react.default.useEffect(() => {
38
+ document.addEventListener("keydown", func);
39
+ return () => document.removeEventListener("keydown", func);
40
+ }, [func]);
41
+ };
42
+ const useControlledState = (controlledValue, defaultVal) => {
43
+ const [internalValue, setInternalValue] = import_react.default.useState(defaultVal ?? null);
44
+ const val = import_react.default.useMemo(() => {
45
+ if (controlledValue !== void 0) return controlledValue;
46
+ return internalValue;
47
+ }, [controlledValue, internalValue]);
48
+ return [val, setInternalValue];
49
+ };
50
+ const useHeadlessTooltip = (config) => {
51
+ const { hasFocus, isHovering, latestOpenInteraction, onOpen = () => {
52
+ }, onClose = () => {
53
+ } } = config ?? {};
54
+ const [finalHasFocus, setInternalHasFocus] = useControlledState(hasFocus, false);
55
+ const [finalIsHovering, setInternalIsHovering] = useControlledState(isHovering, false);
56
+ const [finalLatestOpenInteraction, setLatestOpenInteraction] = useControlledState(latestOpenInteraction, "");
57
+ const [referenceElement, setReferenceElement] = import_react.default.useState(null);
58
+ const [shouldShowPopover, setShouldShowPopover] = import_react.default.useState(false);
59
+ const showTooltip = import_react.default.useCallback(() => {
60
+ setShouldShowPopover(true);
61
+ onOpen();
62
+ }, [onOpen]);
63
+ const hideTooltip = import_react.default.useCallback(() => {
64
+ setShouldShowPopover(false);
65
+ onClose();
66
+ }, [onClose]);
67
+ const trackLatestKeyboardInteraction = import_react.default.useCallback(() => {
68
+ if (!shouldShowPopover) {
69
+ setLatestOpenInteraction("onFocus");
70
+ }
71
+ }, [setLatestOpenInteraction, shouldShowPopover]);
72
+ const trackLatestMouseInteraction = import_react.default.useCallback(() => {
73
+ if (!shouldShowPopover) {
74
+ setLatestOpenInteraction("onMouseEnter");
75
+ }
76
+ }, [setLatestOpenInteraction, shouldShowPopover]);
77
+ const onFocus = import_react.default.useCallback(() => {
78
+ setInternalHasFocus(true);
79
+ trackLatestKeyboardInteraction();
80
+ if (!shouldShowPopover) {
81
+ showTooltip();
82
+ }
83
+ }, [setInternalHasFocus, shouldShowPopover, showTooltip, trackLatestKeyboardInteraction]);
84
+ const onBlur = import_react.default.useCallback(() => {
85
+ setInternalHasFocus(false);
86
+ if (!finalIsHovering || finalLatestOpenInteraction === "onFocus") hideTooltip();
87
+ }, [setInternalHasFocus, finalIsHovering, finalLatestOpenInteraction, hideTooltip]);
88
+ const onMouseEnter = import_react.default.useCallback(() => {
89
+ setInternalIsHovering(true);
90
+ trackLatestMouseInteraction();
91
+ if (!shouldShowPopover) {
92
+ showTooltip();
93
+ }
94
+ }, [setInternalIsHovering, shouldShowPopover, showTooltip, trackLatestMouseInteraction]);
95
+ const onMouseLeave = import_react.default.useCallback(() => {
96
+ setInternalIsHovering(false);
97
+ if (!finalHasFocus || finalLatestOpenInteraction === "onMouseEnter") hideTooltip();
98
+ }, [setInternalIsHovering, finalHasFocus, finalLatestOpenInteraction, hideTooltip]);
99
+ const handleEscKey = import_react.default.useCallback(
100
+ ({ key }) => {
101
+ if (key === "Escape") hideTooltip();
102
+ },
103
+ [hideTooltip]
104
+ );
105
+ useGlobalKeyboardListener(handleEscKey);
106
+ return import_react.default.useMemo(
107
+ () => ({
108
+ hasFocus: finalHasFocus,
109
+ isHovering: finalIsHovering,
110
+ latestOpenInteraction: finalLatestOpenInteraction,
111
+ referenceElement,
112
+ setReferenceElement,
113
+ shouldShowPopover,
114
+ showTooltip,
115
+ hideTooltip,
116
+ onFocus,
117
+ onBlur,
118
+ onMouseEnter,
119
+ onMouseLeave
120
+ }),
121
+ [
122
+ finalHasFocus,
123
+ finalIsHovering,
124
+ finalLatestOpenInteraction,
125
+ referenceElement,
126
+ shouldShowPopover,
127
+ showTooltip,
128
+ hideTooltip,
129
+ onFocus,
130
+ onBlur,
131
+ onMouseEnter,
132
+ onMouseLeave
133
+ ]
134
+ );
135
+ };
136
+ //# sourceMappingURL=DSHooksHeadlessTooltip.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/DSHooksHeadlessTooltip.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
4
+ "sourcesContent": ["import React from 'react';\n\n// This function is a custom hook that adds a keyboard event listener to the document\n// calls the specified function when a key is pressed.\nconst useGlobalKeyboardListener = (func: ({ key }: { key: string }) => void) => {\n React.useEffect(() => {\n document.addEventListener('keydown', func);\n return () => document.removeEventListener('keydown', func);\n }, [func]);\n};\n\nexport type LatestOpenInteraction = '' | 'onFocus' | 'onMouseEnter';\nexport type UseHeadlessTooltipConfig = {\n hasFocus?: boolean;\n isHovering?: boolean;\n latestOpenInteraction?: LatestOpenInteraction;\n onOpen?: () => void;\n onClose?: () => void;\n};\n\nconst useControlledState = <T,>(controlledValue?: T, defaultVal?: T) => {\n const [internalValue, setInternalValue] = React.useState<T | null>(defaultVal ?? null);\n const val = React.useMemo(() => {\n if (controlledValue !== undefined) return controlledValue;\n return internalValue;\n }, [controlledValue, internalValue]);\n return [val, setInternalValue] as const;\n};\n\n/**\n * A custom hook that provides logic for a headless tooltip. This hook can be used in a controlled or uncontrolled way.\n * @param {UseHeadlessTooltipConfig} config - The configuration object for the hook.\n * @param {boolean} config.hasFocus - Whether or not the trigger element has focus. If this is not provided, the hook will track focus internally.\n * @param {boolean} config.isHovering - Whether or not the mouse is hovering over the trigger element. If this is not provided, the hook will track hover internally.\n * @param {LatestOpenInteraction} config.latestOpenInteraction - Whether or not the mouse is hovering over the trigger element. If this is not provided, the hook will track hover internally.\n * @param {Function} config.onOpen - A callback that will be invoked when the tooltip is opened.\n * @param {Function} config.onClose - A callback that will be invoked when the tooltip is closed.\n * @returns {object} - An object containing the following properties:\n *\n * {boolean} hasFocus - Whether or not the trigger element has focus.\n *\n * {boolean} isHovering - Whether or not the mouse is hovering over the trigger element.\n *\n * {'' | 'onFocus' | 'onMouseEnter'} latestOpenInteraction - which was the last operation that is used to control if the tooltip should show or not.\n *\n * {string} finalLatestOpenInteraction - The most recent interaction that caused the tooltip to open.\n *\n * {HTMLDivElement} referenceElement - The trigger element.\n *\n * {function} setReferenceElement - A function that sets the trigger element.\n *\n * {boolean} shouldShowPopover - Whether or not the tooltip is visible.\n *\n * {function} showTooltip - A function that opens the tooltip.\n *\n * {function} hideTooltip - A function that closes the tooltip.\n *\n * {function} onFocus - A function that should be invoked when the trigger element receives focus.\n *\n * {function} onBlur - A function that should be invoked when the trigger element loses focus.\n *\n * {function} onMouseEnter - A function that should be invoked when the mouse enters the trigger element.\n *\n * {function} onMouseLeave - A function that should be invoked when the mouse leaves the trigger element.\n * @example\n * const tooltipHelpers = useHeadlessTooltip({\n * hasFocus: true,\n * isHovering: false,\n * onOpen: () => console.log('tooltip opened'),\n * onClose: () => console.log('tooltip closed'),\n * });\n * ...\n * <div>\n * <button\n * ref={tooltipHelpers.setReferenceElement}\n * onMouseEnter={tooltipHelpers.onMouseEnter}\n * onMouseLeave={tooltipHelpers.onMouseLeave}\n * onPointerEnter={tooltipHelpers.onMouseEnter}\n * onPointerLeave={tooltipHelpers.onMouseLeave}\n * onFocus={tooltipHelpers.onFocus}\n * onBlur={tooltipHelpers.onBlur}\n * >hello</button>\n * <DSPopperJS\n * referenceElement={tooltipHelpers.referenceElement}\n * shouldShowPopover={tooltipHelpers.shouldShowPopover}\n * >\n * <div>Tooltip content</div>\n * </DSPopperJS>\n * </div>\n */\nexport const useHeadlessTooltip = (config?: UseHeadlessTooltipConfig) => {\n // Extract the configuration values or set default values if they are not provided.\n const { hasFocus, isHovering, latestOpenInteraction, onOpen = () => {}, onClose = () => {} } = config ?? {};\n\n // this pattern is basically a way to allow usage of the hook in a controlled or uncontrolled way.\n const [finalHasFocus, setInternalHasFocus] = useControlledState<boolean>(hasFocus, false);\n const [finalIsHovering, setInternalIsHovering] = useControlledState<boolean>(isHovering, false);\n const [finalLatestOpenInteraction, setLatestOpenInteraction] = useControlledState<string>(latestOpenInteraction, '');\n\n // end of controlled/uncontrolled pattern\n\n // Set up state variables for the tooltip's visibility and the most recent interaction that caused it to open.\n // The most recent interaction is used to determine whether or not to close the tooltip when the user\n // moves the mouse away from the trigger element.\n const [referenceElement, setReferenceElement] = React.useState<HTMLDivElement | null>(null);\n const [shouldShowPopover, setShouldShowPopover] = React.useState<boolean>(false);\n\n // memoized versions of the show and hide functions\n // those include the callbacks to allow \"controlled\" usage of the hook\n const showTooltip = React.useCallback(() => {\n setShouldShowPopover(true);\n onOpen();\n }, [onOpen]);\n\n const hideTooltip = React.useCallback(() => {\n setShouldShowPopover(false);\n onClose();\n }, [onClose]);\n\n const trackLatestKeyboardInteraction = React.useCallback(() => {\n if (!shouldShowPopover) {\n setLatestOpenInteraction('onFocus');\n }\n }, [setLatestOpenInteraction, shouldShowPopover]);\n\n const trackLatestMouseInteraction = React.useCallback(() => {\n if (!shouldShowPopover) {\n setLatestOpenInteraction('onMouseEnter');\n }\n }, [setLatestOpenInteraction, shouldShowPopover]);\n\n // following here are the event handlers that are used to control the tooltip's visibility logic\n const onFocus = React.useCallback(() => {\n setInternalHasFocus(true); // uncontrolled usage tracking\n trackLatestKeyboardInteraction();\n if (!shouldShowPopover) {\n showTooltip();\n }\n }, [setInternalHasFocus, shouldShowPopover, showTooltip, trackLatestKeyboardInteraction]);\n\n const onBlur = React.useCallback(() => {\n setInternalHasFocus(false); // uncontrolled usage tracking\n // blur may triggered via keyboard navigation or mouse interaction\n // every time the mouse is hovering, we want to keep the tooltip open\n // but if the mouse is not hovering, we want to close the tooltip only if the last interaction was via keyboard\n // e.g if the user keyboard navigates to the trigger element and then moves the mouse away, we want to keep the tooltip open\n if (!finalIsHovering || finalLatestOpenInteraction === 'onFocus') hideTooltip();\n }, [setInternalHasFocus, finalIsHovering, finalLatestOpenInteraction, hideTooltip]);\n\n const onMouseEnter = React.useCallback(() => {\n setInternalIsHovering(true); // uncontrolled usage tracking\n // kind of debouncing the mouse enter event to reduce the avarge O() notation of the function\n // even if this is continually invoked, it will be O(1) and controlled callbacks will be invoked only once\n trackLatestMouseInteraction();\n if (!shouldShowPopover) {\n showTooltip();\n }\n }, [setInternalIsHovering, shouldShowPopover, showTooltip, trackLatestMouseInteraction]);\n\n const onMouseLeave = React.useCallback(() => {\n setInternalIsHovering(false); // uncontrolled usage tracking\n // mouse leave may be triggered via keyboard navigation or mouse interaction\n // every time the trigger element has focus, we want to keep the tooltip open\n // but if the trigger element does not have focus, we want to close the tooltip only if the last interaction was via mouse\n // e.g if the user keyboard navigates to the trigger element and then moves the mouse away, we want to keep the tooltip open\n if (!finalHasFocus || finalLatestOpenInteraction === 'onMouseEnter') hideTooltip();\n }, [setInternalIsHovering, finalHasFocus, finalLatestOpenInteraction, hideTooltip]);\n\n const handleEscKey = React.useCallback(\n ({ key }: { key: string }) => {\n // accessibility standard: pressing escape should close the tooltip\n if (key === 'Escape') hideTooltip();\n },\n [hideTooltip],\n );\n\n // accessibilty standard: pressing escape should close the tooltip no matter where the focus is\n useGlobalKeyboardListener(handleEscKey);\n\n return React.useMemo(\n () => ({\n hasFocus: finalHasFocus,\n isHovering: finalIsHovering,\n latestOpenInteraction: finalLatestOpenInteraction,\n referenceElement,\n setReferenceElement,\n shouldShowPopover,\n showTooltip,\n hideTooltip,\n onFocus,\n onBlur,\n onMouseEnter,\n onMouseLeave,\n }),\n [\n finalHasFocus,\n finalIsHovering,\n finalLatestOpenInteraction,\n referenceElement,\n shouldShowPopover,\n showTooltip,\n hideTooltip,\n onFocus,\n onBlur,\n onMouseEnter,\n onMouseLeave,\n ],\n );\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAkB;AAIlB,MAAM,4BAA4B,CAAC,SAA6C;AAC9E,eAAAA,QAAM,UAAU,MAAM;AACpB,aAAS,iBAAiB,WAAW,IAAI;AACzC,WAAO,MAAM,SAAS,oBAAoB,WAAW,IAAI;AAAA,EAC3D,GAAG,CAAC,IAAI,CAAC;AACX;AAWA,MAAM,qBAAqB,CAAK,iBAAqB,eAAmB;AACtE,QAAM,CAAC,eAAe,gBAAgB,IAAI,aAAAA,QAAM,SAAmB,cAAc,IAAI;AACrF,QAAM,MAA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 +1,36 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var src_exports = {};
30
+ __export(src_exports, {
31
+ useHeadlessTooltip: () => import_DSHooksHeadlessTooltip.useHeadlessTooltip
32
+ });
33
+ module.exports = __toCommonJS(src_exports);
34
+ var React = __toESM(require("react"));
35
+ var import_DSHooksHeadlessTooltip = require("./DSHooksHeadlessTooltip.js");
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
+ "sourcesContent": ["export {\n type LatestOpenInteraction,\n type UseHeadlessTooltipConfig,\n useHeadlessTooltip,\n} from './DSHooksHeadlessTooltip.js';\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,oCAIO;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "commonjs",
3
+ "sideEffects": [
4
+ "*.css",
5
+ "*.scss"
6
+ ]
7
+ }
@@ -0,0 +1,106 @@
1
+ import * as React from "react";
2
+ import React2 from "react";
3
+ const useGlobalKeyboardListener = (func) => {
4
+ React2.useEffect(() => {
5
+ document.addEventListener("keydown", func);
6
+ return () => document.removeEventListener("keydown", func);
7
+ }, [func]);
8
+ };
9
+ const useControlledState = (controlledValue, defaultVal) => {
10
+ const [internalValue, setInternalValue] = React2.useState(defaultVal ?? null);
11
+ const val = React2.useMemo(() => {
12
+ if (controlledValue !== void 0) return controlledValue;
13
+ return internalValue;
14
+ }, [controlledValue, internalValue]);
15
+ return [val, setInternalValue];
16
+ };
17
+ const useHeadlessTooltip = (config) => {
18
+ const { hasFocus, isHovering, latestOpenInteraction, onOpen = () => {
19
+ }, onClose = () => {
20
+ } } = config ?? {};
21
+ const [finalHasFocus, setInternalHasFocus] = useControlledState(hasFocus, false);
22
+ const [finalIsHovering, setInternalIsHovering] = useControlledState(isHovering, false);
23
+ const [finalLatestOpenInteraction, setLatestOpenInteraction] = useControlledState(latestOpenInteraction, "");
24
+ const [referenceElement, setReferenceElement] = React2.useState(null);
25
+ const [shouldShowPopover, setShouldShowPopover] = React2.useState(false);
26
+ const showTooltip = React2.useCallback(() => {
27
+ setShouldShowPopover(true);
28
+ onOpen();
29
+ }, [onOpen]);
30
+ const hideTooltip = React2.useCallback(() => {
31
+ setShouldShowPopover(false);
32
+ onClose();
33
+ }, [onClose]);
34
+ const trackLatestKeyboardInteraction = React2.useCallback(() => {
35
+ if (!shouldShowPopover) {
36
+ setLatestOpenInteraction("onFocus");
37
+ }
38
+ }, [setLatestOpenInteraction, shouldShowPopover]);
39
+ const trackLatestMouseInteraction = React2.useCallback(() => {
40
+ if (!shouldShowPopover) {
41
+ setLatestOpenInteraction("onMouseEnter");
42
+ }
43
+ }, [setLatestOpenInteraction, shouldShowPopover]);
44
+ const onFocus = React2.useCallback(() => {
45
+ setInternalHasFocus(true);
46
+ trackLatestKeyboardInteraction();
47
+ if (!shouldShowPopover) {
48
+ showTooltip();
49
+ }
50
+ }, [setInternalHasFocus, shouldShowPopover, showTooltip, trackLatestKeyboardInteraction]);
51
+ const onBlur = React2.useCallback(() => {
52
+ setInternalHasFocus(false);
53
+ if (!finalIsHovering || finalLatestOpenInteraction === "onFocus") hideTooltip();
54
+ }, [setInternalHasFocus, finalIsHovering, finalLatestOpenInteraction, hideTooltip]);
55
+ const onMouseEnter = React2.useCallback(() => {
56
+ setInternalIsHovering(true);
57
+ trackLatestMouseInteraction();
58
+ if (!shouldShowPopover) {
59
+ showTooltip();
60
+ }
61
+ }, [setInternalIsHovering, shouldShowPopover, showTooltip, trackLatestMouseInteraction]);
62
+ const onMouseLeave = React2.useCallback(() => {
63
+ setInternalIsHovering(false);
64
+ if (!finalHasFocus || finalLatestOpenInteraction === "onMouseEnter") hideTooltip();
65
+ }, [setInternalIsHovering, finalHasFocus, finalLatestOpenInteraction, hideTooltip]);
66
+ const handleEscKey = React2.useCallback(
67
+ ({ key }) => {
68
+ if (key === "Escape") hideTooltip();
69
+ },
70
+ [hideTooltip]
71
+ );
72
+ useGlobalKeyboardListener(handleEscKey);
73
+ return React2.useMemo(
74
+ () => ({
75
+ hasFocus: finalHasFocus,
76
+ isHovering: finalIsHovering,
77
+ latestOpenInteraction: finalLatestOpenInteraction,
78
+ referenceElement,
79
+ setReferenceElement,
80
+ shouldShowPopover,
81
+ showTooltip,
82
+ hideTooltip,
83
+ onFocus,
84
+ onBlur,
85
+ onMouseEnter,
86
+ onMouseLeave
87
+ }),
88
+ [
89
+ finalHasFocus,
90
+ finalIsHovering,
91
+ finalLatestOpenInteraction,
92
+ referenceElement,
93
+ shouldShowPopover,
94
+ showTooltip,
95
+ hideTooltip,
96
+ onFocus,
97
+ onBlur,
98
+ onMouseEnter,
99
+ onMouseLeave
100
+ ]
101
+ );
102
+ };
103
+ export {
104
+ useHeadlessTooltip
105
+ };
106
+ //# sourceMappingURL=DSHooksHeadlessTooltip.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/DSHooksHeadlessTooltip.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\n\n// This function is a custom hook that adds a keyboard event listener to the document\n// calls the specified function when a key is pressed.\nconst useGlobalKeyboardListener = (func: ({ key }: { key: string }) => void) => {\n React.useEffect(() => {\n document.addEventListener('keydown', func);\n return () => document.removeEventListener('keydown', func);\n }, [func]);\n};\n\nexport type LatestOpenInteraction = '' | 'onFocus' | 'onMouseEnter';\nexport type UseHeadlessTooltipConfig = {\n hasFocus?: boolean;\n isHovering?: boolean;\n latestOpenInteraction?: LatestOpenInteraction;\n onOpen?: () => void;\n onClose?: () => void;\n};\n\nconst useControlledState = <T,>(controlledValue?: T, defaultVal?: T) => {\n const [internalValue, setInternalValue] = React.useState<T | null>(defaultVal ?? null);\n const val = React.useMemo(() => {\n if (controlledValue !== undefined) return controlledValue;\n return internalValue;\n }, [controlledValue, internalValue]);\n return [val, setInternalValue] as const;\n};\n\n/**\n * A custom hook that provides logic for a headless tooltip. This hook can be used in a controlled or uncontrolled way.\n * @param {UseHeadlessTooltipConfig} config - The configuration object for the hook.\n * @param {boolean} config.hasFocus - Whether or not the trigger element has focus. If this is not provided, the hook will track focus internally.\n * @param {boolean} config.isHovering - Whether or not the mouse is hovering over the trigger element. If this is not provided, the hook will track hover internally.\n * @param {LatestOpenInteraction} config.latestOpenInteraction - Whether or not the mouse is hovering over the trigger element. If this is not provided, the hook will track hover internally.\n * @param {Function} config.onOpen - A callback that will be invoked when the tooltip is opened.\n * @param {Function} config.onClose - A callback that will be invoked when the tooltip is closed.\n * @returns {object} - An object containing the following properties:\n *\n * {boolean} hasFocus - Whether or not the trigger element has focus.\n *\n * {boolean} isHovering - Whether or not the mouse is hovering over the trigger element.\n *\n * {'' | 'onFocus' | 'onMouseEnter'} latestOpenInteraction - which was the last operation that is used to control if the tooltip should show or not.\n *\n * {string} finalLatestOpenInteraction - The most recent interaction that caused the tooltip to open.\n *\n * {HTMLDivElement} referenceElement - The trigger element.\n *\n * {function} setReferenceElement - A function that sets the trigger element.\n *\n * {boolean} shouldShowPopover - Whether or not the tooltip is visible.\n *\n * {function} showTooltip - A function that opens the tooltip.\n *\n * {function} hideTooltip - A function that closes the tooltip.\n *\n * {function} onFocus - A function that should be invoked when the trigger element receives focus.\n *\n * {function} onBlur - A function that should be invoked when the trigger element loses focus.\n *\n * {function} onMouseEnter - A function that should be invoked when the mouse enters the trigger element.\n *\n * {function} onMouseLeave - A function that should be invoked when the mouse leaves the trigger element.\n * @example\n * const tooltipHelpers = useHeadlessTooltip({\n * hasFocus: true,\n * isHovering: false,\n * onOpen: () => console.log('tooltip opened'),\n * onClose: () => console.log('tooltip closed'),\n * });\n * ...\n * <div>\n * <button\n * ref={tooltipHelpers.setReferenceElement}\n * onMouseEnter={tooltipHelpers.onMouseEnter}\n * onMouseLeave={tooltipHelpers.onMouseLeave}\n * onPointerEnter={tooltipHelpers.onMouseEnter}\n * onPointerLeave={tooltipHelpers.onMouseLeave}\n * onFocus={tooltipHelpers.onFocus}\n * onBlur={tooltipHelpers.onBlur}\n * >hello</button>\n * <DSPopperJS\n * referenceElement={tooltipHelpers.referenceElement}\n * shouldShowPopover={tooltipHelpers.shouldShowPopover}\n * >\n * <div>Tooltip content</div>\n * </DSPopperJS>\n * </div>\n */\nexport const useHeadlessTooltip = (config?: UseHeadlessTooltipConfig) => {\n // Extract the configuration values or set default values if they are not provided.\n const { hasFocus, isHovering, latestOpenInteraction, onOpen = () => {}, onClose = () => {} } = config ?? {};\n\n // this pattern is basically a way to allow usage of the hook in a controlled or uncontrolled way.\n const [finalHasFocus, setInternalHasFocus] = useControlledState<boolean>(hasFocus, false);\n const [finalIsHovering, setInternalIsHovering] = useControlledState<boolean>(isHovering, false);\n const [finalLatestOpenInteraction, setLatestOpenInteraction] = useControlledState<string>(latestOpenInteraction, '');\n\n // end of controlled/uncontrolled pattern\n\n // Set up state variables for the tooltip's visibility and the most recent interaction that caused it to open.\n // The most recent interaction is used to determine whether or not to close the tooltip when the user\n // moves the mouse away from the trigger element.\n const [referenceElement, setReferenceElement] = React.useState<HTMLDivElement | null>(null);\n const [shouldShowPopover, setShouldShowPopover] = React.useState<boolean>(false);\n\n // memoized versions of the show and hide functions\n // those include the callbacks to allow \"controlled\" usage of the hook\n const showTooltip = React.useCallback(() => {\n setShouldShowPopover(true);\n onOpen();\n }, [onOpen]);\n\n const hideTooltip = React.useCallback(() => {\n setShouldShowPopover(false);\n onClose();\n }, [onClose]);\n\n const trackLatestKeyboardInteraction = React.useCallback(() => {\n if (!shouldShowPopover) {\n setLatestOpenInteraction('onFocus');\n }\n }, [setLatestOpenInteraction, shouldShowPopover]);\n\n const trackLatestMouseInteraction = React.useCallback(() => {\n if (!shouldShowPopover) {\n setLatestOpenInteraction('onMouseEnter');\n }\n }, [setLatestOpenInteraction, shouldShowPopover]);\n\n // following here are the event handlers that are used to control the tooltip's visibility logic\n const onFocus = React.useCallback(() => {\n setInternalHasFocus(true); // uncontrolled usage tracking\n trackLatestKeyboardInteraction();\n if (!shouldShowPopover) {\n showTooltip();\n }\n }, [setInternalHasFocus, shouldShowPopover, showTooltip, trackLatestKeyboardInteraction]);\n\n const onBlur = React.useCallback(() => {\n setInternalHasFocus(false); // uncontrolled usage tracking\n // blur may triggered via keyboard navigation or mouse interaction\n // every time the mouse is hovering, we want to keep the tooltip open\n // but if the mouse is not hovering, we want to close the tooltip only if the last interaction was via keyboard\n // e.g if the user keyboard navigates to the trigger element and then moves the mouse away, we want to keep the tooltip open\n if (!finalIsHovering || finalLatestOpenInteraction === 'onFocus') hideTooltip();\n }, [setInternalHasFocus, finalIsHovering, finalLatestOpenInteraction, hideTooltip]);\n\n const onMouseEnter = React.useCallback(() => {\n setInternalIsHovering(true); // uncontrolled usage tracking\n // kind of debouncing the mouse enter event to reduce the avarge O() notation of the function\n // even if this is continually invoked, it will be O(1) and controlled callbacks will be invoked only once\n trackLatestMouseInteraction();\n if (!shouldShowPopover) {\n showTooltip();\n }\n }, [setInternalIsHovering, shouldShowPopover, showTooltip, trackLatestMouseInteraction]);\n\n const onMouseLeave = React.useCallback(() => {\n setInternalIsHovering(false); // uncontrolled usage tracking\n // mouse leave may be triggered via keyboard navigation or mouse interaction\n // every time the trigger element has focus, we want to keep the tooltip open\n // but if the trigger element does not have focus, we want to close the tooltip only if the last interaction was via mouse\n // e.g if the user keyboard navigates to the trigger element and then moves the mouse away, we want to keep the tooltip open\n if (!finalHasFocus || finalLatestOpenInteraction === 'onMouseEnter') hideTooltip();\n }, [setInternalIsHovering, finalHasFocus, finalLatestOpenInteraction, hideTooltip]);\n\n const handleEscKey = React.useCallback(\n ({ key }: { key: string }) => {\n // accessibility standard: pressing escape should close the tooltip\n if (key === 'Escape') hideTooltip();\n },\n [hideTooltip],\n );\n\n // accessibilty standard: pressing escape should close the tooltip no matter where the focus is\n useGlobalKeyboardListener(handleEscKey);\n\n return React.useMemo(\n () => ({\n hasFocus: finalHasFocus,\n isHovering: finalIsHovering,\n latestOpenInteraction: finalLatestOpenInteraction,\n referenceElement,\n setReferenceElement,\n shouldShowPopover,\n showTooltip,\n hideTooltip,\n onFocus,\n onBlur,\n onMouseEnter,\n onMouseLeave,\n }),\n [\n finalHasFocus,\n finalIsHovering,\n finalLatestOpenInteraction,\n referenceElement,\n shouldShowPopover,\n showTooltip,\n hideTooltip,\n onFocus,\n onBlur,\n onMouseEnter,\n onMouseLeave,\n ],\n );\n};\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACAvB,OAAOA,YA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AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": ["React"]
7
+ }
@@ -0,0 +1,8 @@
1
+ import * as React from "react";
2
+ import {
3
+ useHeadlessTooltip
4
+ } from "./DSHooksHeadlessTooltip.js";
5
+ export {
6
+ useHeadlessTooltip
7
+ };
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/index.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export {\n type LatestOpenInteraction,\n type UseHeadlessTooltipConfig,\n useHeadlessTooltip,\n} from './DSHooksHeadlessTooltip.js';\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACAvB;AAAA,EAGE;AAAA,OACK;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "module",
3
+ "sideEffects": [
4
+ "*.css",
5
+ "*.scss"
6
+ ]
7
+ }
@@ -0,0 +1,84 @@
1
+ import React from 'react';
2
+ export type LatestOpenInteraction = '' | 'onFocus' | 'onMouseEnter';
3
+ export type UseHeadlessTooltipConfig = {
4
+ hasFocus?: boolean;
5
+ isHovering?: boolean;
6
+ latestOpenInteraction?: LatestOpenInteraction;
7
+ onOpen?: () => void;
8
+ onClose?: () => void;
9
+ };
10
+ /**
11
+ * A custom hook that provides logic for a headless tooltip. This hook can be used in a controlled or uncontrolled way.
12
+ * @param {UseHeadlessTooltipConfig} config - The configuration object for the hook.
13
+ * @param {boolean} config.hasFocus - Whether or not the trigger element has focus. If this is not provided, the hook will track focus internally.
14
+ * @param {boolean} config.isHovering - Whether or not the mouse is hovering over the trigger element. If this is not provided, the hook will track hover internally.
15
+ * @param {LatestOpenInteraction} config.latestOpenInteraction - Whether or not the mouse is hovering over the trigger element. If this is not provided, the hook will track hover internally.
16
+ * @param {Function} config.onOpen - A callback that will be invoked when the tooltip is opened.
17
+ * @param {Function} config.onClose - A callback that will be invoked when the tooltip is closed.
18
+ * @returns {object} - An object containing the following properties:
19
+ *
20
+ * {boolean} hasFocus - Whether or not the trigger element has focus.
21
+ *
22
+ * {boolean} isHovering - Whether or not the mouse is hovering over the trigger element.
23
+ *
24
+ * {'' | 'onFocus' | 'onMouseEnter'} latestOpenInteraction - which was the last operation that is used to control if the tooltip should show or not.
25
+ *
26
+ * {string} finalLatestOpenInteraction - The most recent interaction that caused the tooltip to open.
27
+ *
28
+ * {HTMLDivElement} referenceElement - The trigger element.
29
+ *
30
+ * {function} setReferenceElement - A function that sets the trigger element.
31
+ *
32
+ * {boolean} shouldShowPopover - Whether or not the tooltip is visible.
33
+ *
34
+ * {function} showTooltip - A function that opens the tooltip.
35
+ *
36
+ * {function} hideTooltip - A function that closes the tooltip.
37
+ *
38
+ * {function} onFocus - A function that should be invoked when the trigger element receives focus.
39
+ *
40
+ * {function} onBlur - A function that should be invoked when the trigger element loses focus.
41
+ *
42
+ * {function} onMouseEnter - A function that should be invoked when the mouse enters the trigger element.
43
+ *
44
+ * {function} onMouseLeave - A function that should be invoked when the mouse leaves the trigger element.
45
+ * @example
46
+ * const tooltipHelpers = useHeadlessTooltip({
47
+ * hasFocus: true,
48
+ * isHovering: false,
49
+ * onOpen: () => console.log('tooltip opened'),
50
+ * onClose: () => console.log('tooltip closed'),
51
+ * });
52
+ * ...
53
+ * <div>
54
+ * <button
55
+ * ref={tooltipHelpers.setReferenceElement}
56
+ * onMouseEnter={tooltipHelpers.onMouseEnter}
57
+ * onMouseLeave={tooltipHelpers.onMouseLeave}
58
+ * onPointerEnter={tooltipHelpers.onMouseEnter}
59
+ * onPointerLeave={tooltipHelpers.onMouseLeave}
60
+ * onFocus={tooltipHelpers.onFocus}
61
+ * onBlur={tooltipHelpers.onBlur}
62
+ * >hello</button>
63
+ * <DSPopperJS
64
+ * referenceElement={tooltipHelpers.referenceElement}
65
+ * shouldShowPopover={tooltipHelpers.shouldShowPopover}
66
+ * >
67
+ * <div>Tooltip content</div>
68
+ * </DSPopperJS>
69
+ * </div>
70
+ */
71
+ export declare const useHeadlessTooltip: (config?: UseHeadlessTooltipConfig) => {
72
+ hasFocus: boolean | null;
73
+ isHovering: boolean | null;
74
+ latestOpenInteraction: string | null;
75
+ referenceElement: HTMLDivElement | null;
76
+ setReferenceElement: React.Dispatch<React.SetStateAction<HTMLDivElement | null>>;
77
+ shouldShowPopover: boolean;
78
+ showTooltip: () => void;
79
+ hideTooltip: () => void;
80
+ onFocus: () => void;
81
+ onBlur: () => void;
82
+ onMouseEnter: () => void;
83
+ onMouseLeave: () => void;
84
+ };
@@ -0,0 +1 @@
1
+ export { type LatestOpenInteraction, type UseHeadlessTooltipConfig, useHeadlessTooltip, } from './DSHooksHeadlessTooltip.js';
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@elliemae/ds-hooks-headless-tooltip",
3
+ "version": "3.37.0-rc.5",
4
+ "license": "MIT",
5
+ "description": "ICE MT - Dimsum - Headless tooltip Hook",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "module": "./dist/esm/index.js",
10
+ "main": "./dist/cjs/index.js",
11
+ "types": "./dist/types/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/types/index.d.ts",
15
+ "import": "./dist/esm/index.js",
16
+ "require": "./dist/cjs/index.js"
17
+ }
18
+ },
19
+ "sideEffects": [
20
+ "*.css",
21
+ "*.scss"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://git.elliemae.io/platform-ui/dimsum.git"
26
+ },
27
+ "engines": {
28
+ "pnpm": ">=6",
29
+ "node": ">=16"
30
+ },
31
+ "author": "ICE MT",
32
+ "jestSonar": {
33
+ "sonar56x": true,
34
+ "reportPath": "reports",
35
+ "reportFile": "tests.xml",
36
+ "indent": 4
37
+ },
38
+ "devDependencies": {
39
+ "@elliemae/pui-cli": "~9.0.0-next.31",
40
+ "@elliemae/ds-monorepo-devops": "3.37.0-rc.5"
41
+ },
42
+ "peerDependencies": {
43
+ "lodash": "^4.17.21",
44
+ "react": "~17.0.2",
45
+ "react-dom": "^17.0.2",
46
+ "styled-components": "~5.3.9",
47
+ "styled-system": "^5.1.5"
48
+ },
49
+ "publishConfig": {
50
+ "access": "public",
51
+ "typeSafety": false
52
+ },
53
+ "scripts": {
54
+ "dev": "cross-env NODE_ENV=development node ../../../scripts/build/build.mjs --watch",
55
+ "test": "pui-cli test --passWithNoTests --coverage=\"false\"",
56
+ "lint": "node ../../../scripts/lint.mjs --fix",
57
+ "dts": "node ../../../scripts/dts.mjs",
58
+ "build": "cross-env NODE_ENV=production node ../../../scripts/build/build.mjs",
59
+ "checkDeps": "npm exec ../../util/ds-codemods -- check-missing-packages --projectFolderPath=\"./\" --ignorePackagesGlobPattern=\"\" --ignoreFilesGlobPattern=\"**/test-ables/*,**/tests/*\""
60
+ }
61
+ }