datocms-react-ui 2.0.17 → 2.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/HotKey/index.js +105 -0
- package/dist/cjs/HotKey/index.js.map +1 -0
- package/dist/cjs/HotKey/styles.module.css.json +1 -0
- package/dist/cjs/Tooltip/Tooltip/index.js +116 -0
- package/dist/cjs/Tooltip/Tooltip/index.js.map +1 -0
- package/dist/cjs/Tooltip/TooltipContent/index.js +147 -0
- package/dist/cjs/Tooltip/TooltipContent/index.js.map +1 -0
- package/dist/cjs/Tooltip/TooltipContent/styles.module.css.json +1 -0
- package/dist/cjs/Tooltip/TooltipDelayGroup/index.js +140 -0
- package/dist/cjs/Tooltip/TooltipDelayGroup/index.js.map +1 -0
- package/dist/cjs/Tooltip/TooltipTrigger/index.js +102 -0
- package/dist/cjs/Tooltip/TooltipTrigger/index.js.map +1 -0
- package/dist/cjs/Tooltip/index.js +12 -0
- package/dist/cjs/Tooltip/index.js.map +1 -0
- package/dist/cjs/Tooltip/utils.js +165 -0
- package/dist/cjs/Tooltip/utils.js.map +1 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/HotKey/index.d.ts +70 -0
- package/dist/esm/HotKey/index.js +75 -0
- package/dist/esm/HotKey/index.js.map +1 -0
- package/dist/esm/HotKey/styles.module.css.json +1 -0
- package/dist/esm/Tooltip/Tooltip/index.d.ts +74 -0
- package/dist/esm/Tooltip/Tooltip/index.js +89 -0
- package/dist/esm/Tooltip/Tooltip/index.js.map +1 -0
- package/dist/esm/Tooltip/TooltipContent/index.d.ts +68 -0
- package/dist/esm/Tooltip/TooltipContent/index.js +118 -0
- package/dist/esm/Tooltip/TooltipContent/index.js.map +1 -0
- package/dist/esm/Tooltip/TooltipContent/styles.module.css.json +1 -0
- package/dist/esm/Tooltip/TooltipDelayGroup/index.d.ts +118 -0
- package/dist/esm/Tooltip/TooltipDelayGroup/index.js +113 -0
- package/dist/esm/Tooltip/TooltipDelayGroup/index.js.map +1 -0
- package/dist/esm/Tooltip/TooltipTrigger/index.d.ts +45 -0
- package/dist/esm/Tooltip/TooltipTrigger/index.js +76 -0
- package/dist/esm/Tooltip/TooltipTrigger/index.js.map +1 -0
- package/dist/esm/Tooltip/index.d.ts +8 -0
- package/dist/esm/Tooltip/index.js +5 -0
- package/dist/esm/Tooltip/index.js.map +1 -0
- package/dist/esm/Tooltip/utils.d.ts +166 -0
- package/dist/esm/Tooltip/utils.js +135 -0
- package/dist/esm/Tooltip/utils.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/types/HotKey/index.d.ts +70 -0
- package/dist/types/Tooltip/Tooltip/index.d.ts +74 -0
- package/dist/types/Tooltip/TooltipContent/index.d.ts +68 -0
- package/dist/types/Tooltip/TooltipDelayGroup/index.d.ts +118 -0
- package/dist/types/Tooltip/TooltipTrigger/index.d.ts +45 -0
- package/dist/types/Tooltip/index.d.ts +8 -0
- package/dist/types/Tooltip/utils.d.ts +166 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +4 -3
- package/src/HotKey/index.tsx +95 -0
- package/src/HotKey/styles.module.css +22 -0
- package/src/HotKey/styles.module.css.json +1 -0
- package/src/Tooltip/Tooltip/index.tsx +85 -0
- package/src/Tooltip/TooltipContent/index.tsx +145 -0
- package/src/Tooltip/TooltipContent/styles.module.css +10 -0
- package/src/Tooltip/TooltipContent/styles.module.css.json +1 -0
- package/src/Tooltip/TooltipDelayGroup/index.tsx +128 -0
- package/src/Tooltip/TooltipTrigger/index.tsx +71 -0
- package/src/Tooltip/index.ts +8 -0
- package/src/Tooltip/utils.ts +176 -0
- package/src/global.css +2 -0
- package/src/index.ts +2 -0
- package/styles.css +1 -1
- package/types.json +4864 -3053
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { autoUpdate, flip, offset, shift, useDelayGroupContext, useDismiss, useFloating, useFocus, useHover, useInteractions, useRole, } from '@floating-ui/react';
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
// Create a single shared portal root for all tooltips
|
|
15
|
+
var sharedPortalRoot = null;
|
|
16
|
+
var portalRefCount = 0;
|
|
17
|
+
export function getSharedPortalRoot() {
|
|
18
|
+
if (!sharedPortalRoot) {
|
|
19
|
+
sharedPortalRoot = document.createElement('div');
|
|
20
|
+
sharedPortalRoot.style.position = 'relative';
|
|
21
|
+
sharedPortalRoot.style.zIndex = '100000';
|
|
22
|
+
sharedPortalRoot.style.height = '0px';
|
|
23
|
+
// Insert as the first child of body
|
|
24
|
+
if (document.body.firstChild) {
|
|
25
|
+
document.body.insertBefore(sharedPortalRoot, document.body.firstChild);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
document.body.appendChild(sharedPortalRoot);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
portalRefCount++;
|
|
32
|
+
return sharedPortalRoot;
|
|
33
|
+
}
|
|
34
|
+
export function releaseSharedPortalRoot() {
|
|
35
|
+
portalRefCount--;
|
|
36
|
+
if (portalRefCount === 0 && sharedPortalRoot) {
|
|
37
|
+
if (sharedPortalRoot.parentNode) {
|
|
38
|
+
sharedPortalRoot.parentNode.removeChild(sharedPortalRoot);
|
|
39
|
+
}
|
|
40
|
+
sharedPortalRoot = null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Hook that manages tooltip state and positioning logic.
|
|
45
|
+
*
|
|
46
|
+
* This hook provides the core tooltip behavior including hover/focus detection,
|
|
47
|
+
* positioning, and accessibility features. Use this when you need full control
|
|
48
|
+
* over the tooltip structure.
|
|
49
|
+
*
|
|
50
|
+
* @example Basic tooltip hook usage
|
|
51
|
+
*
|
|
52
|
+
* Build a custom tooltip implementation using the hook directly for maximum flexibility:
|
|
53
|
+
*
|
|
54
|
+
* ```js
|
|
55
|
+
* function MyComponent() {
|
|
56
|
+
* const tooltip = useTooltip({ placement: 'top' });
|
|
57
|
+
*
|
|
58
|
+
* return (
|
|
59
|
+
* <>
|
|
60
|
+
* <button
|
|
61
|
+
* ref={tooltip.refs.setReference}
|
|
62
|
+
* {...tooltip.getReferenceProps()}
|
|
63
|
+
* >
|
|
64
|
+
* Hover me
|
|
65
|
+
* </button>
|
|
66
|
+
*
|
|
67
|
+
* {tooltip.open && (
|
|
68
|
+
* <div
|
|
69
|
+
* ref={tooltip.refs.setFloating}
|
|
70
|
+
* style={tooltip.floatingStyles}
|
|
71
|
+
* {...tooltip.getFloatingProps()}
|
|
72
|
+
* >
|
|
73
|
+
* Tooltip content
|
|
74
|
+
* </div>
|
|
75
|
+
* )}
|
|
76
|
+
* </>
|
|
77
|
+
* );
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example Controlled tooltip
|
|
82
|
+
*
|
|
83
|
+
* Control the tooltip's open state programmatically for click-to-toggle behavior:
|
|
84
|
+
*
|
|
85
|
+
* ```js
|
|
86
|
+
* function ControlledTooltip() {
|
|
87
|
+
* const [open, setOpen] = React.useState(false);
|
|
88
|
+
* const tooltip = useTooltip({ open, onOpenChange: setOpen });
|
|
89
|
+
*
|
|
90
|
+
* return (
|
|
91
|
+
* <Canvas ctx={ctx}>
|
|
92
|
+
* <button onClick={() => setOpen(!open)}>
|
|
93
|
+
* Toggle tooltip
|
|
94
|
+
* </button>
|
|
95
|
+
* </Canvas>
|
|
96
|
+
* );
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export function useTooltip(_a) {
|
|
101
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.initialOpen, initialOpen = _c === void 0 ? false : _c, _d = _b.placement, placement = _d === void 0 ? 'top' : _d, controlledOpen = _b.open, setControlledOpen = _b.onOpenChange;
|
|
102
|
+
var _e = React.useState(initialOpen), uncontrolledOpen = _e[0], setUncontrolledOpen = _e[1];
|
|
103
|
+
var open = controlledOpen !== null && controlledOpen !== void 0 ? controlledOpen : uncontrolledOpen;
|
|
104
|
+
var setOpen = setControlledOpen !== null && setControlledOpen !== void 0 ? setControlledOpen : setUncontrolledOpen;
|
|
105
|
+
var delay = useDelayGroupContext().delay;
|
|
106
|
+
var data = useFloating({
|
|
107
|
+
placement: placement,
|
|
108
|
+
open: open,
|
|
109
|
+
onOpenChange: setOpen,
|
|
110
|
+
whileElementsMounted: autoUpdate,
|
|
111
|
+
middleware: [offset(5), flip(), shift()],
|
|
112
|
+
});
|
|
113
|
+
var context = data.context;
|
|
114
|
+
var hover = useHover(context, {
|
|
115
|
+
move: false,
|
|
116
|
+
enabled: controlledOpen == null,
|
|
117
|
+
delay: delay,
|
|
118
|
+
});
|
|
119
|
+
var focus = useFocus(context, {
|
|
120
|
+
enabled: controlledOpen == null,
|
|
121
|
+
});
|
|
122
|
+
var dismiss = useDismiss(context);
|
|
123
|
+
var role = useRole(context, { role: 'tooltip' });
|
|
124
|
+
var interactions = useInteractions([hover, focus, dismiss, role]);
|
|
125
|
+
return React.useMemo(function () { return (__assign(__assign({ open: open, setOpen: setOpen }, interactions), data)); }, [open, setOpen, interactions, data]);
|
|
126
|
+
}
|
|
127
|
+
export var TooltipContext = React.createContext(null);
|
|
128
|
+
export var useTooltipState = function () {
|
|
129
|
+
var context = React.useContext(TooltipContext);
|
|
130
|
+
if (context == null) {
|
|
131
|
+
throw new Error('Tooltip components must be wrapped in <Tooltip />');
|
|
132
|
+
}
|
|
133
|
+
return context;
|
|
134
|
+
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AG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,IAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IAEnD,IAAM,YAAY,GAAG,eAAe,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IAEpE,OAAO,KAAK,CAAC,OAAO,CAClB,cAAM,OAAA,qBACJ,IAAI,MAAA,EACJ,OAAO,SAAA,IACJ,YAAY,GACZ,IAAI,EACP,EALI,CAKJ,EACF,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,CAAC,CACpC,CAAC;AACJ,CAAC;AAID,MAAM,CAAC,IAAM,cAAc,GAAG,KAAK,CAAC,aAAa,CAAc,IAAI,CAAC,CAAC;AAErE,MAAM,CAAC,IAAM,eAAe,GAAG;IAC7B,IAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IAEjD,IAAI,OAAO,IAAI,IAAI,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;KACtE;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from './FieldHint';
|
|
|
9
9
|
export * from './FieldWrapper';
|
|
10
10
|
export * from './Form';
|
|
11
11
|
export * from './FormLabel';
|
|
12
|
+
export * from './HotKey';
|
|
12
13
|
export * from './icons';
|
|
13
14
|
export * from './Section';
|
|
14
15
|
export * from './SelectField';
|
|
@@ -23,6 +24,7 @@ export * from './TextareaInput';
|
|
|
23
24
|
export * from './TextField';
|
|
24
25
|
export * from './TextInput';
|
|
25
26
|
export * from './Toolbar';
|
|
27
|
+
export * from './Tooltip';
|
|
26
28
|
export * from './useClickOutside';
|
|
27
29
|
export * from './useMediaQuery';
|
|
28
30
|
export * from './VerticalSplit';
|
package/dist/esm/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from './FieldHint';
|
|
|
9
9
|
export * from './FieldWrapper';
|
|
10
10
|
export * from './Form';
|
|
11
11
|
export * from './FormLabel';
|
|
12
|
+
export * from './HotKey';
|
|
12
13
|
export * from './icons';
|
|
13
14
|
export * from './Section';
|
|
14
15
|
export * from './SelectField';
|
|
@@ -23,6 +24,7 @@ export * from './TextareaInput';
|
|
|
23
24
|
export * from './TextField';
|
|
24
25
|
export * from './TextInput';
|
|
25
26
|
export * from './Toolbar';
|
|
27
|
+
export * from './Tooltip';
|
|
26
28
|
export * from './useClickOutside';
|
|
27
29
|
export * from './useMediaQuery';
|
|
28
30
|
export * from './VerticalSplit';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type HotKeyProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Keyboard shortcut string. Use "mod" for platform-specific modifier (Cmd on Mac, Ctrl elsewhere).
|
|
5
|
+
* Separate keys with "+". Examples: "mod+s", "mod+shift+p", "alt+enter"
|
|
6
|
+
*/
|
|
7
|
+
hotkey: string;
|
|
8
|
+
/** Optional label to display before the key combination */
|
|
9
|
+
label?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* HotKey component displays keyboard shortcuts in a platform-aware format.
|
|
13
|
+
*
|
|
14
|
+
* The component automatically detects the user's platform and renders appropriate
|
|
15
|
+
* modifier key symbols (⌘ for Mac, Ctrl for Windows/Linux).
|
|
16
|
+
*
|
|
17
|
+
* @example Basic usage
|
|
18
|
+
*
|
|
19
|
+
* Display a simple keyboard shortcut without a label:
|
|
20
|
+
*
|
|
21
|
+
* ```js
|
|
22
|
+
* <Canvas ctx={ctx}>
|
|
23
|
+
* <HotKey hotkey="mod+s" />
|
|
24
|
+
* </Canvas>;
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @example With label
|
|
28
|
+
*
|
|
29
|
+
* Include a descriptive label to explain what the keyboard shortcut does:
|
|
30
|
+
*
|
|
31
|
+
* ```js
|
|
32
|
+
* <Canvas ctx={ctx}>
|
|
33
|
+
* <HotKey hotkey="mod+s" label="Save" />
|
|
34
|
+
* </Canvas>;
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example Multiple hotkeys
|
|
38
|
+
*
|
|
39
|
+
* Display a list of keyboard shortcuts with labels for documenting available commands:
|
|
40
|
+
*
|
|
41
|
+
* ```js
|
|
42
|
+
* <Canvas ctx={ctx}>
|
|
43
|
+
* <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--spacing-m)' }}>
|
|
44
|
+
* <HotKey hotkey="mod+c" label="Copy" />
|
|
45
|
+
* <HotKey hotkey="mod+v" label="Paste" />
|
|
46
|
+
* <HotKey hotkey="mod+shift+z" label="Redo" />
|
|
47
|
+
* <HotKey hotkey="alt+enter" label="Submit" />
|
|
48
|
+
* </div>
|
|
49
|
+
* </Canvas>;
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example Platform-specific rendering
|
|
53
|
+
*
|
|
54
|
+
* The component automatically adapts modifier keys based on the user's platform:
|
|
55
|
+
* - `mod` renders as `⌘` on Mac and `Ctrl` on Windows/Linux
|
|
56
|
+
* - `alt` renders as `⌥` on Mac and `Alt` on Windows/Linux
|
|
57
|
+
*
|
|
58
|
+
* This ensures the correct symbols are displayed for the user's operating system:
|
|
59
|
+
*
|
|
60
|
+
* ```js
|
|
61
|
+
* <Canvas ctx={ctx}>
|
|
62
|
+
* <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--spacing-m)' }}>
|
|
63
|
+
* <HotKey hotkey="mod+k" label="Open command palette" />
|
|
64
|
+
* <HotKey hotkey="alt+enter" label="Submit form" />
|
|
65
|
+
* <HotKey hotkey="mod+alt+f" label="Find and replace" />
|
|
66
|
+
* </div>
|
|
67
|
+
* </Canvas>;
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function HotKey({ hotkey, label }: HotKeyProps): JSX.Element;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { TooltipOptions } from '../utils';
|
|
3
|
+
export declare type TooltipProps = {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
} & TooltipOptions;
|
|
6
|
+
/**
|
|
7
|
+
* Tooltip wrapper component that provides context for TooltipTrigger and TooltipContent.
|
|
8
|
+
*
|
|
9
|
+
* This is a compound component pattern. The Tooltip component itself doesn't render anything,
|
|
10
|
+
* but provides the necessary context for its children (TooltipTrigger and TooltipContent).
|
|
11
|
+
*
|
|
12
|
+
* @example Basic tooltip
|
|
13
|
+
*
|
|
14
|
+
* Create a simple tooltip that appears when hovering over a button:
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* <Canvas ctx={ctx}>
|
|
18
|
+
* <Tooltip>
|
|
19
|
+
* <TooltipTrigger>
|
|
20
|
+
* <Button>Hover me</Button>
|
|
21
|
+
* </TooltipTrigger>
|
|
22
|
+
* <TooltipContent>
|
|
23
|
+
* This is helpful information!
|
|
24
|
+
* </TooltipContent>
|
|
25
|
+
* </Tooltip>
|
|
26
|
+
* </Canvas>;
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example Tooltip with custom placement
|
|
30
|
+
*
|
|
31
|
+
* Control where the tooltip appears relative to its trigger using the `placement` prop:
|
|
32
|
+
*
|
|
33
|
+
* ```js
|
|
34
|
+
* <Canvas ctx={ctx}>
|
|
35
|
+
* <Tooltip placement="right">
|
|
36
|
+
* <TooltipTrigger>
|
|
37
|
+
* <Button>Right tooltip</Button>
|
|
38
|
+
* </TooltipTrigger>
|
|
39
|
+
* <TooltipContent>
|
|
40
|
+
* Appears on the right side
|
|
41
|
+
* </TooltipContent>
|
|
42
|
+
* </Tooltip>
|
|
43
|
+
* </Canvas>;
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example Multiple tooltips
|
|
47
|
+
*
|
|
48
|
+
* Use multiple tooltips on the same page to provide contextual help for different actions:
|
|
49
|
+
*
|
|
50
|
+
* ```js
|
|
51
|
+
* <Canvas ctx={ctx}>
|
|
52
|
+
* <div style={{ display: 'flex', gap: 'var(--spacing-m)' }}>
|
|
53
|
+
* <Tooltip>
|
|
54
|
+
* <TooltipTrigger>
|
|
55
|
+
* <Button leftIcon={<SaveIcon />} />
|
|
56
|
+
* </TooltipTrigger>
|
|
57
|
+
* <TooltipContent>
|
|
58
|
+
* Save changes (⌘S)
|
|
59
|
+
* </TooltipContent>
|
|
60
|
+
* </Tooltip>
|
|
61
|
+
*
|
|
62
|
+
* <Tooltip>
|
|
63
|
+
* <TooltipTrigger>
|
|
64
|
+
* <Button leftIcon={<DeleteIcon />} />
|
|
65
|
+
* </TooltipTrigger>
|
|
66
|
+
* <TooltipContent>
|
|
67
|
+
* Delete item
|
|
68
|
+
* </TooltipContent>
|
|
69
|
+
* </Tooltip>
|
|
70
|
+
* </div>
|
|
71
|
+
* </Canvas>;
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function Tooltip({ children, ...options }: TooltipProps): JSX.Element;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare type TooltipContentProps = {
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* TooltipContent contains the content displayed in the floating tooltip.
|
|
7
|
+
*
|
|
8
|
+
* The content is automatically wrapped in a Canvas component to inherit the DatoCMS
|
|
9
|
+
* theme and styling. The tooltip uses a portal to render outside the normal DOM
|
|
10
|
+
* hierarchy, ensuring proper positioning and z-index stacking.
|
|
11
|
+
*
|
|
12
|
+
* @example Simple text tooltip
|
|
13
|
+
*
|
|
14
|
+
* Display plain text in a tooltip to provide helpful information:
|
|
15
|
+
*
|
|
16
|
+
* ```js
|
|
17
|
+
* <Canvas ctx={ctx}>
|
|
18
|
+
* <Tooltip>
|
|
19
|
+
* <TooltipTrigger>
|
|
20
|
+
* <Button>Delete</Button>
|
|
21
|
+
* </TooltipTrigger>
|
|
22
|
+
* <TooltipContent>
|
|
23
|
+
* This action cannot be undone
|
|
24
|
+
* </TooltipContent>
|
|
25
|
+
* </Tooltip>
|
|
26
|
+
* </Canvas>;
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example Rich content tooltip
|
|
30
|
+
*
|
|
31
|
+
* Include formatted content with custom styles for more detailed information:
|
|
32
|
+
*
|
|
33
|
+
* ```js
|
|
34
|
+
* <Canvas ctx={ctx}>
|
|
35
|
+
* <Tooltip placement="right">
|
|
36
|
+
* <TooltipTrigger>
|
|
37
|
+
* <Button leftIcon={<HelpIcon />}>Help</Button>
|
|
38
|
+
* </TooltipTrigger>
|
|
39
|
+
* <TooltipContent>
|
|
40
|
+
* <div>
|
|
41
|
+
* <strong>Need assistance?</strong>
|
|
42
|
+
* <p style={{ margin: '5px 0 0 0', fontSize: 'var(--font-size-xs)' }}>
|
|
43
|
+
* Contact support@example.com
|
|
44
|
+
* </p>
|
|
45
|
+
* </div>
|
|
46
|
+
* </TooltipContent>
|
|
47
|
+
* </Tooltip>
|
|
48
|
+
* </Canvas>;
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example Tooltip with keyboard shortcut
|
|
52
|
+
*
|
|
53
|
+
* Combine tooltips with the HotKey component to show keyboard shortcuts:
|
|
54
|
+
*
|
|
55
|
+
* ```js
|
|
56
|
+
* <Canvas ctx={ctx}>
|
|
57
|
+
* <Tooltip>
|
|
58
|
+
* <TooltipTrigger>
|
|
59
|
+
* <Button leftIcon={<SaveIcon />}>Save</Button>
|
|
60
|
+
* </TooltipTrigger>
|
|
61
|
+
* <TooltipContent>
|
|
62
|
+
* <HotKey hotkey="mod+s" label="Save changes" />
|
|
63
|
+
* </TooltipContent>
|
|
64
|
+
* </Tooltip>
|
|
65
|
+
* </Canvas>;
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare const TooltipContent: React.ForwardRefExoticComponent<TooltipContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare type TooltipDelayGroupProps = {
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
/** The delay in milliseconds before a tooltip opens on hover (default: 1000) */
|
|
5
|
+
delay?: number | {
|
|
6
|
+
open?: number;
|
|
7
|
+
close?: number;
|
|
8
|
+
};
|
|
9
|
+
/** How long to wait in milliseconds before closing the group (default: 0) */
|
|
10
|
+
timeoutMs?: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* TooltipDelayGroup synchronizes hover delays across multiple tooltips.
|
|
14
|
+
*
|
|
15
|
+
* When tooltips are wrapped in a delay group, hovering over the first tooltip
|
|
16
|
+
* will use the configured delay, but subsequent tooltips in the group will
|
|
17
|
+
* open instantly. This creates a smoother UX when users explore multiple
|
|
18
|
+
* interactive elements with tooltips.
|
|
19
|
+
*
|
|
20
|
+
* @example Basic delay group
|
|
21
|
+
*
|
|
22
|
+
* Group multiple tooltips together so they open instantly after the first one:
|
|
23
|
+
*
|
|
24
|
+
* ```js
|
|
25
|
+
* <Canvas ctx={ctx}>
|
|
26
|
+
* <TooltipDelayGroup delay={500}>
|
|
27
|
+
* <div style={{ display: 'flex', gap: 'var(--spacing-m)' }}>
|
|
28
|
+
* <Tooltip>
|
|
29
|
+
* <TooltipTrigger>
|
|
30
|
+
* <Button leftIcon={<SaveIcon />} />
|
|
31
|
+
* </TooltipTrigger>
|
|
32
|
+
* <TooltipContent>Save changes</TooltipContent>
|
|
33
|
+
* </Tooltip>
|
|
34
|
+
*
|
|
35
|
+
* <Tooltip>
|
|
36
|
+
* <TooltipTrigger>
|
|
37
|
+
* <Button leftIcon={<UndoIcon />} />
|
|
38
|
+
* </TooltipTrigger>
|
|
39
|
+
* <TooltipContent>Undo</TooltipContent>
|
|
40
|
+
* </Tooltip>
|
|
41
|
+
*
|
|
42
|
+
* <Tooltip>
|
|
43
|
+
* <TooltipTrigger>
|
|
44
|
+
* <Button leftIcon={<RedoIcon />} />
|
|
45
|
+
* </TooltipTrigger>
|
|
46
|
+
* <TooltipContent>Redo</TooltipContent>
|
|
47
|
+
* </Tooltip>
|
|
48
|
+
* </div>
|
|
49
|
+
* </TooltipDelayGroup>
|
|
50
|
+
* </Canvas>;
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example Custom delay configuration
|
|
54
|
+
*
|
|
55
|
+
* Configure different delays for opening and closing tooltips in the group:
|
|
56
|
+
*
|
|
57
|
+
* ```js
|
|
58
|
+
* <Canvas ctx={ctx}>
|
|
59
|
+
* <TooltipDelayGroup delay={{ open: 800, close: 200 }} timeoutMs={500}>
|
|
60
|
+
* <div style={{ display: 'flex', gap: 'var(--spacing-s)' }}>
|
|
61
|
+
* <Tooltip>
|
|
62
|
+
* <TooltipTrigger>
|
|
63
|
+
* <Button>Action 1</Button>
|
|
64
|
+
* </TooltipTrigger>
|
|
65
|
+
* <TooltipContent>First action</TooltipContent>
|
|
66
|
+
* </Tooltip>
|
|
67
|
+
*
|
|
68
|
+
* <Tooltip>
|
|
69
|
+
* <TooltipTrigger>
|
|
70
|
+
* <Button>Action 2</Button>
|
|
71
|
+
* </TooltipTrigger>
|
|
72
|
+
* <TooltipContent>Second action</TooltipContent>
|
|
73
|
+
* </Tooltip>
|
|
74
|
+
* </div>
|
|
75
|
+
* </TooltipDelayGroup>
|
|
76
|
+
* </Canvas>;
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @example Toolbar with grouped tooltips
|
|
80
|
+
*
|
|
81
|
+
* Create a toolbar where hovering between tools feels instant and responsive:
|
|
82
|
+
*
|
|
83
|
+
* ```js
|
|
84
|
+
* <Canvas ctx={ctx}>
|
|
85
|
+
* <TooltipDelayGroup delay={600}>
|
|
86
|
+
* <div style={{
|
|
87
|
+
* display: 'flex',
|
|
88
|
+
* gap: 'var(--spacing-xs)',
|
|
89
|
+
* padding: 'var(--spacing-s)',
|
|
90
|
+
* borderRadius: 'var(--border-radius-m)',
|
|
91
|
+
* backgroundColor: 'var(--light-bg-color)'
|
|
92
|
+
* }}>
|
|
93
|
+
* <Tooltip>
|
|
94
|
+
* <TooltipTrigger>
|
|
95
|
+
* <Button buttonSize="s" leftIcon={<BoldIcon />} />
|
|
96
|
+
* </TooltipTrigger>
|
|
97
|
+
* <TooltipContent>Bold</TooltipContent>
|
|
98
|
+
* </Tooltip>
|
|
99
|
+
*
|
|
100
|
+
* <Tooltip>
|
|
101
|
+
* <TooltipTrigger>
|
|
102
|
+
* <Button buttonSize="s" leftIcon={<ItalicIcon />} />
|
|
103
|
+
* </TooltipTrigger>
|
|
104
|
+
* <TooltipContent>Italic</TooltipContent>
|
|
105
|
+
* </Tooltip>
|
|
106
|
+
*
|
|
107
|
+
* <Tooltip>
|
|
108
|
+
* <TooltipTrigger>
|
|
109
|
+
* <Button buttonSize="s" leftIcon={<UnderlineIcon />} />
|
|
110
|
+
* </TooltipTrigger>
|
|
111
|
+
* <TooltipContent>Underline</TooltipContent>
|
|
112
|
+
* </Tooltip>
|
|
113
|
+
* </div>
|
|
114
|
+
* </TooltipDelayGroup>
|
|
115
|
+
* </Canvas>;
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function TooltipDelayGroup({ children, delay, timeoutMs, }: TooltipDelayGroupProps): JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare type TooltipTriggerProps = {
|
|
3
|
+
children: React.ReactElement;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* TooltipTrigger wraps the element that triggers the tooltip on hover/focus.
|
|
7
|
+
*
|
|
8
|
+
* The child must be a single React element that accepts ref and event handler props.
|
|
9
|
+
* Common triggers include buttons, icons, or other interactive elements.
|
|
10
|
+
*
|
|
11
|
+
* @example With Button component
|
|
12
|
+
*
|
|
13
|
+
* Wrap a button to show a tooltip when the user hovers over it:
|
|
14
|
+
*
|
|
15
|
+
* ```js
|
|
16
|
+
* <Canvas ctx={ctx}>
|
|
17
|
+
* <Tooltip>
|
|
18
|
+
* <TooltipTrigger>
|
|
19
|
+
* <Button>Hover for info</Button>
|
|
20
|
+
* </TooltipTrigger>
|
|
21
|
+
* <TooltipContent>
|
|
22
|
+
* Additional information appears here
|
|
23
|
+
* </TooltipContent>
|
|
24
|
+
* </Tooltip>
|
|
25
|
+
* </Canvas>;
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example With icon button
|
|
29
|
+
*
|
|
30
|
+
* Use tooltips with icon-only buttons to explain their purpose:
|
|
31
|
+
*
|
|
32
|
+
* ```js
|
|
33
|
+
* <Canvas ctx={ctx}>
|
|
34
|
+
* <Tooltip placement="bottom">
|
|
35
|
+
* <TooltipTrigger>
|
|
36
|
+
* <Button buttonSize="s" leftIcon={<InfoIcon />} />
|
|
37
|
+
* </TooltipTrigger>
|
|
38
|
+
* <TooltipContent>
|
|
39
|
+
* Click for more details
|
|
40
|
+
* </TooltipContent>
|
|
41
|
+
* </Tooltip>
|
|
42
|
+
* </Canvas>;
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const TooltipTrigger: React.ForwardRefExoticComponent<TooltipTriggerProps & React.RefAttributes<HTMLElement>>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Tooltip } from './Tooltip';
|
|
2
|
+
export type { TooltipProps } from './Tooltip';
|
|
3
|
+
export { TooltipContent } from './TooltipContent';
|
|
4
|
+
export type { TooltipContentProps } from './TooltipContent';
|
|
5
|
+
export { TooltipDelayGroup } from './TooltipDelayGroup';
|
|
6
|
+
export type { TooltipDelayGroupProps } from './TooltipDelayGroup';
|
|
7
|
+
export { TooltipTrigger } from './TooltipTrigger';
|
|
8
|
+
export type { TooltipTriggerProps } from './TooltipTrigger';
|