@stackone/malachite 2.81.1 → 2.83.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.
package/COMPONENTS.md CHANGED
@@ -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 `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; 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`).
@@ -108,13 +108,9 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
108
108
  - **`InlineConfirm`** — A confirmation asked on the control that triggered it rather than in a modal, for a reversible bulk edit where a dialog would be heavier than the change it guards. Drawn to the design's chip: 33px tall, 12px radius, its confirm cell running to the pill's own edge between two rules. Reads its own `inlineConfirm` theme tokens — a shade off the `SelectionBar` it appears beside, by design. Carries a spinning glyph by default — its own, so it takes the pill's colour rather than the sheet's dimmed grey — standing for a change waiting on an answer; pass `icon={null}` to drop it or a node to replace it. Anchored placement is in viewport coordinates, so the chip must not sit inside an ancestor carrying `transform`, `filter` or `contain`. It takes focus on open so `Enter` confirms, dismisses on `Escape` (through the shared escape-layer stack, so the topmost overlay answers) or a click outside, and returns focus to whatever opened it. `role="alertdialog"` named by the message itself, so the confirm button is never announced bare. Only one can be open at a time: opening a second dismisses the first, so it is never ambiguous what Yes answers. Pass `anchorTo` (a ref to the control it answers for) and it pins itself to that control's left, follows it while the page or a sticky header scrolls, dismisses once it scrolls out of view, and treats clicks on it as inside — without which the same click would dismiss and reopen. Left unanchored it renders in flow for the consumer to place, and must then not sit in a container that clips overflow (`Table` header cells among them). Nothing renders while `open` is false, and its listeners are attached only while it is open. _Key props:_ `open`, `message`, `confirmLabel`, `onConfirm`, `onDismiss`, `anchorTo`, `icon`, `className`, `style`.
109
109
  - **`SelectionBar`** — A bar reporting a pending selection and the actions that resolve it, for flows where changes accumulate and save once rather than writing on every toggle. Paints its own inverted surface from the `selectionBar` theme tokens, so its buttons are its own rather than `Button`. A count renders as one phrase (`3 Added`), not a number styled apart from its label, and an empty `value` carries a bare message instead; the separators between counts and before an action are glyphs (`•`, `|`) in the muted colour, not drawn rules. `emphasis` runs `primary` (a light filled button with its own edge, for the action that commits) → `secondary`, the default (a filled chip) → `quiet` (unfilled, taking a wash on hover). The pill is edgeless in light mode and keeps a hairline `border` token in dark, where a shadow alone would not separate it from the sheet. Defaults to `placement="sticky"` — render it as the last child of the scrolling content and it holds its place over a long list. Counts are announced through a live region that outlives the bar, so the first change is not lost; `open` drives an animated mount so it can appear and leave as the selection goes dirty and clean. Every action closes the bar, so the caller must move focus deliberately in `onClick`. `notice` wraps the whole bar in a warning sleeve carrying that message, for state the bar is reporting rather than an action it offers — a refused exit, say — and it leads the announcement; an empty string renders no sleeve. _Key props:_ `open`, `counts` (`value`, `label`), `actions` (`label`, `onClick`, `emphasis`, `icon`, `iconPosition`, `disabled`, `dividerBefore`), `placement`, `notice`, `aria-label`, `className`.
110
110
 
111
- ## Typography
112
-
113
- - **`ClampText`** — Clamps text to N lines; expands to full text on hover/focus with a height animation. Wrapping markdown? Pass `variant="flow"` to the `Typography.MarkdownBlock` inside it, or the clamp counts blocks instead of lines.
114
- - **`Typography`** — Text primitives — use these instead of raw colour tokens on `<span>`s. Includes `Typography.Text`, `Typography.SecondaryText`, `Typography.EllipsisText`, etc., with size/weight/color props. `Typography.Text`'s `size` runs `xsmall` (11px), `12`, `small` (13px), `medium` (14px) and up; `12` is off the named ladder, like the theme's `15`, for a secondary line under a 14px label. `wrap={false}` keeps a `Typography.Text` on one line. `Typography.Text` takes `font="sans" | "heading" | "body" | "mono"`, and `as` (`p`, `h1`–`h6`) for a heading or paragraph that keeps its look; `Typography.CodeText` takes `variant="inline"` for a chip mid-sentence; `Typography.MarkdownBlock` takes `variant="flow"` for use inside `ClampText`, `variant="inline"` for one line of inline syntax set inside another component (no autolinks, images as alt text), `links="inert"` to draw links without an anchor inside a button, `renderLink` to send root-relative links (`/path`, never `//host`) through the app’s router in the same tab while every other link still opens in a new one — without it every link opens in a new tab, and `normalizeSource` for machine-generated descriptions that omit blank lines between blocks. `Typography.PathText` draws one line of path segments (`segments`, root first, each `{ text, tone, minChars }` with `tone` `default` | `secondary`) joined by a `separator` that is never cut: the segments give way in order, each down to `minChars` (2) characters, so the last stays whole the longest, and a cut never leaves a space before its ellipsis, which `text-overflow` does. The full path is always the accessible name and shows in a tooltip only when something is cut (`tooltip`, `tooltipPlacement`, `tooltipSuppressed` while the menu it labels is open). It measures with canvas text metrics against a shared ResizeObserver, so it costs no layout read per instance. `Typography.EllipsisText` takes a `size` and a `fontWeight` (Text's scale) so a truncating label can match the text beside it, and shows its `tooltip` on every hover unless `tooltipWhenTruncated` is set, which limits it to text that is actually cut off — for a tooltip that repeats the label, where a tooltip carrying something the label does not say should keep the default. `inline` wraps the text in a span rather than a div, for inside a clickable `Surface.Row`.
115
-
116
111
  ## Data display
117
112
 
113
+ - **`LevelMeter`** — Rising bars, shortest first, that picture how much of a scale is on — an access level in a level menu or on a level chip. Each step is `on` (a solid accent-green bar), `partial` (a green outline over a faint tint, for a step only some of whose actions are on) or `off` (an empty grey outline); every step keeps 3:1 against the surface, and colours come from the theme. Styled inline so it still draws inside an `ActionMenu`, which portals outside the shadow root and its stylesheet. Beside text that already names the level it is decorative and hidden from assistive tech; give it a `label` only when it stands alone and it reads as an image of that name. As an `ActionMenu` item `icon` or a `Button` `icon`, leave `label` off: the icon joins the item name, and the text already says the level. _Key props:_ `steps` (`LevelMeterStep[]`: `on` | `partial` | `off`), `label`, `className`.
118
114
  - **`Table`** — Data table with columns, sizing, pagination and row selection. `column.align` places a column's header as well as its cells. What lands on the aligned edge is the last thing in the header row rather than the title: the sort caret on a sortable column, the info icon on one carrying `info` without a sorter. `headerVariant` picks the header layout, and only `inline` lines header and body up exactly, because both are cells of one `<table>`. `detached` builds them from flex rows, where a sortable header cell is 32px narrower than a non-sortable one — its padding sits on the inner button rather than on the flex item — so its header cells sit 15–17px off their column at any alignment; reach for `inline` where exact alignment matters. Sorting is internal, so the array passed as `data` is not the order rendered once a column is sorted: `onVisibleOrderChange` reports the rows in render order — the whole of `data`, compared by `rowKey` so an equal order never re-fires — for a consumer stepping a master-detail view the way the user sees it. _Key props:_ `TableColumns` (incl. `align`), `TableSize`, `TableType`, `TableRowSelection`, `TablePaginationPosition`, `headerVariant`, `onVisibleOrderChange`.
119
115
  - **`Statistic`** — Displays a statistic value with a label; primary/secondary sizes. _Key props:_ `StatisticValueSize`.
120
116
  - **`Avatar`** — Logo/initial avatar. Renders the image when available, otherwise a coloured tile with the first letter of `name`, or with `fallback="placeholder"` the generic "no logo available" tile. Encapsulates the fallback colour. _Key props:_ `src`, `name`, `size`, `shape="square" | "circle"`, `fallback="initial" | "placeholder"`.
@@ -126,6 +122,11 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
126
122
  - **`Stepper`** — Progress dots/segments for a multi-step flow; optionally clickable. `groups` takes a long flow in labelled sections: the active step’s group opens into one bar per step across the full width and every other group folds to a short bar. Folded bars keep a fixed width and the open group shares what is left, so allow about 20px per other group and 12px per step in the open group. With `onChange` each folded bar is a button named after its group. _Key props:_ `steps` or `groups` (`{ label, steps }[]`), `active`, `onChange`.
127
123
  - **`Swatch`** — Colour swatch preview.
128
124
 
125
+ ## Typography
126
+
127
+ - **`ClampText`** — Clamps text to N lines; expands to full text on hover/focus with a height animation. Wrapping markdown? Pass `variant="flow"` to the `Typography.MarkdownBlock` inside it, or the clamp counts blocks instead of lines.
128
+ - **`Typography`** — Text primitives — use these instead of raw colour tokens on `<span>`s. Includes `Typography.Text`, `Typography.SecondaryText`, `Typography.EllipsisText`, etc., with size/weight/color props. `Typography.Text`'s `size` runs `xsmall` (11px), `12`, `small` (13px), `medium` (14px) and up; `12` is off the named ladder, like the theme's `15`, for a secondary line under a 14px label. `wrap={false}` keeps a `Typography.Text` on one line. `Typography.Text` takes `font="sans" | "heading" | "body" | "mono"`, and `as` (`p`, `h1`–`h6`) for a heading or paragraph that keeps its look; `Typography.CodeText` takes `variant="inline"` for a chip mid-sentence; `Typography.MarkdownBlock` takes `variant="flow"` for use inside `ClampText`, `variant="inline"` for one line of inline syntax set inside another component (no autolinks, images as alt text), `links="inert"` to draw links without an anchor inside a button, `renderLink` to send root-relative links (`/path`, never `//host`) through the app’s router in the same tab while every other link still opens in a new one — without it every link opens in a new tab, and `normalizeSource` for machine-generated descriptions that omit blank lines between blocks. `Typography.PathText` draws one line of path segments (`segments`, root first, each `{ text, tone, minChars }` with `tone` `default` | `secondary`) joined by a `separator` that is never cut: the segments give way in order, each down to `minChars` (2) characters, so the last stays whole the longest, and a cut never leaves a space before its ellipsis, which `text-overflow` does. The full path is always the accessible name and shows in a tooltip only when something is cut (`tooltip`, `tooltipPlacement`, `tooltipSuppressed` while the menu it labels is open). It measures with canvas text metrics against a shared ResizeObserver, so it costs no layout read per instance. `Typography.EllipsisText` takes a `size` and a `fontWeight` (Text's scale) so a truncating label can match the text beside it, and shows its `tooltip` on every hover unless `tooltipWhenTruncated` is set, which limits it to text that is actually cut off — for a tooltip that repeats the label, where a tooltip carrying something the label does not say should keep the default. `inline` wraps the text in a span rather than a div, for inside a clickable `Surface.Row`.
129
+
129
130
  ## Theming & utility
130
131
 
131
132
  - **`MalachiteContext`** — Wraps a subtree in the shadow root + theme context. Wrap groups of components in this. _Key props:_ `className`, `fillHeight`, `layer` (`'page'` by default; `'sidebar'` lifts the host above the page for a `Sidebar`)
@@ -1,201 +1,260 @@
1
- import { jsxs as E, jsx as o, Fragment as N } from "react/jsx-runtime";
2
- import _, { useState as z, useRef as v, useEffect as G, useMemo as U } from "react";
3
- import { createPortal as $ } from "react-dom";
4
- import { Button as H } from "./Button.js";
5
- import V from "./CustomIcons/MoreHorizontalIcon.js";
6
- import { focusEdge as x, edgeForTriggerKey as X, itemForMenuKey as Z, enabledItems as q } from "./actionMenuKeyboard.js";
7
- import { TRIGGER_SIZES as J, EMPTY_ITEM_STYLE as Q, menuStyle as W, itemStyle as A, TEXT_ITEM_STYLE as ee, ITEM_ICON_LAYOUT as ne, ITEM_ICON_STYLE as re, ITEM_ICON_CLASS as oe, LABEL_STYLE as te, VISUALLY_HIDDEN_STYLE as ae, ITEM_CLASS as le } from "./actionMenuStyles.js";
8
- import { getDeepActiveElement as se } from "./activeElement.js";
9
- import { elementRef as ce, composeRefs as ie, chainHandler as S } from "./composeRefs.js";
10
- import { pushEscapeLayer as ue } from "./escapeLayers.js";
11
- import { isPlainClick as de } from "./linkClick.js";
12
- import { resolveRel as fe } from "./linkRel.js";
13
- import { usePopupLayer as pe } from "./overlayLayers.js";
14
- import { safeHref as ye } from "./safeHref.js";
15
- import { useActionMenuPosition as me } from "./useActionMenuPosition.js";
16
- const he = _.lazy(() => import("./ActionMenuTagHost.js")), ge = (e) => e != null && e !== !1, I = (e) => e.stopPropagation(), Ee = ({ item: e, tone: d, onSelect: b, onFollow: M }) => {
17
- var h;
18
- if (e.type === "divider")
19
- return /* @__PURE__ */ o("div", { style: A(e) });
20
- if (e.type === "text")
21
- return /* @__PURE__ */ o("div", { role: "menuitem", "aria-disabled": "true", style: ee, children: e.label });
22
- const m = {
23
- role: "menuitem",
24
- title: e.tooltip,
25
- "aria-current": e.current ? "page" : void 0,
26
- className: le,
27
- "data-danger": e.danger === "hover" ? "hover" : void 0,
28
- "data-tone": d,
29
- style: A(e, d)
30
- }, c = e.disabled ? void 0 : ye(e.href), T = c !== void 0 && ((h = e.target) == null ? void 0 : h.toLowerCase()) === "_blank", t = /* @__PURE__ */ E(N, { children: [
31
- e.icon && /* @__PURE__ */ o(
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,
28
+ {
29
+ tooltip: o.label,
30
+ tooltipWhenTruncated: !0,
31
+ inline: !0,
32
+ style: ge,
33
+ children: o.label
34
+ }
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(
32
51
  "span",
33
52
  {
34
- className: oe,
35
- style: e.danger === "hover" ? ne : re,
36
- children: e.icon
53
+ className: ke,
54
+ style: o.danger === "hover" ? Te : Ie,
55
+ children: o.icon
37
56
  }
38
57
  ),
39
- /* @__PURE__ */ E("span", { style: te, children: [
40
- e.label,
41
- T && /* @__PURE__ */ o("span", { style: ae, children: " (opens in a new tab)" })
42
- ] }),
43
- ge(e.tag) ? /* @__PURE__ */ o(_.Suspense, { fallback: null, children: /* @__PURE__ */ o(he, { children: e.tag }) }) : null
58
+ s ? /* @__PURE__ */ y("span", { style: Se, children: [
59
+ t,
60
+ /* @__PURE__ */ r(
61
+ "span",
62
+ {
63
+ id: d,
64
+ "aria-hidden": "true",
65
+ className: _e,
66
+ style: ve(o),
67
+ children: o.description
68
+ }
69
+ ),
70
+ o.tooltip ? /* @__PURE__ */ r(
71
+ "span",
72
+ {
73
+ id: `${d}-tooltip`,
74
+ "aria-hidden": "true",
75
+ style: z,
76
+ children: o.tooltip
77
+ }
78
+ ) : 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
44
82
  ] });
45
- return c !== void 0 ? /* @__PURE__ */ o(
83
+ return E !== void 0 ? /* @__PURE__ */ r(
46
84
  "a",
47
85
  {
48
- ...m,
49
- href: c,
50
- target: e.target,
51
- rel: fe(void 0, e.target),
52
- onClick: (f) => {
53
- if (de(f) && e.onClick) {
54
- f.preventDefault(), b(e);
86
+ ...S,
87
+ href: E,
88
+ target: o.target,
89
+ rel: Re(void 0, o.target),
90
+ onClick: (a) => {
91
+ if (Oe(a) && o.onClick) {
92
+ a.preventDefault(), b(o);
55
93
  return;
56
94
  }
57
- M();
95
+ T();
58
96
  },
59
- onAuxClick: (f) => {
60
- f.button === 1 && M();
97
+ onAuxClick: (a) => {
98
+ a.button === 1 && T();
61
99
  },
62
- children: t
100
+ children: i
63
101
  }
64
- ) : /* @__PURE__ */ o("button", { ...m, type: "button", disabled: e.disabled, onClick: () => b(e), children: t });
65
- }, Oe = ({
66
- items: e,
67
- label: d = "More actions",
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",
68
106
  triggerIcon: b,
69
- minWidth: M,
70
- size: m = "small",
71
- showLabel: c = !1,
72
- variant: T = "outline",
73
- trigger: t,
74
- placement: h = "bottom-end",
75
- offset: f,
76
- tone: O = "default"
107
+ minWidth: T,
108
+ size: I = "small",
109
+ showLabel: d = !1,
110
+ variant: m = "outline",
111
+ trigger: s,
112
+ placement: k = "bottom-end",
113
+ offset: S,
114
+ tone: E = "default"
77
115
  }) => {
78
- const D = J[m], [a, i] = z(!1), p = v(null), u = v(null), g = v(null), y = v(!1), P = pe("actionmenu", a, u), K = me(a, p, u, {
79
- minWidth: M,
80
- placement: h,
81
- offset: f
82
- });
83
- G(() => {
84
- if (!a)
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]), $(() => {
124
+ if (!t)
85
125
  return;
86
- g.current && (x(u.current, g.current), g.current = null);
87
- const n = (s) => {
88
- const k = s.composedPath();
89
- [p.current, u.current].some(
90
- (R) => R && k.includes(R)
91
- ) || (y.current = !1, i(!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));
92
131
  };
93
- document.addEventListener("mousedown", n, !0);
94
- const r = ue(() => i(!1));
132
+ document.addEventListener("mousedown", e, !0);
133
+ const n = Ne(() => i(!1));
95
134
  return () => {
96
- var k;
97
- document.removeEventListener("mousedown", n, !0), r();
98
- const s = se();
99
- y.current && (!s || s === document.body) && ((k = p.current) == null || k.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;
100
139
  };
101
- }, [a]);
102
- const C = (n) => {
103
- n.stopPropagation();
104
- const r = !a && n.detail === 0;
105
- g.current = r ? "first" : null, i((s) => !s);
106
- }, L = (n) => {
107
- if (n.key === "Tab" && a) {
140
+ }, [t]);
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) {
108
147
  i(!1);
109
148
  return;
110
149
  }
111
- const r = X(n.key, h);
112
- if (r) {
113
- if (n.preventDefault(), a) {
114
- x(u.current, r);
150
+ const n = ce(e.key, k);
151
+ if (n) {
152
+ if (e.preventDefault(), t) {
153
+ de(c.current, n);
115
154
  return;
116
155
  }
117
- g.current = r, i(!0);
156
+ g.current = n, i(!0);
118
157
  }
119
- }, Y = (n) => {
120
- var s;
121
- if (n.key === "Tab") {
122
- y.current = !1, (s = p.current) == null || s.focus({ preventScroll: !0 }), i(!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);
123
162
  return;
124
163
  }
125
- if (n.key === " " && n.target instanceof HTMLAnchorElement) {
126
- n.preventDefault(), n.target.click();
164
+ if (e.key === " " && e.target instanceof HTMLAnchorElement) {
165
+ e.preventDefault(), e.target.click();
127
166
  return;
128
167
  }
129
- const r = Z(q(u.current), n.target, n.key);
130
- r && (n.preventDefault(), r.focus());
131
- }, F = (n) => {
132
- var r;
133
- n.type === "divider" || n.type === "text" || n.disabled || ((r = n.onClick) == null || r.call(n), i(!1));
134
- }, w = t ? ce(t) : void 0, B = U(
135
- () => ie(w, p),
136
- [w]
137
- ), l = t == null ? void 0 : t.props, j = t ? _.cloneElement(t, {
138
- ref: B,
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,
139
178
  "aria-haspopup": "menu",
140
- "aria-expanded": a,
141
- onClick: S(l == null ? void 0 : l.onClick, C),
142
- onMouseDown: S(l == null ? void 0 : l.onMouseDown, I),
143
- onKeyDown: S(l == null ? void 0 : l.onKeyDown, L)
144
- }) : /* @__PURE__ */ E(
145
- H,
179
+ "aria-expanded": t,
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,
146
185
  {
147
- ref: p,
186
+ ref: a,
148
187
  type: "button",
149
- variant: T,
150
- size: m,
151
- iconOnly: !c,
152
- "aria-label": c ? void 0 : d,
188
+ variant: m,
189
+ size: I,
190
+ iconOnly: !d,
191
+ "aria-label": d ? void 0 : p,
153
192
  "aria-haspopup": "menu",
154
- "aria-expanded": a,
155
- className: `shrink-0${c ? " gap-2" : ""}`,
156
- onClick: C,
157
- onMouseDown: I,
158
- onKeyDown: L,
193
+ "aria-expanded": t,
194
+ className: `shrink-0${d ? " gap-2" : ""}`,
195
+ onClick: R,
196
+ onMouseDown: C,
197
+ onKeyDown: A,
159
198
  children: [
160
- /* @__PURE__ */ o("span", { className: `inline-flex items-center justify-center ${D.iconBox}`, children: b ?? /* @__PURE__ */ o(V, { size: D.icon }) }),
161
- c && /* @__PURE__ */ o("span", { children: d })
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 })
162
201
  ]
163
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
164
213
  );
165
- return /* @__PURE__ */ E(N, { children: [
166
- j,
167
- a && $(
168
- /* @__PURE__ */ E(
214
+ return /* @__PURE__ */ y(U, { children: [
215
+ W,
216
+ t && Q(
217
+ /* @__PURE__ */ y(
169
218
  "div",
170
219
  {
171
- ref: u,
220
+ ref: c,
172
221
  role: "menu",
173
222
  tabIndex: -1,
174
- "aria-label": d,
175
- ...P,
176
- style: W(K),
177
- onMouseDown: I,
178
- onClick: I,
179
- onKeyDown: Y,
223
+ "aria-label": p,
224
+ ...V,
225
+ style: me(N),
226
+ onMouseDown: C,
227
+ onClick: C,
228
+ onKeyDown: X,
180
229
  onFocus: () => {
181
- y.current = !0;
230
+ f.current = !0;
182
231
  },
183
- onBlur: (n) => {
184
- var r;
185
- (r = u.current) != null && r.contains(n.relatedTarget) || (y.current = !1);
232
+ onBlur: (e) => {
233
+ var n;
234
+ (n = c.current) != null && n.contains(e.relatedTarget) || (f.current = !1);
186
235
  },
187
236
  children: [
188
- e.length === 0 && /* @__PURE__ */ o("div", { role: "menuitem", "aria-disabled": "true", style: Q, children: "No actions available" }),
189
- e.map((n) => /* @__PURE__ */ o(
190
- Ee,
191
- {
192
- item: n,
193
- tone: O,
194
- onSelect: F,
195
- onFollow: () => i(!1)
196
- },
197
- n.key
198
- ))
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
+ )
199
258
  ]
200
259
  }
201
260
  ),
@@ -204,6 +263,6 @@ const he = _.lazy(() => import("./ActionMenuTagHost.js")), ge = (e) => e != null
204
263
  ] });
205
264
  };
206
265
  export {
207
- Oe as default
266
+ lo as default
208
267
  };
209
268
  //# sourceMappingURL=ActionMenu.js.map