@allxsmith/bestax-bulma 5.28.0 → 5.30.0

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 (94) hide show
  1. package/dist/bestax.css +1 -1
  2. package/dist/bestax.css.map +1 -1
  3. package/dist/esm/components/ContextMenu.js +244 -0
  4. package/dist/esm/components/ContextMenu.js.map +1 -0
  5. package/dist/esm/components/Dialog.js +8 -4
  6. package/dist/esm/components/Dialog.js.map +1 -1
  7. package/dist/esm/components/HoverCard.js +3 -10
  8. package/dist/esm/components/HoverCard.js.map +1 -1
  9. package/dist/esm/components/Modal.js +19 -11
  10. package/dist/esm/components/Modal.js.map +1 -1
  11. package/dist/esm/components/Popover.js.map +1 -1
  12. package/dist/esm/components/Sidebar.js +12 -3
  13. package/dist/esm/components/Sidebar.js.map +1 -1
  14. package/dist/esm/components/Toast.js +5 -3
  15. package/dist/esm/components/Toast.js.map +1 -1
  16. package/dist/esm/components/Tooltip.js +36 -61
  17. package/dist/esm/components/Tooltip.js.map +1 -1
  18. package/dist/esm/elements/Button.js.map +1 -1
  19. package/dist/esm/elements/Notification.js +3 -1
  20. package/dist/esm/elements/Notification.js.map +1 -1
  21. package/dist/esm/elements/ToggleButton.js +60 -0
  22. package/dist/esm/elements/ToggleButton.js.map +1 -0
  23. package/dist/esm/form/DateInputBase.js.map +1 -1
  24. package/dist/esm/form/DateRangeInputBase.js.map +1 -1
  25. package/dist/esm/form/DateTimeInputBase.js.map +1 -1
  26. package/dist/esm/form/TimeInputBase.js.map +1 -1
  27. package/dist/esm/form/_pickerInternals/PickerPopover.js +3 -1
  28. package/dist/esm/form/_pickerInternals/PickerPopover.js.map +1 -1
  29. package/dist/esm/form/_pickerInternals/pickerTypes.js +14 -6
  30. package/dist/esm/form/_pickerInternals/pickerTypes.js.map +1 -1
  31. package/dist/esm/helpers/Config.js +5 -2
  32. package/dist/esm/helpers/Config.js.map +1 -1
  33. package/dist/esm/helpers/portal.js +30 -5
  34. package/dist/esm/helpers/portal.js.map +1 -1
  35. package/dist/esm/helpers/useContextMenuTrigger.js +166 -0
  36. package/dist/esm/helpers/useContextMenuTrigger.js.map +1 -0
  37. package/dist/esm/helpers/useHoverOpen.js +40 -6
  38. package/dist/esm/helpers/useHoverOpen.js.map +1 -1
  39. package/dist/esm/helpers/useMenuKeys.js +182 -0
  40. package/dist/esm/helpers/useMenuKeys.js.map +1 -0
  41. package/dist/extras.css +1 -1
  42. package/dist/extras.css.map +1 -1
  43. package/dist/index.cjs +2150 -1474
  44. package/dist/index.cjs.map +1 -1
  45. package/dist/index.esm.js +2 -0
  46. package/dist/index.esm.js.map +1 -1
  47. package/dist/types/components/ContextMenu.d.ts +66 -0
  48. package/dist/types/components/HoverCard.d.ts +14 -12
  49. package/dist/types/components/Modal.d.ts +2 -1
  50. package/dist/types/components/Popover.d.ts +8 -7
  51. package/dist/types/components/Tooltip.d.ts +45 -4
  52. package/dist/types/elements/Button.d.ts +1 -1
  53. package/dist/types/elements/ToggleButton.d.ts +90 -0
  54. package/dist/types/form/DateInputBase.d.ts +4 -1
  55. package/dist/types/form/DateRangeInputBase.d.ts +4 -1
  56. package/dist/types/form/DateTimeInputBase.d.ts +8 -2
  57. package/dist/types/form/TimeInputBase.d.ts +7 -3
  58. package/dist/types/form/_pickerInternals/pickerTypes.d.ts +16 -1
  59. package/dist/types/helpers/Config.d.ts +34 -3
  60. package/dist/types/helpers/portal.d.ts +27 -5
  61. package/dist/types/helpers/useContextMenuTrigger.d.ts +67 -0
  62. package/dist/types/helpers/useHoverOpen.d.ts +19 -3
  63. package/dist/types/helpers/useMenuKeys.d.ts +57 -0
  64. package/dist/types/index.d.ts +2 -0
  65. package/dist/types-cjs/components/ContextMenu.d.ts +66 -0
  66. package/dist/types-cjs/components/HoverCard.d.ts +14 -12
  67. package/dist/types-cjs/components/Modal.d.ts +2 -1
  68. package/dist/types-cjs/components/Popover.d.ts +8 -7
  69. package/dist/types-cjs/components/Tooltip.d.ts +45 -4
  70. package/dist/types-cjs/elements/Button.d.ts +1 -1
  71. package/dist/types-cjs/elements/ToggleButton.d.ts +90 -0
  72. package/dist/types-cjs/form/DateInputBase.d.ts +4 -1
  73. package/dist/types-cjs/form/DateRangeInputBase.d.ts +4 -1
  74. package/dist/types-cjs/form/DateTimeInputBase.d.ts +8 -2
  75. package/dist/types-cjs/form/TimeInputBase.d.ts +7 -3
  76. package/dist/types-cjs/form/_pickerInternals/pickerTypes.d.ts +16 -1
  77. package/dist/types-cjs/helpers/Config.d.ts +34 -3
  78. package/dist/types-cjs/helpers/portal.d.ts +27 -5
  79. package/dist/types-cjs/helpers/useContextMenuTrigger.d.ts +67 -0
  80. package/dist/types-cjs/helpers/useHoverOpen.d.ts +19 -3
  81. package/dist/types-cjs/helpers/useMenuKeys.d.ts +57 -0
  82. package/dist/types-cjs/index.d.ts +2 -0
  83. package/dist/versions/bestax-no-dark-mode.css +1 -1
  84. package/dist/versions/bestax-no-dark-mode.css.map +1 -1
  85. package/dist/versions/bestax-no-helpers-prefixed.css +1 -1
  86. package/dist/versions/bestax-no-helpers-prefixed.css.map +1 -1
  87. package/dist/versions/bestax-no-helpers.css +1 -1
  88. package/dist/versions/bestax-no-helpers.css.map +1 -1
  89. package/dist/versions/bestax-prefixed.css +1 -1
  90. package/dist/versions/bestax-prefixed.css.map +1 -1
  91. package/package.json +1 -1
  92. package/src/scss/components/_contextmenu.scss +50 -0
  93. package/src/scss/components/_index.scss +1 -0
  94. package/src/scss/components/_tooltip.scss +76 -1
@@ -0,0 +1,244 @@
1
+ /* @allxsmith/bestax-bulma — AI agents: see AGENTS.md in the package root, or https://bestax.io/llms.txt */
2
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
3
+ import { useState, useRef, useEffect, cloneElement } from 'react';
4
+ import { usePrefixedClassNames, classNames } from '../helpers/classNames.js';
5
+ import { useBulmaClasses } from '../helpers/useBulmaClasses.js';
6
+ import { withSubComponents } from '../helpers/withSubComponents.js';
7
+ import { Portal } from '../helpers/portal.js';
8
+ import { useConfig } from '../helpers/Config.js';
9
+ import { useClientLayoutEffect } from '../helpers/useClientLayoutEffect.js';
10
+ import { getDeepestActiveElement, isEventInside } from '../helpers/shadowDom.js';
11
+ import { warnOnce } from '../helpers/devWarnings.js';
12
+ import { useContextMenuTrigger } from '../helpers/useContextMenuTrigger.js';
13
+ import { useMenuKeys, enabledMenuItems, MENU_ITEM_SELECTOR, isEnabledMenuItem } from '../helpers/useMenuKeys.js';
14
+ import { DropdownDivider, DropdownItem } from './Dropdown.js';
15
+
16
+ /**
17
+ * Where the menu goes along one axis, from the point at `at`: after it when
18
+ * there's room, before it when there's room there instead, and otherwise
19
+ * moved in until it fits in `room`.
20
+ */
21
+ function placeAlong(at, size, room) {
22
+ if (at + size <= room)
23
+ return { start: at, flip: false };
24
+ if (at - size >= 0)
25
+ return { start: at, flip: true };
26
+ return { start: Math.max(0, room - size), flip: false };
27
+ }
28
+ /** Runs the trigger's own handler, then the context menu's. */
29
+ function chain(own, ours) {
30
+ return event => {
31
+ own?.(event);
32
+ ours(event);
33
+ };
34
+ }
35
+ /**
36
+ * The `ContextMenu` component opens a menu of actions where you right-click an element, such as a table row or a card, or long press it on a touch screen.
37
+ *
38
+ * Shift+F10 and the context menu key open it too, where the browser fires
39
+ * `contextmenu` for them, which Windows and Linux do. The menu is Dropdown's
40
+ * markup, portaled into the `portalContainer` a `ConfigProvider` sets, or
41
+ * the end of the trigger's own document's `<body>`, so it never has server
42
+ * markup. It opens below and to the right of the point, flips above or to
43
+ * the left where there's no room, moves in where it fits neither way, and
44
+ * scrolls inside when it's taller than the viewport. It doesn't follow the
45
+ * trigger, since scrolling closes it. Inside a `Modal` or a shadow root,
46
+ * point `portalContainer` inside it, so screen readers that honor
47
+ * `aria-modal` reach the menu and the shadow root's styles apply.
48
+ *
49
+ * Opening moves focus to the first enabled item. The arrow keys, Home, End
50
+ * and typing move between items, and Enter and Space activate one. Escape,
51
+ * Tab, an item, a press outside, scrolling, resizing and the window losing
52
+ * focus close it, handing focus back to what had it unless an item moved it
53
+ * somewhere else. For a menu opened from a button use `Dropdown`.
54
+ *
55
+ * @function
56
+ * @param {ContextMenuProps} props - Props for the ContextMenu component.
57
+ * @returns {JSX.Element} The trigger, and the menu while open.
58
+ *
59
+ * @example
60
+ * <ContextMenu
61
+ * aria-label="Actions for report.pdf"
62
+ * trigger={<Box>report.pdf</Box>}
63
+ * >
64
+ * <ContextMenu.Item as="button">Rename</ContextMenu.Item>
65
+ * <ContextMenu.Divider />
66
+ * <ContextMenu.Item as="button">Delete</ContextMenu.Item>
67
+ * </ContextMenu>
68
+ */
69
+ const ContextMenuComponent = ({ trigger, children, onOpenChange, closeOnClick = true, disabled = false, className, onKeyDown, onClick, onContextMenu, ...props }) => {
70
+ const { bulmaHelperClasses, rest } = useBulmaClasses(props);
71
+ const { portalContainer } = useConfig();
72
+ const [menu, setMenu] = useState(null);
73
+ // Turning `disabled` on closes it.
74
+ if (disabled && menu)
75
+ setMenu(null);
76
+ const open = menu !== null;
77
+ const doc = menu?.doc;
78
+ const placed = menu?.placed;
79
+ const boxRef = useRef(null);
80
+ const menuRef = useRef(null);
81
+ const openerRef = useRef(null);
82
+ const reportedRef = useRef(false);
83
+ const menuKeys = useMenuKeys();
84
+ const named = Boolean(props['aria-label'] || props['aria-labelledby']);
85
+ const handlers = useContextMenuTrigger({
86
+ disabled,
87
+ onOpen: (point, triggerNode) => {
88
+ const ownerDoc = triggerNode.ownerDocument;
89
+ openerRef.current = getDeepestActiveElement(ownerDoc);
90
+ setMenu({ point, doc: ownerDoc });
91
+ },
92
+ });
93
+ // Measured once per opening, before it paints, against what a fixed box
94
+ // resolves against: the root element's client area, which leaves out a
95
+ // classic scrollbar. `useAnchoredPosition` and Tooltip read innerWidth and
96
+ // innerHeight, which count it. A menu pinned to the viewport's edge would
97
+ // sit under the scrollbar by that much, so this reads the narrower box.
98
+ useClientLayoutEffect(() => {
99
+ const menuNode = menuRef.current;
100
+ if (!menu || menu.placed || !menuNode)
101
+ return;
102
+ const root = menuNode.ownerDocument.documentElement;
103
+ const { width, height } = menuNode.getBoundingClientRect();
104
+ const x = placeAlong(menu.point.x, width, root.clientWidth);
105
+ const y = placeAlong(menu.point.y, height, root.clientHeight);
106
+ setMenu({
107
+ ...menu,
108
+ placed: { left: x.start, top: y.start, right: x.flip, up: y.flip },
109
+ });
110
+ }, [menu]);
111
+ const isPlaced = Boolean(placed);
112
+ // What closes it while it's open, and focus back on closing. Nothing
113
+ // listens while it's closed.
114
+ useEffect(() => {
115
+ const box = boxRef.current;
116
+ const menuNode = menuRef.current;
117
+ if (!doc || !box || !menuNode)
118
+ return undefined;
119
+ const view = doc.defaultView;
120
+ // What had focus when it opened. This runs once per opening, so opening
121
+ // again at a new point while it's open keeps it.
122
+ const opener = openerRef.current;
123
+ const close = () => setMenu(null);
124
+ const closeOutside = (event) => {
125
+ if (!isEventInside(event, box))
126
+ close();
127
+ };
128
+ doc.addEventListener('pointerdown', closeOutside, true);
129
+ view.addEventListener('resize', close);
130
+ view.addEventListener('blur', close);
131
+ return () => {
132
+ doc.removeEventListener('pointerdown', closeOutside, true);
133
+ view.removeEventListener('resize', close);
134
+ view.removeEventListener('blur', close);
135
+ // Back to what had focus while the menu still has it, or it dropped to
136
+ // <body> when the menu left. An item that put it somewhere else, such
137
+ // as a Modal or a rename field, keeps it there.
138
+ const now = getDeepestActiveElement(doc);
139
+ if (!now || now === doc.body || menuNode.contains(now))
140
+ opener?.focus();
141
+ };
142
+ }, [doc]);
143
+ // Focus in, and closing on scroll, once it's placed. Placed, it's inside
144
+ // the viewport, so its first item has nothing to scroll into view, and
145
+ // `preventScroll` makes sure: a scroll the focus caused would close it as
146
+ // it opened. Opening again at a new point places it again, and leaves
147
+ // focus where it is in the menu.
148
+ useEffect(() => {
149
+ const box = boxRef.current;
150
+ const menuNode = menuRef.current;
151
+ if (!doc || !isPlaced || !box || !menuNode)
152
+ return undefined;
153
+ if (!menuNode.contains(getDeepestActiveElement(doc))) {
154
+ menuKeys.reset();
155
+ (enabledMenuItems(menuNode)[0] ?? menuNode).focus({
156
+ preventScroll: true,
157
+ });
158
+ }
159
+ const closeOutside = (event) => {
160
+ if (!isEventInside(event, box))
161
+ setMenu(null);
162
+ };
163
+ doc.addEventListener('scroll', closeOutside, true);
164
+ return () => doc.removeEventListener('scroll', closeOutside, true);
165
+ }, [doc, isPlaced, menuKeys]);
166
+ // Before paint, so what the caller does with it, such as highlighting the
167
+ // row, shows with the menu rather than a frame behind it.
168
+ useClientLayoutEffect(() => {
169
+ if (open === reportedRef.current)
170
+ return;
171
+ reportedRef.current = open;
172
+ onOpenChange?.(open);
173
+ });
174
+ useEffect(() => {
175
+ if (open && !named) {
176
+ warnOnce('ContextMenu:unnamed', '[bestax-bulma] <ContextMenu> opened a menu with no accessible ' +
177
+ 'name. Pass aria-label or aria-labelledby.');
178
+ }
179
+ }, [open, named]);
180
+ const handleKeyDown = (event) => {
181
+ onKeyDown?.(event);
182
+ // The menu has the keyboard while focus is in it. React brings its keys
183
+ // up the tree to wherever the ContextMenu sits, where a table that moves
184
+ // between rows on the arrow keys, or a Popover or a Modal waiting for
185
+ // Escape, would take them too.
186
+ event.stopPropagation();
187
+ if (event.key === 'Escape' || event.key === 'Tab') {
188
+ // Tab would go on from the end of <body>, past the rest of the page.
189
+ event.preventDefault();
190
+ setMenu(null);
191
+ return;
192
+ }
193
+ menuKeys.onKeyDown(event);
194
+ };
195
+ const handleClick = (event) => {
196
+ onClick?.(event);
197
+ if (!closeOnClick)
198
+ return;
199
+ const item = event.target.closest(MENU_ITEM_SELECTOR);
200
+ if (item && isEnabledMenuItem(item))
201
+ setMenu(null);
202
+ };
203
+ const handleContextMenu = (event) => {
204
+ onContextMenu?.(event);
205
+ // No other menu over this one: not the browser's, and not a trigger's
206
+ // that React brings the event up to.
207
+ event.preventDefault();
208
+ event.stopPropagation();
209
+ };
210
+ const own = trigger.props;
211
+ const triggerClass = usePrefixedClassNames('context-menu');
212
+ const clonedTrigger = cloneElement(trigger, {
213
+ className: classNames(own.className, !disabled && triggerClass) || undefined,
214
+ onContextMenu: chain(own.onContextMenu, handlers.onContextMenu),
215
+ onPointerDown: chain(own.onPointerDown, handlers.onPointerDown),
216
+ onPointerMove: chain(own.onPointerMove, handlers.onPointerMove),
217
+ onPointerUp: chain(own.onPointerUp, handlers.onPointerUp),
218
+ onPointerCancel: chain(own.onPointerCancel, handlers.onPointerCancel),
219
+ onTouchEnd: chain(own.onTouchEnd, handlers.onTouchEnd),
220
+ });
221
+ const boxClasses = usePrefixedClassNames('context-menu-content', 'dropdown', {
222
+ 'is-active': true,
223
+ 'is-up': placed?.up,
224
+ 'is-right': placed?.right,
225
+ });
226
+ const menuClasses = classNames(usePrefixedClassNames('dropdown-menu'), bulmaHelperClasses, className);
227
+ const contentClasses = usePrefixedClassNames('dropdown-content');
228
+ return (jsxs(Fragment, { children: [clonedTrigger, menu && (jsx(Portal, { container: portalContainer || menu.doc.body, children: jsx("div", { ref: boxRef, className: boxClasses, style: {
229
+ top: placed?.top ?? menu.point.y,
230
+ left: placed?.left ?? menu.point.x,
231
+ }, children: jsx("div", { ...rest, ref: menuRef, role: "menu", tabIndex: -1, className: menuClasses, onKeyDown: handleKeyDown, onClick: handleClick, onContextMenu: handleContextMenu, children: jsx("div", { className: contentClasses, children: children }) }) }) }))] }));
232
+ };
233
+ /**
234
+ * ContextMenu with Item and Divider sub-components, which are `Dropdown.Item`
235
+ * and `Dropdown.Divider`, so items written for a Dropdown work here
236
+ * unchanged.
237
+ */
238
+ const ContextMenu = withSubComponents(ContextMenuComponent, {
239
+ Item: DropdownItem,
240
+ Divider: DropdownDivider,
241
+ }, 'ContextMenu');
242
+
243
+ export { ContextMenu };
244
+ //# sourceMappingURL=ContextMenu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextMenu.js","sources":["../../../src/components/ContextMenu.tsx"],"sourcesContent":["import React, { cloneElement, useEffect, useRef, useState } from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { withSubComponents } from '../helpers/withSubComponents';\nimport { Portal } from '../helpers/portal';\nimport { useConfig } from '../helpers/Config';\nimport { useClientLayoutEffect } from '../helpers/useClientLayoutEffect';\nimport { getDeepestActiveElement, isEventInside } from '../helpers/shadowDom';\nimport { warnOnce } from '../helpers/devWarnings';\nimport {\n useContextMenuTrigger,\n type ContextMenuPoint,\n type ContextMenuTriggerHandlers,\n} from '../helpers/useContextMenuTrigger';\nimport {\n enabledMenuItems,\n isEnabledMenuItem,\n MENU_ITEM_SELECTOR,\n useMenuKeys,\n} from '../helpers/useMenuKeys';\nimport { DropdownDivider, DropdownItem } from './Dropdown';\n\n/**\n * Props for the ContextMenu component. `className`, `id`, `aria-label`, the\n * other HTML attributes and the helper props land on the menu\n * (`role=\"menu\"`). The trigger keeps its own.\n * @extraProp {string} [aria-label] - The menu's accessible name, such as \"Actions for report.pdf\". There's no button to borrow a name from, so pass this or `aria-labelledby`, and a development build warns when the menu opens with neither.\n * @extraProp {string} [className] - Additional classes for the menu (`role=\"menu\"`). The trigger keeps its own.\n */\nexport interface ContextMenuProps\n extends\n Omit<React.HTMLAttributes<HTMLDivElement>, 'color' | 'children'>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /**\n * The element a right-click, Shift+F10, the context menu key or a long\n * press opens the menu from: a table row, a card, an image. It's cloned,\n * not wrapped, so a row stays a row, which means it has to be a single\n * element that passes `className` and the `onContextMenu`,\n * `onPointerDown`, `onPointerMove`, `onPointerUp`, `onPointerCancel` and\n * `onTouchEnd` handlers to its DOM node. Its own handlers for those run\n * first, and one that calls `preventDefault()` on `contextmenu` keeps the\n * menu closed. A `ContextMenu` inside it opens instead of this one.\n *\n * It gets no ARIA and no tab stop, since it can be any element and a\n * right-click isn't an activation. Keyboard users reach it through\n * something focusable inside it, such as the row's own `Dropdown` button,\n * or a `tabIndex={0}` you give it, and press Shift+F10 or the context menu\n * key there. It gets `-webkit-touch-callout: none`, so iOS doesn't put its\n * own callout for a link or an image over the menu. A long press still\n * selects text the way it does anywhere, so give a region where it\n * shouldn't `interaction=\"unselectable\"`.\n */\n trigger: React.ReactElement;\n /**\n * The menu's items: `ContextMenu.Item` and `ContextMenu.Divider`, the same\n * components as `Dropdown.Item` and `Dropdown.Divider`. Every action in it\n * needs a visible way in as well, such as a `Dropdown` on the same row:\n * nothing tells a screen reader user the menu is there, and on macOS only\n * VoiceOver opens it from the keyboard.\n */\n children: React.ReactNode;\n /**\n * Called with `true` when the menu opens and `false` when it closes,\n * whatever closed it, such as for highlighting the row whose menu is open.\n * Nothing fires after ContextMenu unmounts. There's no `open` prop to go\n * with it: a menu opened from code has no point to open at.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * Close the menu when an item is clicked, or activated with Enter or\n * Space. A click on a divider or between items leaves it open either way.\n */\n closeOnClick?: boolean;\n /**\n * Leave the trigger to the browser: a right-click shows the browser's own\n * menu, a long press does what it does anywhere, and an open menu closes.\n */\n disabled?: boolean;\n}\n\n/** Where the menu goes once it's measured. */\ninterface Placement {\n /** The box's corner in the viewport, which the menu hangs from. */\n top: number;\n left: number;\n /** The menu sits above the box rather than below it. */\n up: boolean;\n /** The menu sits to the left of the box rather than to its right. */\n right: boolean;\n}\n\n/** An open menu. */\ninterface OpenMenu {\n point: ContextMenuPoint;\n /** The trigger's document, where presses and scrolling are watched. */\n doc: Document;\n /** Unset until the menu is measured, which happens before it paints. */\n placed?: Placement;\n}\n\n/**\n * Where the menu goes along one axis, from the point at `at`: after it when\n * there's room, before it when there's room there instead, and otherwise\n * moved in until it fits in `room`.\n */\nfunction placeAlong(\n at: number,\n size: number,\n room: number\n): { start: number; flip: boolean } {\n if (at + size <= room) return { start: at, flip: false };\n if (at - size >= 0) return { start: at, flip: true };\n return { start: Math.max(0, room - size), flip: false };\n}\n\n/** Runs the trigger's own handler, then the context menu's. */\nfunction chain<E>(\n own: ((event: E) => void) | undefined,\n ours: (event: E) => void\n): (event: E) => void {\n return event => {\n own?.(event);\n ours(event);\n };\n}\n\n/**\n * The `ContextMenu` component opens a menu of actions where you right-click an element, such as a table row or a card, or long press it on a touch screen.\n *\n * Shift+F10 and the context menu key open it too, where the browser fires\n * `contextmenu` for them, which Windows and Linux do. The menu is Dropdown's\n * markup, portaled into the `portalContainer` a `ConfigProvider` sets, or\n * the end of the trigger's own document's `<body>`, so it never has server\n * markup. It opens below and to the right of the point, flips above or to\n * the left where there's no room, moves in where it fits neither way, and\n * scrolls inside when it's taller than the viewport. It doesn't follow the\n * trigger, since scrolling closes it. Inside a `Modal` or a shadow root,\n * point `portalContainer` inside it, so screen readers that honor\n * `aria-modal` reach the menu and the shadow root's styles apply.\n *\n * Opening moves focus to the first enabled item. The arrow keys, Home, End\n * and typing move between items, and Enter and Space activate one. Escape,\n * Tab, an item, a press outside, scrolling, resizing and the window losing\n * focus close it, handing focus back to what had it unless an item moved it\n * somewhere else. For a menu opened from a button use `Dropdown`.\n *\n * @function\n * @param {ContextMenuProps} props - Props for the ContextMenu component.\n * @returns {JSX.Element} The trigger, and the menu while open.\n *\n * @example\n * <ContextMenu\n * aria-label=\"Actions for report.pdf\"\n * trigger={<Box>report.pdf</Box>}\n * >\n * <ContextMenu.Item as=\"button\">Rename</ContextMenu.Item>\n * <ContextMenu.Divider />\n * <ContextMenu.Item as=\"button\">Delete</ContextMenu.Item>\n * </ContextMenu>\n */\nconst ContextMenuComponent: React.FC<ContextMenuProps> = ({\n trigger,\n children,\n onOpenChange,\n closeOnClick = true,\n disabled = false,\n className,\n onKeyDown,\n onClick,\n onContextMenu,\n ...props\n}) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n const { portalContainer } = useConfig();\n const [menu, setMenu] = useState<OpenMenu | null>(null);\n // Turning `disabled` on closes it.\n if (disabled && menu) setMenu(null);\n const open = menu !== null;\n const doc = menu?.doc;\n const placed = menu?.placed;\n\n const boxRef = useRef<HTMLDivElement>(null);\n const menuRef = useRef<HTMLDivElement>(null);\n const openerRef = useRef<Element | null>(null);\n const reportedRef = useRef(false);\n const menuKeys = useMenuKeys();\n const named = Boolean(props['aria-label'] || props['aria-labelledby']);\n\n const handlers = useContextMenuTrigger({\n disabled,\n onOpen: (point, triggerNode) => {\n const ownerDoc = triggerNode.ownerDocument;\n openerRef.current = getDeepestActiveElement(ownerDoc);\n setMenu({ point, doc: ownerDoc });\n },\n });\n\n // Measured once per opening, before it paints, against what a fixed box\n // resolves against: the root element's client area, which leaves out a\n // classic scrollbar. `useAnchoredPosition` and Tooltip read innerWidth and\n // innerHeight, which count it. A menu pinned to the viewport's edge would\n // sit under the scrollbar by that much, so this reads the narrower box.\n useClientLayoutEffect(() => {\n const menuNode = menuRef.current;\n if (!menu || menu.placed || !menuNode) return;\n const root = menuNode.ownerDocument.documentElement;\n const { width, height } = menuNode.getBoundingClientRect();\n const x = placeAlong(menu.point.x, width, root.clientWidth);\n const y = placeAlong(menu.point.y, height, root.clientHeight);\n setMenu({\n ...menu,\n placed: { left: x.start, top: y.start, right: x.flip, up: y.flip },\n });\n }, [menu]);\n const isPlaced = Boolean(placed);\n\n // What closes it while it's open, and focus back on closing. Nothing\n // listens while it's closed.\n useEffect(() => {\n const box = boxRef.current;\n const menuNode = menuRef.current;\n if (!doc || !box || !menuNode) return undefined;\n const view = doc.defaultView as Window;\n // What had focus when it opened. This runs once per opening, so opening\n // again at a new point while it's open keeps it.\n const opener = openerRef.current as HTMLElement | null;\n const close = () => setMenu(null);\n const closeOutside = (event: Event) => {\n if (!isEventInside(event, box)) close();\n };\n doc.addEventListener('pointerdown', closeOutside, true);\n view.addEventListener('resize', close);\n view.addEventListener('blur', close);\n return () => {\n doc.removeEventListener('pointerdown', closeOutside, true);\n view.removeEventListener('resize', close);\n view.removeEventListener('blur', close);\n // Back to what had focus while the menu still has it, or it dropped to\n // <body> when the menu left. An item that put it somewhere else, such\n // as a Modal or a rename field, keeps it there.\n const now = getDeepestActiveElement(doc);\n if (!now || now === doc.body || menuNode.contains(now)) opener?.focus();\n };\n }, [doc]);\n\n // Focus in, and closing on scroll, once it's placed. Placed, it's inside\n // the viewport, so its first item has nothing to scroll into view, and\n // `preventScroll` makes sure: a scroll the focus caused would close it as\n // it opened. Opening again at a new point places it again, and leaves\n // focus where it is in the menu.\n useEffect(() => {\n const box = boxRef.current;\n const menuNode = menuRef.current;\n if (!doc || !isPlaced || !box || !menuNode) return undefined;\n if (!menuNode.contains(getDeepestActiveElement(doc))) {\n menuKeys.reset();\n (enabledMenuItems(menuNode)[0] ?? menuNode).focus({\n preventScroll: true,\n });\n }\n const closeOutside = (event: Event) => {\n if (!isEventInside(event, box)) setMenu(null);\n };\n doc.addEventListener('scroll', closeOutside, true);\n return () => doc.removeEventListener('scroll', closeOutside, true);\n }, [doc, isPlaced, menuKeys]);\n\n // Before paint, so what the caller does with it, such as highlighting the\n // row, shows with the menu rather than a frame behind it.\n useClientLayoutEffect(() => {\n if (open === reportedRef.current) return;\n reportedRef.current = open;\n onOpenChange?.(open);\n });\n\n useEffect(() => {\n if (open && !named) {\n warnOnce(\n 'ContextMenu:unnamed',\n '[bestax-bulma] <ContextMenu> opened a menu with no accessible ' +\n 'name. Pass aria-label or aria-labelledby.'\n );\n }\n }, [open, named]);\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {\n onKeyDown?.(event);\n // The menu has the keyboard while focus is in it. React brings its keys\n // up the tree to wherever the ContextMenu sits, where a table that moves\n // between rows on the arrow keys, or a Popover or a Modal waiting for\n // Escape, would take them too.\n event.stopPropagation();\n if (event.key === 'Escape' || event.key === 'Tab') {\n // Tab would go on from the end of <body>, past the rest of the page.\n event.preventDefault();\n setMenu(null);\n return;\n }\n menuKeys.onKeyDown(event);\n };\n\n const handleClick = (event: React.MouseEvent<HTMLDivElement>) => {\n onClick?.(event);\n if (!closeOnClick) return;\n const item = (event.target as Element).closest(MENU_ITEM_SELECTOR);\n if (item && isEnabledMenuItem(item)) setMenu(null);\n };\n\n const handleContextMenu = (event: React.MouseEvent<HTMLDivElement>) => {\n onContextMenu?.(event);\n // No other menu over this one: not the browser's, and not a trigger's\n // that React brings the event up to.\n event.preventDefault();\n event.stopPropagation();\n };\n\n const own = trigger.props as Partial<ContextMenuTriggerHandlers> & {\n className?: string;\n };\n const triggerClass = usePrefixedClassNames('context-menu');\n const clonedTrigger = cloneElement(\n trigger as React.ReactElement<Record<string, unknown>>,\n {\n className:\n classNames(own.className, !disabled && triggerClass) || undefined,\n onContextMenu: chain(own.onContextMenu, handlers.onContextMenu),\n onPointerDown: chain(own.onPointerDown, handlers.onPointerDown),\n onPointerMove: chain(own.onPointerMove, handlers.onPointerMove),\n onPointerUp: chain(own.onPointerUp, handlers.onPointerUp),\n onPointerCancel: chain(own.onPointerCancel, handlers.onPointerCancel),\n onTouchEnd: chain(own.onTouchEnd, handlers.onTouchEnd),\n }\n );\n\n const boxClasses = usePrefixedClassNames('context-menu-content', 'dropdown', {\n 'is-active': true,\n 'is-up': placed?.up,\n 'is-right': placed?.right,\n });\n const menuClasses = classNames(\n usePrefixedClassNames('dropdown-menu'),\n bulmaHelperClasses,\n className\n );\n const contentClasses = usePrefixedClassNames('dropdown-content');\n\n return (\n <>\n {clonedTrigger}\n {menu && (\n <Portal container={portalContainer || menu.doc.body}>\n <div\n ref={boxRef}\n className={boxClasses}\n style={{\n top: placed?.top ?? menu.point.y,\n left: placed?.left ?? menu.point.x,\n }}\n >\n <div\n {...rest}\n ref={menuRef}\n role=\"menu\"\n tabIndex={-1}\n className={menuClasses}\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n onContextMenu={handleContextMenu}\n >\n <div className={contentClasses}>{children}</div>\n </div>\n </div>\n </Portal>\n )}\n </>\n );\n};\n\n/**\n * ContextMenu with Item and Divider sub-components, which are `Dropdown.Item`\n * and `Dropdown.Divider`, so items written for a Dropdown work here\n * unchanged.\n */\nexport const ContextMenu = withSubComponents(\n ContextMenuComponent,\n {\n Item: DropdownItem,\n Divider: Dropdown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EACb,IAAI,KACHC,GAAA,CAAC,MAAM,EAAA,EAAC,SAAS,EAAE,eAAe,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,EAAA,QAAA,EACjDA,GAAA,CAAA,KAAA,EAAA,EACE,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,UAAU,EACrB,KAAK,EAAE;wBACL,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;wBAChC,IAAI,EAAE,MAAM,EAAE,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;qBACnC,EAAA,QAAA,EAEDA,GAAA,CAAA,KAAA,EAAA,EAAA,GACM,IAAI,EACR,GAAG,EAAE,OAAO,EACZ,IAAI,EAAC,MAAM,EACX,QAAQ,EAAE,EAAE,EACZ,SAAS,EAAE,WAAW,EACtB,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,WAAW,EACpB,aAAa,EAAE,iBAAiB,YAEhCA,GAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,cAAc,EAAA,QAAA,EAAG,QAAQ,EAAA,CAAO,EAAA,CAC5C,GACF,EAAA,CACC,CACV,CAAA,EAAA,CACA;AAEP,CAAC;AAED;;;;AAIG;AACI,MAAM,WAAW,GAAG,iBAAiB,CAC1C,oBAAoB,EACpB;AACE,IAAA,IAAI,EAAE,YAAY;AAClB,IAAA,OAAO,EAAE,eAAe;CACzB,EACD,aAAa;;"}
@@ -4,6 +4,7 @@ import { forwardRef, useRef, useCallback, useEffect, useSyncExternalStore } from
4
4
  import { usePrefixedClassNames, classNames } from '../helpers/classNames.js';
5
5
  import { useBulmaClasses } from '../helpers/useBulmaClasses.js';
6
6
  import { useIsHydrated } from '../helpers/useIsHydrated.js';
7
+ import { useConfig } from '../helpers/Config.js';
7
8
  import { Modal } from './Modal.js';
8
9
 
9
10
  /**
@@ -60,11 +61,14 @@ const Dialog = forwardRef(({ isOpen, title, message, type = 'default', confirmTe
60
61
  handleCancel();
61
62
  }
62
63
  }, [canCancel, handleCancel]);
63
- // Moving into the portal remounts the Modal's subtree — these buttons
64
- // included — so the focus effect below has to re-run against the new
65
- // nodes, exactly as the Modal's own focus effect does.
64
+ // Moving into the portal, or from one portal target to another, remounts
65
+ // the Modal's subtree, these buttons included, so the focus effect below
66
+ // has to re-run against the new nodes, exactly as the Modal's own focus
67
+ // effect does, on the same inputs.
66
68
  const isHydrated = useIsHydrated();
67
69
  const isPortaled = Boolean(portal) && isHydrated;
70
+ const { portalContainer } = useConfig();
71
+ const defaultTarget = isPortaled && portal === true ? portalContainer : undefined;
68
72
  // Focus management — Dialog picks a specific button rather than the
69
73
  // Modal's default (first focusable/root); this effect runs after the
70
74
  // inner Modal's own focus-on-open effect, so it wins.
@@ -73,7 +77,7 @@ const Dialog = forwardRef(({ isOpen, title, message, type = 'default', confirmTe
73
77
  const buttonToFocus = focusCancel && showCancel ? cancelRef.current : confirmRef.current;
74
78
  buttonToFocus?.focus();
75
79
  }
76
- }, [isOpen, focusCancel, showCancel, isPortaled]);
80
+ }, [isOpen, focusCancel, showCancel, isPortaled, portal, defaultTarget]);
77
81
  // Use combined ref
78
82
  const combinedRef = useCallback((node) => {
79
83
  dialogRef.current =
@@ -1 +1 @@
1
- {"version":3,"file":"Dialog.js","sources":["../../../src/components/Dialog.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { useIsHydrated } from '../helpers/useIsHydrated';\nimport { Modal } from './Modal';\n\n/** Valid dialog type/color values. */\nexport type DialogType = 'default' | 'success' | 'danger' | 'warning' | 'info';\n\n/**\n * Props for the Dialog component.\n * @extraProp {string} [className] - Additional CSS classes.\n * @extraProp {React.Ref<HTMLElement>} [ref] - Ref forwarded to the dialog element.\n */\nexport interface DialogProps\n extends\n Omit<React.HTMLAttributes<HTMLDivElement>, 'color'>,\n Omit<BulmaClassesProps, 'color'> {\n /** Whether the dialog is open (required). */\n isOpen: boolean;\n /** Dialog title. */\n title?: string;\n /** Dialog message/content (required). */\n message: string | React.ReactNode;\n /** The type/color of the dialog. Default: 'default'. */\n type?: DialogType;\n /** Text for confirm button. Default: 'OK'. */\n confirmText?: string;\n /** Text for cancel button. Default: 'Cancel'. */\n cancelText?: string;\n /** Callback when confirm button is clicked. */\n onConfirm?: () => void;\n /** Callback when cancel button is clicked or dismissed. */\n onCancel?: () => void;\n /** Whether to show cancel button. Default: true for confirm dialogs. */\n showCancel?: boolean;\n /** Whether the dialog can be dismissed. Default: true. */\n canCancel?: boolean;\n /** Focus cancel button instead of confirm. Default: false. */\n focusCancel?: boolean;\n /** Custom icon to display. */\n icon?: React.ReactNode;\n /**\n * Renders the dialog into a portal target instead of inline. Forwarded to\n * the underlying `Modal`; see its `portal` prop for the accepted values.\n * @defaultValue false\n */\n portal?: boolean | string | HTMLElement;\n}\n\n/**\n * The `Dialog` component provides ready-made confirm and alert dialogs, so a destructive action stays one `await dialog.confirm()` call away.\n *\n * @function\n * @param {DialogProps} props - Props for the Dialog component.\n * @param {React.Ref<HTMLDivElement>} ref - Forwarded ref to the dialog element.\n * @returns {JSX.Element | null} The rendered dialog component.\n *\n * @example\n * // Alert dialog\n * <Dialog\n * isOpen={showAlert}\n * title=\"Success\"\n * message=\"Operation completed successfully!\"\n * type=\"success\"\n * onConfirm={() => setShowAlert(false)}\n * showCancel={false}\n * />\n *\n * @example\n * // Confirm dialog\n * <Dialog\n * isOpen={showConfirm}\n * title=\"Delete Item?\"\n * message=\"This action cannot be undone.\"\n * type=\"danger\"\n * confirmText=\"Delete\"\n * onConfirm={handleDelete}\n * onCancel={() => setShowConfirm(false)}\n * />\n */\nexport const Dialog = forwardRef<HTMLDivElement, DialogProps>(\n (\n {\n isOpen,\n title,\n message,\n type = 'default',\n confirmText = 'OK',\n cancelText = 'Cancel',\n onConfirm,\n onCancel,\n showCancel = true,\n canCancel = true,\n focusCancel = false,\n icon,\n portal,\n className,\n ...props\n },\n ref\n ) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n const dialogRef = useRef<HTMLDivElement>(null);\n // Cleanup returned by a consumer's callback ref on attach, held until detach.\n const consumerCleanupRef = useRef<(() => void) | null>(null);\n const confirmRef = useRef<HTMLButtonElement>(null);\n const cancelRef = useRef<HTMLButtonElement>(null);\n\n // Handle cancel\n const handleCancel = useCallback(() => {\n if (canCancel) {\n onCancel?.();\n }\n }, [canCancel, onCancel]);\n\n // Handle confirm\n const handleConfirm = useCallback(() => {\n onConfirm?.();\n }, [onConfirm]);\n\n // Handle background click\n const handleBackgroundClick = useCallback(() => {\n if (canCancel) {\n handleCancel();\n }\n }, [canCancel, handleCancel]);\n\n // Moving into the portal remounts the Modal's subtree — these buttons\n // included — so the focus effect below has to re-run against the new\n // nodes, exactly as the Modal's own focus effect does.\n const isHydrated = useIsHydrated();\n const isPortaled = Boolean(portal) && isHydrated;\n\n // Focus management — Dialog picks a specific button rather than the\n // Modal's default (first focusable/root); this effect runs after the\n // inner Modal's own focus-on-open effect, so it wins.\n useEffect(() => {\n if (isOpen) {\n const buttonToFocus =\n focusCancel && showCancel ? cancelRef.current : confirmRef.current;\n buttonToFocus?.focus();\n }\n }, [isOpen, focusCancel, showCancel, isPortaled]);\n\n // Use combined ref\n const combinedRef = useCallback(\n (node: HTMLDivElement | null) => {\n (dialogRef as React.MutableRefObject<HTMLDivElement | null>).current =\n node;\n if (typeof ref === 'function') {\n // React 19 lets a callback ref return a cleanup function and detaches by\n // running it instead of calling the ref with `null`; React 18 discards the\n // return value entirely. Returning it from here would be a React-19-only\n // contract, so we hold the cleanup and run it ourselves on detach — the\n // same shape as `Dropdown`, `Modal`, `Sidebar`, `Toast` and `Carousel`.\n // The form controls that merge a forwarded ref still discard the cleanup\n // and detach with `ref(null)`, so this is not yet library-wide — grep\n // `typeof ref === 'function'` for the current split.\n if (node === null) {\n const consumerCleanup = consumerCleanupRef.current;\n consumerCleanupRef.current = null;\n if (consumerCleanup) {\n consumerCleanup();\n } else {\n ref(null);\n }\n return;\n }\n const cleanup: unknown = ref(node);\n consumerCleanupRef.current =\n typeof cleanup === 'function' ? (cleanup as () => void) : null;\n } else if (ref) {\n (ref as React.MutableRefObject<HTMLDivElement | null>).current = node;\n }\n },\n [ref]\n );\n\n // Generate classes\n const dialogClasses = usePrefixedClassNames('dialog', {\n [`is-${type}`]: type !== 'default',\n });\n const headerClass = usePrefixedClassNames('dialog-header');\n const iconClass = usePrefixedClassNames('dialog-icon');\n const titleClass = usePrefixedClassNames('dialog-title');\n const bodyClass = usePrefixedClassNames('dialog-body');\n const footerClass = usePrefixedClassNames('dialog-footer');\n const cancelButtonClass = usePrefixedClassNames('button');\n const confirmButtonClass = usePrefixedClassNames('button', {\n 'is-success': type === 'success',\n 'is-danger': type === 'danger',\n 'is-warning': type === 'warning',\n 'is-info': type === 'info',\n 'is-primary': type === 'default',\n });\n\n const combinedClasses = classNames(\n dialogClasses,\n bulmaHelperClasses,\n className\n );\n\n // Get default icon based on type\n const getDefaultIcon = () => {\n switch (type) {\n case 'success':\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n >\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n );\n case 'danger':\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n >\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"15\" y1=\"9\" x2=\"9\" y2=\"15\" />\n <line x1=\"9\" y1=\"9\" x2=\"15\" y2=\"15\" />\n </svg>\n );\n case 'warning':\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n stroke=\"none\"\n >\n <path d=\"M12 2L1 21h22L12 2zm0 3.99L19.53 19H4.47L12 5.99zM11 16h2v2h-2zm0-6h2v4h-2z\" />\n </svg>\n );\n case 'info':\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n stroke=\"none\"\n >\n <path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-1-9h2v6h-2zm0-4h2v2h-2z\" />\n </svg>\n );\n default:\n return null;\n }\n };\n\n const displayIcon = icon !== undefined ? icon : getDefaultIcon();\n\n if (!isOpen) {\n return null;\n }\n\n return (\n <Modal\n isActive={isOpen}\n onClose={handleCancel}\n role=\"presentation\"\n portal={portal}\n >\n <Modal.Background onClick={handleBackgroundClick} />\n <div\n ref={combinedRef}\n className={combinedClasses}\n role=\"alertdialog\"\n aria-modal=\"true\"\n aria-labelledby={title ? 'dialog-title' : undefined}\n aria-describedby=\"dialog-message\"\n {...rest}\n >\n {title && (\n <div className={headerClass}>\n {displayIcon && <span className={iconClass}>{displayIcon}</span>}\n <h3 id=\"dialog-title\" className={titleClass}>\n {title}\n </h3>\n </div>\n )}\n <div id=\"dialog-message\" className={bodyClass}>\n {message}\n </div>\n <div className={footerClass}>\n {showCancel && (\n <button\n ref={cancelRef}\n type=\"button\"\n className={cancelButtonClass}\n onClick={handleCancel}\n >\n {cancelText}\n </button>\n )}\n <button\n ref={confirmRef}\n type=\"button\"\n className={confirmButtonClass}\n onClick={handleConfirm}\n >\n {confirmText}\n </button>\n </div>\n </div>\n </Modal>\n );\n }\n);\n\nDialog.displayName = 'Dialog';\n\n// Dialog Manager for programmatic dialogs\n\n/**\n * Options for showing a programmatic alert dialog.\n */\nexport interface AlertOptions {\n /** Dialog title. */\n title?: string;\n /** Dialog message/content. */\n message: string | React.ReactNode;\n /** Dialog type/color. */\n type?: DialogType;\n /** Text for the confirm button. */\n confirmText?: string;\n /** Custom icon to display. */\n icon?: React.ReactNode;\n}\n\n/**\n * Options for showing a programmatic confirm dialog.\n */\nexport interface ConfirmOptions extends AlertOptions {\n /** Text for the cancel button. */\n cancelText?: string;\n /** Focus cancel button instead of confirm. */\n focusCancel?: boolean;\n}\n\n/**\n * Options for showing a programmatic prompt dialog.\n */\nexport interface PromptOptions extends ConfirmOptions {\n /** Input placeholder text. */\n placeholder?: string;\n /** Default input value. */\n defaultValue?: string;\n}\n\ntype DialogResolve = (value?: void | boolean | string) => void;\n\ntype DialogState = {\n type: 'alert' | 'confirm' | 'prompt';\n options: PromptOptions;\n resolve: DialogResolve;\n};\n\nlet dialogListeners: Set<(dialog: DialogState | null) => void> = new Set();\nlet currentDialog: DialogState | null = null;\n\n// DialogContainer renders from the open dialog rather than from updates alone,\n// so a dialog raised before it mounted still opens once it does.\nconst getCurrentDialog = () => currentDialog;\n\n// The server renders no dialog: its copy of this module is shared by every\n// request, so the dialog it holds may belong to another page. Hydration reads\n// the same empty value, which keeps the first client render matching the\n// server's, and the dialog opens right after.\nconst getServerDialog = (): DialogState | null => null;\n\nconst notifyDialogListeners = () => {\n dialogListeners.forEach(listener => listener(currentDialog));\n};\n\n/**\n * Programmatic dialog API for showing dialogs from anywhere.\n */\nexport const dialog = {\n /**\n * Show an alert dialog. Returns a promise that resolves when closed.\n */\n alert: (options: AlertOptions | string): Promise<void> => {\n return new Promise<void>(resolve => {\n const opts = typeof options === 'string' ? { message: options } : options;\n currentDialog = {\n type: 'alert',\n options: opts,\n resolve: () => resolve(),\n };\n notifyDialogListeners();\n });\n },\n\n /**\n * Show a confirm dialog. Returns a promise that resolves to true/false.\n */\n confirm: (options: ConfirmOptions | string): Promise<boolean> => {\n return new Promise<boolean>(resolve => {\n const opts = typeof options === 'string' ? { message: options } : options;\n currentDialog = {\n type: 'confirm',\n options: opts,\n resolve: value => resolve(Boolean(value)),\n };\n notifyDialogListeners();\n });\n },\n\n /**\n * Close the current dialog.\n */\n close: (value?: void | boolean | string): void => {\n if (currentDialog) {\n currentDialog.resolve(value);\n currentDialog = null;\n notifyDialogListeners();\n }\n },\n\n /**\n * Subscribe to dialog changes.\n */\n subscribe: (listener: (dialog: DialogState | null) => void): (() => void) => {\n dialogListeners.add(listener);\n return () => dialogListeners.delete(listener);\n },\n};\n\n/**\n * DialogContainer component to render programmatic dialogs.\n * Place this once at the root of your app.\n *\n * @function\n * @returns {JSX.Element | null} The rendered dialog, or null if none is active.\n */\nexport const DialogContainer: React.FC = () => {\n // Starts from the dialog already open instead of none, then follows changes.\n const current = useSyncExternalStore(\n dialog.subscribe,\n getCurrentDialog,\n getServerDialog\n );\n\n if (!current) {\n return null;\n }\n\n const { type, options } = current;\n\n return (\n <Dialog\n isOpen\n title={options.title}\n message={options.message}\n type={options.type}\n confirmText={options.confirmText}\n cancelText={options.cancelText}\n icon={options.icon}\n showCancel={type === 'confirm'}\n focusCancel={options.focusCancel}\n onConfirm={() => dialog.close(type === 'confirm' ? true : undefined)}\n onCancel={() => dialog.close(type === 'confirm' ? false : undefined)}\n />\n );\n};\n\nexport default Dialog;\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;AAwDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BG;AACI,MAAM,MAAM,GAAG,UAAU,CAC9B,CACE,EACE,MAAM,EACN,KAAK,EACL,OAAO,EACP,IAAI,GAAG,SAAS,EAChB,WAAW,GAAG,IAAI,EAClB,UAAU,GAAG,QAAQ,EACrB,SAAS,EACT,QAAQ,EACR,UAAU,GAAG,IAAI,EACjB,SAAS,GAAG,IAAI,EAChB,WAAW,GAAG,KAAK,EACnB,IAAI,EACJ,MAAM,EACN,SAAS,EACT,GAAG,KAAK,EACT,EACD,GAAG,KACD;IACF,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC;AAC3D,IAAA,MAAM,SAAS,GAAG,MAAM,CAAiB,IAAI,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,EACpB,OAAO,EAAE,OAAO,CAAC,OAAO,EACxB,IAAI,EAAE,OAAO,CAAC,IAAI,EAClB,WAAW,EAAE,OAAO,CAAC,WAAW,EAChC,UAAU,EAAE,OAAO,CAAC,UAAU,EAC9B,IAAI,EAAE,OAAO,CAAC,IAAI,EAClB,UAAU,EAAE,IAAI,KAAK,SAAS,EAC9B,WAAW,EAAE,OAAO,CAAC,WAAW,EAChC,SAAS,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC,EACpE,QAAQ,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,GAAG,KAAK,GAAG,SAAS,CAAC,EAAA,CACpE;AAEN;;"}
1
+ {"version":3,"file":"Dialog.js","sources":["../../../src/components/Dialog.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n useSyncExternalStore,\n} from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { useIsHydrated } from '../helpers/useIsHydrated';\nimport { useConfig } from '../helpers/Config';\nimport { Modal } from './Modal';\n\n/** Valid dialog type/color values. */\nexport type DialogType = 'default' | 'success' | 'danger' | 'warning' | 'info';\n\n/**\n * Props for the Dialog component.\n * @extraProp {string} [className] - Additional CSS classes.\n * @extraProp {React.Ref<HTMLElement>} [ref] - Ref forwarded to the dialog element.\n */\nexport interface DialogProps\n extends\n Omit<React.HTMLAttributes<HTMLDivElement>, 'color'>,\n Omit<BulmaClassesProps, 'color'> {\n /** Whether the dialog is open (required). */\n isOpen: boolean;\n /** Dialog title. */\n title?: string;\n /** Dialog message/content (required). */\n message: string | React.ReactNode;\n /** The type/color of the dialog. Default: 'default'. */\n type?: DialogType;\n /** Text for confirm button. Default: 'OK'. */\n confirmText?: string;\n /** Text for cancel button. Default: 'Cancel'. */\n cancelText?: string;\n /** Callback when confirm button is clicked. */\n onConfirm?: () => void;\n /** Callback when cancel button is clicked or dismissed. */\n onCancel?: () => void;\n /** Whether to show cancel button. Default: true for confirm dialogs. */\n showCancel?: boolean;\n /** Whether the dialog can be dismissed. Default: true. */\n canCancel?: boolean;\n /** Focus cancel button instead of confirm. Default: false. */\n focusCancel?: boolean;\n /** Custom icon to display. */\n icon?: React.ReactNode;\n /**\n * Renders the dialog into a portal target instead of inline. Forwarded to\n * the underlying `Modal`; see its `portal` prop for the accepted values.\n * @defaultValue false\n */\n portal?: boolean | string | HTMLElement;\n}\n\n/**\n * The `Dialog` component provides ready-made confirm and alert dialogs, so a destructive action stays one `await dialog.confirm()` call away.\n *\n * @function\n * @param {DialogProps} props - Props for the Dialog component.\n * @param {React.Ref<HTMLDivElement>} ref - Forwarded ref to the dialog element.\n * @returns {JSX.Element | null} The rendered dialog component.\n *\n * @example\n * // Alert dialog\n * <Dialog\n * isOpen={showAlert}\n * title=\"Success\"\n * message=\"Operation completed successfully!\"\n * type=\"success\"\n * onConfirm={() => setShowAlert(false)}\n * showCancel={false}\n * />\n *\n * @example\n * // Confirm dialog\n * <Dialog\n * isOpen={showConfirm}\n * title=\"Delete Item?\"\n * message=\"This action cannot be undone.\"\n * type=\"danger\"\n * confirmText=\"Delete\"\n * onConfirm={handleDelete}\n * onCancel={() => setShowConfirm(false)}\n * />\n */\nexport const Dialog = forwardRef<HTMLDivElement, DialogProps>(\n (\n {\n isOpen,\n title,\n message,\n type = 'default',\n confirmText = 'OK',\n cancelText = 'Cancel',\n onConfirm,\n onCancel,\n showCancel = true,\n canCancel = true,\n focusCancel = false,\n icon,\n portal,\n className,\n ...props\n },\n ref\n ) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n const dialogRef = useRef<HTMLDivElement>(null);\n // Cleanup returned by a consumer's callback ref on attach, held until detach.\n const consumerCleanupRef = useRef<(() => void) | null>(null);\n const confirmRef = useRef<HTMLButtonElement>(null);\n const cancelRef = useRef<HTMLButtonElement>(null);\n\n // Handle cancel\n const handleCancel = useCallback(() => {\n if (canCancel) {\n onCancel?.();\n }\n }, [canCancel, onCancel]);\n\n // Handle confirm\n const handleConfirm = useCallback(() => {\n onConfirm?.();\n }, [onConfirm]);\n\n // Handle background click\n const handleBackgroundClick = useCallback(() => {\n if (canCancel) {\n handleCancel();\n }\n }, [canCancel, handleCancel]);\n\n // Moving into the portal, or from one portal target to another, remounts\n // the Modal's subtree, these buttons included, so the focus effect below\n // has to re-run against the new nodes, exactly as the Modal's own focus\n // effect does, on the same inputs.\n const isHydrated = useIsHydrated();\n const isPortaled = Boolean(portal) && isHydrated;\n const { portalContainer } = useConfig();\n const defaultTarget =\n isPortaled && portal === true ? portalContainer : undefined;\n\n // Focus management — Dialog picks a specific button rather than the\n // Modal's default (first focusable/root); this effect runs after the\n // inner Modal's own focus-on-open effect, so it wins.\n useEffect(() => {\n if (isOpen) {\n const buttonToFocus =\n focusCancel && showCancel ? cancelRef.current : confirmRef.current;\n buttonToFocus?.focus();\n }\n }, [isOpen, focusCancel, showCancel, isPortaled, portal, defaultTarget]);\n\n // Use combined ref\n const combinedRef = useCallback(\n (node: HTMLDivElement | null) => {\n (dialogRef as React.MutableRefObject<HTMLDivElement | null>).current =\n node;\n if (typeof ref === 'function') {\n // React 19 lets a callback ref return a cleanup function and detaches by\n // running it instead of calling the ref with `null`; React 18 discards the\n // return value entirely. Returning it from here would be a React-19-only\n // contract, so we hold the cleanup and run it ourselves on detach — the\n // same shape as `Dropdown`, `Modal`, `Sidebar`, `Toast` and `Carousel`.\n // The form controls that merge a forwarded ref still discard the cleanup\n // and detach with `ref(null)`, so this is not yet library-wide — grep\n // `typeof ref === 'function'` for the current split.\n if (node === null) {\n const consumerCleanup = consumerCleanupRef.current;\n consumerCleanupRef.current = null;\n if (consumerCleanup) {\n consumerCleanup();\n } else {\n ref(null);\n }\n return;\n }\n const cleanup: unknown = ref(node);\n consumerCleanupRef.current =\n typeof cleanup === 'function' ? (cleanup as () => void) : null;\n } else if (ref) {\n (ref as React.MutableRefObject<HTMLDivElement | null>).current = node;\n }\n },\n [ref]\n );\n\n // Generate classes\n const dialogClasses = usePrefixedClassNames('dialog', {\n [`is-${type}`]: type !== 'default',\n });\n const headerClass = usePrefixedClassNames('dialog-header');\n const iconClass = usePrefixedClassNames('dialog-icon');\n const titleClass = usePrefixedClassNames('dialog-title');\n const bodyClass = usePrefixedClassNames('dialog-body');\n const footerClass = usePrefixedClassNames('dialog-footer');\n const cancelButtonClass = usePrefixedClassNames('button');\n const confirmButtonClass = usePrefixedClassNames('button', {\n 'is-success': type === 'success',\n 'is-danger': type === 'danger',\n 'is-warning': type === 'warning',\n 'is-info': type === 'info',\n 'is-primary': type === 'default',\n });\n\n const combinedClasses = classNames(\n dialogClasses,\n bulmaHelperClasses,\n className\n );\n\n // Get default icon based on type\n const getDefaultIcon = () => {\n switch (type) {\n case 'success':\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n >\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n );\n case 'danger':\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n >\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"15\" y1=\"9\" x2=\"9\" y2=\"15\" />\n <line x1=\"9\" y1=\"9\" x2=\"15\" y2=\"15\" />\n </svg>\n );\n case 'warning':\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n stroke=\"none\"\n >\n <path d=\"M12 2L1 21h22L12 2zm0 3.99L19.53 19H4.47L12 5.99zM11 16h2v2h-2zm0-6h2v4h-2z\" />\n </svg>\n );\n case 'info':\n return (\n <svg\n xmlns=\"http://www.w3.org/2000/svg\"\n viewBox=\"0 0 24 24\"\n fill=\"currentColor\"\n stroke=\"none\"\n >\n <path d=\"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm-1-9h2v6h-2zm0-4h2v2h-2z\" />\n </svg>\n );\n default:\n return null;\n }\n };\n\n const displayIcon = icon !== undefined ? icon : getDefaultIcon();\n\n if (!isOpen) {\n return null;\n }\n\n return (\n <Modal\n isActive={isOpen}\n onClose={handleCancel}\n role=\"presentation\"\n portal={portal}\n >\n <Modal.Background onClick={handleBackgroundClick} />\n <div\n ref={combinedRef}\n className={combinedClasses}\n role=\"alertdialog\"\n aria-modal=\"true\"\n aria-labelledby={title ? 'dialog-title' : undefined}\n aria-describedby=\"dialog-message\"\n {...rest}\n >\n {title && (\n <div className={headerClass}>\n {displayIcon && <span className={iconClass}>{displayIcon}</span>}\n <h3 id=\"dialog-title\" className={titleClass}>\n {title}\n </h3>\n </div>\n )}\n <div id=\"dialog-message\" className={bodyClass}>\n {message}\n </div>\n <div className={footerClass}>\n {showCancel && (\n <button\n ref={cancelRef}\n type=\"button\"\n className={cancelButtonClass}\n onClick={handleCancel}\n >\n {cancelText}\n </button>\n )}\n <button\n ref={confirmRef}\n type=\"button\"\n className={confirmButtonClass}\n onClick={handleConfirm}\n >\n {confirmText}\n </button>\n </div>\n </div>\n </Modal>\n );\n }\n);\n\nDialog.displayName = 'Dialog';\n\n// Dialog Manager for programmatic dialogs\n\n/**\n * Options for showing a programmatic alert dialog.\n */\nexport interface AlertOptions {\n /** Dialog title. */\n title?: string;\n /** Dialog message/content. */\n message: string | React.ReactNode;\n /** Dialog type/color. */\n type?: DialogType;\n /** Text for the confirm button. */\n confirmText?: string;\n /** Custom icon to display. */\n icon?: React.ReactNode;\n}\n\n/**\n * Options for showing a programmatic confirm dialog.\n */\nexport interface ConfirmOptions extends AlertOptions {\n /** Text for the cancel button. */\n cancelText?: string;\n /** Focus cancel button instead of confirm. */\n focusCancel?: boolean;\n}\n\n/**\n * Options for showing a programmatic prompt dialog.\n */\nexport interface PromptOptions extends ConfirmOptions {\n /** Input placeholder text. */\n placeholder?: string;\n /** Default input value. */\n defaultValue?: string;\n}\n\ntype DialogResolve = (value?: void | boolean | string) => void;\n\ntype DialogState = {\n type: 'alert' | 'confirm' | 'prompt';\n options: PromptOptions;\n resolve: DialogResolve;\n};\n\nlet dialogListeners: Set<(dialog: DialogState | null) => void> = new Set();\nlet currentDialog: DialogState | null = null;\n\n// DialogContainer renders from the open dialog rather than from updates alone,\n// so a dialog raised before it mounted still opens once it does.\nconst getCurrentDialog = () => currentDialog;\n\n// The server renders no dialog: its copy of this module is shared by every\n// request, so the dialog it holds may belong to another page. Hydration reads\n// the same empty value, which keeps the first client render matching the\n// server's, and the dialog opens right after.\nconst getServerDialog = (): DialogState | null => null;\n\nconst notifyDialogListeners = () => {\n dialogListeners.forEach(listener => listener(currentDialog));\n};\n\n/**\n * Programmatic dialog API for showing dialogs from anywhere.\n */\nexport const dialog = {\n /**\n * Show an alert dialog. Returns a promise that resolves when closed.\n */\n alert: (options: AlertOptions | string): Promise<void> => {\n return new Promise<void>(resolve => {\n const opts = typeof options === 'string' ? { message: options } : options;\n currentDialog = {\n type: 'alert',\n options: opts,\n resolve: () => resolve(),\n };\n notifyDialogListeners();\n });\n },\n\n /**\n * Show a confirm dialog. Returns a promise that resolves to true/false.\n */\n confirm: (options: ConfirmOptions | string): Promise<boolean> => {\n return new Promise<boolean>(resolve => {\n const opts = typeof options === 'string' ? { message: options } : options;\n currentDialog = {\n type: 'confirm',\n options: opts,\n resolve: value => resolve(Boolean(value)),\n };\n notifyDialogListeners();\n });\n },\n\n /**\n * Close the current dialog.\n */\n close: (value?: void | boolean | string): void => {\n if (currentDialog) {\n currentDialog.resolve(value);\n currentDialog = null;\n notifyDialogListeners();\n }\n },\n\n /**\n * Subscribe to dialog changes.\n */\n subscribe: (listener: (dialog: DialogState | null) => void): (() => void) => {\n dialogListeners.add(listener);\n return () => dialogListeners.delete(listener);\n },\n};\n\n/**\n * DialogContainer component to render programmatic dialogs.\n * Place this once at the root of your app.\n *\n * @function\n * @returns {JSX.Element | null} The rendered dialog, or null if none is active.\n */\nexport const DialogContainer: React.FC = () => {\n // Starts from the dialog already open instead of none, then follows changes.\n const current = useSyncExternalStore(\n dialog.subscribe,\n getCurrentDialog,\n getServerDialog\n );\n\n if (!current) {\n return null;\n }\n\n const { type, options } = current;\n\n return (\n <Dialog\n isOpen\n title={options.title}\n message={options.message}\n type={options.type}\n confirmText={options.confirmText}\n cancelText={options.cancelText}\n icon={options.icon}\n showCancel={type === 'confirm'}\n focusCancel={options.focusCancel}\n onConfirm={() => dialog.close(type === 'confirm' ? true : undefined)}\n onCancel={() => dialog.close(type === 'confirm' ? false : undefined)}\n />\n );\n};\n\nexport default Dialog;\n"],"names":["_jsx","_jsxs"],"mappings":";;;;;;;;;AAyDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BG;AACI,MAAM,MAAM,GAAG,UAAU,CAC9B,CACE,EACE,MAAM,EACN,KAAK,EACL,OAAO,EACP,IAAI,GAAG,SAAS,EAChB,WAAW,GAAG,IAAI,EAClB,UAAU,GAAG,QAAQ,EACrB,SAAS,EACT,QAAQ,EACR,UAAU,GAAG,IAAI,EACjB,SAAS,GAAG,IAAI,EAChB,WAAW,GAAG,KAAK,EACnB,IAAI,EACJ,MAAM,EACN,SAAS,EACT,GAAG,KAAK,EACT,EACD,GAAG,KACD;IACF,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC;AAC3D,IAAA,MAAM,SAAS,GAAG,MAAM,CAAiB,IAAI,CAAC;;AAE9C,IAAA,MAAM,kBAAkB,GAAG,MAAM,CAAsB,IAAI,CAAC;AAC5D,IAAA,MAAM,UAAU,GAAG,MAAM,CAAoB,IAAI,CAAC;AAClD,IAAA,MAAM,SAAS,GAAG,MAAM,CAAoB,I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AK,EACpB,OAAO,EAAE,OAAO,CAAC,OAAO,EACxB,IAAI,EAAE,OAAO,CAAC,IAAI,EAClB,WAAW,EAAE,OAAO,CAAC,WAAW,EAChC,UAAU,EAAE,OAAO,CAAC,UAAU,EAC9B,IAAI,EAAE,OAAO,CAAC,IAAI,EAClB,UAAU,EAAE,IAAI,KAAK,SAAS,EAC9B,WAAW,EAAE,OAAO,CAAC,WAAW,EAChC,SAAS,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,GAAG,IAAI,GAAG,SAAS,CAAC,EACpE,QAAQ,EAAE,MAAM,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,GAAG,KAAK,GAAG,SAAS,CAAC,EAAA,CACpE;AAEN;;"}
@@ -6,17 +6,10 @@ import { useBulmaClasses } from '../helpers/useBulmaClasses.js';
6
6
  import { Portal } from '../helpers/portal.js';
7
7
  import { useIsHydrated } from '../helpers/useIsHydrated.js';
8
8
  import { useAnchoredPosition, marginGap } from '../helpers/useAnchoredPosition.js';
9
- import { useHoverOpen } from '../helpers/useHoverOpen.js';
9
+ import { useHoverOpen, chain } from '../helpers/useHoverOpen.js';
10
10
  import { isTabbableKind } from '../helpers/useFocusTrap.js';
11
11
  import { isDev, warnOnce } from '../helpers/devWarnings.js';
12
12
 
13
- /** Runs the caller's handler on the wrapper, then the hover card's. */
14
- function chain(own, ours) {
15
- return event => {
16
- own?.(event);
17
- ours(event);
18
- };
19
- }
20
13
  /**
21
14
  * The `HoverCard` component shows a card previewing what's behind a link or a button while the pointer rests on it or keyboard focus is on it.
22
15
  *
@@ -41,7 +34,7 @@ function chain(own, ours) {
41
34
  */
42
35
  const HoverCard = ({ trigger, children, open: controlledOpen, defaultOpen = false, onOpenChange, openDelay = 600, closeDelay = 300, position = 'bottom-left', appendToBody = false, openOnTap = false, className, contentClassName, ...props }) => {
43
36
  const { bulmaHelperClasses, rest } = useBulmaClasses(props);
44
- const { onPointerEnter, onPointerLeave, onPointerDown, onPointerUp, onFocus, onBlur, ...attrs } = rest;
37
+ const { onPointerEnter, onPointerOver, onPointerLeave, onPointerDown, onPointerUp, onFocus, onBlur, ...attrs } = rest;
45
38
  const rootRef = useRef(null);
46
39
  const cardRef = useRef(null);
47
40
  const cardId = `${useId()}-card`;
@@ -114,7 +107,7 @@ const HoverCard = ({ trigger, children, open: controlledOpen, defaultOpen = fals
114
107
  [`is-${resolved.position}`]: true,
115
108
  'is-portal': appendToBody,
116
109
  }), contentClassName);
117
- return (jsxs("span", { className: rootClasses, ...attrs, onPointerEnter: chain(onPointerEnter, hover.onPointerEnter), onPointerLeave: chain(onPointerLeave, hover.onPointerLeave), onFocus: chain(onFocus, hover.onFocus), onBlur: chain(onBlur, hover.onBlur), onPointerDown: chain(onPointerDown, hover.onPointerDown), onPointerUp: chain(onPointerUp, hover.onPointerUp), ref: rootRef, children: [clonedTrigger, isOpen && (jsx(Portal, { disabled: !appendToBody, children: jsx("div", { ref: cardRef, id: cardId, className: cardClasses, style: appendToBody
110
+ return (jsxs("span", { className: rootClasses, ...attrs, onPointerEnter: chain(onPointerEnter, hover.onPointerEnter), onPointerOver: chain(onPointerOver, hover.onPointerOver), onPointerLeave: chain(onPointerLeave, hover.onPointerLeave), onFocus: chain(onFocus, hover.onFocus), onBlur: chain(onBlur, hover.onBlur), onPointerDown: chain(onPointerDown, hover.onPointerDown), onPointerUp: chain(onPointerUp, hover.onPointerUp), ref: rootRef, children: [clonedTrigger, isOpen && (jsx(Portal, { disabled: !appendToBody, children: jsx("div", { ref: cardRef, id: cardId, className: cardClasses, style: appendToBody
118
111
  ? {
119
112
  position: 'fixed',
120
113
  top: resolved.top,
@@ -1 +1 @@
1
- {"version":3,"file":"HoverCard.js","sources":["../../../src/components/HoverCard.tsx"],"sourcesContent":["import React, {\n cloneElement,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { Portal } from '../helpers/portal';\nimport { useIsHydrated } from '../helpers/useIsHydrated';\nimport { marginGap, useAnchoredPosition } from '../helpers/useAnchoredPosition';\nimport { useHoverOpen } from '../helpers/useHoverOpen';\nimport { isTabbableKind } from '../helpers/useFocusTrap';\nimport { isDev, warnOnce } from '../helpers/devWarnings';\nimport type { PickerPosition } from '../form/_pickerInternals/pickerTypes';\n\n/**\n * Where the card opens against its trigger: below (`bottom-*`) or above\n * (`top-*`), lined up with the trigger's left or right edge. `auto` picks the\n * one that keeps the card in the viewport, preferring below and lined up on\n * the left. The same union `Popover` and the date and time pickers take.\n */\nexport type HoverCardPosition = PickerPosition;\n\n/**\n * Props for the HoverCard component. `className`, `id`, the other HTML\n * attributes and the helper props land on the `span` around the trigger, not\n * on the card; `contentClassName` reaches the card.\n * @extraProp {string} [className] - Additional classes for the `span` around the trigger. The card takes `contentClassName`.\n */\nexport interface HoverCardProps\n extends\n Omit<React.HTMLAttributes<HTMLSpanElement>, 'color' | 'children'>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /**\n * The element the card previews, such as a link or a `Button`. The element\n * itself has to take focus, so keyboard users can open the card too: a\n * link inside a `<span>` doesn't do, since focus comes back to the trigger\n * and its ARIA is on it. HoverCard gives it no role and no tab stop, since\n * it can't know what the element is, and a development build warns when\n * it can't take focus: use a link or a button, or give the element\n * `tabIndex={0}`. A disabled button can't take focus either. HoverCard adds\n * `aria-expanded` and `aria-controls`, both naming the card only while it\n * is on the page, so it has to be a single element that passes those to\n * its DOM node. Its own click and keys stay its own, and the card doesn't\n * toggle on them, except Escape while the card is open, which closes the\n * card before the trigger sees it.\n */\n trigger: React.ReactElement;\n /**\n * The card's content: a preview whose links and buttons are fine, but not a\n * form, which belongs in a `Popover`. The card pads itself, so content goes\n * straight in.\n */\n children?: React.ReactNode;\n /**\n * Controlled open state. When set, hover, focus and Escape only report\n * through `onOpenChange`, so an action inside the card can close it. While\n * the card is open, Escape is reported, and when focus is in the card, on\n * its trigger or nowhere, the key stops there even if you keep the card\n * open, so a `Modal` around it doesn't close from the keyboard until the\n * card does.\n */\n open?: boolean;\n /**\n * Initial open state when uncontrolled. A card that starts open stays open\n * until the pointer or focus has been and gone, or Escape closes it.\n * @defaultValue false\n */\n defaultOpen?: boolean;\n /**\n * Called with the state asked for: when `openDelay` or `closeDelay` runs\n * out, and right away on Escape. Fires in both controlled and uncontrolled\n * use. An Escape it reports stops at the card when focus is in the card,\n * on its trigger or nowhere, so nothing around it sees that key. With\n * focus anywhere else, the card still closes and the key goes on to\n * whatever has focus.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * How long the pointer or keyboard focus waits on the trigger before the\n * card opens, in milliseconds.\n * @defaultValue 600\n */\n openDelay?: number;\n /**\n * How long the card stays after the pointer and focus have left the trigger\n * and the card, in milliseconds. It is the time the pointer has to cross\n * the gap between the trigger and the card: with `0` the card closes as the\n * pointer leaves the trigger, before the pointer can reach it.\n * @defaultValue 300\n */\n closeDelay?: number;\n /**\n * Where the card opens against the trigger.\n * @defaultValue 'bottom-left'\n */\n position?: HoverCardPosition;\n /**\n * Render the card at the end of `document.body` through `Portal`, fixed to\n * the viewport, so an ancestor's `overflow`, `transform` or stacking\n * context can't clip it. A trigger in running text needs it too, since the\n * card's block content can't sit inside a `<p>`. The card then shows from\n * the commit after hydration, never in server markup, and it sits last in\n * the Tab order, at the end of `<body>`. Tab reaches it only after the rest\n * of the page, and focus leaving the trigger on the way closes it, so\n * keyboard users can open it, read it and close it with Escape, and\n * whatever it links to has to be reachable from the page as well. It is\n * measured against the trigger when it opens and on resize and scroll, so\n * it doesn't follow content that changes size while it is open. Theming\n * variables set on an ancestor of the trigger don't reach it there.\n * @defaultValue false\n */\n appendToBody?: boolean;\n /**\n * Open the card with a tap on a touch screen. Touch has no hover, so\n * without this a phone or tablet never opens the card. With it, a tap on\n * the trigger opens the card at once, and it stays until a second tap on\n * the trigger, a tap outside the trigger and the card, or Escape. The tap\n * still does whatever the trigger does, so turn this on only for a trigger\n * with no tap action of its own, such as a `Button` with no `onClick`: on\n * a link, the first tap would follow the link rather than show the card.\n * Mouse and pen work the same either way.\n * @defaultValue false\n */\n openOnTap?: boolean;\n /** Additional classes for the card (`.hover-card-content`). */\n contentClassName?: string;\n}\n\n/** Runs the caller's handler on the wrapper, then the hover card's. */\nfunction chain<E>(\n own: ((event: E) => void) | undefined,\n ours: (event: E) => void\n): (event: E) => void {\n return event => {\n own?.(event);\n ours(event);\n };\n}\n\n/**\n * The `HoverCard` component shows a card previewing what's behind a link or a button while the pointer rests on it or keyboard focus is on it.\n *\n * Nothing moves focus when the card opens, and nothing traps it. In place,\n * the card comes right after the trigger, so Tab goes from the trigger into\n * its links and tabbing past them closes it. The pointer can move onto the\n * card, Escape closes it from anywhere, and by default touch doesn't open it,\n * so tapping the trigger just does what the trigger does. `openOnTap` opens\n * it with a tap, for a trigger with no tap action of its own. For hints with nothing to\n * click use `Tooltip`, and for content opened on purpose, such as a form,\n * use `Popover`.\n *\n * @function\n * @param {HoverCardProps} props - Props for the HoverCard component.\n * @returns {JSX.Element} The trigger in its wrapper, and the card while open.\n *\n * @example\n * <HoverCard trigger={<a href=\"/people/ada\">Ada Lovelace</a>}>\n * <Title as=\"p\" size=\"6\">Ada Lovelace</Title>\n * <SubTitle as=\"p\" size=\"6\">Analytical Engine team</SubTitle>\n * </HoverCard>\n */\nexport const HoverCard: React.FC<HoverCardProps> = ({\n trigger,\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n openDelay = 600,\n closeDelay = 300,\n position = 'bottom-left',\n appendToBody = false,\n openOnTap = false,\n className,\n contentClassName,\n ...props\n}) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n const {\n onPointerEnter,\n onPointerLeave,\n onPointerDown,\n onPointerUp,\n onFocus,\n onBlur,\n ...attrs\n } = rest;\n const rootRef = useRef<HTMLSpanElement>(null);\n const cardRef = useRef<HTMLDivElement>(null);\n const cardId = `${useId()}-card`;\n\n const isControlled = controlledOpen !== undefined;\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const isOpen = controlledOpen ?? internalOpen;\n\n const requestOpen = useCallback(\n (next: boolean) => {\n onOpenChange?.(next);\n if (!isControlled) setInternalOpen(next);\n },\n [isControlled, onOpenChange]\n );\n\n // A portaled card has no server markup, so it only exists from the commit\n // after hydration, and nothing measures it before then.\n const hydrated = useIsHydrated();\n const cardMounted = isOpen && (hydrated || !appendToBody);\n\n const resolved = useAnchoredPosition(rootRef, cardRef, {\n active: cardMounted,\n position,\n fixed: appendToBody,\n // The gap comes from `--bulma-hover-card-offset` in the stylesheet, so\n // the coordinates leave it out and `auto` reads it off the card.\n offset: 0,\n styledGap: marginGap,\n });\n\n // The trigger renders first inside the wrapper. Read when needed rather\n // than held, so a trigger that remounted is still the one found.\n const triggerRef = useMemo(\n () => ({\n get current() {\n const first = (rootRef.current as HTMLSpanElement).firstElementChild;\n return first && first !== cardRef.current\n ? (first as HTMLElement)\n : null;\n },\n }),\n []\n );\n\n const hover = useHoverOpen({\n open: isOpen,\n onOpenChange: requestOpen,\n openDelay,\n closeDelay,\n triggerRef,\n floatingRef: cardRef,\n openOnTap,\n });\n\n // A trigger that can't take focus leaves keyboard users no way to open the\n // card. It has to be the trigger element itself, not something inside it,\n // since focus comes back to it and its ARIA is on it. Judged by what the\n // element is rather than by its styles, which can hide it for now. After\n // every commit, since the trigger can change, and only in development.\n useEffect(() => {\n if (!isDev()) return;\n const triggerNode = triggerRef.current;\n if (!triggerNode) return;\n if (!triggerNode.matches(':disabled') && isTabbableKind(triggerNode)) {\n return;\n }\n warnOnce(\n 'HoverCard:unfocusable-trigger',\n \"[bestax-bulma] <HoverCard> has a trigger that can't take focus, so \" +\n \"keyboard users can't open the card. Use a link or a button as the \" +\n 'trigger, or give it tabIndex={0}.'\n );\n });\n\n // Expanded only while the card is on the page, so a portaled card that\n // waits for hydration isn't announced before it exists.\n const clonedTrigger = cloneElement(\n trigger as React.ReactElement<Record<string, unknown>>,\n {\n 'aria-expanded': cardMounted,\n 'aria-controls': cardMounted ? cardId : undefined,\n }\n );\n\n const rootClasses = classNames(\n usePrefixedClassNames('hover-card', { 'is-active': cardMounted }),\n bulmaHelperClasses,\n className\n );\n const cardClasses = classNames(\n usePrefixedClassNames('hover-card-content', {\n [`is-${resolved.position}`]: true,\n 'is-portal': appendToBody,\n }),\n contentClassName\n );\n\n return (\n // The ref after the spread: React 19 hands a function component a `ref`\n // prop like any other, and the wrapper has to stay ours. The card is in\n // the wrapper's React tree even when portaled, so the hover and focus\n // handlers here hear from both.\n <span\n className={rootClasses}\n {...attrs}\n onPointerEnter={chain(onPointerEnter, hover.onPointerEnter)}\n onPointerLeave={chain(onPointerLeave, hover.onPointerLeave)}\n onFocus={chain(onFocus, hover.onFocus)}\n onBlur={chain(onBlur, hover.onBlur)}\n onPointerDown={chain(onPointerDown, hover.onPointerDown)}\n onPointerUp={chain(onPointerUp, hover.onPointerUp)}\n ref={rootRef}\n >\n {clonedTrigger}\n {isOpen && (\n <Portal disabled={!appendToBody}>\n <div\n ref={cardRef}\n id={cardId}\n className={cardClasses}\n style={\n appendToBody\n ? {\n position: 'fixed',\n top: resolved.top,\n left: resolved.left,\n }\n : undefined\n }\n >\n {children}\n </div>\n </Portal>\n )}\n </span>\n );\n};\n\nexport default HoverCard;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;AAqIA;AACA,SAAS,KAAK,CACZ,GAAqC,EACrC,IAAwB,EAAA;IAExB,OAAO,KAAK,IAAG;AACb,QAAA,GAAG,GAAG,KAAK,CAAC;QACZ,IAAI,CAAC,KAAK,CAAC;AACb,IAAA,CAAC;AACH;AAEA;;;;;;;;;;;;;;;;;;;;;AAqBG;MACU,SAAS,GAA6B,CAAC,EAClD,OAAO,EACP,QAAQ,EACR,IAAI,EAAE,cAAc,EACpB,WAAW,GAAG,KAAK,EACnB,YAAY,EACZ,SAAS,GAAG,GAAG,EACf,UAAU,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I;AACjC,QAAA,WAAW,EAAE,YAAY;KAC1B,CAAC,EACF,gBAAgB,CACjB;IAED,QAKEA,eACE,SAAS,EAAE,WAAW,EAAA,GAClB,KAAK,EACT,cAAc,EAAE,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,EAC3D,cAAc,EAAE,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,cAAc,CAAC,EAC3D,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,EACtC,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,EACnC,aAAa,EAAE,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,EACxD,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,EAClD,GAAG,EAAE,OAAO,EAAA,QAAA,EAAA,CAEX,aAAa,EACb,MAAM,KACLC,GAAA,CAAC,MAAM,EAAA,EAAC,QAAQ,EAAE,CAAC,YAAY,EAAA,QAAA,EAC7BA,GAAA,CAAA,KAAA,EAAA,EACE,GAAG,EAAE,OAAO,EACZ,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,WAAW,EACtB,KAAK,EACH;AACE,0BAAE;AACE,4BAAA,QAAQ,EAAE,OAAO;4BACjB,GAAG,EAAE,QAAQ,CAAC,GAAG;4BACjB,IAAI,EAAE,QAAQ,CAAC,IAAI;AACpB;0BACD,SAAS,EAAA,QAAA,EAGd,QAAQ,GACL,EAAA,CACC,CACV,CAAA,EAAA,CACI;AAEX;;"}
1
+ {"version":3,"file":"HoverCard.js","sources":["../../../src/components/HoverCard.tsx"],"sourcesContent":["import React, {\n cloneElement,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { classNames, usePrefixedClassNames } from '../helpers/classNames';\nimport { useBulmaClasses, BulmaClassesProps } from '../helpers/useBulmaClasses';\nimport { Portal } from '../helpers/portal';\nimport { useIsHydrated } from '../helpers/useIsHydrated';\nimport { marginGap, useAnchoredPosition } from '../helpers/useAnchoredPosition';\nimport { chain, useHoverOpen } from '../helpers/useHoverOpen';\nimport { isTabbableKind } from '../helpers/useFocusTrap';\nimport { isDev, warnOnce } from '../helpers/devWarnings';\nimport type { PickerPosition } from '../form/_pickerInternals/pickerTypes';\n\n/**\n * Where the card opens against its trigger: below (`bottom-*`) or above\n * (`top-*`), lined up with the trigger's left or right edge. `auto` picks the\n * one that keeps the card in the viewport, preferring below and lined up on\n * the left. The same union `Popover` and the date and time pickers take.\n */\nexport type HoverCardPosition = PickerPosition;\n\n/**\n * Props for the HoverCard component. `className`, `id`, the other HTML\n * attributes and the helper props land on the `span` around the trigger, not\n * on the card; `contentClassName` reaches the card.\n * @extraProp {string} [className] - Additional classes for the `span` around the trigger. The card takes `contentClassName`.\n */\nexport interface HoverCardProps\n extends\n Omit<React.HTMLAttributes<HTMLSpanElement>, 'color' | 'children'>,\n Omit<BulmaClassesProps, 'color' | 'backgroundColor'> {\n /**\n * The element the card previews, such as a link or a `Button`. The element\n * itself has to take focus, so keyboard users can open the card too: a\n * link inside a `<span>` doesn't do, since focus comes back to the trigger\n * and its ARIA is on it. HoverCard gives it no role and no tab stop, since\n * it can't know what the element is, and a development build warns when\n * it can't take focus: use a link or a button, or give the element\n * `tabIndex={0}`. A disabled button can't take focus either. HoverCard adds\n * `aria-expanded` and `aria-controls`, both naming the card only while it\n * is on the page, so it has to be a single element that passes those to\n * its DOM node. Its own click and keys stay its own, and the card doesn't\n * toggle on them, except Escape while the card is open, which closes the\n * card before the trigger sees it.\n */\n trigger: React.ReactElement;\n /**\n * The card's content: a preview whose links and buttons are fine, but not a\n * form, which belongs in a `Popover`. The card pads itself, so content goes\n * straight in.\n */\n children?: React.ReactNode;\n /**\n * Controlled open state. When set, hover, focus and Escape only report\n * through `onOpenChange`, so an action inside the card can close it. While\n * the card is open, Escape is reported, and when focus is in the card, on\n * its trigger or nowhere, the key stops there even if you keep the card\n * open, so a `Modal` around it doesn't close from the keyboard until the\n * card does.\n */\n open?: boolean;\n /**\n * Initial open state when uncontrolled. A card that starts open stays open\n * until the pointer or focus has been and gone, or Escape closes it.\n * @defaultValue false\n */\n defaultOpen?: boolean;\n /**\n * Called with the state asked for: when `openDelay` or `closeDelay` runs\n * out, and right away on Escape. Fires in both controlled and uncontrolled\n * use. An Escape it reports stops at the card when focus is in the card,\n * on its trigger or nowhere, so nothing around it sees that key. With\n * focus anywhere else, the card still closes and the key goes on to\n * whatever has focus.\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * How long the pointer or keyboard focus waits on the trigger before the\n * card opens, in milliseconds.\n * @defaultValue 600\n */\n openDelay?: number;\n /**\n * How long the card stays after the pointer and focus have left the trigger\n * and the card, in milliseconds. It is the time the pointer has to cross\n * the gap between the trigger and the card: with `0` the card closes as the\n * pointer leaves the trigger, before the pointer can reach it.\n * @defaultValue 300\n */\n closeDelay?: number;\n /**\n * Where the card opens against the trigger.\n * @defaultValue 'bottom-left'\n */\n position?: HoverCardPosition;\n /**\n * Render the card through `Portal`, into the `portalContainer` a\n * `ConfigProvider` sets, `document.body` by default, fixed to the viewport,\n * so an ancestor's `overflow`, `transform` or stacking context can't clip\n * it. A trigger in running text needs it too, since the card's block\n * content can't sit inside a `<p>`. The card then shows from the commit\n * after hydration, never in server markup, and it sits in the Tab order\n * where its container is. At the end of `<body>`, the default, Tab reaches\n * it only after the rest of the page, and focus leaving the trigger on the\n * way closes it, so keyboard users can open it, read it and close it with\n * Escape, and whatever it links to has to be reachable from the page as\n * well. It is measured against the trigger when it opens and on resize and\n * scroll, so it doesn't follow content that changes size while it is open.\n * Theming variables set on an ancestor of the trigger reach it only when its\n * container is inside that ancestor.\n * @defaultValue false\n */\n appendToBody?: boolean;\n /**\n * Open the card with a tap on a touch screen. Touch has no hover, so\n * without this a phone or tablet never opens the card. With it, a tap on\n * the trigger opens the card at once, and it stays until a second tap on\n * the trigger, a tap outside the trigger and the card, or Escape. The tap\n * still does whatever the trigger does, so turn this on only for a trigger\n * with no tap action of its own, such as a `Button` with no `onClick`: on\n * a link, the first tap would follow the link rather than show the card.\n * Mouse and pen work the same either way.\n * @defaultValue false\n */\n openOnTap?: boolean;\n /** Additional classes for the card (`.hover-card-content`). */\n contentClassName?: string;\n}\n\n/**\n * The `HoverCard` component shows a card previewing what's behind a link or a button while the pointer rests on it or keyboard focus is on it.\n *\n * Nothing moves focus when the card opens, and nothing traps it. In place,\n * the card comes right after the trigger, so Tab goes from the trigger into\n * its links and tabbing past them closes it. The pointer can move onto the\n * card, Escape closes it from anywhere, and by default touch doesn't open it,\n * so tapping the trigger just does what the trigger does. `openOnTap` opens\n * it with a tap, for a trigger with no tap action of its own. For hints with nothing to\n * click use `Tooltip`, and for content opened on purpose, such as a form,\n * use `Popover`.\n *\n * @function\n * @param {HoverCardProps} props - Props for the HoverCard component.\n * @returns {JSX.Element} The trigger in its wrapper, and the card while open.\n *\n * @example\n * <HoverCard trigger={<a href=\"/people/ada\">Ada Lovelace</a>}>\n * <Title as=\"p\" size=\"6\">Ada Lovelace</Title>\n * <SubTitle as=\"p\" size=\"6\">Analytical Engine team</SubTitle>\n * </HoverCard>\n */\nexport const HoverCard: React.FC<HoverCardProps> = ({\n trigger,\n children,\n open: controlledOpen,\n defaultOpen = false,\n onOpenChange,\n openDelay = 600,\n closeDelay = 300,\n position = 'bottom-left',\n appendToBody = false,\n openOnTap = false,\n className,\n contentClassName,\n ...props\n}) => {\n const { bulmaHelperClasses, rest } = useBulmaClasses(props);\n const {\n onPointerEnter,\n onPointerOver,\n onPointerLeave,\n onPointerDown,\n onPointerUp,\n onFocus,\n onBlur,\n ...attrs\n } = rest;\n const rootRef = useRef<HTMLSpanElement>(null);\n const cardRef = useRef<HTMLDivElement>(null);\n const cardId = `${useId()}-card`;\n\n const isControlled = controlledOpen !== undefined;\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const isOpen = controlledOpen ?? internalOpen;\n\n const requestOpen = useCallback(\n (next: boolean) => {\n onOpenChange?.(next);\n if (!isControlled) setInternalOpen(next);\n },\n [isControlled, onOpenChange]\n );\n\n // A portaled card has no server markup, so it only exists from the commit\n // after hydration, and nothing measures it before then.\n const hydrated = useIsHydrated();\n const cardMounted = isOpen && (hydrated || !appendToBody);\n\n const resolved = useAnchoredPosition(rootRef, cardRef, {\n active: cardMounted,\n position,\n fixed: appendToBody,\n // The gap comes from `--bulma-hover-card-offset` in the stylesheet, so\n // the coordinates leave it out and `auto` reads it off the card.\n offset: 0,\n styledGap: marginGap,\n });\n\n // The trigger renders first inside the wrapper. Read when needed rather\n // than held, so a trigger that remounted is still the one found.\n const triggerRef = useMemo(\n () => ({\n get current() {\n const first = (rootRef.current as HTMLSpanElement).firstElementChild;\n return first && first !== cardRef.current\n ? (first as HTMLElement)\n : null;\n },\n }),\n []\n );\n\n const hover = useHoverOpen({\n open: isOpen,\n onOpenChange: requestOpen,\n openDelay,\n closeDelay,\n triggerRef,\n floatingRef: cardRef,\n openOnTap,\n });\n\n // A trigger that can't take focus leaves keyboard users no way to open the\n // card. It has to be the trigger element itself, not something inside it,\n // since focus comes back to it and its ARIA is on it. Judged by what the\n // element is rather than by its styles, which can hide it for now. After\n // every commit, since the trigger can change, and only in development.\n useEffect(() => {\n if (!isDev()) return;\n const triggerNode = triggerRef.current;\n if (!triggerNode) return;\n if (!triggerNode.matches(':disabled') && isTabbableKind(triggerNode)) {\n return;\n }\n warnOnce(\n 'HoverCard:unfocusable-trigger',\n \"[bestax-bulma] <HoverCard> has a trigger that can't take focus, so \" +\n \"keyboard users can't open the card. Use a link or a button as the \" +\n 'trigger, or give it tabIndex={0}.'\n );\n });\n\n // Expanded only while the card is on the page, so a portaled card that\n // waits for hydration isn't announced before it exists.\n const clonedTrigger = cloneElement(\n trigger as React.ReactElement<Record<string, unknown>>,\n {\n 'aria-expanded': cardMounted,\n 'aria-controls': cardMounted ? cardId : undefined,\n }\n );\n\n const rootClasses = classNames(\n usePrefixedClassNames('hover-card', { 'is-active': cardMounted }),\n bulmaHelperClasses,\n className\n );\n const cardClasses = classNames(\n usePrefixedClassNames('hover-card-content', {\n [`is-${resolved.position}`]: true,\n 'is-portal': appendToBody,\n }),\n contentClassName\n );\n\n return (\n // The ref after the spread: React 19 hands a function component a `ref`\n // prop like any other, and the wrapper has to stay ours. The card is in\n // the wrapper's React tree even when portaled, so the hover and focus\n // handlers here hear from both.\n <span\n className={rootClasses}\n {...attrs}\n onPointerEnter={chain(onPointerEnter, hover.onPointerEnter)}\n onPointerOver={chain(onPointerOver, hover.onPointerOver)}\n onPointerLeave={chain(onPointerLeave, hover.onPointerLeave)}\n onFocus={chain(onFocus, hover.onFocus)}\n onBlur={chain(onBlur, hover.onBlur)}\n onPointerDown={chain(onPointerDown, hover.onPointerDown)}\n onPointerUp={chain(onPointerUp, hover.onPointerUp)}\n ref={rootRef}\n >\n {clonedTrigger}\n {isOpen && (\n <Portal disabled={!appendToBody}>\n <div\n ref={cardRef}\n id={cardId}\n className={cardClasses}\n style={\n appendToBody\n ? {\n position: 'fixed',\n top: resolved.top,\n left: resolved.left,\n }\n : undefined\n }\n >\n {children}\n </div>\n </Portal>\n )}\n </span>\n );\n};\n\nexport default HoverCard;\n"],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;;AAuIA;;;;;;;;;;;;;;;;;;;;;AAqBG;MACU,SAAS,GAA6B,CAAC,EAClD,OAAO,EACP,QAAQ,EACR,IAAI,EAAE,cAAc,EACpB,WAAW,GAAG,KAAK,EACnB,YAAY,EACZ,SAAS,GAAG,GAAG,EACf,UAAU,GAAG,GAAG,EAChB,QAAQ,GAAG,aAAa,EACxB,YAAY,GAAG,KAAK,EACpB,SAAS,GAAG,KAAK,EACjB,SAAS,EACT,gBAAgB,EAChB,GAAG,KAAK,EACT,KAAI;IACH,MAAM,EAAE,kBAAkB,EAAE,IAAI,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC;IAC3D,MAAM,EACJ,cAAc,EACd,aAAa,EACb,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