datocms-react-ui 2.0.17 → 2.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/cjs/HotKey/index.js +105 -0
  2. package/dist/cjs/HotKey/index.js.map +1 -0
  3. package/dist/cjs/HotKey/styles.module.css.json +1 -0
  4. package/dist/cjs/Tooltip/Tooltip/index.js +116 -0
  5. package/dist/cjs/Tooltip/Tooltip/index.js.map +1 -0
  6. package/dist/cjs/Tooltip/TooltipContent/index.js +147 -0
  7. package/dist/cjs/Tooltip/TooltipContent/index.js.map +1 -0
  8. package/dist/cjs/Tooltip/TooltipContent/styles.module.css.json +1 -0
  9. package/dist/cjs/Tooltip/TooltipTrigger/index.js +102 -0
  10. package/dist/cjs/Tooltip/TooltipTrigger/index.js.map +1 -0
  11. package/dist/cjs/Tooltip/index.js +10 -0
  12. package/dist/cjs/Tooltip/index.js.map +1 -0
  13. package/dist/cjs/Tooltip/utils.js +165 -0
  14. package/dist/cjs/Tooltip/utils.js.map +1 -0
  15. package/dist/cjs/index.js +2 -0
  16. package/dist/cjs/index.js.map +1 -1
  17. package/dist/esm/HotKey/index.d.ts +70 -0
  18. package/dist/esm/HotKey/index.js +75 -0
  19. package/dist/esm/HotKey/index.js.map +1 -0
  20. package/dist/esm/HotKey/styles.module.css.json +1 -0
  21. package/dist/esm/Tooltip/Tooltip/index.d.ts +74 -0
  22. package/dist/esm/Tooltip/Tooltip/index.js +89 -0
  23. package/dist/esm/Tooltip/Tooltip/index.js.map +1 -0
  24. package/dist/esm/Tooltip/TooltipContent/index.d.ts +68 -0
  25. package/dist/esm/Tooltip/TooltipContent/index.js +118 -0
  26. package/dist/esm/Tooltip/TooltipContent/index.js.map +1 -0
  27. package/dist/esm/Tooltip/TooltipContent/styles.module.css.json +1 -0
  28. package/dist/esm/Tooltip/TooltipTrigger/index.d.ts +43 -0
  29. package/dist/esm/Tooltip/TooltipTrigger/index.js +76 -0
  30. package/dist/esm/Tooltip/TooltipTrigger/index.js.map +1 -0
  31. package/dist/esm/Tooltip/index.d.ts +6 -0
  32. package/dist/esm/Tooltip/index.js +4 -0
  33. package/dist/esm/Tooltip/index.js.map +1 -0
  34. package/dist/esm/Tooltip/utils.d.ts +166 -0
  35. package/dist/esm/Tooltip/utils.js +135 -0
  36. package/dist/esm/Tooltip/utils.js.map +1 -0
  37. package/dist/esm/index.d.ts +2 -0
  38. package/dist/esm/index.js +2 -0
  39. package/dist/esm/index.js.map +1 -1
  40. package/dist/types/HotKey/index.d.ts +70 -0
  41. package/dist/types/Tooltip/Tooltip/index.d.ts +74 -0
  42. package/dist/types/Tooltip/TooltipContent/index.d.ts +68 -0
  43. package/dist/types/Tooltip/TooltipTrigger/index.d.ts +43 -0
  44. package/dist/types/Tooltip/index.d.ts +6 -0
  45. package/dist/types/Tooltip/utils.d.ts +166 -0
  46. package/dist/types/index.d.ts +2 -0
  47. package/package.json +4 -3
  48. package/src/HotKey/index.tsx +95 -0
  49. package/src/HotKey/styles.module.css +22 -0
  50. package/src/HotKey/styles.module.css.json +1 -0
  51. package/src/Tooltip/Tooltip/index.tsx +85 -0
  52. package/src/Tooltip/TooltipContent/index.tsx +140 -0
  53. package/src/Tooltip/TooltipContent/styles.module.css +10 -0
  54. package/src/Tooltip/TooltipContent/styles.module.css.json +1 -0
  55. package/src/Tooltip/TooltipTrigger/index.tsx +68 -0
  56. package/src/Tooltip/index.ts +6 -0
  57. package/src/Tooltip/utils.ts +176 -0
  58. package/src/global.css +2 -0
  59. package/src/index.ts +2 -0
  60. package/styles.css +1 -1
  61. package/types.json +7549 -1770
@@ -0,0 +1,43 @@
1
+ import * as React from 'react';
2
+ export declare type TooltipTriggerProps = React.HTMLProps<HTMLElement>;
3
+ /**
4
+ * TooltipTrigger wraps the element that triggers the tooltip on hover/focus.
5
+ *
6
+ * The child must be a single React element that accepts ref and event handler props.
7
+ * Common triggers include buttons, icons, or other interactive elements.
8
+ *
9
+ * @example With Button component
10
+ *
11
+ * Wrap a button to show a tooltip when the user hovers over it:
12
+ *
13
+ * ```js
14
+ * <Canvas ctx={ctx}>
15
+ * <Tooltip>
16
+ * <TooltipTrigger>
17
+ * <Button>Hover for info</Button>
18
+ * </TooltipTrigger>
19
+ * <TooltipContent>
20
+ * Additional information appears here
21
+ * </TooltipContent>
22
+ * </Tooltip>
23
+ * </Canvas>;
24
+ * ```
25
+ *
26
+ * @example With icon button
27
+ *
28
+ * Use tooltips with icon-only buttons to explain their purpose:
29
+ *
30
+ * ```js
31
+ * <Canvas ctx={ctx}>
32
+ * <Tooltip placement="bottom">
33
+ * <TooltipTrigger>
34
+ * <Button buttonSize="s" leftIcon={<InfoIcon />} />
35
+ * </TooltipTrigger>
36
+ * <TooltipContent>
37
+ * Click for more details
38
+ * </TooltipContent>
39
+ * </Tooltip>
40
+ * </Canvas>;
41
+ * ```
42
+ */
43
+ export declare const TooltipTrigger: React.ForwardRefExoticComponent<Pick<TooltipTriggerProps, "width" | "height" | "style" | "className" | "cite" | "data" | "form" | "label" | "slot" | "span" | "summary" | "title" | "pattern" | "type" | "muted" | "children" | "disabled" | "onClick" | "target" | "href" | "selected" | "value" | "open" | "name" | "rel" | "useMap" | "color" | "hidden" | "onChange" | "onKeyDown" | "placeholder" | "id" | "required" | "htmlFor" | "default" | "onSubmit" | "alt" | "aria-errormessage" | "aria-invalid" | "aria-label" | "aria-labelledby" | "aria-live" | "autoFocus" | "onBlur" | "onFocus" | "tabIndex" | "defaultValue" | "content" | "translate" | "start" | "size" | "wrap" | "multiple" | "onMouseDown" | "onMouseMove" | "onMouseUp" | "action" | "list" | "role" | "onTouchStart" | "sizes" | "onDragStart" | "onDragEnd" | "defaultChecked" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "lang" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-keyshortcuts" | "aria-level" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlurCapture" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "step" | "key" | "autoComplete" | "cols" | "maxLength" | "minLength" | "readOnly" | "rows" | "accept" | "capture" | "checked" | "crossOrigin" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "max" | "min" | "src" | "acceptCharset" | "allowFullScreen" | "allowTransparency" | "as" | "async" | "autoPlay" | "cellPadding" | "cellSpacing" | "charSet" | "challenge" | "classID" | "colSpan" | "controls" | "coords" | "dateTime" | "defer" | "download" | "encType" | "frameBorder" | "headers" | "high" | "hrefLang" | "httpEquiv" | "integrity" | "keyParams" | "keyType" | "kind" | "loop" | "low" | "manifest" | "marginHeight" | "marginWidth" | "media" | "mediaGroup" | "method" | "nonce" | "noValidate" | "optimum" | "playsInline" | "poster" | "preload" | "reversed" | "rowSpan" | "sandbox" | "scope" | "scoped" | "scrolling" | "seamless" | "shape" | "srcDoc" | "srcLang" | "srcSet" | "wmode"> & React.RefAttributes<HTMLElement>>;
@@ -0,0 +1,6 @@
1
+ export { Tooltip } from './Tooltip';
2
+ export type { TooltipProps } from './Tooltip';
3
+ export { TooltipContent } from './TooltipContent';
4
+ export type { TooltipContentProps } from './TooltipContent';
5
+ export { TooltipTrigger } from './TooltipTrigger';
6
+ export type { TooltipTriggerProps } from './TooltipTrigger';
@@ -0,0 +1,166 @@
1
+ import type { Placement } from '@floating-ui/react';
2
+ import * as React from 'react';
3
+ export declare function getSharedPortalRoot(): HTMLDivElement;
4
+ export declare function releaseSharedPortalRoot(): void;
5
+ export interface TooltipOptions {
6
+ /** Whether the tooltip is initially open (uncontrolled mode) */
7
+ initialOpen?: boolean;
8
+ /** Placement of the tooltip relative to its trigger */
9
+ placement?: Placement;
10
+ /** Controlled open state */
11
+ open?: boolean;
12
+ /** Callback when open state changes (controlled mode) */
13
+ onOpenChange?: (open: boolean) => void;
14
+ }
15
+ /**
16
+ * Hook that manages tooltip state and positioning logic.
17
+ *
18
+ * This hook provides the core tooltip behavior including hover/focus detection,
19
+ * positioning, and accessibility features. Use this when you need full control
20
+ * over the tooltip structure.
21
+ *
22
+ * @example Basic tooltip hook usage
23
+ *
24
+ * Build a custom tooltip implementation using the hook directly for maximum flexibility:
25
+ *
26
+ * ```js
27
+ * function MyComponent() {
28
+ * const tooltip = useTooltip({ placement: 'top' });
29
+ *
30
+ * return (
31
+ * <>
32
+ * <button
33
+ * ref={tooltip.refs.setReference}
34
+ * {...tooltip.getReferenceProps()}
35
+ * >
36
+ * Hover me
37
+ * </button>
38
+ *
39
+ * {tooltip.open && (
40
+ * <div
41
+ * ref={tooltip.refs.setFloating}
42
+ * style={tooltip.floatingStyles}
43
+ * {...tooltip.getFloatingProps()}
44
+ * >
45
+ * Tooltip content
46
+ * </div>
47
+ * )}
48
+ * </>
49
+ * );
50
+ * }
51
+ * ```
52
+ *
53
+ * @example Controlled tooltip
54
+ *
55
+ * Control the tooltip's open state programmatically for click-to-toggle behavior:
56
+ *
57
+ * ```js
58
+ * function ControlledTooltip() {
59
+ * const [open, setOpen] = React.useState(false);
60
+ * const tooltip = useTooltip({ open, onOpenChange: setOpen });
61
+ *
62
+ * return (
63
+ * <Canvas ctx={ctx}>
64
+ * <button onClick={() => setOpen(!open)}>
65
+ * Toggle tooltip
66
+ * </button>
67
+ * </Canvas>
68
+ * );
69
+ * }
70
+ * ```
71
+ */
72
+ export declare function useTooltip({ initialOpen, placement, open: controlledOpen, onOpenChange: setControlledOpen, }?: TooltipOptions): {
73
+ placement: Placement;
74
+ strategy: import("@floating-ui/utils").Strategy;
75
+ middlewareData: import("@floating-ui/core").MiddlewareData;
76
+ x: number;
77
+ y: number;
78
+ isPositioned: boolean;
79
+ update: () => void;
80
+ floatingStyles: React.CSSProperties;
81
+ refs: {
82
+ reference: React.MutableRefObject<import("@floating-ui/react-dom").ReferenceType | null>;
83
+ floating: React.MutableRefObject<HTMLElement | null>;
84
+ setReference: (node: import("@floating-ui/react-dom").ReferenceType | null) => void;
85
+ setFloating: (node: HTMLElement | null) => void;
86
+ } & import("@floating-ui/react").ExtendedRefs<import("@floating-ui/react").ReferenceType>;
87
+ elements: {
88
+ reference: import("@floating-ui/react-dom").ReferenceType | null;
89
+ floating: HTMLElement | null;
90
+ } & import("@floating-ui/react").ExtendedElements<import("@floating-ui/react").ReferenceType>;
91
+ context: {
92
+ x: number;
93
+ y: number;
94
+ placement: Placement;
95
+ strategy: import("@floating-ui/utils").Strategy;
96
+ middlewareData: import("@floating-ui/core").MiddlewareData;
97
+ isPositioned: boolean;
98
+ update: () => void;
99
+ floatingStyles: React.CSSProperties;
100
+ open: boolean;
101
+ onOpenChange: (open: boolean, event?: Event | undefined, reason?: import("@floating-ui/react").OpenChangeReason | undefined) => void;
102
+ events: import("@floating-ui/react").FloatingEvents;
103
+ dataRef: React.MutableRefObject<import("@floating-ui/react").ContextData>;
104
+ nodeId: string | undefined;
105
+ floatingId: string | undefined;
106
+ refs: import("@floating-ui/react").ExtendedRefs<import("@floating-ui/react").ReferenceType>;
107
+ elements: import("@floating-ui/react").ExtendedElements<import("@floating-ui/react").ReferenceType>;
108
+ };
109
+ getReferenceProps: (userProps?: React.HTMLProps<Element> | undefined) => Record<string, unknown>;
110
+ getFloatingProps: (userProps?: React.HTMLProps<HTMLElement> | undefined) => Record<string, unknown>;
111
+ getItemProps: (userProps?: (Omit<React.HTMLProps<HTMLElement>, "selected" | "active"> & {
112
+ active?: boolean | undefined;
113
+ selected?: boolean | undefined;
114
+ }) | undefined) => Record<string, unknown>;
115
+ open: boolean;
116
+ setOpen: (open: boolean) => void;
117
+ };
118
+ declare type ContextType = ReturnType<typeof useTooltip> | null;
119
+ export declare const TooltipContext: React.Context<ContextType>;
120
+ export declare const useTooltipState: () => {
121
+ placement: Placement;
122
+ strategy: import("@floating-ui/utils").Strategy;
123
+ middlewareData: import("@floating-ui/core").MiddlewareData;
124
+ x: number;
125
+ y: number;
126
+ isPositioned: boolean;
127
+ update: () => void;
128
+ floatingStyles: React.CSSProperties;
129
+ refs: {
130
+ reference: React.MutableRefObject<import("@floating-ui/react-dom").ReferenceType | null>;
131
+ floating: React.MutableRefObject<HTMLElement | null>;
132
+ setReference: (node: import("@floating-ui/react-dom").ReferenceType | null) => void;
133
+ setFloating: (node: HTMLElement | null) => void;
134
+ } & import("@floating-ui/react").ExtendedRefs<import("@floating-ui/react").ReferenceType>;
135
+ elements: {
136
+ reference: import("@floating-ui/react-dom").ReferenceType | null;
137
+ floating: HTMLElement | null;
138
+ } & import("@floating-ui/react").ExtendedElements<import("@floating-ui/react").ReferenceType>;
139
+ context: {
140
+ x: number;
141
+ y: number;
142
+ placement: Placement;
143
+ strategy: import("@floating-ui/utils").Strategy;
144
+ middlewareData: import("@floating-ui/core").MiddlewareData;
145
+ isPositioned: boolean;
146
+ update: () => void;
147
+ floatingStyles: React.CSSProperties;
148
+ open: boolean;
149
+ onOpenChange: (open: boolean, event?: Event | undefined, reason?: import("@floating-ui/react").OpenChangeReason | undefined) => void;
150
+ events: import("@floating-ui/react").FloatingEvents;
151
+ dataRef: React.MutableRefObject<import("@floating-ui/react").ContextData>;
152
+ nodeId: string | undefined;
153
+ floatingId: string | undefined;
154
+ refs: import("@floating-ui/react").ExtendedRefs<import("@floating-ui/react").ReferenceType>;
155
+ elements: import("@floating-ui/react").ExtendedElements<import("@floating-ui/react").ReferenceType>;
156
+ };
157
+ getReferenceProps: (userProps?: React.HTMLProps<Element> | undefined) => Record<string, unknown>;
158
+ getFloatingProps: (userProps?: React.HTMLProps<HTMLElement> | undefined) => Record<string, unknown>;
159
+ getItemProps: (userProps?: (Omit<React.HTMLProps<HTMLElement>, "selected" | "active"> & {
160
+ active?: boolean | undefined;
161
+ selected?: boolean | undefined;
162
+ }) | undefined) => Record<string, unknown>;
163
+ open: boolean;
164
+ setOpen: (open: boolean) => void;
165
+ };
166
+ export {};
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datocms-react-ui",
3
- "version": "2.0.17",
3
+ "version": "2.0.18",
4
4
  "description": "React components to use inside DatoCMS plugins",
5
5
  "keywords": [
6
6
  "datocms",
@@ -40,8 +40,9 @@
40
40
  "url": "https://github.com/datocms/plugins-sdk/issues"
41
41
  },
42
42
  "dependencies": {
43
+ "@floating-ui/react": "^0.27.16",
43
44
  "classnames": "^2.3.1",
44
- "datocms-plugin-sdk": "^2.0.17",
45
+ "datocms-plugin-sdk": "^2.0.18",
45
46
  "react-intersection-observer": "^8.31.0",
46
47
  "react-select": "^5.2.1",
47
48
  "scroll-into-view-if-needed": "^2.2.20"
@@ -57,5 +58,5 @@
57
58
  "postcss-nested": "^5.0.6",
58
59
  "typedoc": "^0.26.7"
59
60
  },
60
- "gitHead": "ce4d1125e8f52a499965e5aad358ffd78d9cc8fd"
61
+ "gitHead": "59657aeaa34d9723d21537503933b2d7c92e7e39"
61
62
  }
@@ -0,0 +1,95 @@
1
+ import * as React from 'react';
2
+ import styles from './styles.module.css.json';
3
+
4
+ const isMac = navigator.platform.indexOf('Mac') > -1;
5
+ const modifierKey = isMac ? '⌘' : 'Ctrl';
6
+
7
+ export type HotKeyProps = {
8
+ /**
9
+ * Keyboard shortcut string. Use "mod" for platform-specific modifier (Cmd on Mac, Ctrl elsewhere).
10
+ * Separate keys with "+". Examples: "mod+s", "mod+shift+p", "alt+enter"
11
+ */
12
+ hotkey: string;
13
+ /** Optional label to display before the key combination */
14
+ label?: string;
15
+ };
16
+
17
+ /**
18
+ * HotKey component displays keyboard shortcuts in a platform-aware format.
19
+ *
20
+ * The component automatically detects the user's platform and renders appropriate
21
+ * modifier key symbols (⌘ for Mac, Ctrl for Windows/Linux).
22
+ *
23
+ * @example Basic usage
24
+ *
25
+ * Display a simple keyboard shortcut without a label:
26
+ *
27
+ * ```js
28
+ * <Canvas ctx={ctx}>
29
+ * <HotKey hotkey="mod+s" />
30
+ * </Canvas>;
31
+ * ```
32
+ *
33
+ * @example With label
34
+ *
35
+ * Include a descriptive label to explain what the keyboard shortcut does:
36
+ *
37
+ * ```js
38
+ * <Canvas ctx={ctx}>
39
+ * <HotKey hotkey="mod+s" label="Save" />
40
+ * </Canvas>;
41
+ * ```
42
+ *
43
+ * @example Multiple hotkeys
44
+ *
45
+ * Display a list of keyboard shortcuts with labels for documenting available commands:
46
+ *
47
+ * ```js
48
+ * <Canvas ctx={ctx}>
49
+ * <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--spacing-m)' }}>
50
+ * <HotKey hotkey="mod+c" label="Copy" />
51
+ * <HotKey hotkey="mod+v" label="Paste" />
52
+ * <HotKey hotkey="mod+shift+z" label="Redo" />
53
+ * <HotKey hotkey="alt+enter" label="Submit" />
54
+ * </div>
55
+ * </Canvas>;
56
+ * ```
57
+ *
58
+ * @example Platform-specific rendering
59
+ *
60
+ * The component automatically adapts modifier keys based on the user's platform:
61
+ * - `mod` renders as `⌘` on Mac and `Ctrl` on Windows/Linux
62
+ * - `alt` renders as `⌥` on Mac and `Alt` on Windows/Linux
63
+ *
64
+ * This ensures the correct symbols are displayed for the user's operating system:
65
+ *
66
+ * ```js
67
+ * <Canvas ctx={ctx}>
68
+ * <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--spacing-m)' }}>
69
+ * <HotKey hotkey="mod+k" label="Open command palette" />
70
+ * <HotKey hotkey="alt+enter" label="Submit form" />
71
+ * <HotKey hotkey="mod+alt+f" label="Find and replace" />
72
+ * </div>
73
+ * </Canvas>;
74
+ * ```
75
+ */
76
+ export function HotKey({ hotkey, label }: HotKeyProps) {
77
+ const keys = hotkey
78
+ .replace('mod', modifierKey)
79
+ .replace('alt', isMac ? '⌥' : 'Alt')
80
+ .split(/\+/)
81
+ .map((e) => e.charAt(0).toUpperCase() + e.slice(1));
82
+
83
+ return (
84
+ <div className={styles.hotKey}>
85
+ {label && <span className={styles.label}>{label}</span>}
86
+ <div className={styles.keys}>
87
+ {keys.map((key) => (
88
+ <span key={key} className={styles.hotKeyKey}>
89
+ {key}
90
+ </span>
91
+ ))}
92
+ </div>
93
+ </div>
94
+ );
95
+ }
@@ -0,0 +1,22 @@
1
+ .hotKey {
2
+ display: inline-flex;
3
+ align-items: center;
4
+ gap: 15px;
5
+ }
6
+
7
+ .label {
8
+ display: flex;
9
+ align-items: center;
10
+ }
11
+
12
+ .keys {
13
+ display: inline-flex;
14
+ align-items: center;
15
+ gap: 4px;
16
+ }
17
+
18
+ .hotKeyKey {
19
+ padding: 5px 8px;
20
+ background: var(--light-color);
21
+ border-radius: 3px;
22
+ }
@@ -0,0 +1 @@
1
+ {"hotKey":"_hotKey_1eko8_1","label":"_label_1eko8_7","keys":"_keys_1eko8_12","hotKeyKey":"_hotKeyKey_1eko8_18"}
@@ -0,0 +1,85 @@
1
+ import * as React from 'react';
2
+ import { TooltipContext, useTooltip, TooltipOptions } from '../utils';
3
+
4
+ export type TooltipProps = {
5
+ children?: React.ReactNode;
6
+ } & TooltipOptions;
7
+
8
+ /**
9
+ * Tooltip wrapper component that provides context for TooltipTrigger and TooltipContent.
10
+ *
11
+ * This is a compound component pattern. The Tooltip component itself doesn't render anything,
12
+ * but provides the necessary context for its children (TooltipTrigger and TooltipContent).
13
+ *
14
+ * @example Basic tooltip
15
+ *
16
+ * Create a simple tooltip that appears when hovering over a button:
17
+ *
18
+ * ```js
19
+ * <Canvas ctx={ctx}>
20
+ * <Tooltip>
21
+ * <TooltipTrigger>
22
+ * <Button>Hover me</Button>
23
+ * </TooltipTrigger>
24
+ * <TooltipContent>
25
+ * This is helpful information!
26
+ * </TooltipContent>
27
+ * </Tooltip>
28
+ * </Canvas>;
29
+ * ```
30
+ *
31
+ * @example Tooltip with custom placement
32
+ *
33
+ * Control where the tooltip appears relative to its trigger using the `placement` prop:
34
+ *
35
+ * ```js
36
+ * <Canvas ctx={ctx}>
37
+ * <Tooltip placement="right">
38
+ * <TooltipTrigger>
39
+ * <Button>Right tooltip</Button>
40
+ * </TooltipTrigger>
41
+ * <TooltipContent>
42
+ * Appears on the right side
43
+ * </TooltipContent>
44
+ * </Tooltip>
45
+ * </Canvas>;
46
+ * ```
47
+ *
48
+ * @example Multiple tooltips
49
+ *
50
+ * Use multiple tooltips on the same page to provide contextual help for different actions:
51
+ *
52
+ * ```js
53
+ * <Canvas ctx={ctx}>
54
+ * <div style={{ display: 'flex', gap: 'var(--spacing-m)' }}>
55
+ * <Tooltip>
56
+ * <TooltipTrigger>
57
+ * <Button leftIcon={<SaveIcon />} />
58
+ * </TooltipTrigger>
59
+ * <TooltipContent>
60
+ * Save changes (⌘S)
61
+ * </TooltipContent>
62
+ * </Tooltip>
63
+ *
64
+ * <Tooltip>
65
+ * <TooltipTrigger>
66
+ * <Button leftIcon={<DeleteIcon />} />
67
+ * </TooltipTrigger>
68
+ * <TooltipContent>
69
+ * Delete item
70
+ * </TooltipContent>
71
+ * </Tooltip>
72
+ * </div>
73
+ * </Canvas>;
74
+ * ```
75
+ */
76
+ export function Tooltip({ children, ...options }: TooltipProps) {
77
+ // This can accept any props as options, e.g. `placement`,
78
+ // or other positioning options.
79
+ const tooltip = useTooltip(options);
80
+ return (
81
+ <TooltipContext.Provider value={tooltip}>
82
+ {children}
83
+ </TooltipContext.Provider>
84
+ );
85
+ }
@@ -0,0 +1,140 @@
1
+ import * as React from 'react';
2
+ import {
3
+ FloatingPortal,
4
+ useMergeRefs,
5
+ useDelayGroup,
6
+ useDelayGroupContext,
7
+ useTransitionStyles,
8
+ } from '@floating-ui/react';
9
+ import { Canvas, useCtx } from '../../Canvas';
10
+ import { useTooltipState, getSharedPortalRoot, releaseSharedPortalRoot } from '../utils';
11
+ import s from './styles.module.css.json';
12
+
13
+ export type TooltipContentProps = {
14
+ children?: React.ReactNode;
15
+ };
16
+
17
+ /**
18
+ * TooltipContent contains the content displayed in the floating tooltip.
19
+ *
20
+ * The content is automatically wrapped in a Canvas component to inherit the DatoCMS
21
+ * theme and styling. The tooltip uses a portal to render outside the normal DOM
22
+ * hierarchy, ensuring proper positioning and z-index stacking.
23
+ *
24
+ * @example Simple text tooltip
25
+ *
26
+ * Display plain text in a tooltip to provide helpful information:
27
+ *
28
+ * ```js
29
+ * <Canvas ctx={ctx}>
30
+ * <Tooltip>
31
+ * <TooltipTrigger>
32
+ * <Button>Delete</Button>
33
+ * </TooltipTrigger>
34
+ * <TooltipContent>
35
+ * This action cannot be undone
36
+ * </TooltipContent>
37
+ * </Tooltip>
38
+ * </Canvas>;
39
+ * ```
40
+ *
41
+ * @example Rich content tooltip
42
+ *
43
+ * Include formatted content with custom styles for more detailed information:
44
+ *
45
+ * ```js
46
+ * <Canvas ctx={ctx}>
47
+ * <Tooltip placement="right">
48
+ * <TooltipTrigger>
49
+ * <Button leftIcon={<HelpIcon />}>Help</Button>
50
+ * </TooltipTrigger>
51
+ * <TooltipContent>
52
+ * <div>
53
+ * <strong>Need assistance?</strong>
54
+ * <p style={{ margin: '5px 0 0 0', fontSize: 'var(--font-size-xs)' }}>
55
+ * Contact support@example.com
56
+ * </p>
57
+ * </div>
58
+ * </TooltipContent>
59
+ * </Tooltip>
60
+ * </Canvas>;
61
+ * ```
62
+ *
63
+ * @example Tooltip with keyboard shortcut
64
+ *
65
+ * Combine tooltips with the HotKey component to show keyboard shortcuts:
66
+ *
67
+ * ```js
68
+ * <Canvas ctx={ctx}>
69
+ * <Tooltip>
70
+ * <TooltipTrigger>
71
+ * <Button leftIcon={<SaveIcon />}>Save</Button>
72
+ * </TooltipTrigger>
73
+ * <TooltipContent>
74
+ * <HotKey hotkey="mod+s" label="Save changes" />
75
+ * </TooltipContent>
76
+ * </Tooltip>
77
+ * </Canvas>;
78
+ * ```
79
+ */
80
+ export const TooltipContent = React.forwardRef<HTMLDivElement, TooltipContentProps>(
81
+ function TooltipContent({ children }, propRef) {
82
+ const ctx = useCtx();
83
+ const state = useTooltipState();
84
+ const { isInstantPhase, currentId } = useDelayGroupContext();
85
+ const ref = useMergeRefs([state.refs.setFloating, propRef]);
86
+
87
+ // Use the shared portal root
88
+ const portalRootRef = React.useRef<HTMLDivElement | null>(null);
89
+
90
+ React.useEffect(() => {
91
+ // Get the shared portal root and increment ref count
92
+ portalRootRef.current = getSharedPortalRoot();
93
+
94
+ // Cleanup function to release the shared portal root
95
+ return () => {
96
+ releaseSharedPortalRoot();
97
+ };
98
+ }, []);
99
+
100
+ useDelayGroup(state.context, { id: state.context.floatingId });
101
+
102
+ const instantDuration = 0;
103
+ const duration = 250;
104
+
105
+ const { isMounted, styles } = useTransitionStyles(state.context, {
106
+ duration: isInstantPhase
107
+ ? {
108
+ open: instantDuration,
109
+ // `id` is this component's `id`
110
+ // `currentId` is the current group's `id`
111
+ close:
112
+ currentId === state.context.floatingId ? duration : instantDuration,
113
+ }
114
+ : duration,
115
+ initial: {
116
+ opacity: 0,
117
+ },
118
+ });
119
+
120
+ if (!isMounted) return null;
121
+
122
+ return (
123
+ <FloatingPortal root={portalRootRef}>
124
+ <Canvas ctx={ctx} noAutoResizer>
125
+ <div
126
+ ref={ref}
127
+ style={{
128
+ ...state.floatingStyles,
129
+ ...styles,
130
+ }}
131
+ {...state.getFloatingProps()}
132
+ className={s.tooltip}
133
+ >
134
+ {children}
135
+ </div>
136
+ </Canvas>
137
+ </FloatingPortal>
138
+ );
139
+ },
140
+ );
@@ -0,0 +1,10 @@
1
+ .tooltip {
2
+ padding: 10px 15px;
3
+ box-shadow: 0 1px 9px rgba(0, 0, 0, 0.2);
4
+ background: white;
5
+ border-radius: 4px;
6
+ max-width: 400px;
7
+ word-wrap: break-word;
8
+ overflow-wrap: break-word;
9
+ hyphens: auto;
10
+ }
@@ -0,0 +1 @@
1
+ {"tooltip":"_tooltip_3z5rn_1"}