@crisp-ui-kit/crisp 0.41.0 → 0.42.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.
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.ContextMenu = ContextMenu;
37
37
  const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const react_slot_1 = require("@radix-ui/react-slot");
38
39
  const React = __importStar(require("react"));
39
40
  const core_1 = require("../../core");
40
41
  const menu_1 = require("../menu");
@@ -44,7 +45,7 @@ const contextmenu_recipe_1 = require("./contextmenu.recipe");
44
45
  * Wrap the target; right-clicking it opens the menu (flipping at the viewport
45
46
  * edges), closing on select, outside pointer-down, and Escape.
46
47
  */
47
- function ContextMenu({ children, items, menuLabel = "Context menu", className, }) {
48
+ function ContextMenu({ children, items, menuLabel = "Context menu", className, asChild = false, }) {
48
49
  const rootRef = React.useRef(null);
49
50
  const menuRef = React.useRef(null);
50
51
  const returnFocusTo = React.useRef(null);
@@ -109,7 +110,7 @@ function ContextMenu({ children, items, menuLabel = "Context menu", className, }
109
110
  document.removeEventListener("keydown", onKey);
110
111
  };
111
112
  }, [pos, close]);
112
- return ((0, jsx_runtime_1.jsxs)("div", { ref: rootRef, className: (0, contextmenu_recipe_1.contextmenuRecipe)({ className }), children: [(0, jsx_runtime_1.jsx)("div", { onContextMenu: open, children: children }), pos && ((0, jsx_runtime_1.jsx)(core_1.FloatingPortal, { sourceRef: rootRef, children: (0, jsx_runtime_1.jsx)("div", { ref: menuRef, className: "crisp-contextmenu-content", role: "menu", "aria-label": menuLabel, style: { left: pos.x, top: pos.y }, onKeyDown: onMenuKeyDown, children: items.map((item, i) => item.separator ? ((0, jsx_runtime_1.jsx)("hr", { className: "crisp-contextmenu-sep" }, i)) : ((0, jsx_runtime_1.jsxs)("button", { type: "button", role: "menuitem", disabled: item.disabled, className: item.danger
113
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [asChild ? ((0, jsx_runtime_1.jsx)(react_slot_1.Slot, { ref: rootRef, className: className, onContextMenu: open, children: children })) : ((0, jsx_runtime_1.jsx)("div", { ref: rootRef, className: (0, contextmenu_recipe_1.contextmenuRecipe)({ className }), children: (0, jsx_runtime_1.jsx)("div", { onContextMenu: open, children: children }) })), pos && ((0, jsx_runtime_1.jsx)(core_1.FloatingPortal, { sourceRef: rootRef, children: (0, jsx_runtime_1.jsx)("div", { ref: menuRef, className: "crisp-contextmenu-content", role: "menu", "aria-label": menuLabel, style: { left: pos.x, top: pos.y }, onKeyDown: onMenuKeyDown, children: items.map((item, i) => item.separator ? ((0, jsx_runtime_1.jsx)("hr", { className: "crisp-contextmenu-sep" }, i)) : ((0, jsx_runtime_1.jsxs)("button", { type: "button", role: "menuitem", disabled: item.disabled, className: item.danger
113
114
  ? "crisp-contextmenu-item crisp-contextmenu-item--danger"
114
115
  : "crisp-contextmenu-item", tabIndex: -1, onClick: () => {
115
116
  item.onSelect?.();
@@ -1,4 +1,5 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Slot } from "@radix-ui/react-slot";
2
3
  import * as React from "react";
3
4
  import { FloatingPortal, isInsideLaterFloatingLayer, registerFloatingLayer, } from "../../core/index.js";
4
5
  import { useMenuKeyboard } from "../menu/index.js";
@@ -8,7 +9,7 @@ import { contextmenuRecipe } from "./contextmenu.recipe.js";
8
9
  * Wrap the target; right-clicking it opens the menu (flipping at the viewport
9
10
  * edges), closing on select, outside pointer-down, and Escape.
10
11
  */
11
- export function ContextMenu({ children, items, menuLabel = "Context menu", className, }) {
12
+ export function ContextMenu({ children, items, menuLabel = "Context menu", className, asChild = false, }) {
12
13
  const rootRef = React.useRef(null);
13
14
  const menuRef = React.useRef(null);
14
15
  const returnFocusTo = React.useRef(null);
@@ -73,7 +74,7 @@ export function ContextMenu({ children, items, menuLabel = "Context menu", class
73
74
  document.removeEventListener("keydown", onKey);
74
75
  };
75
76
  }, [pos, close]);
76
- return (_jsxs("div", { ref: rootRef, className: contextmenuRecipe({ className }), children: [_jsx("div", { onContextMenu: open, children: children }), pos && (_jsx(FloatingPortal, { sourceRef: rootRef, children: _jsx("div", { ref: menuRef, className: "crisp-contextmenu-content", role: "menu", "aria-label": menuLabel, style: { left: pos.x, top: pos.y }, onKeyDown: onMenuKeyDown, children: items.map((item, i) => item.separator ? (_jsx("hr", { className: "crisp-contextmenu-sep" }, i)) : (_jsxs("button", { type: "button", role: "menuitem", disabled: item.disabled, className: item.danger
77
+ return (_jsxs(_Fragment, { children: [asChild ? (_jsx(Slot, { ref: rootRef, className: className, onContextMenu: open, children: children })) : (_jsx("div", { ref: rootRef, className: contextmenuRecipe({ className }), children: _jsx("div", { onContextMenu: open, children: children }) })), pos && (_jsx(FloatingPortal, { sourceRef: rootRef, children: _jsx("div", { ref: menuRef, className: "crisp-contextmenu-content", role: "menu", "aria-label": menuLabel, style: { left: pos.x, top: pos.y }, onKeyDown: onMenuKeyDown, children: items.map((item, i) => item.separator ? (_jsx("hr", { className: "crisp-contextmenu-sep" }, i)) : (_jsxs("button", { type: "button", role: "menuitem", disabled: item.disabled, className: item.danger
77
78
  ? "crisp-contextmenu-item crisp-contextmenu-item--danger"
78
79
  : "crisp-contextmenu-item", tabIndex: -1, onClick: () => {
79
80
  item.onSelect?.();
@@ -17,13 +17,23 @@ export type ContextMenuProps = {
17
17
  /** Accessible name for the menu surface. */
18
18
  menuLabel?: string;
19
19
  className?: string;
20
+ /**
21
+ * Render `onContextMenu` and the trigger ref directly onto `children`
22
+ * instead of wrapping it in a `<div>` (#340) — needed when `children` is
23
+ * an element that cannot have a wrapping element inserted around it, such
24
+ * as a `<tr>` inside a `<tbody>` (the browser's HTML parser hoists the row
25
+ * out of the wrapping `<div>`, breaking both the layout and the
26
+ * right-click target). `children` must then be a single valid React
27
+ * element, same as any other `asChild` in crisp (`core/primitive.tsx`).
28
+ */
29
+ asChild?: boolean;
20
30
  };
21
31
  /**
22
32
  * A right-click context menu — the popover surface positioned at the cursor.
23
33
  * Wrap the target; right-clicking it opens the menu (flipping at the viewport
24
34
  * edges), closing on select, outside pointer-down, and Escape.
25
35
  */
26
- export declare function ContextMenu({ children, items, menuLabel, className, }: ContextMenuProps): React.JSX.Element;
36
+ export declare function ContextMenu({ children, items, menuLabel, className, asChild, }: ContextMenuProps): React.JSX.Element;
27
37
  export declare namespace ContextMenu {
28
38
  var displayName: string;
29
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crisp-ui-kit/crisp",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "description": "A lean React design system, measured pixel-for-pixel from Attio.",
5
5
  "license": "MIT",
6
6
  "type": "module",