@stackone/malachite 2.99.2 → 2.100.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
@@ -12,6 +12,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
12
12
  - **`SurfaceExpandableRow`** — A row that opens to reveal a body (used as `Surface.ExpandableRow`), for a line that carries its own controls. Not `Accordion`, which puts its header inside the toggle button, so a header holding a dropdown or a second button would be invalid: here the row surface takes the click and a cell opts out by wrapping its controls in `ExpandableRow.Controls`, while the arrow stays a real button so the keyboard reaches it. That opt-out is explicit rather than sniffing the event target for an interactive ancestor, because a control rendering into a shadow root retargets the event to its host. `sticky` pins the row while its body scrolls, offset by `stickyTopOffset` for whatever is already pinned above it; it only pins while open, since a closed row has nothing to scroll past. _Key props:_ `header`, `children`, `expanded`, `onToggle`, `sticky`, `stickyTopOffset`, `divider`, `tone`, `aria-label`, `className`, `style`.
13
13
  - **`DisclosureArrow`** — The expand/collapse triangle disclosure UI shares (`Accordion`, `Surface.ExpandableRow`). Owns its colour states so they never drift between usages: `text-primary` when expanded, `text-placeholder` otherwise, and dark on hover inside a `group` ancestor — put `group` on the clickable header or row so that hover state activates. _Key props:_ `expanded`, `size`, `className`.
14
14
  - **`Card`** — Generic content card. `title` heads it, with dimmed `subtitle` text beside it and `extra` actions at the right of the title row. `variant="framed"` draws the detached `Table`’s frame instead: the title row sits on a grey frame and the children in a bordered section inside it, so a card above a table, such as a chart over a log list, reads as part of the same set. `dimmed`, `border`, `size`, `glassFooter` and `headerConfig` do not apply to a framed card. _Key props:_ `variant` (`CardVariant`: `default` | `framed`), `title`, `subtitle`, `extra`, `padding`, `footer`.
15
+ - **`LinkCard`** — A compact card that opens more about one thing elsewhere on the screen, such as another tab of a side panel: an optional icon, a title coloured by `tone`, a one-line description cut with an ellipsis, optional `trailing` content such as a level scale, and an accent “Open →”. The whole card is one button, or an anchor with `href` (an unsafe scheme such as `javascript:` is dropped); with neither `onClick` nor a safe `href` it is a static card without the action. Tone is colour alone, so the title has to say the outcome. For a resource in a new tab use `ResourceCard`; for a row in a list use `Surface.Row`. _Key props:_ `title`, `description`, `tone` (`LinkCardTone`: `neutral` | `success` | `warning` | `error`), `icon`, `trailing` (both decorative; `trailing` sits inside the control, so never interactive), `actionLabel` (default `Open`), `onClick`, `href`, `className`.
15
16
  - **`ResourceCard`** — A card pointing at a resource elsewhere, such as an SDK’s documentation: a muted icon tile, a title, a description clamped to two lines and a link that opens in a new tab. `ResourceCard.Header` is the icon, title and description on their own, all phrasing content, so a section that opens on them, such as an `Accordion` header, can use it inside its button. _Key props:_ `icon`, `title`, `description`, `href`, `linkLabel` (default `Documentation`), `titleAs` (`h3` | `h4`), `className`. `ResourceCard.Header`: `icon`, `title`, `description`; phrasing content only, so its title is never a heading.
16
17
  - **`SelectableCard`** — A card that is one option in a radio group — eyebrow, optional status tag, title, description, a count label and a top-right action slot. Use inside a `CardStrip`. Selection is controlled by the consumer: pass `selected`, which drives both the visual treatment and `aria-checked`. A selected card meets the sheet below the way a browser tab meets its toolbar — its bottom corners flare outward onto the strip’s rule — so its outline is one SVG path rather than borders, which would split into two lines at the tangent. `variant` picks the palette: `profile` (green), `library` (neutral) or `editing` (amber, for a profile with unsaved changes). `actions` stands in the card’s top-right corner, on the eyebrow row, and renders outside the control so a menu or icon button inside it stays clickable and keeps its own tab stop. Nothing else marks that corner: the flared outline, the tint and the green eyebrow already say which card is selected, so a radio there would only repeat them. `onDismiss` adds an x after `actions`, tinted like the eyebrow so it reads as part of the card — for discarding a draft card; `dismissDisabledReason` disables it and explains why in its tooltip. `isDefault` marks the card as the account default with a pin beside the title, named for assistive tech and tooltipped for everyone else — it belongs with the name it qualifies rather than among the actions, which read as things to press. `address` puts a one-line chip above the count for a copyable address such as a server URL: its `label` is cut short with an ellipsis, and its full `value` shows in a tooltip and is copied on click, without selecting the card. It takes the place of `description`, since the card has room for one or the other. For a row-shaped selectable use `Surface.Row` instead. _Key props:_ `value`, `title`, `titleIcon`, `isDefault`, `variant` (`profile` | `library` | `editing`), `eyebrow`, `status` (`label`, `type`, `tooltip`), `description`, `address` (`label`, `value`), `countLabel`, `actions`, `onDismiss` (`dismissLabel`, `dismissDisabledReason`), `selected`, `loading` (`loadingLabel`, `loadingHint`), `disabled`, `dimmed`, `onSelect`, `tabIndex`, `aria-label`, `className`, `style`.
17
18
  - **`CardStrip`** — Horizontally scrolling radio group of cards, with edge arrows that appear only when the content overflows, an edge fade, scroll-snap and arrow-key navigation matching `SegmentedControl`. Owns interaction only: it finds its options by looking for `role="radio"` descendants carrying `data-value`, so any such child works (`SelectableCard` emits both). Pass a non-selectable terminal tile as `CardStrip.AddTile` — it sits inside the group but outside the radio set, and must be a direct child or it scrolls with the cards. Use `leading` to pin a card that should not scroll away; the strip tells the cards which slot they are in, so a pinned `SelectableCard` drops the left rule the scrolling ones draw. A strip too narrow to show a card beside `leading` scrolls it with the cards rather than squeezing them, so the selected card always has its full width. Set `bleed` when the strip sits in a `PageLayout`: the strip stretches past the horizontal padding of the layout so its bottom rule runs the full width of the page card, while the cards stay aligned to the gutter. With no cards at all the strip degenerates to its pinned slots alone — no trough, no scroller and no arrows — with the add tile standing beside `leading` and taking `primary` emphasis automatically, since adding the first card is the only thing on offer. _Key props:_ `value`, `tone` (`profile` | `library` | `editing` — read off the selected card unless set), `onChange`, `children`, `leading`, `arrows`, `fadeEdges`, `snap`, `bleed`, `scrollSelectedIntoView`, `aria-label`, `aria-labelledby`, `className`, `style`. `CardStrip.AddTile`: `label`, `icon`, `onClick`, `disabled`, `emphasis` (`primary` | `secondary` — left to the strip unless set: `primary` while there are no cards, `secondary` once there are), `className`.
@@ -117,7 +118,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
117
118
  - **`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
119
  - **`TimeBarChart`** — Counts per time bucket as stacked bars on a UTC axis, the request-volume chart above a log list. Every bucket in `range` takes a slot whether or not it has data, so gaps read as gaps; a zone-less time string is read as UTC. Hover or arrow-key through buckets for a tooltip listing every series and the total; `highlightTime` shades the bucket holding a time from elsewhere on the page, such as the hovered log row. With `onRangeSelect`, dragging across bars reports the whole buckets covered, `end` exclusive so it goes straight back in as `range`, and whether the selection takes in the last bucket. `loading` dims bars already drawn rather than replacing them, and shows a spinner only when there is nothing to dim. Series colours follow the theme’s status tokens by `tone`, and failures always stack above successes whatever order `series` comes in, so position separates them where colour alone might not; a legend names them unless `legend={false}`. A visually hidden table carries the same numbers for screen readers. _Key props:_ `series` (`{ key, label, tone }[]`, stacked by tone with `error` on top; `TimeBarChartTone`: `success` | `error` | `neutral`), `buckets` (`{ start, values }[]`), `interval` (`{ unit, step }`; `TimeBarChartUnit`: `minute` | `hour` | `day` | `week` | `month`), `range` (`end` exclusive, as a selection reports it; at most 2,000 buckets, the newest kept), `TimeBarChartSize` (`small` | `medium` | `large`), `loading`, `error`, `errorTitle`, `errorSubTitle`, `valueLabel`, `legend`, `highlightTime`, `onRangeSelect`, `aria-label`, `aria-labelledby`, `className`, `style`.
119
120
  - **`TimeBarChartSwatch`** — The mark a `TimeBarChart` draws a series in, by its `tone`, for naming the series somewhere other than the chart's legend, such as a count beside the chart standing in for it. It matches the legend and the tooltip, and the bars draw the same colour at 40%; it follows the theme with them. Decorative: the label beside it does the naming. _Key props:_ `tone` (`TimeBarChartTone`).
120
- - **`Timeline`** — A vertical sequence of steps as an ordered list (`Timeline.Item`): a dot on a connecting line, a title, its timing at the right and a free-form body below, such as what happened to one API call. The dot is painted by `tone` from the theme’s text tokens (`neutral` is secondary text, the rest their status colours), or replaced by a decorative `marker` such as the caller’s logo. `stopped` puts an error badge (`stoppedLabel`, default "Stopped here") after the title of the step a flow ended on and paints its dot `error` unless a `tone` is set; the line ends at the last item. For steps a person works through (complete, open, locked) use `StepList`. _Key props:_ `aria-label`, `aria-labelledby`; on `Timeline.Item`: `title`, `time`, `tone` (`TimelineTone`: `neutral` | `info` | `success` | `warning` | `error`), `marker` (fills the 24px circle in place of the ringed dot), `stopped`, `stoppedLabel`.
121
+ - **`Timeline`** — A vertical sequence of steps as an ordered list (`Timeline.Item`): a dot on a connecting line, a title, its timing at the right and a free-form body below, such as what happened to one API call. The dot is painted by `tone` from the theme’s text tokens (`neutral` is secondary text, the rest their status colours), or replaced by a decorative `marker` such as the caller’s logo. `stopped` puts an error badge (`stoppedLabel`, default "Stopped here") after the title of the step a flow ended on and paints its dot `error` unless a `tone` is set; the line ends at the last item. `meta` puts facts about a step in one wrapping row under its title, such as `calls` 2 and `status` 200, each label secondary and its value in the mono face, 18px apart, as a `dl`. `skipped` marks a step that never ran with a grey chevron in place of the dot; the title has to say so. For steps a person works through (complete, open, locked) use `StepList`. _Key props:_ `aria-label`, `aria-labelledby`; on `Timeline.Item`: `title`, `time`, `tone` (`TimelineTone`: `neutral` | `info` | `success` | `warning` | `error`), `marker` (fills the 24px circle in place of the ringed dot), `skipped`, `stopped`, `stoppedLabel`, `meta` (`TimelineMetaEntry[]`: `label`, `value`).
121
122
  - **`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. On the detached header, `title`, `subtitle` and `extra` add a title row on the frame above the column headers, the row a `framed` `Card` draws, and it docks with them under `stickyHeaderTop` (with `showHeader={false}` nothing docks and it scrolls with the rows). The inline header has no frame, so it draws none of the three and warns in development. _Key props:_ `TableColumns` (incl. `align`), `TableSize`, `TableType`, `TableRowSelection`, `TablePaginationPosition` (`pagination.position`, in antd naming: a pager on each edge named, aligned as named, 16px from the rows; bottom right by default), `headerVariant`, `title`, `subtitle`, `extra`, `onVisibleOrderChange`, `scrollHeight` (a height, or `"fill"` for the room left in its scroller once the content above and below it fits, so the page itself never scrolls).
122
123
  - **`Statistic`** — Displays a statistic value with a label; primary/secondary sizes. _Key props:_ `StatisticValueSize`.
123
124
  - **`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"`.
@@ -127,6 +128,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
127
128
  - **`AppLogo`** — A connector's mark, optionally with its name and version tag. Builds on `Avatar`, so a missing or broken logo falls back to the generic "no logo available" placeholder, a neutral grey tile with a darker square, the same mark stackone-logos.com serves. The gap tightens below 18px so the mark and label still read as one unit. _Key props:_ `src`, `name`, `showName`, `size`, `nameSize`, `nameWeight`, `version`, `truncate`, `className`.
128
129
  - **`ConnectionHeader`** — Two tilted logo tiles (from → to) showing a connection between apps. _Key props:_ `from`, `to` (`ConnectionEndpoint`: `icon`, `label`, `background`).
129
130
  - **`CodeBlock`** — Syntax-styled code block, a JSON tree, or a diff. A `json` tree folds by depth with `collapsed`; `collapseLargerThan` also starts any nested array or object with more entries than the limit collapsed at any depth, so a large payload mounts a row per node rather than per item; a node over the limit gets a keyboard toggle named by its path and size, and a folded one says how many entries it holds. _Key props:_ `code`, `json`, `language` (`yaml` | `cedar`), `collapsed`, `collapseLargerThan`, `diff`, `showLineNumbers`, `wrapLines`, `enableCopy`, `height`, `aria-label`, `aria-labelledby`.
131
+ - **`CodePreview`** — A framed payload, such as the raw request or response under a step of a trace: a header naming it with mono `meta` at the right, its first `previewLines` lines (5 by default) with line numbers, and a full-width “Show All N Lines” toggle for the rest that becomes “Show Less”; the toggle carries `aria-expanded`, is described by the title, says how many flagged lines the fold hides, and only appears when there is more to show. The body is a focusable region named by the title, so a keyboard can scroll it. An empty `code` says so. The body scrolls past 360px, folded or open; past `maxRenderedLines` (2,000 by default) the expanded body stops mounting lines and says how many it left out. `highlightLines` flags 1-based lines with the error tint, a rule down their start edge and a visually hidden “Flagged:” for assistive tech; say why nearby. Plain text, no syntax colouring or JSON tree: for those use `CodeBlock`. _Key props:_ `title`, `meta`, `code`, `previewLines`, `highlightLines`, `showLineNumbers` (default `true`), `maxRenderedLines`, `className`.
130
132
  - **`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`.
131
133
  - **`Swatch`** — Colour swatch preview.
132
134
 
@@ -0,0 +1,142 @@
1
+ import { jsxs as l, jsx as r } from "react/jsx-runtime";
2
+ import { useState as A, useId as N, useMemo as v } from "react";
3
+ import L from "./CustomIcons/CaretDownIcon.js";
4
+ import c from "./Typography/Text.js";
5
+ import { rowsWrapperStyle as M } from "./codeBlockStyles.js";
6
+ import { FOCUS_RING_INSET as E } from "./focusRing.js";
7
+ import { isRenderableNode as O } from "./renderableNode.js";
8
+ const w = 5, I = 2e3, T = 360, F = "var(--malachite-card-border,rgb(232,232,232))", S = "var(--malachite-card-subtle-divider,rgb(241,241,241))", W = (e) => e === "" ? [] : e.replace(/\r?\n$/, "").split(/\r\n|\r|\n/), $ = (e, o) => !Number.isNaN(e) && e >= 1 ? Math.floor(e) : o, j = (e) => e ? "flex border-0 border-s-[3px] border-solid border-[var(--malachite-error-background,rgb(197,63,63))] bg-[var(--malachite-alert-error-background,rgba(197,63,63,0.08))]" : "flex border-0 border-s-[3px] border-solid border-transparent", H = (e, o, s) => {
9
+ if (e)
10
+ return "Show Less";
11
+ const m = s > 0 ? ` · ${s} flagged` : "";
12
+ return `Show All ${o} Lines${m}`;
13
+ }, q = ({
14
+ title: e,
15
+ meta: o,
16
+ code: s,
17
+ previewLines: m = w,
18
+ highlightLines: f = [],
19
+ showLineNumbers: i = !0,
20
+ maxRenderedLines: D = I,
21
+ className: _ = ""
22
+ }) => {
23
+ const [d, k] = A(!1), h = N(), u = N(), a = v(() => W(s), [s]), p = v(
24
+ () => new Set(
25
+ f.filter(
26
+ (t) => Number.isInteger(t) && t >= 1 && t <= a.length
27
+ )
28
+ ),
29
+ [f, a.length]
30
+ ), x = $(m, w), y = a.length > x, b = d || !y, g = Math.min(
31
+ b ? a.length : x,
32
+ $(D, I)
33
+ ), C = a.slice(0, g), R = [...p].filter((t) => t > x).length, z = `max(40px, calc(${String(a.length).length}ch + 14px))`;
34
+ return /* @__PURE__ */ l(
35
+ "div",
36
+ {
37
+ className: `overflow-hidden rounded-[var(--malachite-radius-10,10px)] border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] ${_}`,
38
+ style: { borderColor: F },
39
+ children: [
40
+ /* @__PURE__ */ l(
41
+ "div",
42
+ {
43
+ className: "flex items-center justify-between gap-[12px] border-0 border-b border-solid bg-[var(--malachite-card-sunken-background,rgb(250,250,250))] px-[12px] py-[7px] leading-[14px]",
44
+ style: { borderColor: S },
45
+ children: [
46
+ /* @__PURE__ */ r("span", { id: h, className: "flex min-w-0", children: /* @__PURE__ */ r(c, { size: "xsmall", color: "secondary", fontWeight: "semi-bold", children: e }) }),
47
+ O(o) && /* @__PURE__ */ r(
48
+ c,
49
+ {
50
+ size: "xsmall",
51
+ color: "secondary",
52
+ font: "mono",
53
+ wrap: !1,
54
+ className: "truncate",
55
+ children: o
56
+ }
57
+ )
58
+ ]
59
+ }
60
+ ),
61
+ a.length === 0 ? /* @__PURE__ */ r(c, { as: "p", size: "xsmall", color: "secondary", className: "m-0 px-[12px] py-[8px]", children: "Empty" }) : (
62
+ // Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.
63
+ /* @__PURE__ */ r(
64
+ "pre",
65
+ {
66
+ id: u,
67
+ role: "region",
68
+ "aria-labelledby": h,
69
+ tabIndex: 0,
70
+ className: `m-0 overflow-auto font-mono text-[length:var(--malachite-font-size-xsmall,11px)] ${i ? "py-[6px] leading-[14px]" : "py-[10px] leading-[1.65]"} text-[var(--malachite-text-primary,rgb(10,10,10))] ${E}`,
71
+ style: { maxHeight: T },
72
+ children: /* @__PURE__ */ l("span", { className: "block", style: M(!1), children: [
73
+ C.map((t, n) => (
74
+ // A line's position is its identity: its text can repeat.
75
+ /* @__PURE__ */ l(
76
+ "span",
77
+ {
78
+ "data-flagged": p.has(n + 1) || void 0,
79
+ className: j(p.has(n + 1)),
80
+ children: [
81
+ i && /* @__PURE__ */ r(
82
+ "span",
83
+ {
84
+ "aria-hidden": "true",
85
+ className: "flex-none select-none pe-[10px] text-end text-[var(--malachite-text-dimmed,rgb(161,161,161))]",
86
+ style: { width: z },
87
+ children: n + 1
88
+ }
89
+ ),
90
+ /* @__PURE__ */ l(
91
+ "span",
92
+ {
93
+ className: `min-w-0 whitespace-pre ${i ? "" : "px-[11px]"}`,
94
+ children: [
95
+ p.has(n + 1) && /* @__PURE__ */ r("span", { className: "sr-only select-none", children: "Flagged: " }),
96
+ t || " "
97
+ ]
98
+ }
99
+ )
100
+ ]
101
+ },
102
+ n
103
+ )
104
+ )),
105
+ !b && !i && /* @__PURE__ */ r("span", { "aria-hidden": "true", className: "block select-none px-[14px]", children: "…" })
106
+ ] })
107
+ }
108
+ )
109
+ ),
110
+ b && g < a.length && /* @__PURE__ */ r(c, { as: "p", size: "xsmall", color: "secondary", className: "m-0 px-[12px] pb-[8px]", children: `Showing the first ${g.toLocaleString()} of ${a.length.toLocaleString()} lines.` }),
111
+ y && /* @__PURE__ */ l(
112
+ "button",
113
+ {
114
+ type: "button",
115
+ "aria-expanded": d,
116
+ "aria-controls": u,
117
+ "aria-describedby": h,
118
+ onClick: () => k((t) => !t),
119
+ className: `m-0 flex w-full cursor-pointer appearance-none items-center gap-[5px] border-0 border-t border-solid bg-transparent px-[12px] py-[7px] text-start font-[inherit] text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${E}`,
120
+ style: { borderColor: S },
121
+ children: [
122
+ /* @__PURE__ */ r(c, { size: "xsmall", fontWeight: "semi-bold", color: "inherit", children: H(d, a.length, R) }),
123
+ /* @__PURE__ */ r("span", { "aria-hidden": "true", className: "flex", children: /* @__PURE__ */ r(
124
+ L,
125
+ {
126
+ size: 12,
127
+ className: "transition-transform",
128
+ style: { transform: d ? "rotate(180deg)" : void 0 }
129
+ }
130
+ ) })
131
+ ]
132
+ }
133
+ )
134
+ ]
135
+ }
136
+ );
137
+ };
138
+ export {
139
+ q as CodePreview,
140
+ q as default
141
+ };
142
+ //# sourceMappingURL=CodePreview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CodePreview.js","sources":["../../src/components/CodePreview.tsx"],"sourcesContent":["import type React from 'react';\nimport { useId, useMemo, useState } from 'react';\nimport CaretDownIcon from './CustomIcons/CaretDownIcon';\nimport Text from './Typography/Text';\nimport { rowsWrapperStyle } from './codeBlockStyles';\nimport { FOCUS_RING_INSET } from './focusRing';\nimport { isRenderableNode } from './renderableNode';\n\nexport interface CodePreviewProps {\n /** Names the payload in the header and its body and toggle for assistive tech, e.g. `Request`. */\n title: string;\n /** At the right of the header in the mono face, e.g. `POST · acc_8f2…`. */\n meta?: React.ReactNode;\n code: string;\n /** How many lines show until the reader asks for all of them. `Infinity` shows them all. */\n previewLines?: number;\n /** 1-based line numbers to flag, such as the fields a scanner caught. Colour alone, so say why nearby. */\n highlightLines?: readonly number[];\n showLineNumbers?: boolean;\n /** The most lines the expanded body mounts; past it a note says how many are not shown. */\n maxRenderedLines?: number;\n className?: string;\n}\n\nconst DEFAULT_PREVIEW_LINES = 5;\nconst DEFAULT_MAX_RENDERED_LINES = 2000;\n\n// Past this the body scrolls, folded or open, so a long preview never crowds out what is around it.\nconst MAX_BODY_HEIGHT = 360;\n\nconst BORDER = 'var(--malachite-card-border,rgb(232,232,232))';\nconst DIVIDER = 'var(--malachite-card-subtle-divider,rgb(241,241,241))';\n\n// Any line ending, and no empty last line for a trailing newline.\nconst linesOf = (code: string): string[] =>\n code === '' ? [] : code.replace(/\\r?\\n$/, '').split(/\\r\\n|\\r|\\n/);\n\nconst countOf = (value: number, fallback: number): number =>\n !Number.isNaN(value) && value >= 1 ? Math.floor(value) : fallback;\n\nconst lineClasses = (flagged: boolean): string =>\n flagged\n ? 'flex border-0 border-s-[3px] border-solid border-[var(--malachite-error-background,rgb(197,63,63))] bg-[var(--malachite-alert-error-background,rgba(197,63,63,0.08))]'\n : 'flex border-0 border-s-[3px] border-solid border-transparent';\n\nconst toggleLabel = (expanded: boolean, total: number, hiddenFlags: number): string => {\n if (expanded) {\n return 'Show Less';\n }\n const flags = hiddenFlags > 0 ? ` · ${hiddenFlags} flagged` : '';\n return `Show All ${total} Lines${flags}`;\n};\n\n/**\n * A framed payload: a header naming it, its first lines, and a toggle for the rest. For the raw\n * request or response under a step of a trace, where the whole body would crowd out the steps.\n */\nconst CodePreview: React.FC<CodePreviewProps> = ({\n title,\n meta,\n code,\n previewLines = DEFAULT_PREVIEW_LINES,\n highlightLines = [],\n showLineNumbers = true,\n maxRenderedLines = DEFAULT_MAX_RENDERED_LINES,\n className = '',\n}) => {\n const [expanded, setExpanded] = useState(false);\n const titleId = useId();\n const bodyId = useId();\n const lines = useMemo(() => linesOf(code), [code]);\n const flagged = useMemo(\n () =>\n new Set(\n highlightLines.filter(\n (line) => Number.isInteger(line) && line >= 1 && line <= lines.length,\n ),\n ),\n [highlightLines, lines.length],\n );\n const limit = countOf(previewLines, DEFAULT_PREVIEW_LINES);\n const foldable = lines.length > limit;\n const open = expanded || !foldable;\n const rendered = Math.min(\n open ? lines.length : limit,\n countOf(maxRenderedLines, DEFAULT_MAX_RENDERED_LINES),\n );\n const shown = lines.slice(0, rendered);\n const hiddenFlags = [...flagged].filter((line) => line > limit).length;\n // 40px as designed, wider only when the last line's number would crowd the code.\n const gutter = `max(40px, calc(${String(lines.length).length}ch + 14px))`;\n return (\n <div\n className={`overflow-hidden rounded-[var(--malachite-radius-10,10px)] border border-solid bg-[var(--malachite-card-background,rgb(255,255,255))] ${className}`}\n style={{ borderColor: BORDER }}\n >\n <div\n className=\"flex items-center justify-between gap-[12px] border-0 border-b border-solid bg-[var(--malachite-card-sunken-background,rgb(250,250,250))] px-[12px] py-[7px] leading-[14px]\"\n style={{ borderColor: DIVIDER }}\n >\n <span id={titleId} className=\"flex min-w-0\">\n <Text size=\"xsmall\" color=\"secondary\" fontWeight=\"semi-bold\">\n {title}\n </Text>\n </span>\n {isRenderableNode(meta) && (\n <Text\n size=\"xsmall\"\n color=\"secondary\"\n font=\"mono\"\n wrap={false}\n className=\"truncate\"\n >\n {meta}\n </Text>\n )}\n </div>\n {lines.length === 0 ? (\n <Text as=\"p\" size=\"xsmall\" color=\"secondary\" className=\"m-0 px-[12px] py-[8px]\">\n Empty\n </Text>\n ) : (\n // Tabbable so a keyboard can scroll it: Safari never focuses a scroll container on its own.\n <pre\n id={bodyId}\n role=\"region\"\n aria-labelledby={titleId}\n tabIndex={0}\n // Numbered rows sit tight like an editor's; a bare payload keeps code spacing, as designed.\n className={`m-0 overflow-auto font-mono text-[length:var(--malachite-font-size-xsmall,11px)] ${showLineNumbers ? 'py-[6px] leading-[14px]' : 'py-[10px] leading-[1.65]'} text-[var(--malachite-text-primary,rgb(10,10,10))] ${FOCUS_RING_INSET}`}\n style={{ maxHeight: MAX_BODY_HEIGHT }}\n >\n <span className=\"block\" style={rowsWrapperStyle(false)}>\n {shown.map((line, index) => (\n // A line's position is its identity: its text can repeat.\n <span\n key={index}\n data-flagged={flagged.has(index + 1) || undefined}\n className={lineClasses(flagged.has(index + 1))}\n >\n {showLineNumbers && (\n <span\n aria-hidden=\"true\"\n className=\"flex-none select-none pe-[10px] text-end text-[var(--malachite-text-dimmed,rgb(161,161,161))]\"\n style={{ width: gutter }}\n >\n {index + 1}\n </span>\n )}\n <span\n className={`min-w-0 whitespace-pre ${showLineNumbers ? '' : 'px-[11px]'}`}\n >\n {flagged.has(index + 1) && (\n <span className=\"sr-only select-none\">Flagged: </span>\n )}\n {line || ' '}\n </span>\n </span>\n ))}\n {!open && !showLineNumbers && (\n <span aria-hidden=\"true\" className=\"block select-none px-[14px]\">\n …\n </span>\n )}\n </span>\n </pre>\n )}\n {open && rendered < lines.length && (\n <Text as=\"p\" size=\"xsmall\" color=\"secondary\" className=\"m-0 px-[12px] pb-[8px]\">\n {`Showing the first ${rendered.toLocaleString()} of ${lines.length.toLocaleString()} lines.`}\n </Text>\n )}\n {foldable && (\n <button\n type=\"button\"\n aria-expanded={expanded}\n aria-controls={bodyId}\n aria-describedby={titleId}\n onClick={() => setExpanded((isOpen) => !isOpen)}\n className={`m-0 flex w-full cursor-pointer appearance-none items-center gap-[5px] border-0 border-t border-solid bg-transparent px-[12px] py-[7px] text-start font-[inherit] text-[var(--malachite-accent-foreground,rgb(2,122,66))] ${FOCUS_RING_INSET}`}\n style={{ borderColor: DIVIDER }}\n >\n <Text size=\"xsmall\" fontWeight=\"semi-bold\" color=\"inherit\">\n {toggleLabel(expanded, lines.length, hiddenFlags)}\n </Text>\n <span aria-hidden=\"true\" className=\"flex\">\n <CaretDownIcon\n size={12}\n className=\"transition-transform\"\n style={{ transform: expanded ? 'rotate(180deg)' : undefined }}\n />\n </span>\n </button>\n )}\n </div>\n );\n};\n\nexport default CodePreview;\nexport { CodePreview };\n"],"names":["DEFAULT_PREVIEW_LINES","DEFAULT_MAX_RENDERED_LINES","MAX_BODY_HEIGHT","BORDER","DIVIDER","linesOf","code","countOf","value","fallback","lineClasses","flagged","toggleLabel","expanded","total","hiddenFlags","flags","CodePreview","title","meta","previewLines","highlightLines","showLineNumbers","maxRenderedLines","className","setExpanded","useState","titleId","useId","bodyId","lines","useMemo","line","limit","foldable","open","rendered","shown","gutter","jsxs","jsx","Text","isRenderableNode","FOCUS_RING_INSET","rowsWrapperStyle","index","isOpen","CaretDownIcon"],"mappings":";;;;;;;AAwBA,MAAMA,IAAwB,GACxBC,IAA6B,KAG7BC,IAAkB,KAElBC,IAAS,iDACTC,IAAU,yDAGVC,IAAU,CAACC,MACbA,MAAS,KAAK,CAAA,IAAKA,EAAK,QAAQ,UAAU,EAAE,EAAE,MAAM,YAAY,GAE9DC,IAAU,CAACC,GAAeC,MAC5B,CAAC,OAAO,MAAMD,CAAK,KAAKA,KAAS,IAAI,KAAK,MAAMA,CAAK,IAAIC,GAEvDC,IAAc,CAACC,MACjBA,IACM,0KACA,gEAEJC,IAAc,CAACC,GAAmBC,GAAeC,MAAgC;AACnF,MAAIF;AACA,WAAO;AAEX,QAAMG,IAAQD,IAAc,IAAI,MAAMA,CAAW,aAAa;AAC9D,SAAO,YAAYD,CAAK,SAASE,CAAK;AAC1C,GAMMC,IAA0C,CAAC;AAAA,EAC7C,OAAAC;AAAA,EACA,MAAAC;AAAA,EACA,MAAAb;AAAA,EACA,cAAAc,IAAepB;AAAA,EACf,gBAAAqB,IAAiB,CAAA;AAAA,EACjB,iBAAAC,IAAkB;AAAA,EAClB,kBAAAC,IAAmBtB;AAAA,EACnB,WAAAuB,IAAY;AAChB,MAAM;AACF,QAAM,CAACX,GAAUY,CAAW,IAAIC,EAAS,EAAK,GACxCC,IAAUC,EAAA,GACVC,IAASD,EAAA,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AAAA,kBAAA;AAAA,iBAsBZ;AAAA,gBACA,CAACV,KAAQ,CAACb,KACP,gBAAAkB,EAAC,UAAK,eAAY,QAAO,WAAU,+BAA8B,UAAA,IAAA,CAEjE;AAAA,cAAA,EAAA,CAER;AAAA,YAAA;AAAA,UAAA;AAAA;AAAA,QAGPL,KAAQC,IAAWN,EAAM,4BACrBW,GAAA,EAAK,IAAG,KAAI,MAAK,UAAS,OAAM,aAAY,WAAU,0BAClD,UAAA,qBAAqBL,EAAS,eAAA,CAAgB,OAAON,EAAM,OAAO,gBAAgB,UAAA,CACvF;AAAA,QAEHI,KACG,gBAAAK;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,MAAK;AAAA,YACL,iBAAe1B;AAAA,YACf,iBAAegB;AAAA,YACf,oBAAkBF;AAAA,YAClB,SAAS,MAAMF,EAAY,CAACqB,MAAW,CAACA,CAAM;AAAA,YAC9C,WAAW,4NAA4NH,CAAgB;AAAA,YACvP,OAAO,EAAE,aAAavC,EAAA;AAAA,YAEtB,UAAA;AAAA,cAAA,gBAAAoC,EAACC,GAAA,EAAK,MAAK,UAAS,YAAW,aAAY,OAAM,WAC5C,UAAA7B,EAAYC,GAAUiB,EAAM,QAAQf,CAAW,GACpD;AAAA,cACA,gBAAAyB,EAAC,QAAA,EAAK,eAAY,QAAO,WAAU,QAC/B,UAAA,gBAAAA;AAAA,gBAACO;AAAA,gBAAA;AAAA,kBACG,MAAM;AAAA,kBACN,WAAU;AAAA,kBACV,OAAO,EAAE,WAAWlC,IAAW,mBAAmB,OAAA;AAAA,gBAAU;AAAA,cAAA,EAChE,CACJ;AAAA,YAAA;AAAA,UAAA;AAAA,QAAA;AAAA,MACJ;AAAA,IAAA;AAAA,EAAA;AAIhB;"}
@@ -0,0 +1,83 @@
1
+ import { jsxs as l, Fragment as g, jsx as e } from "react/jsx-runtime";
2
+ import v from "./CustomIcons/ForwardArrowIcon.js";
3
+ import $ from "./Typography/EllipsisText.js";
4
+ import m from "./Typography/Text.js";
5
+ import { devWarning as N } from "./devWarning.js";
6
+ import { FOCUS_RING as y } from "./focusRing.js";
7
+ import { isRenderableNode as p } from "./renderableNode.js";
8
+ import { safeHref as C } from "./safeHref.js";
9
+ const L = {
10
+ neutral: "primary",
11
+ success: "success",
12
+ warning: "warning",
13
+ error: "error"
14
+ }, s = "flex w-full items-center gap-[12px] rounded-[var(--malachite-radius-10,10px)] border border-solid border-[var(--malachite-card-border,rgb(232,232,232))] bg-[var(--malachite-card-background,rgb(255,255,255))] px-[12px] py-[10px] text-start text-[var(--malachite-text-primary,rgb(10,10,10))] no-underline", h = `cursor-pointer transition-colors hover:border-[var(--malachite-secondary-border-hover,rgb(186,186,186))] hover:bg-[var(--malachite-buttonlist-hover-background,rgb(245,245,245))] ${y}`, O = ({
15
+ title: f,
16
+ description: t,
17
+ tone: x = "neutral",
18
+ icon: c,
19
+ trailing: d,
20
+ actionLabel: u = "Open",
21
+ onClick: r,
22
+ href: a,
23
+ className: o = ""
24
+ }) => {
25
+ const n = C(a);
26
+ a && !n && N(
27
+ `LinkCard.href:${a}`,
28
+ `LinkCard dropped the unsafe href "${a}"; without an onClick it is a static card.`
29
+ );
30
+ const b = !!(n || r), i = /* @__PURE__ */ l(g, { children: [
31
+ p(c) && /* @__PURE__ */ e("span", { "aria-hidden": "true", className: "flex flex-none items-center", children: c }),
32
+ /* @__PURE__ */ l("span", { className: "flex min-w-0 flex-1 flex-col gap-[1px] leading-[15px]", children: [
33
+ /* @__PURE__ */ e(
34
+ m,
35
+ {
36
+ size: "small",
37
+ fontWeight: "bold",
38
+ color: L[x],
39
+ className: "leading-[17px]",
40
+ children: f
41
+ }
42
+ ),
43
+ t && /* @__PURE__ */ e(
44
+ $,
45
+ {
46
+ size: "xsmall",
47
+ color: "secondary",
48
+ tooltip: t,
49
+ tooltipWhenTruncated: !0,
50
+ inline: !0,
51
+ children: t
52
+ }
53
+ )
54
+ ] }),
55
+ p(d) && /* @__PURE__ */ e("span", { "aria-hidden": "true", className: "flex flex-none items-center", children: d }),
56
+ b && /* @__PURE__ */ l("span", { className: "flex flex-none items-center gap-[3px] text-[var(--malachite-accent-foreground,rgb(2,122,66))]", children: [
57
+ /* @__PURE__ */ e(m, { size: "xsmall", fontWeight: "semi-bold", color: "inherit", wrap: !1, children: u }),
58
+ /* @__PURE__ */ e("span", { "aria-hidden": "true", className: "flex", children: /* @__PURE__ */ e(v, { size: 12 }) })
59
+ ] })
60
+ ] });
61
+ return n ? /* @__PURE__ */ e(
62
+ "a",
63
+ {
64
+ href: n,
65
+ onClick: r,
66
+ className: `${s} ${h} ${o}`,
67
+ children: i
68
+ }
69
+ ) : r ? /* @__PURE__ */ e(
70
+ "button",
71
+ {
72
+ type: "button",
73
+ onClick: r,
74
+ className: `m-0 appearance-none font-[inherit] ${s} ${h} ${o}`,
75
+ children: i
76
+ }
77
+ ) : /* @__PURE__ */ e("div", { className: `${s} ${o}`, children: i });
78
+ };
79
+ export {
80
+ O as LinkCard,
81
+ O as default
82
+ };
83
+ //# sourceMappingURL=LinkCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkCard.js","sources":["../../src/components/LinkCard.tsx"],"sourcesContent":["import type React from 'react';\nimport ForwardArrowIcon from './CustomIcons/ForwardArrowIcon';\nimport EllipsisText from './Typography/EllipsisText';\nimport Text from './Typography/Text';\nimport { devWarning } from './devWarning';\nimport { FOCUS_RING } from './focusRing';\nimport { isRenderableNode } from './renderableNode';\nimport { safeHref } from './safeHref';\n\nexport type LinkCardTone = 'neutral' | 'success' | 'warning' | 'error';\n\nexport interface LinkCardProps {\n title: string;\n /** One line under the title; truncated text shows in full on hover. */\n description?: string;\n /** Colours the title. */\n tone?: LinkCardTone;\n /** Decorative, before the title. Coloured paths need `data-malachite-shape`. */\n icon?: React.ReactNode;\n /** Decorative content before the action, e.g. a level scale. Must not be interactive. */\n trailing?: React.ReactNode;\n actionLabel?: string;\n onClick?: (event: React.MouseEvent<HTMLElement>) => void;\n /** Renders a link instead of a button; unsafe schemes are dropped. */\n href?: string;\n className?: string;\n}\n\nconst TITLE_COLOR = {\n neutral: 'primary',\n success: 'success',\n warning: 'warning',\n error: 'error',\n} as const;\n\nconst CARD_CLASSES =\n 'flex w-full items-center gap-[12px] rounded-[var(--malachite-radius-10,10px)] border border-solid border-[var(--malachite-card-border,rgb(232,232,232))] bg-[var(--malachite-card-background,rgb(255,255,255))] px-[12px] py-[10px] text-start text-[var(--malachite-text-primary,rgb(10,10,10))] no-underline';\n\nconst INTERACTIVE_CLASSES = `cursor-pointer transition-colors hover:border-[var(--malachite-secondary-border-hover,rgb(186,186,186))] hover:bg-[var(--malachite-buttonlist-hover-background,rgb(245,245,245))] ${FOCUS_RING}`;\n\n/** A compact card that opens more detail elsewhere, such as another tab of a panel. */\nconst LinkCard: React.FC<LinkCardProps> = ({\n title,\n description,\n tone = 'neutral',\n icon,\n trailing,\n actionLabel = 'Open',\n onClick,\n href: rawHref,\n className = '',\n}) => {\n const href = safeHref(rawHref);\n if (rawHref && !href) {\n devWarning(\n `LinkCard.href:${rawHref}`,\n `LinkCard dropped the unsafe href \"${rawHref}\"; without an onClick it is a static card.`,\n );\n }\n const interactive = Boolean(href || onClick);\n const body = (\n <>\n {isRenderableNode(icon) && (\n <span aria-hidden=\"true\" className=\"flex flex-none items-center\">\n {icon}\n </span>\n )}\n <span className=\"flex min-w-0 flex-1 flex-col gap-[1px] leading-[15px]\">\n <Text\n size=\"small\"\n fontWeight=\"bold\"\n color={TITLE_COLOR[tone]}\n className=\"leading-[17px]\"\n >\n {title}\n </Text>\n {description && (\n <EllipsisText\n size=\"xsmall\"\n color=\"secondary\"\n tooltip={description}\n tooltipWhenTruncated\n inline\n >\n {description}\n </EllipsisText>\n )}\n </span>\n {isRenderableNode(trailing) && (\n <span aria-hidden=\"true\" className=\"flex flex-none items-center\">\n {trailing}\n </span>\n )}\n {interactive && (\n <span className=\"flex flex-none items-center gap-[3px] text-[var(--malachite-accent-foreground,rgb(2,122,66))]\">\n <Text size=\"xsmall\" fontWeight=\"semi-bold\" color=\"inherit\" wrap={false}>\n {actionLabel}\n </Text>\n <span aria-hidden=\"true\" className=\"flex\">\n <ForwardArrowIcon size={12} />\n </span>\n </span>\n )}\n </>\n );\n if (href) {\n return (\n <a\n href={href}\n onClick={onClick}\n className={`${CARD_CLASSES} ${INTERACTIVE_CLASSES} ${className}`}\n >\n {body}\n </a>\n );\n }\n if (onClick) {\n return (\n <button\n type=\"button\"\n onClick={onClick}\n className={`m-0 appearance-none font-[inherit] ${CARD_CLASSES} ${INTERACTIVE_CLASSES} ${className}`}\n >\n {body}\n </button>\n );\n }\n return <div className={`${CARD_CLASSES} ${className}`}>{body}</div>;\n};\n\nexport default LinkCard;\nexport { LinkCard };\n"],"names":["TITLE_COLOR","CARD_CLASSES","INTERACTIVE_CLASSES","FOCUS_RING","LinkCard","title","description","tone","icon","trailing","actionLabel","onClick","rawHref","className","href","safeHref","devWarning","interactive","body","jsxs","Fragment","isRenderableNode","jsx","Text","EllipsisText","ForwardArrowIcon"],"mappings":";;;;;;;;AA4BA,MAAMA,IAAc;AAAA,EAChB,SAAS;AAAA,EACT,SAAS;AAAA,EACT,SAAS;AAAA,EACT,OAAO;AACX,GAEMC,IACF,kTAEEC,IAAsB,qLAAqLC,CAAU,IAGrNC,IAAoC,CAAC;AAAA,EACvC,OAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,SAAAC;AAAA,EACA,MAAMC;AAAA,EACN,WAAAC,IAAY;AAChB,MAAM;AACF,QAAMC,IAAOC,EAASH,CAAO;AAC7B,EAAIA,KAAW,CAACE,KACZE;AAAA,IACI,iBAAiBJ,CAAO;AAAA,IACxB,qCAAqCA,CAAO;AAAA,EAAA;AAGpD,QAAMK,IAAc,GAAQH,KAAQH,IAC9BO,IACF,gBAAAC,EAAAC,GAAA,EACK,UAAA;AAAA,IAAAC,EAAiBb,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,WAAW,sCAAsCV,CAAY,IAAIC,CAAmB,IAAIW,CAAS;AAAA,MAEhG,UAAAK;AAAA,IAAA;AAAA,EAAA,IAIN,gBAAAI,EAAC,SAAI,WAAW,GAAGrB,CAAY,IAAIY,CAAS,IAAK,UAAAK,EAAA,CAAK;AACjE;"}
@@ -1 +1 @@
1
- {"version":3,"file":"PillButton.js","sources":["../../src/components/PillButton.tsx"],"sourcesContent":["import React from 'react';\nimport { FOCUS_RING } from './focusRing';\nimport { resolveRel } from './linkRel';\nimport { safeHref } from './safeHref';\n\ntype PillButtonSize = 'xsmall' | 'small' | 'medium';\ntype PillButtonVariant = 'default' | 'inverted';\n/**\n * `tab` squares the top corners so the pill reads as attached to whatever sits above it —\n * a row of controls hanging under an input, rather than free-floating pills.\n */\ntype PillButtonShape = 'pill' | 'tab';\n/**\n * `assistant` is the chrome for AI-authored chips (e.g. `ChangeReview.Jump`): a fixed\n * violet-on-white look with its own border, independent of `variant`/`selected`.\n */\ntype PillButtonTone = 'default' | 'assistant';\n\ninterface PillButtonProps {\n label: string;\n icon?: React.ReactNode;\n className?: string;\n selected?: boolean;\n disabled?: boolean;\n interactive?: boolean;\n size?: PillButtonSize;\n variant?: PillButtonVariant;\n shape?: PillButtonShape;\n tone?: PillButtonTone;\n /** Sits after the label — a caret on a pill that opens a menu. */\n trailingIcon?: React.ReactNode;\n onClick?: (event: React.MouseEvent<HTMLElement>) => void;\n /** Renders the pill as a real anchor, so a link pill keeps cmd-click, copy-link and the status bar. */\n href?: string;\n target?: React.HTMLAttributeAnchorTarget;\n rel?: string;\n}\n\nconst BASE_CLASSES =\n 'inline-flex items-center justify-center gap-1.5 font-medium whitespace-nowrap shrink-0 transition-colors duration-150 ease-in-out';\n\nconst SHAPE_CLASSES: Record<PillButtonShape, string> = {\n pill: 'rounded-[var(--malachite-radius-10,10px)]',\n tab: 'rounded-b-[var(--malachite-radius-10,10px)] rounded-t-none',\n};\n\n// Box-sizing is border-box, so trading `border-0` for a 1px border only eats into the padding\n// box — it never grows the element past the `h-[...]` each size already fixes. Only one of these\n// ever applies per render, so there's no `border-0`/`border` class collision to referee.\nconst TONE_BORDER_CLASSES: Record<PillButtonTone, string> = {\n default: 'border-0',\n assistant: 'border border-solid border-[var(--malachite-tag-assistant-border)]',\n};\n\nconst ASSISTANT_COLORS =\n 'bg-[var(--malachite-card-background)] text-[var(--malachite-assistant-foreground)]';\n\nconst SIZE_CLASSES: Record<\n PillButtonSize,\n { text: string; padding: string; paddingWithIcon: string }\n> = {\n // For a row that labels other content rather than being read on its own — a context\n // strip above a chat, say. The only size that drops below the 13px the others share.\n xsmall: {\n text: 'text-[length:var(--malachite-font-size-xsmall,11px)] h-[22px] leading-none',\n padding: 'px-2',\n paddingWithIcon: 'pl-1 pr-1.5',\n },\n small: {\n text: 'text-[length:var(--malachite-font-size-small,13px)] h-[var(--malachite-control-height-small,28px)] leading-none',\n padding: 'px-2.5',\n paddingWithIcon: 'pl-1.5 pr-2',\n },\n medium: {\n text: 'text-[length:var(--malachite-font-size-small,13px)] h-[var(--malachite-control-height-medium,32px)] leading-none',\n padding: 'px-2.5',\n paddingWithIcon: 'pl-1.5 pr-2',\n },\n};\n\nconst STATIC_COLORS =\n 'bg-[var(--malachite-pillbutton-static-background)] text-[var(--malachite-pillbutton-static-foreground)]';\n\nconst CLICKABLE_TAIL = 'active:opacity-60 cursor-pointer';\n\nconst VARIANT_COLORS: Record<PillButtonVariant, { base: string; selected: string; hover: string }> =\n {\n default: {\n base: 'bg-[var(--malachite-pillbutton-background)] text-[var(--malachite-pillbutton-foreground)]',\n selected:\n 'bg-[var(--malachite-pillbutton-hover-background)] text-[var(--malachite-pillbutton-hover-foreground)]',\n hover: 'hover:bg-[var(--malachite-pillbutton-hover-background)] hover:text-[var(--malachite-pillbutton-hover-foreground)] active:bg-[var(--malachite-pillbutton-pressed-background)] active:text-[var(--malachite-pillbutton-pressed-foreground)]',\n },\n inverted: {\n base: 'bg-[var(--malachite-pillbutton-inverted-background)] text-[var(--malachite-pillbutton-inverted-foreground)]',\n selected:\n 'bg-[var(--malachite-pillbutton-inverted-hover-background)] text-[var(--malachite-pillbutton-inverted-hover-foreground)]',\n hover: 'hover:bg-[var(--malachite-pillbutton-inverted-hover-background)] hover:text-[var(--malachite-pillbutton-inverted-hover-foreground)] active:bg-[var(--malachite-pillbutton-inverted-pressed-background)] active:text-[var(--malachite-pillbutton-inverted-pressed-foreground)]',\n },\n };\n\nexport const PillButton: React.FC<PillButtonProps> = ({\n label = 'Label',\n icon,\n className = '',\n selected = false,\n disabled = false,\n interactive = true,\n size = 'small',\n variant = 'default',\n shape = 'pill',\n tone = 'default',\n trailingIcon,\n onClick,\n href,\n target,\n rel,\n}) => {\n const sizeBlock = SIZE_CLASSES[size];\n const padding = icon ? sizeBlock.paddingWithIcon : sizeBlock.padding;\n const variantBlock = VARIANT_COLORS[variant];\n const isInteractiveLook = interactive && !disabled;\n // A rejected href (e.g. `javascript:`) takes the button or static path, never an anchor.\n const linkHref = safeHref(href);\n const isClickable = isInteractiveLook && (!!onClick || !!linkHref);\n const clickableTail = isClickable ? ` ${CLICKABLE_TAIL}` : '';\n\n let colorClasses: string;\n if (tone === 'assistant') {\n // Assistant chips read the same in every interaction state — the click affordance is\n // the shared `active:opacity-60` from `clickableTail`, not a colour swap.\n colorClasses = isClickable ? `${ASSISTANT_COLORS}${clickableTail}` : ASSISTANT_COLORS;\n } else if (!interactive) {\n colorClasses = STATIC_COLORS;\n } else if (selected) {\n colorClasses = isInteractiveLook\n ? `${variantBlock.selected}${clickableTail}`\n : variantBlock.selected;\n } else if (isInteractiveLook) {\n colorClasses = `${variantBlock.base} ${variantBlock.hover}${clickableTail}`;\n } else {\n colorClasses = variantBlock.base;\n }\n\n const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed pointer-events-none' : '';\n\n const merged = `${BASE_CLASSES} ${SHAPE_CLASSES[shape]} ${sizeBlock.text} ${padding} ${TONE_BORDER_CLASSES[tone]} ${colorClasses} ${disabledClasses} ${className}`;\n\n const iconSlot = icon ? (\n <span className=\"inline-flex items-center justify-center w-4 h-4 shrink-0 [&>img]:max-w-full [&>img]:max-h-full [&>img]:object-contain\">\n {icon}\n </span>\n ) : null;\n\n const trailingSlot = trailingIcon ? (\n <span className=\"inline-flex shrink-0 items-center justify-center\">{trailingIcon}</span>\n ) : null;\n\n // An anchor cannot be disabled, so a disabled link pill falls through to the static one.\n if (isClickable && linkHref) {\n return (\n <a\n href={linkHref}\n target={target}\n rel={resolveRel(rel, target)}\n className={`${FOCUS_RING} ${merged} no-underline`}\n onClick={onClick}\n >\n {iconSlot}\n {label}\n {trailingSlot}\n </a>\n );\n }\n\n if (isClickable) {\n return (\n <button type=\"button\" className={`${FOCUS_RING} ${merged}`} onClick={onClick}>\n {iconSlot}\n {label}\n {trailingSlot}\n </button>\n );\n }\n\n return (\n <div className={merged}>\n {iconSlot}\n {label}\n {trailingSlot}\n </div>\n );\n};\n\nexport default PillButton;\n"],"names":["BASE_CLASSES","SHAPE_CLASSES","TONE_BORDER_CLASSES","ASSISTANT_COLORS","SIZE_CLASSES","STATIC_COLORS","CLICKABLE_TAIL","VARIANT_COLORS","PillButton","label","icon","className","selected","disabled","interactive","size","variant","shape","tone","trailingIcon","onClick","href","target","rel","sizeBlock","padding","variantBlock","isInteractiveLook","linkHref","safeHref","isClickable","clickableTail","colorClasses","disabledClasses","merged","iconSlot","jsx","trailingSlot","jsxs","resolveRel","FOCUS_RING"],"mappings":";;;;AAsCA,MAAMA,IACF,qIAEEC,IAAiD;AAAA,EACnD,MAAM;AAAA,EACN,KAAK;AACT,GAKMC,IAAsD;AAAA,EACxD,SAAS;AAAA,EACT,WAAW;AACf,GAEMC,IACF,sFAEEC,IAGF;AAAA;AAAA;AAAA,EAGA,QAAQ;AAAA,IACJ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,iBAAiB;AAAA,EAAA;AAAA,EAErB,OAAO;AAAA,IACH,MAAM;AAAA,IACN,SAAS;AAAA,IACT,iBAAiB;A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BpB,IAAW,sDAAsD,IAEnFqB,IAAS,GAAGlC,CAAY,IAAIC,EAAcgB,CAAK,CAAC,IAAIO,EAAU,IAAI,IAAIC,CAAO,IAAIvB,EAAoBgB,CAAI,CAAC,IAAIc,CAAY,IAAIC,CAAe,IAAItB,CAAS,IAE1JwB,IAAWzB,IACb,gBAAA0B,EAAC,UAAK,WAAU,yHACX,aACL,IACA,MAEEC,IAAelB,IACjB,gBAAAiB,EAAC,UAAK,WAAU,oDAAoD,aAAa,IACjF;AAGJ,SAAIN,KAAeF,IAEX,gBAAAU;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAMV;AAAA,MACN,QAAAN;AAAA,MACA,KAAKiB,EAAWhB,GAAKD,CAAM;AAAA,MAC3B,WAAW,GAAGkB,CAAU,IAAIN,CAAM;AAAA,MAClC,SAAAd;AAAA,MAEC,UAAA;AAAA,QAAAe;AAAA,QACA1B;AAAA,QACA4B;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,IAKTP,IAEI,gBAAAQ,EAAC,UAAA,EAAO,MAAK,UAAS,WAAW,GAAGE,CAAU,IAAIN,CAAM,IAAI,SAAAd,GACvD,UAAA;AAAA,IAAAe;AAAA,IACA1B;AAAA,IACA4B;AAAA,EAAA,GACL,IAKJ,gBAAAC,EAAC,OAAA,EAAI,WAAWJ,GACX,UAAA;AAAA,IAAAC;AAAA,IACA1B;AAAA,IACA4B;AAAA,EAAA,GACL;AAER;"}
1
+ {"version":3,"file":"PillButton.js","sources":["../../src/components/PillButton.tsx"],"sourcesContent":["import React from 'react';\nimport { FOCUS_RING } from './focusRing';\nimport { resolveRel } from './linkRel';\nimport { safeHref } from './safeHref';\n\ntype PillButtonSize = 'xsmall' | 'small' | 'medium';\ntype PillButtonVariant = 'default' | 'inverted';\n/**\n * `tab` squares the top corners so the pill reads as attached to whatever sits above it —\n * a row of controls hanging under an input, rather than free-floating pills.\n */\ntype PillButtonShape = 'pill' | 'tab';\n/**\n * `assistant` is the chrome for AI-authored chips (e.g. `ChangeReview.Jump`): a fixed\n * violet-on-white look with its own border, independent of `variant`/`selected`.\n */\ntype PillButtonTone = 'default' | 'assistant';\n\ninterface PillButtonProps {\n label: string;\n icon?: React.ReactNode;\n className?: string;\n selected?: boolean;\n disabled?: boolean;\n interactive?: boolean;\n size?: PillButtonSize;\n variant?: PillButtonVariant;\n shape?: PillButtonShape;\n tone?: PillButtonTone;\n /** Sits after the label — a caret on a pill that opens a menu. */\n trailingIcon?: React.ReactNode;\n onClick?: (event: React.MouseEvent<HTMLElement>) => void;\n /** Renders the pill as a real anchor, so a link pill keeps cmd-click, copy-link and the status bar. */\n href?: string;\n target?: React.HTMLAttributeAnchorTarget;\n rel?: string;\n}\n\nconst BASE_CLASSES =\n 'inline-flex items-center justify-center gap-1.5 font-medium whitespace-nowrap shrink-0 transition-colors duration-150 ease-in-out';\n\nconst SHAPE_CLASSES: Record<PillButtonShape, string> = {\n pill: 'rounded-[var(--malachite-radius-10,10px)]',\n tab: 'rounded-b-[var(--malachite-radius-10,10px)] rounded-t-none',\n};\n\n// Box-sizing is border-box, so trading `border-0` for a 1px border only eats into the padding\n// box — it never grows the element past the fixed height each size already sets. Only one of these\n// ever applies per render, so there's no `border-0`/`border` class collision to referee.\nconst TONE_BORDER_CLASSES: Record<PillButtonTone, string> = {\n default: 'border-0',\n assistant: 'border border-solid border-[var(--malachite-tag-assistant-border)]',\n};\n\nconst ASSISTANT_COLORS =\n 'bg-[var(--malachite-card-background)] text-[var(--malachite-assistant-foreground)]';\n\nconst SIZE_CLASSES: Record<\n PillButtonSize,\n { text: string; padding: string; paddingWithIcon: string }\n> = {\n // For a row that labels other content rather than being read on its own — a context\n // strip above a chat, say. The only size that drops below the 13px the others share.\n xsmall: {\n text: 'text-[length:var(--malachite-font-size-xsmall,11px)] h-[22px] leading-none',\n padding: 'px-2',\n paddingWithIcon: 'pl-1 pr-1.5',\n },\n small: {\n text: 'text-[length:var(--malachite-font-size-small,13px)] h-[var(--malachite-control-height-small,28px)] leading-none',\n padding: 'px-2.5',\n paddingWithIcon: 'pl-1.5 pr-2',\n },\n medium: {\n text: 'text-[length:var(--malachite-font-size-small,13px)] h-[var(--malachite-control-height-medium,32px)] leading-none',\n padding: 'px-2.5',\n paddingWithIcon: 'pl-1.5 pr-2',\n },\n};\n\nconst STATIC_COLORS =\n 'bg-[var(--malachite-pillbutton-static-background)] text-[var(--malachite-pillbutton-static-foreground)]';\n\nconst CLICKABLE_TAIL = 'active:opacity-60 cursor-pointer';\n\nconst VARIANT_COLORS: Record<PillButtonVariant, { base: string; selected: string; hover: string }> =\n {\n default: {\n base: 'bg-[var(--malachite-pillbutton-background)] text-[var(--malachite-pillbutton-foreground)]',\n selected:\n 'bg-[var(--malachite-pillbutton-hover-background)] text-[var(--malachite-pillbutton-hover-foreground)]',\n hover: 'hover:bg-[var(--malachite-pillbutton-hover-background)] hover:text-[var(--malachite-pillbutton-hover-foreground)] active:bg-[var(--malachite-pillbutton-pressed-background)] active:text-[var(--malachite-pillbutton-pressed-foreground)]',\n },\n inverted: {\n base: 'bg-[var(--malachite-pillbutton-inverted-background)] text-[var(--malachite-pillbutton-inverted-foreground)]',\n selected:\n 'bg-[var(--malachite-pillbutton-inverted-hover-background)] text-[var(--malachite-pillbutton-inverted-hover-foreground)]',\n hover: 'hover:bg-[var(--malachite-pillbutton-inverted-hover-background)] hover:text-[var(--malachite-pillbutton-inverted-hover-foreground)] active:bg-[var(--malachite-pillbutton-inverted-pressed-background)] active:text-[var(--malachite-pillbutton-inverted-pressed-foreground)]',\n },\n };\n\nexport const PillButton: React.FC<PillButtonProps> = ({\n label = 'Label',\n icon,\n className = '',\n selected = false,\n disabled = false,\n interactive = true,\n size = 'small',\n variant = 'default',\n shape = 'pill',\n tone = 'default',\n trailingIcon,\n onClick,\n href,\n target,\n rel,\n}) => {\n const sizeBlock = SIZE_CLASSES[size];\n const padding = icon ? sizeBlock.paddingWithIcon : sizeBlock.padding;\n const variantBlock = VARIANT_COLORS[variant];\n const isInteractiveLook = interactive && !disabled;\n // A rejected href (e.g. `javascript:`) takes the button or static path, never an anchor.\n const linkHref = safeHref(href);\n const isClickable = isInteractiveLook && (!!onClick || !!linkHref);\n const clickableTail = isClickable ? ` ${CLICKABLE_TAIL}` : '';\n\n let colorClasses: string;\n if (tone === 'assistant') {\n // Assistant chips read the same in every interaction state — the click affordance is\n // the shared `active:opacity-60` from `clickableTail`, not a colour swap.\n colorClasses = isClickable ? `${ASSISTANT_COLORS}${clickableTail}` : ASSISTANT_COLORS;\n } else if (!interactive) {\n colorClasses = STATIC_COLORS;\n } else if (selected) {\n colorClasses = isInteractiveLook\n ? `${variantBlock.selected}${clickableTail}`\n : variantBlock.selected;\n } else if (isInteractiveLook) {\n colorClasses = `${variantBlock.base} ${variantBlock.hover}${clickableTail}`;\n } else {\n colorClasses = variantBlock.base;\n }\n\n const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed pointer-events-none' : '';\n\n const merged = `${BASE_CLASSES} ${SHAPE_CLASSES[shape]} ${sizeBlock.text} ${padding} ${TONE_BORDER_CLASSES[tone]} ${colorClasses} ${disabledClasses} ${className}`;\n\n const iconSlot = icon ? (\n <span className=\"inline-flex items-center justify-center w-4 h-4 shrink-0 [&>img]:max-w-full [&>img]:max-h-full [&>img]:object-contain\">\n {icon}\n </span>\n ) : null;\n\n const trailingSlot = trailingIcon ? (\n <span className=\"inline-flex shrink-0 items-center justify-center\">{trailingIcon}</span>\n ) : null;\n\n // An anchor cannot be disabled, so a disabled link pill falls through to the static one.\n if (isClickable && linkHref) {\n return (\n <a\n href={linkHref}\n target={target}\n rel={resolveRel(rel, target)}\n className={`${FOCUS_RING} ${merged} no-underline`}\n onClick={onClick}\n >\n {iconSlot}\n {label}\n {trailingSlot}\n </a>\n );\n }\n\n if (isClickable) {\n return (\n <button type=\"button\" className={`${FOCUS_RING} ${merged}`} onClick={onClick}>\n {iconSlot}\n {label}\n {trailingSlot}\n </button>\n );\n }\n\n return (\n <div className={merged}>\n {iconSlot}\n {label}\n {trailingSlot}\n </div>\n );\n};\n\nexport default PillButton;\n"],"names":["BASE_CLASSES","SHAPE_CLASSES","TONE_BORDER_CLASSES","ASSISTANT_COLORS","SIZE_CLASSES","STATIC_COLORS","CLICKABLE_TAIL","VARIANT_COLORS","PillButton","label","icon","className","selected","disabled","interactive","size","variant","shape","tone","trailingIcon","onClick","href","target","rel","sizeBlock","padding","variantBlock","isInteractiveLook","linkHref","safeHref","isClickable","clickableTail","colorClasses","disabledClasses","merged","iconSlot","jsx","trailingSlot","jsxs","resolveRel","FOCUS_RING"],"mappings":";;;;AAsCA,MAAMA,IACF,qIAEEC,IAAiD;AAAA,EACnD,MAAM;AAAA,EACN,KAAK;AACT,GAKMC,IAAsD;AAAA,EACxD,SAAS;AAAA,EACT,WAAW;AACf,GAEMC,IACF,sFAEEC,IAGF;AAAA;AAAA;AAAA,EAGA,QAAQ;AAAA,IACJ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,iBAAiB;AAAA,EAAA;AAAA,EAErB,OAAO;AAAA,IACH,MAAM;AAAA,IACN,SAAS;AAAA,IACT,iBAAiB;AAAA,EAAA;AAAA,EAErB,QAAQ;AAAA,IACJ,MAAM;AAAA,IACN,SAAS;AAAA,IACT,iBAAiB;AAAA,EAAA;AAEzB,GAEMC,IACF,2GAEEC,IAAiB,oCAEjBC,IACF;AAAA,EACI,SAAS;AAAA,IACL,MAAM;AAAA,IACN,UACI;AAAA,IACJ,OAAO;AAAA,EAAA;AAAA,EAEX,UAAU;AAAA,IACN,MAAM;AAAA,IACN,UACI;AAAA,IACJ,OAAO;AAAA,EAAA;AAEf,GAESC,IAAwC,CAAC;AAAA,EAClD,OAAAC,IAAQ;AAAA,EACR,MAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,UAAAC,IAAW;AAAA,EACX,UAAAC,IAAW;AAAA,EACX,aAAAC,IAAc;AAAA,EACd,MAAAC,IAAO;AAAA,EACP,SAAAC,IAAU;AAAA,EACV,OAAAC,IAAQ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AAe;AAAA,QACA1B;AAAA,QACA4B;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,IAKTP,IAEI,gBAAAQ,EAAC,UAAA,EAAO,MAAK,UAAS,WAAW,GAAGE,CAAU,IAAIN,CAAM,IAAI,SAAAd,GACvD,UAAA;AAAA,IAAAe;AAAA,IACA1B;AAAA,IACA4B;AAAA,EAAA,GACL,IAKJ,gBAAAC,EAAC,OAAA,EAAI,WAAWJ,GACX,UAAA;AAAA,IAAAC;AAAA,IACA1B;AAAA,IACA4B;AAAA,EAAA,GACL;AAER;"}
@@ -67,7 +67,7 @@ const N = {
67
67
  },
68
68
  className: `${w} ${j} ${d.text} ${d.item} ${i} ${x ? "flex-1" : ""} ${e.disabled && !r ? "opacity-50 cursor-not-allowed" : ""}`,
69
69
  style: {
70
- // Inline rather than a `shadow-[...]` class: Tailwind's shadow
70
+ // Inline rather than a Tailwind shadow class: Tailwind's shadow
71
71
  // utilities compose `--tw-shadow-*` custom properties that rely on
72
72
  // document-level @property registration and silently don't paint
73
73
  // inside a shadow root (same caveat as `ring-*`).
@@ -1 +1 @@
1
- {"version":3,"file":"SegmentedControl.js","sources":["../../src/components/SegmentedControl.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport { FOCUS_RING } from './focusRing';\nimport { nextRovingIndex, rovingTabStop } from './rovingKeys';\n\ntype SegmentedControlSize = 'small' | 'medium' | 'large';\n\ninterface SegmentedControlOption<T extends string = string> {\n value: T;\n label: string;\n icon?: React.ReactNode;\n /**\n * Small mark after the label, e.g. a compact `Tag` naming a saving. It renders inside\n * the segment's `<button>`, so it must not be interactive — no `onClick` or `onRemove`.\n */\n badge?: React.ReactNode;\n disabled?: boolean;\n}\n\ninterface SegmentedControlProps<T extends string = string> {\n options: SegmentedControlOption<T>[];\n /** The selected option's value. A value not present in `options` renders nothing selected. */\n value: T;\n onChange: (value: T) => void;\n size?: SegmentedControlSize;\n /** Stretch the track to its container and split it into equal segments. */\n fullWidth?: boolean;\n /** Disables every segment. Individual segments can also be disabled via `options`. */\n disabled?: boolean;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n}\n\n// The ladder governs a control's outer box. The height therefore sits on the track and\n// the items fill whatever the 4px inset leaves — putting it on the item instead makes a\n// `medium` segmented control 40px tall beside a 32px Dropdown.\nconst SIZE_CLASSES: Record<SegmentedControlSize, { text: string; track: string; item: string }> = {\n small: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-small,28px)]',\n item: 'h-full px-2.5',\n },\n medium: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-medium,32px)]',\n item: 'h-full px-2.5',\n },\n large: {\n text: 'text-[length:var(--malachite-font-size-15,15px)]',\n track: 'h-[var(--malachite-control-height-large,42px)]',\n item: 'h-full px-4',\n },\n};\n\n// Deliberately no `bg-*` here: each state branch below supplies exactly one\n// background-color utility. Both `bg-transparent` and `bg-[var(--…)]` are plain\n// single-class utilities in the same `@layer utilities`, so an element carrying both\n// resolves by stylesheet order — and the arbitrary value loses, silently rendering the\n// selected thumb transparent.\nconst ITEM_BASE =\n 'inline-flex items-center justify-center gap-1.5 rounded-[var(--malachite-radius-10,10px)] border-0 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ease-in-out';\n\n/**\n * A rounded track of mutually-exclusive options — the segmented \"one of these\" control.\n *\n * Owns the track background, the selected-thumb chrome and the radiogroup semantics in\n * one place, so consumers never hand-roll a track around `PillButton` (whose `default`\n * variant tokens are tuned for standalone filter pills, not for a sunken track).\n *\n * Selection is conveyed non-visually via `role=\"radio\"` + `aria-checked`, and by a\n * foreground-colour change as well as the thumb, so it does not rest on background\n * colour alone.\n */\nconst SegmentedControl = <T extends string = string>({\n options,\n value,\n onChange,\n size = 'medium',\n fullWidth = false,\n disabled = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n}: SegmentedControlProps<T>) => {\n const itemRefs = useRef<(HTMLButtonElement | null)[]>([]);\n const sizeBlock = SIZE_CLASSES[size];\n\n const selectedIndex = options.findIndex((option) => option.value === value);\n const enabled = options.map((option) => !option.disabled);\n // Roving tabindex: the group is a single tab stop. When the selected option is\n // missing or disabled, the first enabled option takes the stop so the control is\n // still reachable by keyboard.\n const tabStopIndex = rovingTabStop(selectedIndex, enabled);\n\n // Arrow keys move AND select, per the WAI-ARIA radiogroup pattern, from the focused option.\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (disabled) {\n return;\n }\n const focused = itemRefs.current.findIndex((item) => item === event.target);\n const next = nextRovingIndex(event, focused >= 0 ? focused : tabStopIndex, enabled);\n if (next === undefined) {\n return;\n }\n\n // Only once we know we'll act — otherwise Home/End etc. should still scroll.\n event.preventDefault();\n if (options[next].value !== value) {\n onChange(options[next].value);\n }\n itemRefs.current[next]?.focus();\n };\n\n return (\n <div\n role=\"radiogroup\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-disabled={disabled || undefined}\n onKeyDown={handleKeyDown}\n className={`${\n // One display utility, not two: `flex` and `inline-flex` are both plain\n // `display` utilities, so emitting both would resolve by stylesheet order\n // (same hazard as the background above).\n fullWidth ? 'flex w-full' : 'inline-flex'\n } ${sizeBlock.track} items-center gap-1 p-0.5 rounded-xl bg-[var(--malachite-segmented-control-track-background)] ${\n disabled ? 'opacity-50' : ''\n } ${className}`}\n >\n {options.map((option, index) => {\n const isSelected = option.value === value;\n const isDisabled = disabled || option.disabled;\n const hasBadge =\n option.badge !== undefined && option.badge !== null && option.badge !== false;\n\n let colorClasses: string;\n if (isSelected) {\n colorClasses =\n 'bg-[var(--malachite-segmented-control-selected-background)] text-[var(--malachite-segmented-control-selected-foreground)]';\n } else if (isDisabled) {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)]';\n } else {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)] hover:text-[var(--malachite-segmented-control-item-hover-foreground)] cursor-pointer';\n }\n\n return (\n <button\n key={option.value}\n ref={(element) => {\n itemRefs.current[index] = element;\n }}\n type=\"button\"\n role=\"radio\"\n aria-checked={isSelected}\n disabled={isDisabled}\n tabIndex={index === tabStopIndex ? 0 : -1}\n onClick={() => {\n // Radios don't toggle off on re-click.\n if (!isDisabled && !isSelected) {\n onChange(option.value);\n }\n }}\n className={`${FOCUS_RING} ${ITEM_BASE} ${sizeBlock.text} ${sizeBlock.item} ${colorClasses} ${\n fullWidth ? 'flex-1' : ''\n } ${option.disabled && !disabled ? 'opacity-50 cursor-not-allowed' : ''}`}\n style={{\n // Inline rather than a `shadow-[...]` class: Tailwind's shadow\n // utilities compose `--tw-shadow-*` custom properties that rely on\n // document-level @property registration and silently don't paint\n // inside a shadow root (same caveat as `ring-*`).\n boxShadow: isSelected\n ? 'var(--malachite-segmented-control-selected-shadow, 0px 1px 5px 0px rgba(0, 0, 0, 0.1))'\n : undefined,\n }}\n >\n {option.icon ? (\n <span className=\"inline-flex items-center justify-center w-4 h-4 shrink-0\">\n {option.icon}\n </span>\n ) : null}\n {option.label}\n {/* The space keeps the name \"Annual Save\" rather than \"AnnualSave\";\n the flex gap already spaces the two visually. */}\n {hasBadge ? ' ' : null}\n {hasBadge ? (\n <span className=\"inline-flex items-center shrink-0\">\n {option.badge}\n </span>\n ) : null}\n </button>\n );\n })}\n </div>\n );\n};\n\nexport default SegmentedControl;\nexport { SegmentedControl };\nexport type { SegmentedControlProps, SegmentedControlOption, SegmentedControlSize };\n"],"names":["SIZE_CLASSES","ITEM_BASE","SegmentedControl","options","value","onChange","size","fullWidth","disabled","ariaLabel","ariaLabelledBy","className","itemRefs","useRef","sizeBlock","selectedIndex","option","enabled","tabStopIndex","rovingTabStop","jsx","event","focused","item","next","nextRovingIndex","_a","index","isSelected","isDisabled","hasBadge","colorClasses","jsxs","element","FOCUS_RING"],"mappings":";;;;AAoCA,MAAMA,IAA4F;AAAA,EAC9F,OAAO;AAAA,IACH,MAAM;AAAA,I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EAAA;AAGb;"}
1
+ {"version":3,"file":"SegmentedControl.js","sources":["../../src/components/SegmentedControl.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport { FOCUS_RING } from './focusRing';\nimport { nextRovingIndex, rovingTabStop } from './rovingKeys';\n\ntype SegmentedControlSize = 'small' | 'medium' | 'large';\n\ninterface SegmentedControlOption<T extends string = string> {\n value: T;\n label: string;\n icon?: React.ReactNode;\n /**\n * Small mark after the label, e.g. a compact `Tag` naming a saving. It renders inside\n * the segment's `<button>`, so it must not be interactive — no `onClick` or `onRemove`.\n */\n badge?: React.ReactNode;\n disabled?: boolean;\n}\n\ninterface SegmentedControlProps<T extends string = string> {\n options: SegmentedControlOption<T>[];\n /** The selected option's value. A value not present in `options` renders nothing selected. */\n value: T;\n onChange: (value: T) => void;\n size?: SegmentedControlSize;\n /** Stretch the track to its container and split it into equal segments. */\n fullWidth?: boolean;\n /** Disables every segment. Individual segments can also be disabled via `options`. */\n disabled?: boolean;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n}\n\n// The ladder governs a control's outer box. The height therefore sits on the track and\n// the items fill whatever the 4px inset leaves — putting it on the item instead makes a\n// `medium` segmented control 40px tall beside a 32px Dropdown.\nconst SIZE_CLASSES: Record<SegmentedControlSize, { text: string; track: string; item: string }> = {\n small: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-small,28px)]',\n item: 'h-full px-2.5',\n },\n medium: {\n text: 'text-[length:var(--malachite-font-size-small,13px)]',\n track: 'h-[var(--malachite-control-height-medium,32px)]',\n item: 'h-full px-2.5',\n },\n large: {\n text: 'text-[length:var(--malachite-font-size-15,15px)]',\n track: 'h-[var(--malachite-control-height-large,42px)]',\n item: 'h-full px-4',\n },\n};\n\n// Deliberately no `bg-*` here: each state branch below supplies exactly one\n// background-color utility. Both `bg-transparent` and an arbitrary-value `bg-` are plain\n// single-class utilities in the same `@layer utilities`, so an element carrying both\n// resolves by stylesheet order — and the arbitrary value loses, silently rendering the\n// selected thumb transparent.\nconst ITEM_BASE =\n 'inline-flex items-center justify-center gap-1.5 rounded-[var(--malachite-radius-10,10px)] border-0 font-medium tracking-[0.13px] whitespace-nowrap transition-colors duration-150 ease-in-out';\n\n/**\n * A rounded track of mutually-exclusive options — the segmented \"one of these\" control.\n *\n * Owns the track background, the selected-thumb chrome and the radiogroup semantics in\n * one place, so consumers never hand-roll a track around `PillButton` (whose `default`\n * variant tokens are tuned for standalone filter pills, not for a sunken track).\n *\n * Selection is conveyed non-visually via `role=\"radio\"` + `aria-checked`, and by a\n * foreground-colour change as well as the thumb, so it does not rest on background\n * colour alone.\n */\nconst SegmentedControl = <T extends string = string>({\n options,\n value,\n onChange,\n size = 'medium',\n fullWidth = false,\n disabled = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n}: SegmentedControlProps<T>) => {\n const itemRefs = useRef<(HTMLButtonElement | null)[]>([]);\n const sizeBlock = SIZE_CLASSES[size];\n\n const selectedIndex = options.findIndex((option) => option.value === value);\n const enabled = options.map((option) => !option.disabled);\n // Roving tabindex: the group is a single tab stop. When the selected option is\n // missing or disabled, the first enabled option takes the stop so the control is\n // still reachable by keyboard.\n const tabStopIndex = rovingTabStop(selectedIndex, enabled);\n\n // Arrow keys move AND select, per the WAI-ARIA radiogroup pattern, from the focused option.\n const handleKeyDown = (event: React.KeyboardEvent) => {\n if (disabled) {\n return;\n }\n const focused = itemRefs.current.findIndex((item) => item === event.target);\n const next = nextRovingIndex(event, focused >= 0 ? focused : tabStopIndex, enabled);\n if (next === undefined) {\n return;\n }\n\n // Only once we know we'll act — otherwise Home/End etc. should still scroll.\n event.preventDefault();\n if (options[next].value !== value) {\n onChange(options[next].value);\n }\n itemRefs.current[next]?.focus();\n };\n\n return (\n <div\n role=\"radiogroup\"\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n aria-disabled={disabled || undefined}\n onKeyDown={handleKeyDown}\n className={`${\n // One display utility, not two: `flex` and `inline-flex` are both plain\n // `display` utilities, so emitting both would resolve by stylesheet order\n // (same hazard as the background above).\n fullWidth ? 'flex w-full' : 'inline-flex'\n } ${sizeBlock.track} items-center gap-1 p-0.5 rounded-xl bg-[var(--malachite-segmented-control-track-background)] ${\n disabled ? 'opacity-50' : ''\n } ${className}`}\n >\n {options.map((option, index) => {\n const isSelected = option.value === value;\n const isDisabled = disabled || option.disabled;\n const hasBadge =\n option.badge !== undefined && option.badge !== null && option.badge !== false;\n\n let colorClasses: string;\n if (isSelected) {\n colorClasses =\n 'bg-[var(--malachite-segmented-control-selected-background)] text-[var(--malachite-segmented-control-selected-foreground)]';\n } else if (isDisabled) {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)]';\n } else {\n colorClasses =\n 'bg-transparent text-[var(--malachite-segmented-control-item-foreground)] hover:text-[var(--malachite-segmented-control-item-hover-foreground)] cursor-pointer';\n }\n\n return (\n <button\n key={option.value}\n ref={(element) => {\n itemRefs.current[index] = element;\n }}\n type=\"button\"\n role=\"radio\"\n aria-checked={isSelected}\n disabled={isDisabled}\n tabIndex={index === tabStopIndex ? 0 : -1}\n onClick={() => {\n // Radios don't toggle off on re-click.\n if (!isDisabled && !isSelected) {\n onChange(option.value);\n }\n }}\n className={`${FOCUS_RING} ${ITEM_BASE} ${sizeBlock.text} ${sizeBlock.item} ${colorClasses} ${\n fullWidth ? 'flex-1' : ''\n } ${option.disabled && !disabled ? 'opacity-50 cursor-not-allowed' : ''}`}\n style={{\n // Inline rather than a Tailwind shadow class: Tailwind's shadow\n // utilities compose `--tw-shadow-*` custom properties that rely on\n // document-level @property registration and silently don't paint\n // inside a shadow root (same caveat as `ring-*`).\n boxShadow: isSelected\n ? 'var(--malachite-segmented-control-selected-shadow, 0px 1px 5px 0px rgba(0, 0, 0, 0.1))'\n : undefined,\n }}\n >\n {option.icon ? (\n <span className=\"inline-flex items-center justify-center w-4 h-4 shrink-0\">\n {option.icon}\n </span>\n ) : null}\n {option.label}\n {/* The space keeps the name \"Annual Save\" rather than \"AnnualSave\";\n the flex gap already spaces the two visually. */}\n {hasBadge ? ' ' : null}\n {hasBadge ? (\n <span className=\"inline-flex items-center shrink-0\">\n {option.badge}\n </span>\n ) : null}\n </button>\n );\n })}\n </div>\n );\n};\n\nexport default SegmentedControl;\nexport { SegmentedControl };\nexport type { SegmentedControlProps, SegmentedControlOption, SegmentedControlSize };\n"],"names":["SIZE_CLASSES","ITEM_BASE","SegmentedControl","options","value","onChange","size","fullWidth","disabled","ariaLabel","ariaLabelledBy","className","itemRefs","useRef","sizeBlock","selectedIndex","option","enabled","tabStopIndex","rovingTabStop","jsx","event","focused","item","next","nextRovingIndex","_a","index","isSelected","isDisabled","hasBadge","colorClasses","jsxs","element","FOCUS_RING"],"mappings":";;;;AAoCA,MAAMA,IAA4F;AAAA,EAC9F,OAAO;AAAA,IACH,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAAA,EAEV,QAAQ;AAAA,IACJ,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAAA,EAEV,OAAO;AAAA,IACH,MAAM;AAAA,IACN,OAAO;AAAA,IACP,MAAM;AAAA,EAAA;AAEd,GAOMC,IACF,iMAaEC,IAAmB,CAA4B;AAAA,EACjD,SAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,WAAAC,IAAY;AAAA,EACZ,UAAAC,IAAW;AAAA,EACX,cAAcC;AAAA,EACd,mBAAmBC;AAAA,EACnB,WAAAC,IAAY;AAChB,MAAgC;AAC5B,QAAMC,IAAWC,EAAqC,EAAE,GAClDC,IAAYd,EAAaM,CAAI,GAE7BS,IAAgBZ,EAAQ,UAAU,CAACa,MAAWA,EAAO,UAAUZ,CAAK,GACpEa,IAAUd,EAAQ,IAAI,CAACa,MAAW,CAACA,EAAO,QAAQ,GAIlDE,IAAeC,EAAcJ,GAAeE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