@stackone/malachite 2.82.0 → 2.83.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/COMPONENTS.md CHANGED
@@ -51,7 +51,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
51
51
  - **`Tooltip`** — Hover/focus tooltip; also works on disabled controls (see CLAUDE.md). It describes its trigger once shown, so `describesTrigger={false}` where the same sentence is already on screen and referenced — otherwise a screen reader reads it twice. _Key props:_ `text`, `placement`, `delay`, `maxWidth`, `shouldShow`, `triggerAs`, `describesTrigger`, `isShrinkable`, `fill`, `wrapChildren`, `suppressed` (holds the tooltip back, e.g. while the popup its trigger opens is up), `showOnFocus` (false where script can move focus onto the trigger, e.g. an option a panel focuses on open), `focusableTrigger` (makes a trigger that cannot take focus — text, a static `Tag` — a tab stop, so the tooltip is not mouse-only; not for focusable children).
52
52
  - **`TruncatedTooltip`** — Shows a tooltip only when its text is truncated.
53
53
  - **`Confetti`** — Celebratory confetti burst for success moments. _Key props:_ `pieces`.
54
- - **`ConfirmationDialog`** — Asks the customer to confirm one consequential action — a preset over `Modal`, not a second dialog implementation. `variant` picks a whole coherent set at once (badge fill, tray tint, caption colour, badge icon and confirm-button variant), so `destructive` cannot end up with a non-destructive confirm button; `destructive` also renders as `role="alertdialog"`, and `description` is wired to the dialog through `aria-describedby`, so the consequence is announced and not just the title. `confirmPhrase` gates the confirm action on typing that exact phrase, for a consequence severe enough that one click should not be able to cause it — the typed value is trimmed, since copying a name picks up a trailing space, but stays case-sensitive, and the field clears each time the dialog opens, being a per-decision gate rather than a value. Neither a destructive dialog nor one carrying a `confirmPhrase` dismisses on a scrim click, and `loading` suppresses the pointer routes — the scrim and the close button — as well as disabling the buttons. It never suppresses ESC: that is the only guaranteed keyboard exit from a focus trap, so it always reaches `onClose` and whether to abort is left to the caller. ESC reaches it whenever it is the topmost overlay, so it can be opened over a panel. `callout` renders an `Alert` in a full-width band at the top of the body — it scrolls with the body rather than being pinned under the header, and with no `description`, `children` or `confirmPhrase` there is no body, so the band sits directly on the footer — and its `type` is chosen independently of `variant` — the frames pair a green badge with an amber callout. `titleAdornment` names the entity beside the title, `badgeIcon` overrides the variant’s glyph for an action-specific one, and `tip` is the `{ label?, message }` caption on the tray beneath the card, which `Modal` renders and describes. `children` is where extra body content goes. `onConfirm` does not close the dialog, so the caller can hold it open on `loading` while the request is in flight. `confirmPhraseLabel` also takes `{ prefix, suffix }`, which renders the phrase itself as a copyable token between the two — the gate is case-sensitive and space-exact, so a customer who has identified the right entity should not be locked out by a glyph they cannot tell apart. The copy control sits outside the element that names the field, so “Copy…” never lands in the field’s accessible name; `confirmPhraseCopyLabel` names it and `onPhraseCopied` reports a completed write with the phrase it copied. A rejected write says so in the field rather than failing silently, and the control is disabled where the Clipboard API is unavailable. A near miss is named rather than left to a disabled button: typing the phrase with the wrong case or the wrong spacing says which, once the whole phrase is there, and that message is the field’s `aria-describedby`. _Key props:_ `open`, `onClose`, `onConfirm`, `title`, `description`, `titleAdornment`, `badgeIcon`, `variant` (`default` | `warning` | `destructive` | `success`), `callout`, `confirmPhrase`, `confirmPhraseLabel`, `confirmPhraseCopyLabel`, `confirmPhrasePlaceholder`, `onPhraseCopied`, `confirmLabel`, `cancelLabel`, `loading`, `tip`, `size`, `aria-label`, `aria-labelledby`.
54
+ - **`ConfirmationDialog`** — Asks the customer to confirm one consequential action — a preset over `Modal`, not a second dialog implementation. `variant` picks a whole coherent set at once (badge fill, tray tint, caption colour, badge icon and confirm-button variant), so `destructive` cannot end up with a non-destructive confirm button; `destructive` also renders as `role="alertdialog"`, and `description` is wired to the dialog through `aria-describedby`, so the consequence is announced and not just the title. `confirmPhrase` gates the confirm action on typing that exact phrase, for a consequence severe enough that one click should not be able to cause it — the typed value and the phrase are both trimmed, since copying a name picks up a trailing space and a saved name can carry padding that never renders, except that a phrase of only whitespace is matched exactly as given, so an empty field cannot confirm it; the match stays case-sensitive, and the field clears each time the dialog opens, being a per-decision gate rather than a value. Neither a destructive dialog nor one carrying a `confirmPhrase` dismisses on a scrim click, and `loading` suppresses the pointer routes — the scrim and the close button — as well as disabling the buttons. It never suppresses ESC: that is the only guaranteed keyboard exit from a focus trap, so it always reaches `onClose` and whether to abort is left to the caller. ESC reaches it whenever it is the topmost overlay, so it can be opened over a panel. `callout` renders an `Alert` in a full-width band at the top of the body — it scrolls with the body rather than being pinned under the header, and with no `description`, `children` or `confirmPhrase` there is no body, so the band sits directly on the footer — and its `type` is chosen independently of `variant` — the frames pair a green badge with an amber callout. `titleAdornment` names the entity beside the title, `badgeIcon` overrides the variant’s glyph for an action-specific one, and `tip` is the `{ label?, message }` caption on the tray beneath the card, which `Modal` renders and describes. `children` is where extra body content goes. `onConfirm` does not close the dialog, so the caller can hold it open on `loading` while the request is in flight. `confirmPhraseLabel` also takes `{ prefix, suffix }`, which renders the phrase itself as a copyable token between the two — the gate is case-sensitive and space-exact inside the phrase, so a customer who has identified the right entity should not be locked out by a glyph they cannot tell apart. The copy control sits outside the element that names the field, so “Copy…” never lands in the field’s accessible name; `confirmPhraseCopyLabel` names it and `onPhraseCopied` reports a completed write with the phrase it copied. A rejected write says so in the field rather than failing silently, and the control is disabled where the Clipboard API is unavailable. A near miss is named rather than left to a disabled button: typing the phrase with the wrong case or the wrong spacing says which, once the whole phrase is there, and that message is the field’s `aria-describedby`. _Key props:_ `open`, `onClose`, `onConfirm`, `title`, `description`, `titleAdornment`, `badgeIcon`, `variant` (`default` | `warning` | `destructive` | `success`), `callout`, `confirmPhrase`, `confirmPhraseLabel`, `confirmPhraseCopyLabel`, `confirmPhrasePlaceholder`, `onPhraseCopied`, `confirmLabel`, `cancelLabel`, `loading`, `tip`, `size`, `aria-label`, `aria-labelledby`.
55
55
 
56
56
  ## Lists, rows & navigation
57
57
 
@@ -62,7 +62,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
62
62
  - **`PreviewTreeRow`** — A single labelled row within a PreviewTree. _Key props:_ `label`.
63
63
  - **`Tabs`** — Tabbed navigation switching between content panels. `trailing` puts content on the same row, settled against its end — a count, a scope picker, the state the tabs are showing — inside the rule this component already draws. Without it a consumer had to redraw that rule to carry it past the tabs, and the tab list, which cannot wrap, would not yield any width to what sat beside it. The tabs hold their width and the trailing content gives ground; the `tablist` role stays on the tabs alone, so the extra content is not announced as one. _Key props:_ `TabItem[]`, `activeKey`, `onChange`, `trailing`, `className`, `style`.
64
64
  - **`Breadcrumbs`** — Breadcrumb trail with caret separators, an optional back button (shown only when there is more than one crumb AND the parent — the second-to-last — carries a `url` to target) and a right-aligned `actions` row. A lone crumb marked `isRoot` switches to title mode: plain emphasised text, no trail chrome, but the `actions` row still renders. Renders as a `nav`/`ol` with `aria-current="page"` on the last crumb. Pass `renderLink` to route crumbs through the app's own router instead of a plain `<a>`. Used by `PageLayout`, but standalone too. _Key props:_ `links[]` (`name`, `url`, `isRoot`), `actions[]`, `renderLink`, `className`, `style`.
65
- - **`ActionMenu`** — Dropdown menu of actions (kebab/overflow style). The trigger is an icon-only `Button` by default, so `size` draws exactly the square a `Button` of that size draws beside it: `xsmall` is Figma's 20px "Button Element - Square (X-Small)", `small` the 28px rung above it. Both squares are fixed rather than read off the `controlHeights` tokens, so re-theming those does not resize the trigger. A supplied `triggerIcon` is held to the tier's glyph size — 11px at `xsmall`, 16px at `small`. At 20px the `xsmall` trigger meets WCAG 2.5.8 through the *Spacing* exception rather than the 24px minimum, so keep at least 4px between adjacent triggers. `showLabel` draws `label` beside the icon instead of leaving it to the accessible name — for a menu that is the point of its corner rather than an overflow for a row that already says what it acts on — and `variant` puts the trigger on any `Button` variant, so a menu handing work to the assistant can wear the assistant ground rather than the overflow-kebab outline. An item's `icon` leads its label: every caller's names the action itself — copy, open, delete — and an icon that is part of an item's identity belongs where the eye starts rather than right-aligned, where it reads as a status column. The menu is Figma's `Dropdown Component - Options List`: a fixed sized to its widest item between a 180px floor and the 280px Figma draws, by default under the trigger's right edge, 14px below it, flipping above or clamping sideways when the viewport has no room, rounding at the library's 12px and padding wider (8px) than the menu a `Dropdown` opens. Items read in the primary text colour, or the secondary one with `tone="muted"` (e.g. a sidebar's menus); destructive ones in red; `danger: 'hover'` keeps an item in its normal colour and turns it destructive (red text on a light red ground) only on hover or keyboard focus, for an action like signing out. A ceiling rather than a flat width: taken literally it gave a menu of four short verbs 130px of air and made every kebab in an app the same width whatever it held. `minWidth` only raises it above that ceiling, so it is the one way to go past 280px, and a label too long for the box truncates rather than wrapping. _Key props:_ `ActionMenuItem[]`, `size`, `label`, `triggerIcon`, `minWidth`, `showLabel`, `variant`, `tone` (`default` | `muted`), `trigger` (your own control in place of the kebab, cloned with the menu's ref and aria state), `placement` (`bottom-end` default | `bottom-start` | `right-start` | `top-start` | `top-center`), `offset` (`small` 8px | `medium` 12px | `large` 14px; applies to every placement; without it the default `bottom-end` keeps the options menu's 14px and the others use 8px). An item's `tag` (e.g. an "Early access" `Tag`) follows its label in a lazily loaded shadow host of its own, since the menu renders into `document.body`, and joins its accessible name; `current: true` marks the item for the page the user is on (`aria-current="page"` and the selected row paint; a `danger` item keeps its red text). An item with an `href` is a link: Cmd/Ctrl-click or a middle click opens it in a new tab and closes the menu, while a plain click runs `onClick` in its place when one is given (so a router can navigate in-app); Enter and Space both activate it. `target: '_blank'` opens it in a new tab, adds `noopener noreferrer` and tells screen readers it opens a new tab. An item with `checked` is one of a set of choices: a `menuitemradio` with `aria-checked` and a trailing check while true; picking it still runs `onClick` and closes. `description` adds a quieter second line under the label, announced as the item's description rather than its name. An item with `type: 'text'` is context rather than an action (an account's email above its actions): secondary text the arrow keys skip. Opened from the keyboard, focus lands on the first item, or on the checked choice in a menu of choices; Up/Down/Home/End move through enabled items, Tab closes the menu and moves on as usual; Escape or a picked item returns focus to the trigger.
65
+ - **`ActionMenu`** — Dropdown menu of actions (kebab/overflow style). The trigger is an icon-only `Button` by default, so `size` draws exactly the square a `Button` of that size draws beside it: `xsmall` is Figma's 20px "Button Element - Square (X-Small)", `small` the 28px rung above it. Both squares are fixed rather than read off the `controlHeights` tokens, so re-theming those does not resize the trigger. A supplied `triggerIcon` is held to the tier's glyph size — 11px at `xsmall`, 16px at `small`. At 20px the `xsmall` trigger meets WCAG 2.5.8 through the *Spacing* exception rather than the 24px minimum, so keep at least 4px between adjacent triggers. `showLabel` draws `label` beside the icon instead of leaving it to the accessible name — for a menu that is the point of its corner rather than an overflow for a row that already says what it acts on — and `variant` puts the trigger on any `Button` variant, so a menu handing work to the assistant can wear the assistant ground rather than the overflow-kebab outline. An item's `icon` leads its label: every caller's names the action itself — copy, open, delete — and an icon that is part of an item's identity belongs where the eye starts rather than right-aligned, where it reads as a status column. The menu is Figma's `Dropdown Component - Options List`: a fixed sized to its widest item between a 180px floor and the 280px Figma draws, by default under the trigger's right edge, 14px below it, flipping above or clamping sideways when the viewport has no room, rounding at the library's 12px and padding wider (8px) than the menu a `Dropdown` opens. Items read in the primary text colour, or the secondary one with `tone="muted"` (e.g. a sidebar's menus); destructive ones in red; `danger: 'hover'` keeps an item in its normal colour and turns it destructive (red text on a light red ground) only on hover or keyboard focus, for an action like signing out. A ceiling rather than a flat width: taken literally it gave a menu of four short verbs 130px of air and made every kebab in an app the same width whatever it held. `minWidth` only raises it above that ceiling, so it is the one way to go past 280px, and a label too long for the box truncates rather than wrapping. _Key props:_ `ActionMenuItem[]`, `size`, `label`, `triggerIcon`, `minWidth`, `showLabel`, `variant`, `tone` (`default` | `muted`), `trigger` (your own control in place of the kebab, cloned with the menu's ref and aria state), `placement` (`bottom-end` default | `bottom-start` | `right-start` | `top-start` | `top-center`), `offset` (`small` 8px | `medium` 12px | `large` 14px; applies to every placement; without it the default `bottom-end` keeps the options menu's 14px and the others use 8px). An item's `tag` (e.g. an "Early access" `Tag`) follows its label in a lazily loaded shadow host of its own, since the menu renders into `document.body`, and joins its accessible name; `current: true` marks the item for the page the user is on (`aria-current="page"` and the selected row paint; a `danger` item keeps its red text). An item with an `href` is a link: Cmd/Ctrl-click or a middle click opens it in a new tab and closes the menu, while a plain click runs `onClick` in its place when one is given (so a router can navigate in-app); Enter and Space both activate it. `target: '_blank'` opens it in a new tab, adds `noopener noreferrer` and tells screen readers it opens a new tab. An item with `checked` is one of a set of choices: a `menuitemradio` with `aria-checked` and a trailing check while true; picking it still runs `onClick` and closes. Give the choices of one set the same `group` and, where they sit next to each other, they share a `role="group"` named by it, so a screen reader can tell where the set ends; choices with the same `group` split by another item form separate groups. `description` adds a quieter second line under the label, announced as the item's description rather than its name. An item with `type: 'text'` is context rather than an action (an account's email above its actions): secondary text the arrow keys skip. Opened from the keyboard, focus lands on the first item, or on the checked choice in a menu of choices; Up/Down/Home/End move through enabled items, Tab closes the menu and moves on as usual; Escape or a picked item returns focus to the trigger.
66
66
  - **`NavItem`** — A row in an app's side navigation. Idle rows read secondary and take the list hover; the `active` row wears the accent tint and sets `aria-current="page"` on a link. `collapsed` shrinks it to a 36px icon tile whose label becomes the accessible name and a right-hand tooltip, with any `badge` pinned to the tile's corner. `variant="subitem"` indents a child row behind a dot instead of an icon; `disclosure` makes a group header button with `aria-expanded` and a rotating chevron, and `hasActiveChild` colours its text while a child is current. Renders an `<a>` with `href`, the element passed with `asChild` (a router `Link`), or a `<button>`, and forwards its ref and extra attributes so it can be a `Popover` or `ActionMenu` trigger. `disabled` keeps the row a tab stop with `aria-disabled`, drops its hover and pointer, and ignores clicks, Enter and Space; a `Popover` or `ActionMenu` it triggers stays shut on press, hover, focus and arrow keys, while other keys still reach a passed `onKeyDown` so arrow navigation through a list keeps working; a disabled `href` row renders as a button so it cannot be followed. `disabledReason` explains it in a right-hand tooltip on hover and focus and is the row's accessible description from the first focus. Not with `asChild`, whose child would still navigate. _Key props:_ `label`, `icon`, `active`, `hasActiveChild`, `collapsed`, `variant` (`item` | `subitem`), `danger`, `trailing`, `badge`, `disclosure` (`expanded` | `collapsed`), `tooltip`, `accessibleLabel` (overrides the accessible name; collapsed it defaults to the tooltip text plus `badgeLabel`), `href`, `target`, `rel`, `onClick`, `asChild` + `children`, `className`, `size` (`medium` | `small`, the tighter row for lists inside a popover), `tag` (beside the label, e.g. early access), `badgeLabel` (read in place of the badge and added to the collapsed name), `disabled`, `disabledReason`. A passed `aria-expanded` (e.g. from a `Popover`) wins over `disclosure`, and a button row forwards a passed `aria-current`.
67
67
  - **`Sidebar`** — An app's left navigation shell, pinned to the viewport's left edge: 260px wide, 60px `collapsed`, on the sunken page background. Composed from `Sidebar.Header` (a 56px band for `Sidebar.Switcher`, the logo + workspace + parent trigger), `Sidebar.Body` (the part that scrolls), `Sidebar.Notices`, `Sidebar.Search`, `Sidebar.Section` (rows of `NavItem`s at the gutter), `Sidebar.Group` + `Sidebar.GroupItems` (a disclosure header and its sub-items), `Sidebar.Divider`, `Sidebar.Usage` (a `UsageCard` placed at the sidebar's gutter) and `Sidebar.Footer` holding `Sidebar.Account`. Popovers opened from it (with `padding="none"`) wrap their body in `Sidebar.Panel`, sized so the popover comes to `SIDEBAR_POPOVER_WIDTH_PX`, and build it from the `Popover` parts. `onToggleCollapse` adds the edge toggle, shown in CSS while the pointer is over the sidebar or a keyboard focus is inside it, and always on a touch screen, which has no hover to reveal it. A workspace, organization or account name cut off in the expanded sidebar shows in full on hover. Notices, the divider and the usage card hide while collapsed. Render it inside `<MalachiteContext layer="sidebar">`, or the page paints over the edge toggle. _Key props:_ `collapsed`, `onToggleCollapse`, `expandLabel`, `collapseLabel`, `aria-label`; `Sidebar.Switcher`: `logo`, `title`, `subtitle`, `titleTooltip`/`subtitleTooltip` (shown when the name is cut off, the name by default; pass a node to wrap it, e.g. to keep it out of session recordings) + button attributes; `Sidebar.Account`: `avatar` or `initials` (a small chip when there is no photo), `name`, `tooltip` (on the collapsed rail, and expanded when the name is cut off; `name` by default; pass a node to wrap it) + button attributes; `Sidebar.Usage`: the `UsageCard` props; `Sidebar.Notices`: `aria-label` (required); `Sidebar.Panel`: `width` (`SIDEBAR_POPOVER_WIDTH_PX` by default). `useSidebarCollapsed()` reads the state from inside; `SIDEBAR_WIDTH_PX` gives the page its offset beside the sidebar; `SIDEBAR_TOOLTIP_DELAY_S` is the 0.2s delay its name and rail tooltips use, for tooltips a consumer adds inside it.
68
68
  - **`SearchTrigger`** — A button drawn as a filled search field, for opening a command palette or search dialog from app chrome such as a sidebar. It is not an input — typing happens in what it opens. `shortcut` draws flat `<kbd>` chips at the end (not `Keycap`, whose raised shadow reads as a second button inside a filled field), kept out of the accessible name; `iconOnly` makes a 36px icon tile matching a collapsed `NavItem`, named by `label`. _Key props:_ `label` (default `Search`), `shortcut` (`ReactNode[]`), `iconOnly`, `aria-label`, `className`, plus native button attributes (`onClick`, `aria-haspopup`, `aria-expanded`, `aria-keyshortcuts`).
@@ -1,239 +1,260 @@
1
- import { jsxs as h, jsx as r, Fragment as F } from "react/jsx-runtime";
2
- import D, { useState as X, useRef as _, useEffect as P, useMemo as G, useId as H } from "react";
3
- import { createPortal as U } from "react-dom";
4
- import { Button as W } from "./Button.js";
5
- import Z from "./CustomIcons/CheckmarkIcon.js";
6
- import q from "./CustomIcons/MoreHorizontalIcon.js";
7
- import J from "./Typography/EllipsisText.js";
8
- import { scrollCheckedIntoView as Q, focusOpeningItem as ee, scrollFocusedIntoView as ne, edgeForTriggerKey as re, focusEdge as oe, itemForMenuKey as te, enabledItems as le } from "./actionMenuKeyboard.js";
9
- import { TRIGGER_SIZES as ae, EMPTY_ITEM_STYLE as ie, menuStyle as se, itemStyle as Y, TEXT_ITEM_STYLE as ce, TEXT_ITEM_LABEL_STYLE as de, LABEL_STYLE as ue, VISUALLY_HIDDEN_STYLE as K, ITEM_ICON_LAYOUT as pe, ITEM_ICON_STYLE as fe, ITEM_ICON_CLASS as ye, ITEM_TEXT_STYLE as he, DESCRIPTION_CLASS as Ee, descriptionStyle as ge, CHECK_SLOT_STYLE as Te, ITEM_CLASS as be } from "./actionMenuStyles.js";
10
- import { getDeepActiveElement as me } from "./activeElement.js";
11
- import { elementRef as Ie, composeRefs as ke, chainHandler as L } from "./composeRefs.js";
12
- import { pushEscapeLayer as Se } from "./escapeLayers.js";
13
- import { isPlainClick as _e } from "./linkClick.js";
14
- import { resolveRel as Me } from "./linkRel.js";
15
- import { usePopupLayer as Ce } from "./overlayLayers.js";
16
- import { isRenderableNode as v } from "./renderableNode.js";
17
- import { safeHref as Le } from "./safeHref.js";
18
- import { useActionMenuPosition as ve } from "./useActionMenuPosition.js";
19
- const De = D.lazy(() => import("./ActionMenuTagHost.js")), M = (e) => e.stopPropagation(), we = ({ item: e, tone: f, onSelect: m, onFollow: I }) => {
20
- var l;
21
- const p = H();
22
- if (e.type === "divider")
23
- return /* @__PURE__ */ r("div", { role: "separator", style: Y(e) });
24
- if (e.type === "text")
25
- return /* @__PURE__ */ r("div", { role: "menuitem", "aria-disabled": "true", style: ce, children: typeof e.label == "string" ? /* @__PURE__ */ r(
26
- J,
1
+ import { jsxs as y, jsx as r, Fragment as U } from "react/jsx-runtime";
2
+ import w, { useState as J, useId as j, useRef as M, useEffect as $, useMemo as B } from "react";
3
+ import { createPortal as Q } from "react-dom";
4
+ import { Button as ee } from "./Button.js";
5
+ import oe from "./CustomIcons/CheckmarkIcon.js";
6
+ import ne from "./CustomIcons/MoreHorizontalIcon.js";
7
+ import re from "./Typography/EllipsisText.js";
8
+ import { groupChoices as te, isChoiceItem as le } from "./actionMenuGroups.js";
9
+ import { scrollCheckedIntoView as ie, focusOpeningItem as ae, scrollFocusedIntoView as se, edgeForTriggerKey as ce, focusEdge as de, itemForMenuKey as ue, enabledItems as pe } from "./actionMenuKeyboard.js";
10
+ import { TRIGGER_SIZES as fe, EMPTY_ITEM_STYLE as he, MENU_COLUMN_STYLE as ye, menuStyle as me, itemStyle as F, TEXT_ITEM_STYLE as Ee, TEXT_ITEM_LABEL_STYLE as ge, LABEL_STYLE as be, VISUALLY_HIDDEN_STYLE as z, ITEM_ICON_LAYOUT as Te, ITEM_ICON_STYLE as Ie, ITEM_ICON_CLASS as ke, ITEM_TEXT_STYLE as Se, DESCRIPTION_CLASS as _e, descriptionStyle as ve, CHECK_SLOT_STYLE as Me, ITEM_CLASS as Ce } from "./actionMenuStyles.js";
11
+ import { getDeepActiveElement as Le } from "./activeElement.js";
12
+ import { elementRef as De, composeRefs as we, chainHandler as L } from "./composeRefs.js";
13
+ import { pushEscapeLayer as Ne } from "./escapeLayers.js";
14
+ import { isPlainClick as Oe } from "./linkClick.js";
15
+ import { resolveRel as Re } from "./linkRel.js";
16
+ import { usePopupLayer as Ae } from "./overlayLayers.js";
17
+ import { isRenderableNode as D } from "./renderableNode.js";
18
+ import { safeHref as Pe } from "./safeHref.js";
19
+ import { useActionMenuPosition as xe } from "./useActionMenuPosition.js";
20
+ const Ye = w.lazy(() => import("./ActionMenuTagHost.js")), C = (o) => o.stopPropagation(), Ke = ({ item: o, tone: p, onSelect: b, onFollow: T, labelId: I }) => {
21
+ var v;
22
+ const d = j();
23
+ if (o.type === "divider")
24
+ return /* @__PURE__ */ r("div", { role: "separator", style: F(o) });
25
+ if (o.type === "text")
26
+ return /* @__PURE__ */ r("div", { id: I, role: "menuitem", "aria-disabled": "true", style: Ee, children: typeof o.label == "string" ? /* @__PURE__ */ r(
27
+ re,
27
28
  {
28
- tooltip: e.label,
29
+ tooltip: o.label,
29
30
  tooltipWhenTruncated: !0,
30
31
  inline: !0,
31
- style: de,
32
- children: e.label
32
+ style: ge,
33
+ children: o.label
33
34
  }
34
- ) : e.label });
35
- const u = e.checked !== void 0, k = v(e.description), s = v(e.tag), E = {
36
- role: u ? "menuitemradio" : "menuitem",
37
- "aria-checked": u ? e.checked : void 0,
38
- "aria-describedby": k ? `${p}${e.tooltip ? ` ${p}-tooltip` : ""}` : void 0,
39
- title: e.tooltip,
40
- "aria-current": e.current ? "page" : void 0,
41
- className: be,
42
- "data-danger": e.danger === "hover" ? "hover" : void 0,
43
- "data-tone": f,
44
- style: Y(e, f)
45
- }, g = e.disabled ? void 0 : Le(e.href), C = g !== void 0 && ((l = e.target) == null ? void 0 : l.toLowerCase()) === "_blank", T = /* @__PURE__ */ h("span", { style: ue, children: [
46
- e.label,
47
- C && /* @__PURE__ */ r("span", { style: K, children: " (opens in a new tab)" })
48
- ] }), t = /* @__PURE__ */ h(F, { children: [
49
- v(e.icon) && /* @__PURE__ */ r(
35
+ ) : o.label });
36
+ const m = le(o), s = D(o.description), k = D(o.tag), S = {
37
+ role: m ? "menuitemradio" : "menuitem",
38
+ "aria-checked": m ? o.checked : void 0,
39
+ "aria-describedby": s ? `${d}${o.tooltip ? ` ${d}-tooltip` : ""}` : void 0,
40
+ title: o.tooltip,
41
+ "aria-current": o.current ? "page" : void 0,
42
+ className: Ce,
43
+ "data-danger": o.danger === "hover" ? "hover" : void 0,
44
+ "data-tone": p,
45
+ style: F(o, p)
46
+ }, E = o.disabled ? void 0 : Pe(o.href), _ = E !== void 0 && ((v = o.target) == null ? void 0 : v.toLowerCase()) === "_blank", t = /* @__PURE__ */ y("span", { style: be, children: [
47
+ o.label,
48
+ _ && /* @__PURE__ */ r("span", { style: z, children: " (opens in a new tab)" })
49
+ ] }), i = /* @__PURE__ */ y(U, { children: [
50
+ D(o.icon) && /* @__PURE__ */ r(
50
51
  "span",
51
52
  {
52
- className: ye,
53
- style: e.danger === "hover" ? pe : fe,
54
- children: e.icon
53
+ className: ke,
54
+ style: o.danger === "hover" ? Te : Ie,
55
+ children: o.icon
55
56
  }
56
57
  ),
57
- k ? /* @__PURE__ */ h("span", { style: he, children: [
58
- T,
58
+ s ? /* @__PURE__ */ y("span", { style: Se, children: [
59
+ t,
59
60
  /* @__PURE__ */ r(
60
61
  "span",
61
62
  {
62
- id: p,
63
+ id: d,
63
64
  "aria-hidden": "true",
64
- className: Ee,
65
- style: ge(e),
66
- children: e.description
65
+ className: _e,
66
+ style: ve(o),
67
+ children: o.description
67
68
  }
68
69
  ),
69
- e.tooltip ? /* @__PURE__ */ r(
70
+ o.tooltip ? /* @__PURE__ */ r(
70
71
  "span",
71
72
  {
72
- id: `${p}-tooltip`,
73
+ id: `${d}-tooltip`,
73
74
  "aria-hidden": "true",
74
- style: K,
75
- children: e.tooltip
75
+ style: z,
76
+ children: o.tooltip
76
77
  }
77
78
  ) : null
78
- ] }) : T,
79
- s ? /* @__PURE__ */ r(D.Suspense, { fallback: null, children: /* @__PURE__ */ r(De, { children: e.tag }) }) : null,
80
- u ? /* @__PURE__ */ r("span", { "aria-hidden": "true", style: Te, children: e.checked ? /* @__PURE__ */ r(Z, { size: 14 }) : null }) : null
79
+ ] }) : t,
80
+ k ? /* @__PURE__ */ r(w.Suspense, { fallback: null, children: /* @__PURE__ */ r(Ye, { children: o.tag }) }) : null,
81
+ m ? /* @__PURE__ */ r("span", { "aria-hidden": "true", style: Me, children: o.checked ? /* @__PURE__ */ r(oe, { size: 14 }) : null }) : null
81
82
  ] });
82
- return g !== void 0 ? /* @__PURE__ */ r(
83
+ return E !== void 0 ? /* @__PURE__ */ r(
83
84
  "a",
84
85
  {
85
- ...E,
86
- href: g,
87
- target: e.target,
88
- rel: Me(void 0, e.target),
86
+ ...S,
87
+ href: E,
88
+ target: o.target,
89
+ rel: Re(void 0, o.target),
89
90
  onClick: (a) => {
90
- if (_e(a) && e.onClick) {
91
- a.preventDefault(), m(e);
91
+ if (Oe(a) && o.onClick) {
92
+ a.preventDefault(), b(o);
92
93
  return;
93
94
  }
94
- I();
95
+ T();
95
96
  },
96
97
  onAuxClick: (a) => {
97
- a.button === 1 && I();
98
+ a.button === 1 && T();
98
99
  },
99
- children: t
100
+ children: i
100
101
  }
101
- ) : /* @__PURE__ */ r("button", { ...E, type: "button", disabled: e.disabled, onClick: () => m(e), children: t });
102
- }, Ze = ({
103
- items: e,
104
- label: f = "More actions",
105
- triggerIcon: m,
106
- minWidth: I,
107
- size: p = "small",
108
- showLabel: u = !1,
109
- variant: k = "outline",
102
+ ) : /* @__PURE__ */ r("button", { ...S, type: "button", disabled: o.disabled, onClick: () => b(o), children: i });
103
+ }, lo = ({
104
+ items: o,
105
+ label: p = "More actions",
106
+ triggerIcon: b,
107
+ minWidth: T,
108
+ size: I = "small",
109
+ showLabel: d = !1,
110
+ variant: m = "outline",
110
111
  trigger: s,
111
- placement: E = "bottom-end",
112
- offset: g,
113
- tone: C = "default"
112
+ placement: k = "bottom-end",
113
+ offset: S,
114
+ tone: E = "default"
114
115
  }) => {
115
- const T = ae[p], [t, l] = X(!1), a = _(null), i = _(null), b = _(null), y = _(!1), $ = Ce("actionmenu", t, i), w = ve(t, a, i, {
116
- minWidth: I,
117
- placement: E,
118
- offset: g
119
- }), R = w !== null;
120
- P(() => {
121
- !t || !R || (Q(i.current), b.current && (ee(i.current, b.current), b.current = null, ne(i.current)));
122
- }, [t, R]), P(() => {
116
+ const _ = fe[I], [t, i] = J(!1), v = j(), a = M(null), c = M(null), g = M(null), f = M(!1), V = Ae("actionmenu", t, c), N = xe(t, a, c, {
117
+ minWidth: T,
118
+ placement: k,
119
+ offset: S
120
+ }), O = N !== null;
121
+ $(() => {
122
+ !t || !O || (ie(c.current), g.current && (ae(c.current, g.current), g.current = null, se(c.current)));
123
+ }, [t, O]), $(() => {
123
124
  if (!t)
124
125
  return;
125
- const n = (d) => {
126
- const S = d.composedPath();
127
- [a.current, i.current].some(
128
- (x) => x && S.includes(x)
129
- ) || (y.current = !1, l(!1));
126
+ const e = (l) => {
127
+ const h = l.composedPath();
128
+ [a.current, c.current].some(
129
+ (K) => K && h.includes(K)
130
+ ) || (f.current = !1, i(!1));
130
131
  };
131
- document.addEventListener("mousedown", n, !0);
132
- const o = Se(() => l(!1));
132
+ document.addEventListener("mousedown", e, !0);
133
+ const n = Ne(() => i(!1));
133
134
  return () => {
134
- var S;
135
- document.removeEventListener("mousedown", n, !0), o();
136
- const d = me();
137
- y.current && (!d || d === document.body) && ((S = a.current) == null || S.focus({ preventScroll: !0 })), y.current = !1;
135
+ var h;
136
+ document.removeEventListener("mousedown", e, !0), n();
137
+ const l = Le();
138
+ f.current && (!l || l === document.body) && ((h = a.current) == null || h.focus({ preventScroll: !0 })), f.current = !1;
138
139
  };
139
140
  }, [t]);
140
- const A = (n) => {
141
- n.stopPropagation();
142
- const o = !t && n.detail === 0;
143
- b.current = o ? "first" : null, l((d) => !d);
144
- }, N = (n) => {
145
- if (n.key === "Tab" && t) {
146
- l(!1);
141
+ const R = (e) => {
142
+ e.stopPropagation();
143
+ const n = !t && e.detail === 0;
144
+ g.current = n ? "first" : null, i((l) => !l);
145
+ }, A = (e) => {
146
+ if (e.key === "Tab" && t) {
147
+ i(!1);
147
148
  return;
148
149
  }
149
- const o = re(n.key, E);
150
- if (o) {
151
- if (n.preventDefault(), t) {
152
- oe(i.current, o);
150
+ const n = ce(e.key, k);
151
+ if (n) {
152
+ if (e.preventDefault(), t) {
153
+ de(c.current, n);
153
154
  return;
154
155
  }
155
- b.current = o, l(!0);
156
+ g.current = n, i(!0);
156
157
  }
157
- }, B = (n) => {
158
- var d;
159
- if (n.key === "Tab") {
160
- y.current = !1, (d = a.current) == null || d.focus({ preventScroll: !0 }), l(!1);
158
+ }, X = (e) => {
159
+ var l;
160
+ if (e.key === "Tab") {
161
+ f.current = !1, (l = a.current) == null || l.focus({ preventScroll: !0 }), i(!1);
161
162
  return;
162
163
  }
163
- if (n.key === " " && n.target instanceof HTMLAnchorElement) {
164
- n.preventDefault(), n.target.click();
164
+ if (e.key === " " && e.target instanceof HTMLAnchorElement) {
165
+ e.preventDefault(), e.target.click();
165
166
  return;
166
167
  }
167
- const o = te(le(i.current), n.target, n.key);
168
- o && (n.preventDefault(), o.focus());
169
- }, z = (n) => {
170
- var o;
171
- n.type === "divider" || n.type === "text" || n.disabled || ((o = n.onClick) == null || o.call(n), l(!1));
172
- }, O = s ? Ie(s) : void 0, j = G(
173
- () => ke(O, a),
174
- [O]
175
- ), c = s == null ? void 0 : s.props, V = s ? D.cloneElement(s, {
176
- ref: j,
168
+ const n = ue(pe(c.current), e.target, e.key);
169
+ n && (e.preventDefault(), n.focus());
170
+ }, G = (e) => {
171
+ var n;
172
+ e.type === "divider" || e.type === "text" || e.disabled || ((n = e.onClick) == null || n.call(e), i(!1));
173
+ }, P = s ? De(s) : void 0, H = B(
174
+ () => we(P, a),
175
+ [P]
176
+ ), u = s == null ? void 0 : s.props, W = s ? w.cloneElement(s, {
177
+ ref: H,
177
178
  "aria-haspopup": "menu",
178
179
  "aria-expanded": t,
179
- onClick: L(c == null ? void 0 : c.onClick, A),
180
- onMouseDown: L(c == null ? void 0 : c.onMouseDown, M),
181
- onKeyDown: L(c == null ? void 0 : c.onKeyDown, N)
182
- }) : /* @__PURE__ */ h(
183
- W,
180
+ onClick: L(u == null ? void 0 : u.onClick, R),
181
+ onMouseDown: L(u == null ? void 0 : u.onMouseDown, C),
182
+ onKeyDown: L(u == null ? void 0 : u.onKeyDown, A)
183
+ }) : /* @__PURE__ */ y(
184
+ ee,
184
185
  {
185
186
  ref: a,
186
187
  type: "button",
187
- variant: k,
188
- size: p,
189
- iconOnly: !u,
190
- "aria-label": u ? void 0 : f,
188
+ variant: m,
189
+ size: I,
190
+ iconOnly: !d,
191
+ "aria-label": d ? void 0 : p,
191
192
  "aria-haspopup": "menu",
192
193
  "aria-expanded": t,
193
- className: `shrink-0${u ? " gap-2" : ""}`,
194
- onClick: A,
195
- onMouseDown: M,
196
- onKeyDown: N,
194
+ className: `shrink-0${d ? " gap-2" : ""}`,
195
+ onClick: R,
196
+ onMouseDown: C,
197
+ onKeyDown: A,
197
198
  children: [
198
- /* @__PURE__ */ r("span", { className: `inline-flex items-center justify-center ${T.iconBox}`, children: m ?? /* @__PURE__ */ r(q, { size: T.icon }) }),
199
- u && /* @__PURE__ */ r("span", { children: f })
199
+ /* @__PURE__ */ r("span", { className: `inline-flex items-center justify-center ${_.iconBox}`, children: b ?? /* @__PURE__ */ r(ne, { size: _.icon }) }),
200
+ d && /* @__PURE__ */ r("span", { children: p })
200
201
  ]
201
202
  }
203
+ ), Z = B(() => te(o), [o]), q = () => i(!1), x = (e) => `${v}-${e}`, Y = (e, n, l = e.key) => /* @__PURE__ */ r(
204
+ Ke,
205
+ {
206
+ item: e,
207
+ tone: E,
208
+ onSelect: G,
209
+ onFollow: q,
210
+ labelId: n
211
+ },
212
+ l
202
213
  );
203
- return /* @__PURE__ */ h(F, { children: [
204
- V,
205
- t && U(
206
- /* @__PURE__ */ h(
214
+ return /* @__PURE__ */ y(U, { children: [
215
+ W,
216
+ t && Q(
217
+ /* @__PURE__ */ y(
207
218
  "div",
208
219
  {
209
- ref: i,
220
+ ref: c,
210
221
  role: "menu",
211
222
  tabIndex: -1,
212
- "aria-label": f,
213
- ...$,
214
- style: se(w),
215
- onMouseDown: M,
216
- onClick: M,
217
- onKeyDown: B,
223
+ "aria-label": p,
224
+ ...V,
225
+ style: me(N),
226
+ onMouseDown: C,
227
+ onClick: C,
228
+ onKeyDown: X,
218
229
  onFocus: () => {
219
- y.current = !0;
230
+ f.current = !0;
220
231
  },
221
- onBlur: (n) => {
222
- var o;
223
- (o = i.current) != null && o.contains(n.relatedTarget) || (y.current = !1);
232
+ onBlur: (e) => {
233
+ var n;
234
+ (n = c.current) != null && n.contains(e.relatedTarget) || (f.current = !1);
224
235
  },
225
236
  children: [
226
- e.length === 0 && /* @__PURE__ */ r("div", { role: "menuitem", "aria-disabled": "true", style: ie, children: "No actions available" }),
227
- e.map((n) => /* @__PURE__ */ r(
228
- we,
229
- {
230
- item: n,
231
- tone: C,
232
- onSelect: z,
233
- onFollow: () => l(!1)
234
- },
235
- n.key
236
- ))
237
+ o.length === 0 && /* @__PURE__ */ r("div", { role: "menuitem", "aria-disabled": "true", style: he, children: "No actions available" }),
238
+ Z.map(
239
+ (e, n) => {
240
+ var l;
241
+ return e.kind === "item" ? Y(
242
+ e.item,
243
+ e.labelsNext ? x(n) : void 0,
244
+ `item:${e.item.key}`
245
+ ) : /* @__PURE__ */ r(
246
+ "div",
247
+ {
248
+ role: "group",
249
+ "aria-labelledby": e.labelledByPrevious ? x(n - 1) : void 0,
250
+ "aria-label": e.labelledByPrevious ? void 0 : e.name,
251
+ style: ye,
252
+ children: e.items.map((h) => Y(h))
253
+ },
254
+ `group:${(l = e.items[0]) == null ? void 0 : l.key}`
255
+ );
256
+ }
257
+ )
237
258
  ]
238
259
  }
239
260
  ),
@@ -242,6 +263,6 @@ const De = D.lazy(() => import("./ActionMenuTagHost.js")), M = (e) => e.stopProp
242
263
  ] });
243
264
  };
244
265
  export {
245
- Ze as default
266
+ lo as default
246
267
  };
247
268
  //# sourceMappingURL=ActionMenu.js.map