@stackone/malachite 2.100.1 → 2.101.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
@@ -101,6 +101,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
101
101
  - **`Keycap`** — One key on a keyboard, drawn as a cap — `esc`, `⌘`, a caret, or a sigil a user types to scope a search. Renders a `<kbd>`, or a button as soon as either `onClick` or `disabled` is passed — `disabled={false}` included, since naming the prop at all is the statement that the cap is a control. `SidePanelNavFooter` is built on it.
102
102
  - **`CollapsibleSection`** — Collapsible sunken-card section (title - subtitle header, disclosure arrow right) for stacked detail sections in side panels and detail pages. A preset over `Accordion`’s `sunken` variant.
103
103
  - **`KeyValueList`** — Bordered card of label/value rows (`KeyValueList.Row`) for entity details: fixed-width secondary labels, free-form values, row dividers. `truncate` keeps a long value (an ID) to one line with an ellipsis at the cell width and a tooltip only when it is actually cut off — the value itself when it is text, else the row’s `tooltip` (`null` turns it off). For inline content only: a Tag or AppLogo is clipped without an ellipsis, so use its own truncate, as with `CodeText truncate`. `size="small"` tightens the rows for a list inside a dialog or panel. _Key props:_ `size` (`small` | `medium`), `label`, `truncate`, `tooltip`.
104
+ - **`KeyValueStrip`** — Label/value cells side by side in one sunken band, divided by rules (`KeyValueStrip.Item`), for the facts under a side panel’s header. Cells share the width equally and text values are small, in medium weight. `truncate` keeps a value to one line with an ellipsis and, for text, a tooltip only when it is cut off; with `truncate`, a given `tooltip` always shows, since it may say more than the value (a full id behind a shortened one), and `null` turns it off. `prefix` (an icon) and `suffix` (a copy button) stay whole while the value truncates. For a vertical list of rows use `KeyValueList`. _Key props:_ `aria-label`, `label`, `truncate`, `tooltip`, `prefix`, `suffix`.
104
105
 
105
106
  ## Buttons & actions
106
107
 
@@ -135,7 +136,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
135
136
  ## Typography
136
137
 
137
138
  - **`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.
138
- - **`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`.
139
+ - **`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. `tooltipDelay` sets the seconds before it opens, and `focusableTrigger` makes the text a tab stop that opens it on focus, for a tooltip that says what the text does not (ignored with `tooltipWhenTruncated`). `inline` wraps the text in a span rather than a div, for inside a clickable `Surface.Row`.
139
140
 
140
141
  ## Theming & utility
141
142
 
@@ -1,7 +1,8 @@
1
- import { jsx as a, jsxs as x } from "react/jsx-runtime";
2
- import { createContext as s, useContext as p, Children as n } from "react";
3
- import m from "./Typography/EllipsisText.js";
4
- const c = {
1
+ import { jsx as r, jsxs as x } from "react/jsx-runtime";
2
+ import { createContext as m, useContext as p } from "react";
3
+ import s from "./Typography/EllipsisText.js";
4
+ import { textOf as c } from "./childrenText.js";
5
+ const n = {
5
6
  small: {
6
7
  row: "min-h-[36px]",
7
8
  label: "w-[140px] px-[12px] py-[8px]",
@@ -12,61 +13,58 @@ const c = {
12
13
  label: "w-[200px] p-[16px]",
13
14
  value: "py-[16px] pr-[16px]"
14
15
  }
15
- }, i = s("medium"), u = (e) => typeof e == "string" || typeof e == "number", b = (e) => {
16
- const r = n.toArray(e);
17
- return r.length > 0 && r.every(u) ? r.join("") : void 0;
18
- }, f = ({
19
- label: e,
20
- className: r = "",
21
- children: t,
22
- truncate: d = !1,
16
+ }, d = m("medium"), b = ({
17
+ label: t,
18
+ className: a = "",
19
+ children: e,
20
+ truncate: i = !1,
23
21
  tooltip: o
24
22
  }) => {
25
- const l = c[p(i)];
23
+ const l = n[p(d)];
26
24
  return /* @__PURE__ */ x(
27
25
  "div",
28
26
  {
29
- className: `flex ${l.row} w-full items-start border-0 border-b border-solid border-[var(--malachite-card-border)] last:border-b-0 ${r}`,
27
+ className: `flex ${l.row} w-full items-start border-0 border-b border-solid border-[var(--malachite-card-border)] last:border-b-0 ${a}`,
30
28
  children: [
31
- /* @__PURE__ */ a(
29
+ /* @__PURE__ */ r(
32
30
  "dt",
33
31
  {
34
32
  className: `m-0 shrink-0 ${l.label} text-[13px] leading-[1.6] tracking-[0.13px] text-[var(--malachite-text-secondary)]`,
35
- children: e
33
+ children: t
36
34
  }
37
35
  ),
38
- /* @__PURE__ */ a(
36
+ /* @__PURE__ */ r(
39
37
  "dd",
40
38
  {
41
39
  className: `m-0 flex min-w-0 flex-1 flex-wrap items-center gap-[6px] ${l.value} text-[13px] leading-[1.6] tracking-[0.13px] text-[var(--malachite-text-primary)]`,
42
- children: d ? /* @__PURE__ */ a(
43
- m,
40
+ children: i ? /* @__PURE__ */ r(
41
+ s,
44
42
  {
45
43
  maxWidth: "100%",
46
- tooltip: o !== void 0 ? o : b(t),
44
+ tooltip: o !== void 0 ? o : c(e),
47
45
  tooltipWhenTruncated: !0,
48
- children: t
46
+ children: e
49
47
  }
50
- ) : t
48
+ ) : e
51
49
  }
52
50
  )
53
51
  ]
54
52
  }
55
53
  );
56
- }, h = ({
57
- className: e = "",
58
- children: r,
59
- size: t = "medium"
60
- }) => /* @__PURE__ */ a(i.Provider, { value: t, children: /* @__PURE__ */ a(
54
+ }, u = ({
55
+ className: t = "",
56
+ children: a,
57
+ size: e = "medium"
58
+ }) => /* @__PURE__ */ r(d.Provider, { value: e, children: /* @__PURE__ */ r(
61
59
  "dl",
62
60
  {
63
- className: `m-0 flex w-full flex-col overflow-hidden rounded-lg border border-solid border-[var(--malachite-card-border)] bg-[var(--malachite-card-background)] ${e}`,
64
- children: r
61
+ className: `m-0 flex w-full flex-col overflow-hidden rounded-lg border border-solid border-[var(--malachite-card-border)] bg-[var(--malachite-card-background)] ${t}`,
62
+ children: a
65
63
  }
66
64
  ) });
67
- h.Row = f;
65
+ u.Row = b;
68
66
  export {
69
- h as KeyValueList,
70
- h as default
67
+ u as KeyValueList,
68
+ u as default
71
69
  };
72
70
  //# sourceMappingURL=KeyValueList.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KeyValueList.js","sources":["../../src/components/KeyValueList.tsx"],"sourcesContent":["import React, { Children, createContext, useContext } from 'react';\nimport EllipsisText from './Typography/EllipsisText';\n\nexport type KeyValueListSize = 'small' | 'medium';\n\nexport interface KeyValueListProps {\n className?: string;\n children: React.ReactNode;\n /** `small` tightens the rows for a list inside a dialog or panel. */\n size?: KeyValueListSize;\n}\n\nexport interface KeyValueListRowProps {\n label: React.ReactNode;\n className?: string;\n children: React.ReactNode;\n /**\n * Keep the value to one line, cut with an ellipsis at the cell's width. For inline content:\n * block/flex children (Tag, AppLogo) are clipped without an ellipsis, so use their own truncate.\n */\n truncate?: boolean;\n /**\n * Shown on hover/focus when a `truncate` value is actually cut off. Defaults to the value\n * itself when it is text (strings/numbers); give one for any other value, or none is shown.\n * Pass `null` to turn the tooltip off.\n */\n tooltip?: React.ReactNode;\n}\n\nconst SIZE_ROW: Record<KeyValueListSize, { row: string; label: string; value: string }> = {\n small: {\n row: 'min-h-[36px]',\n label: 'w-[140px] px-[12px] py-[8px]',\n value: 'py-[8px] pr-[12px]',\n },\n medium: {\n row: 'min-h-[52px]',\n label: 'w-[200px] p-[16px]',\n value: 'py-[16px] pr-[16px]',\n },\n};\n\nconst SizeContext = createContext<KeyValueListSize>('medium');\n\nconst isText = (node: React.ReactNode): node is string | number =>\n typeof node === 'string' || typeof node === 'number';\n\nconst textOf = (children: React.ReactNode): string | undefined => {\n const parts = Children.toArray(children);\n return parts.length > 0 && parts.every(isText) ? parts.join('') : undefined;\n};\n\nconst Row: React.FC<KeyValueListRowProps> = ({\n label,\n className = '',\n children,\n truncate = false,\n tooltip,\n}) => {\n const size = SIZE_ROW[useContext(SizeContext)];\n return (\n <div\n className={`flex ${size.row} w-full items-start border-0 border-b border-solid border-[var(--malachite-card-border)] last:border-b-0 ${className}`}\n >\n <dt\n className={`m-0 shrink-0 ${size.label} text-[13px] leading-[1.6] tracking-[0.13px] text-[var(--malachite-text-secondary)]`}\n >\n {label}\n </dt>\n <dd\n className={`m-0 flex min-w-0 flex-1 flex-wrap items-center gap-[6px] ${size.value} text-[13px] leading-[1.6] tracking-[0.13px] text-[var(--malachite-text-primary)]`}\n >\n {truncate ? (\n <EllipsisText\n maxWidth=\"100%\"\n tooltip={tooltip !== undefined ? tooltip : textOf(children)}\n tooltipWhenTruncated\n >\n {children}\n </EllipsisText>\n ) : (\n children\n )}\n </dd>\n </div>\n );\n};\n\nconst KeyValueList: React.FC<KeyValueListProps> & { Row: typeof Row } = ({\n className = '',\n children,\n size = 'medium',\n}) => (\n <SizeContext.Provider value={size}>\n <dl\n className={`m-0 flex w-full flex-col overflow-hidden rounded-lg border border-solid border-[var(--malachite-card-border)] bg-[var(--malachite-card-background)] ${className}`}\n >\n {children}\n </dl>\n </SizeContext.Provider>\n);\n\nKeyValueList.Row = Row;\n\nexport default KeyValueList;\nexport { KeyValueList };\n"],"names":["SIZE_ROW","SizeContext","createContext","isText","node","textOf","children","parts","Children","Row","label","className","truncate","tooltip","size","useContext","jsxs","jsx","EllipsisText","KeyValueList"],"mappings":";;;AA6BA,MAAMA,IAAoF;AAAA,EACtF,OAAO;AAAA,IACH,KAAK;AAAA,IACL,OAAO;AAAA,IACP,OAAO;AAAA,EAAA;AAAA,EAEX,QAAQ;AAAA,IACJ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,OAAO;AAAA,EAAA;AAEf,GAEMC,IAAcC,EAAgC,QAAQ,GAEtDC,IAAS,CAACC,MACZ,OAAOA,KAAS,YAAY,OAAOA,KAAS,UAE1CC,IAAS,CAACC,MAAkD;AAC9D,QAAMC,IAAQC,EAAS,QAAQF,CAAQ;AACvC,SAAOC,EAAM,SAAS,KAAKA,EAAM,MAAMJ,CAAM,IAAII,EAAM,KAAK,EAAE,IAAI;AACtE,GAEME,IAAsC,CAAC;AAAA,EACzC,OAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,UAAAL;AAAA,EACA,UAAAM,IAAW;AAAA,EACX,SAAAC;AACJ,MAAM;AACF,QAAMC,IAAOd,EAASe,EAAWd,CAAW,CAAC;AAC7C,SACI,gBAAAe;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAW,QAAQF,EAAK,GAAG,4GAA4GH,CAAS;AAAA,MAEhJ,UAAA;AAAA,QAAA,gBAAAM;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,WAAW,gBAAgBH,EAAK,KAAK;AAAA,YAEpC,UAAAJ;AAAA,UAAA;AAAA,QAAA;AAAA,QAEL,gBAAAO;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,WAAW,4DAA4DH,EAAK,KAAK;AAAA,YAEhF,UAAAF,IACG,gBAAAK;AAAA,cAACC;AAAA,cAAA;AAAA,gBACG,UAAS;AAAA,gBACT,SAASL,MAAY,SAAYA,IAAUR,EAAOC,CAAQ;AAAA,gBAC1D,sBAAoB;AAAA,gBAEnB,UAAAA;AAAA,cAAA;AAAA,YAAA,IAGLA;AAAA,UAAA;AAAA,QAAA;AAAA,MAER;AAAA,IAAA;AAAA,EAAA;AAGZ,GAEMa,IAAkE,CAAC;AAAA,EACrE,WAAAR,IAAY;AAAA,EACZ,UAAAL;AAAA,EACA,MAAAQ,IAAO;AACX,MACI,gBAAAG,EAAChB,EAAY,UAAZ,EAAqB,OAAOa,GACzB,UAAA,gBAAAG;AAAA,EAAC;AAAA,EAAA;AAAA,IACG,WAAW,uJAAuJN,CAAS;AAAA,IAE1K,UAAAL;AAAA,EAAA;AACL,EAAA,CACJ;AAGJa,EAAa,MAAMV;"}
1
+ {"version":3,"file":"KeyValueList.js","sources":["../../src/components/KeyValueList.tsx"],"sourcesContent":["import React, { createContext, useContext } from 'react';\nimport EllipsisText from './Typography/EllipsisText';\nimport { textOf } from './childrenText';\n\nexport type KeyValueListSize = 'small' | 'medium';\n\nexport interface KeyValueListProps {\n className?: string;\n children: React.ReactNode;\n /** `small` tightens the rows for a list inside a dialog or panel. */\n size?: KeyValueListSize;\n}\n\nexport interface KeyValueListRowProps {\n label: React.ReactNode;\n className?: string;\n children: React.ReactNode;\n /**\n * Keep the value to one line, cut with an ellipsis at the cell's width. For inline content:\n * block/flex children (Tag, AppLogo) are clipped without an ellipsis, so use their own truncate.\n */\n truncate?: boolean;\n /**\n * Shown on hover/focus when a `truncate` value is actually cut off. Defaults to the value\n * itself when it is text (strings/numbers); give one for any other value, or none is shown.\n * Pass `null` to turn the tooltip off.\n */\n tooltip?: React.ReactNode;\n}\n\nconst SIZE_ROW: Record<KeyValueListSize, { row: string; label: string; value: string }> = {\n small: {\n row: 'min-h-[36px]',\n label: 'w-[140px] px-[12px] py-[8px]',\n value: 'py-[8px] pr-[12px]',\n },\n medium: {\n row: 'min-h-[52px]',\n label: 'w-[200px] p-[16px]',\n value: 'py-[16px] pr-[16px]',\n },\n};\n\nconst SizeContext = createContext<KeyValueListSize>('medium');\n\nconst Row: React.FC<KeyValueListRowProps> = ({\n label,\n className = '',\n children,\n truncate = false,\n tooltip,\n}) => {\n const size = SIZE_ROW[useContext(SizeContext)];\n return (\n <div\n className={`flex ${size.row} w-full items-start border-0 border-b border-solid border-[var(--malachite-card-border)] last:border-b-0 ${className}`}\n >\n <dt\n className={`m-0 shrink-0 ${size.label} text-[13px] leading-[1.6] tracking-[0.13px] text-[var(--malachite-text-secondary)]`}\n >\n {label}\n </dt>\n <dd\n className={`m-0 flex min-w-0 flex-1 flex-wrap items-center gap-[6px] ${size.value} text-[13px] leading-[1.6] tracking-[0.13px] text-[var(--malachite-text-primary)]`}\n >\n {truncate ? (\n <EllipsisText\n maxWidth=\"100%\"\n tooltip={tooltip !== undefined ? tooltip : textOf(children)}\n tooltipWhenTruncated\n >\n {children}\n </EllipsisText>\n ) : (\n children\n )}\n </dd>\n </div>\n );\n};\n\nconst KeyValueList: React.FC<KeyValueListProps> & { Row: typeof Row } = ({\n className = '',\n children,\n size = 'medium',\n}) => (\n <SizeContext.Provider value={size}>\n <dl\n className={`m-0 flex w-full flex-col overflow-hidden rounded-lg border border-solid border-[var(--malachite-card-border)] bg-[var(--malachite-card-background)] ${className}`}\n >\n {children}\n </dl>\n </SizeContext.Provider>\n);\n\nKeyValueList.Row = Row;\n\nexport default KeyValueList;\nexport { KeyValueList };\n"],"names":["SIZE_ROW","SizeContext","createContext","Row","label","className","children","truncate","tooltip","size","useContext","jsxs","jsx","EllipsisText","textOf","KeyValueList"],"mappings":";;;;AA8BA,MAAMA,IAAoF;AAAA,EACtF,OAAO;AAAA,IACH,KAAK;AAAA,IACL,OAAO;AAAA,IACP,OAAO;AAAA,EAAA;AAAA,EAEX,QAAQ;AAAA,IACJ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,OAAO;AAAA,EAAA;AAEf,GAEMC,IAAcC,EAAgC,QAAQ,GAEtDC,IAAsC,CAAC;AAAA,EACzC,OAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,UAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,SAAAC;AACJ,MAAM;AACF,QAAMC,IAAOT,EAASU,EAAWT,CAAW,CAAC;AAC7C,SACI,gBAAAU;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,WAAW,QAAQF,EAAK,GAAG,4GAA4GJ,CAAS;AAAA,MAEhJ,UAAA;AAAA,QAAA,gBAAAO;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,WAAW,gBAAgBH,EAAK,KAAK;AAAA,YAEpC,UAAAL;AAAA,UAAA;AAAA,QAAA;AAAA,QAEL,gBAAAQ;AAAA,UAAC;AAAA,UAAA;AAAA,YACG,WAAW,4DAA4DH,EAAK,KAAK;AAAA,YAEhF,UAAAF,IACG,gBAAAK;AAAA,cAACC;AAAA,cAAA;AAAA,gBACG,UAAS;AAAA,gBACT,SAASL,MAAY,SAAYA,IAAUM,EAAOR,CAAQ;AAAA,gBAC1D,sBAAoB;AAAA,gBAEnB,UAAAA;AAAA,cAAA;AAAA,YAAA,IAGLA;AAAA,UAAA;AAAA,QAAA;AAAA,MAER;AAAA,IAAA;AAAA,EAAA;AAGZ,GAEMS,IAAkE,CAAC;AAAA,EACrE,WAAAV,IAAY;AAAA,EACZ,UAAAC;AAAA,EACA,MAAAG,IAAO;AACX,MACI,gBAAAG,EAACX,EAAY,UAAZ,EAAqB,OAAOQ,GACzB,UAAA,gBAAAG;AAAA,EAAC;AAAA,EAAA;AAAA,IACG,WAAW,uJAAuJP,CAAS;AAAA,IAE1K,UAAAC;AAAA,EAAA;AACL,EAAA,CACJ;AAGJS,EAAa,MAAMZ;"}
@@ -0,0 +1,66 @@
1
+ import { jsx as e, jsxs as p } from "react/jsx-runtime";
2
+ import x from "./Typography/EllipsisText.js";
3
+ import f from "./Typography/Text.js";
4
+ import { textOf as b } from "./childrenText.js";
5
+ import { isRenderableNode as t } from "./renderableNode.js";
6
+ const h = 0.2, v = ({
7
+ label: o,
8
+ className: s = "",
9
+ children: l,
10
+ truncate: a = !1,
11
+ tooltip: r,
12
+ prefix: i,
13
+ suffix: n
14
+ }) => {
15
+ const m = r !== void 0, d = t(r) ? r : null, c = b(l);
16
+ return /* @__PURE__ */ p(
17
+ "div",
18
+ {
19
+ className: `flex min-w-0 flex-1 basis-0 flex-col gap-[3px] border-0 border-s border-solid border-[var(--malachite-card-border,#e8e8e8)] px-[18px] first:border-s-0 ${s}`,
20
+ children: [
21
+ /* @__PURE__ */ e("dt", { className: "m-0 min-w-0 break-words", children: /* @__PURE__ */ e(f, { size: "xsmall", color: "secondary", children: o }) }),
22
+ /* @__PURE__ */ p("dd", { className: "m-0 flex min-w-0 items-center text-[length:var(--malachite-font-size-small,13px)] leading-[1.5] font-medium text-[var(--malachite-text-primary,#0a0a0a)] [overflow-wrap:anywhere]", children: [
23
+ t(i) && /* @__PURE__ */ e("span", { className: "me-[8px] flex shrink-0 items-center", children: i }),
24
+ a ? /* @__PURE__ */ e(
25
+ x,
26
+ {
27
+ color: "inherit",
28
+ tooltip: m ? d : c,
29
+ tooltipWhenTruncated: !m,
30
+ tooltipDelay: h,
31
+ focusableTrigger: d !== null && !!c,
32
+ children: l
33
+ }
34
+ ) : /* @__PURE__ */ e("span", { className: "min-w-0", children: l }),
35
+ t(n) && /* @__PURE__ */ e("span", { className: "ms-[4px] flex shrink-0 items-center", children: n })
36
+ ] })
37
+ ]
38
+ }
39
+ );
40
+ }, u = ({
41
+ className: o = "",
42
+ children: s,
43
+ "aria-label": l,
44
+ "aria-labelledby": a
45
+ }) => {
46
+ const r = !!(l || a);
47
+ return (
48
+ // A role on the dl would drop its term/definition semantics.
49
+ /* @__PURE__ */ e(
50
+ "div",
51
+ {
52
+ role: r ? "group" : void 0,
53
+ "aria-label": r && l || void 0,
54
+ "aria-labelledby": r && a || void 0,
55
+ className: `w-full ${o}`,
56
+ children: /* @__PURE__ */ e("dl", { className: "m-0 flex w-full rounded-[10px] bg-[var(--malachite-table-background,#f7f7f7)] py-[11px]", children: s })
57
+ }
58
+ )
59
+ );
60
+ };
61
+ u.Item = v;
62
+ export {
63
+ u as KeyValueStrip,
64
+ u as default
65
+ };
66
+ //# sourceMappingURL=KeyValueStrip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeyValueStrip.js","sources":["../../src/components/KeyValueStrip.tsx"],"sourcesContent":["import type React from 'react';\nimport EllipsisText from './Typography/EllipsisText';\nimport Text from './Typography/Text';\nimport { textOf } from './childrenText';\nimport { isRenderableNode } from './renderableNode';\n\nexport interface KeyValueStripProps {\n className?: string;\n children: React.ReactNode;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n}\n\nexport interface KeyValueStripItemProps {\n label: React.ReactNode;\n className?: string;\n children: React.ReactNode;\n /** One line with an ellipsis. Block/flex children clip without one, so use their own truncate. */\n truncate?: boolean;\n /**\n * Needs `truncate`. By default a text value shows in full when cut off; a given tooltip always\n * shows and makes a text value a tab stop. `null` turns it off.\n */\n tooltip?: React.ReactNode;\n /** Before the value, never truncated, e.g. an icon. */\n prefix?: React.ReactNode;\n /** After the value, never truncated, e.g. a copy button. */\n suffix?: React.ReactNode;\n}\n\n// Faster than Tooltip's 1s: a strip is read by hovering along it.\nconst TOOLTIP_DELAY_S = 0.2;\n\nconst Item: React.FC<KeyValueStripItemProps> = ({\n label,\n className = '',\n children,\n truncate = false,\n tooltip,\n prefix,\n suffix,\n}) => {\n const ownTooltip = tooltip !== undefined;\n const given = isRenderableNode(tooltip) ? tooltip : null;\n const text = textOf(children);\n return (\n <div\n className={`flex min-w-0 flex-1 basis-0 flex-col gap-[3px] border-0 border-s border-solid border-[var(--malachite-card-border,#e8e8e8)] px-[18px] first:border-s-0 ${className}`}\n >\n <dt className=\"m-0 min-w-0 break-words\">\n <Text size=\"xsmall\" color=\"secondary\">\n {label}\n </Text>\n </dt>\n <dd className=\"m-0 flex min-w-0 items-center text-[length:var(--malachite-font-size-small,13px)] leading-[1.5] font-medium text-[var(--malachite-text-primary,#0a0a0a)] [overflow-wrap:anywhere]\">\n {isRenderableNode(prefix) && (\n <span className=\"me-[8px] flex shrink-0 items-center\">{prefix}</span>\n )}\n {truncate ? (\n <EllipsisText\n color=\"inherit\"\n tooltip={ownTooltip ? given : text}\n tooltipWhenTruncated={!ownTooltip}\n tooltipDelay={TOOLTIP_DELAY_S}\n focusableTrigger={given !== null && !!text}\n >\n {children}\n </EllipsisText>\n ) : (\n <span className=\"min-w-0\">{children}</span>\n )}\n {isRenderableNode(suffix) && (\n <span className=\"ms-[4px] flex shrink-0 items-center\">{suffix}</span>\n )}\n </dd>\n </div>\n );\n};\n\n/**\n * Label/value cells in one sunken band, e.g. the facts under a side panel header. Not for table\n * rows: a given tooltip mounts up front.\n */\nconst KeyValueStrip: React.FC<KeyValueStripProps> & { Item: typeof Item } = ({\n className = '',\n children,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n}) => {\n const named = !!(ariaLabel || ariaLabelledBy);\n return (\n // A role on the dl would drop its term/definition semantics.\n <div\n role={named ? 'group' : undefined}\n aria-label={named ? ariaLabel || undefined : undefined}\n aria-labelledby={named ? ariaLabelledBy || undefined : undefined}\n className={`w-full ${className}`}\n >\n <dl className=\"m-0 flex w-full rounded-[10px] bg-[var(--malachite-table-background,#f7f7f7)] py-[11px]\">\n {children}\n </dl>\n </div>\n );\n};\n\nKeyValueStrip.Item = Item;\n\nexport default KeyValueStrip;\nexport { KeyValueStrip };\n"],"names":["TOOLTIP_DELAY_S","Item","label","className","children","truncate","tooltip","prefix","suffix","ownTooltip","given","isRenderableNode","text","textOf","jsxs","jsx","Text","EllipsisText","KeyValueStrip","ariaLabel","ariaLabelledBy","named"],"mappings":";;;;;AA+BA,MAAMA,IAAkB,KAElBC,IAAyC,CAAC;AAAA,EAC5C,OAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,UAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,SAAAC;AAAA,EACA,QAAAC;AAAA,EACA,QAAAC;AACJ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KAAkB;AAAA,QAC3C,WAAW,UAAUjB,CAAS;AAAA,QAE9B,UAAA,gBAAAY,EAAC,MAAA,EAAG,WAAU,2FACT,UAAAX,EAAA,CACL;AAAA,MAAA;AAAA,IAAA;AAAA;AAGZ;AAEAc,EAAc,OAAOjB;"}
@@ -1,20 +1,20 @@
1
- import { jsx as m, jsxs as G, Fragment as ae } from "react/jsx-runtime";
2
- import F, { useState as y, useRef as u, useCallback as z, useId as se, useEffect as b, useInsertionEffect as le } from "react";
3
- import { createPortal as ce } from "react-dom";
4
- import { FOCUS_RING as fe } from "./focusRing.js";
5
- import { ensureOverlayStyles as de, overlayIdentity as ue } from "./portalOverlay.js";
6
- import { useTopLayer as me } from "./topLayer.js";
7
- import { useFollowTrigger as pe } from "./useFollowTrigger.js";
8
- const he = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), ge = (r) => r.split(he).map((a, w) => /* @__PURE__ */ G(F.Fragment, { children: [
1
+ import { jsx as m, jsxs as G, Fragment as se } from "react/jsx-runtime";
2
+ import F, { useState as y, useRef as u, useCallback as z, useId as le, useEffect as b, useInsertionEffect as ce } from "react";
3
+ import { createPortal as fe } from "react-dom";
4
+ import { FOCUS_RING as de } from "./focusRing.js";
5
+ import { ensureOverlayStyles as ue, overlayIdentity as me } from "./portalOverlay.js";
6
+ import { useTopLayer as pe } from "./topLayer.js";
7
+ import { useFollowTrigger as he } from "./useFollowTrigger.js";
8
+ const ge = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), ve = (r) => r.split(ge).map((a, w) => /* @__PURE__ */ G(F.Fragment, { children: [
9
9
  a,
10
10
  /* @__PURE__ */ m("wbr", {})
11
- ] }, w)), ve = {
11
+ ] }, w)), ye = {
12
12
  minWidth: 0,
13
13
  overflow: "hidden"
14
14
  }, U = {
15
15
  flex: 1,
16
16
  minWidth: 0
17
- }, Y = 8, Ie = ({
17
+ }, Y = 8, Le = ({
18
18
  text: r,
19
19
  children: a,
20
20
  delay: w = 1,
@@ -31,38 +31,38 @@ const he = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), ge = (r) => r.split(he).map((a
31
31
  showOnFocus: c = !0,
32
32
  focusableTrigger: h = !1
33
33
  }) => {
34
- const X = $ || R ? { ...$ ? ve : {}, ...R ? U : {} } : void 0, [t, f] = y(!1), [g, D] = y(h), v = u(null), s = u(null), n = z(() => {
34
+ const X = $ || R ? { ...$ ? ye : {}, ...R ? U : {} } : void 0, [t, f] = y(!1), [D, J] = y(!1), g = D || h, v = u(null), s = u(null), n = z(() => {
35
35
  v.current && (clearTimeout(v.current), v.current = null), s.current !== null && (cancelAnimationFrame(s.current), s.current = null);
36
36
  }, []), B = () => {
37
- D(!0), s.current !== null && cancelAnimationFrame(s.current), s.current = requestAnimationFrame(() => {
37
+ J(!0), s.current !== null && cancelAnimationFrame(s.current), s.current = requestAnimationFrame(() => {
38
38
  s.current = null, f(!0);
39
39
  });
40
40
  }, E = u(null), d = u(null);
41
- me(E, t);
42
- const _ = se(), l = r != null && r !== "" && r !== !1, J = (e) => {
41
+ pe(E, t);
42
+ const M = le(), l = r != null && r !== "" && r !== !1, Q = (e) => {
43
43
  e.stopPropagation(), !(!l || o || p && !p()) && (n(), v.current = setTimeout(() => {
44
44
  B();
45
45
  }, w * 1e3));
46
- }, Q = (e) => {
46
+ }, Z = (e) => {
47
47
  e.stopPropagation(), n(), f(!1);
48
- }, M = () => {
48
+ }, _ = () => {
49
49
  !c || !l || o || p && !p() || (n(), B());
50
- }, Z = () => {
50
+ }, ee = () => {
51
51
  n(), f(!1);
52
52
  }, C = u(c);
53
53
  b(() => {
54
54
  var i;
55
55
  const e = c && !C.current;
56
- C.current = c, e && ((i = d.current) != null && i.matches(":focus-within")) && M();
56
+ C.current = c, e && ((i = d.current) != null && i.matches(":focus-within")) && _();
57
57
  });
58
- const [ee, te] = y(o);
59
- o !== ee && (te(o), o && f(!1)), b(() => {
58
+ const [te, ne] = y(o);
59
+ o !== te && (ne(o), o && f(!1)), b(() => {
60
60
  o && n();
61
61
  }, [o, n]);
62
- const [, S] = y({}), ne = z(() => {
62
+ const [, S] = y({}), re = z(() => {
63
63
  n(), f(!1);
64
64
  }, [n]);
65
- pe(t, d, () => S({}), ne), b(() => {
65
+ he(t, d, () => S({}), re), b(() => {
66
66
  if (!t)
67
67
  return () => {
68
68
  n();
@@ -76,7 +76,7 @@ const he = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), ge = (r) => r.split(he).map((a
76
76
  }, [t, n]), b(() => {
77
77
  t && S({});
78
78
  }, [t]);
79
- const re = () => {
79
+ const oe = () => {
80
80
  if (!d.current)
81
81
  return { display: "none" };
82
82
  const e = d.current.getBoundingClientRect(), i = {
@@ -146,39 +146,39 @@ const he = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), ge = (r) => r.split(he).map((a
146
146
  transform: `translate(-50%, -100%) ${t ? "scale(1)" : "scale(0.95)"}`
147
147
  };
148
148
  }
149
- }, I = l && g && A ? _ : void 0;
150
- le(() => {
151
- l && g && de();
149
+ }, I = l && g && A ? M : void 0;
150
+ ce(() => {
151
+ l && g && ue();
152
152
  }, [l, g]);
153
- const oe = h ? a : O || !F.isValidElement(a) ? /* @__PURE__ */ m("span", { "aria-describedby": I, style: R ? U : void 0, children: a }) : F.cloneElement(a, {
153
+ const ie = h ? a : O || !F.isValidElement(a) ? /* @__PURE__ */ m("span", { "aria-describedby": I, style: R ? U : void 0, children: a }) : F.cloneElement(a, {
154
154
  "aria-describedby": [a.props["aria-describedby"], I].filter(Boolean).join(" ") || void 0
155
- }), ie = W ? "span" : q, P = h && l && !o && c;
156
- return /* @__PURE__ */ G(ae, { children: [
155
+ }), ae = W ? "span" : q, P = h && l && !o && c;
156
+ return /* @__PURE__ */ G(se, { children: [
157
157
  /* @__PURE__ */ m(
158
- ie,
158
+ ae,
159
159
  {
160
160
  ref: d,
161
- className: `relative ${W ? "inline-flex max-w-full align-middle" : "flex"} items-center${P ? ` ${fe}` : ""}`,
161
+ className: `relative ${W ? "inline-flex max-w-full align-middle" : "flex"} items-center${P ? ` ${de}` : ""}`,
162
162
  style: X,
163
163
  tabIndex: P ? 0 : void 0,
164
164
  "aria-describedby": h ? I : void 0,
165
- onMouseEnter: J,
166
- onMouseLeave: Q,
167
- onFocus: M,
168
- onBlur: Z,
169
- children: oe
165
+ onMouseEnter: Q,
166
+ onMouseLeave: Z,
167
+ onFocus: _,
168
+ onBlur: ee,
169
+ children: ie
170
170
  }
171
171
  ),
172
- l && g && ce(
172
+ l && g && fe(
173
173
  /* @__PURE__ */ m(
174
174
  "div",
175
175
  {
176
176
  ref: E,
177
- id: _,
177
+ id: M,
178
178
  role: "tooltip",
179
179
  "aria-hidden": A ? void 0 : !0,
180
- ...ue("tooltip"),
181
- style: re(),
180
+ ...me("tooltip"),
181
+ style: oe(),
182
182
  children: /* @__PURE__ */ m(
183
183
  "span",
184
184
  {
@@ -186,7 +186,7 @@ const he = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), ge = (r) => r.split(he).map((a
186
186
  minWidth: 0,
187
187
  overflowWrap: "anywhere"
188
188
  },
189
- children: typeof r == "string" ? ge(r) : r
189
+ children: typeof r == "string" ? ve(r) : r
190
190
  }
191
191
  )
192
192
  }
@@ -196,6 +196,6 @@ const he = new RegExp("(?<=[/\\\\.\\-_?&#=:@])"), ge = (r) => r.split(he).map((a
196
196
  ] });
197
197
  };
198
198
  export {
199
- Ie as default
199
+ Le as default
200
200
  };
201
201
  //# sourceMappingURL=Tooltip.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.js","sources":["../../src/components/Tooltip.tsx"],"sourcesContent":["import React, { useState, useRef, useEffect, useId, useInsertionEffect, useCallback } from 'react';\nimport { createPortal } from 'react-dom';\nimport { FOCUS_RING } from './focusRing';\nimport { ensureOverlayStyles, overlayIdentity } from './portalOverlay';\nimport { useTopLayer } from './topLayer';\nimport { useFollowTrigger } from './useFollowTrigger';\n\n// Split after each delimiter so long values (URLs, dotted paths) wrap at \"/\" or \".\"\n// instead of mid-token. <wbr> is copy-safe (a zero-width space would corrupt a copied\n// URL); overflow-wrap still handles a single run too long to fit.\nconst WRAP_AFTER = /(?<=[/\\\\.\\-_?&#=:@])/;\nconst withBreakOpportunities = (value: string): React.ReactNode =>\n value.split(WRAP_AFTER).map((chunk, i) => (\n <React.Fragment key={i}>\n {chunk}\n <wbr />\n </React.Fragment>\n ));\n\ninterface TooltipProps {\n text: React.ReactNode | string;\n children: React.ReactNode;\n delay?: number;\n wrapChildren?: boolean;\n placement?: 'top' | 'bottom' | 'left' | 'right';\n isShrinkable?: boolean;\n fill?: boolean;\n /** Max width of tooltip. Default: 320px */\n maxWidth?: number | string;\n /** Called synchronously when the trigger is hovered/focused; return false to\n * suppress the tooltip for this interaction. Lets wrappers defer expensive\n * checks (e.g. truncation measurement) to interaction time instead of mount. */\n shouldShow?: () => boolean;\n suppressed?: boolean;\n triggerAs?: 'div' | 'span';\n inline?: boolean;\n /** Whether the tooltip acts as the trigger's accessible description. False where the\n * trigger already points at the same sentence on screen, so it is not announced twice. */\n describesTrigger?: boolean;\n /** False to open on hover only, e.g. where script moves focus onto the trigger. */\n showOnFocus?: boolean;\n /** Makes a trigger that cannot take focus a tab stop. Not for focusable children. */\n focusableTrigger?: boolean;\n}\n\nconst SHRINKABLE_STYLE: React.CSSProperties = {\n minWidth: 0,\n overflow: 'hidden',\n};\n\nconst FILL_STYLE: React.CSSProperties = {\n flex: 1,\n minWidth: 0,\n};\n\n/** Kept clear of the viewport edge so a clamped tooltip does not sit flush against it. */\nconst VIEWPORT_MARGIN = 8;\n\nconst Tooltip: React.FC<TooltipProps> = ({\n text,\n children,\n delay = 1,\n wrapChildren = false,\n triggerAs = 'div',\n inline = false,\n placement = 'top',\n isShrinkable = false,\n maxWidth = '320px',\n fill = false,\n shouldShow,\n suppressed = false,\n describesTrigger = true,\n showOnFocus = true,\n focusableTrigger = false,\n}) => {\n const triggerStyle =\n isShrinkable || fill\n ? { ...(isShrinkable ? SHRINKABLE_STYLE : {}), ...(fill ? FILL_STYLE : {}) }\n : undefined;\n\n const [isVisible, setIsVisible] = useState(false);\n // Portal mounts on first show, not on mount: an at-rest tooltip otherwise\n // costs a hidden document.body node plus a getBoundingClientRect per render —\n // multiplied by every row in a large table.\n // Mounted up front so a focusable trigger is described on first focus.\n const [hasShown, setHasShown] = useState(focusableTrigger);\n const timeoutRef = useRef<NodeJS.Timeout | null>(null);\n const showFrameRef = useRef<number | null>(null);\n\n const cancelPendingShow = useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n if (showFrameRef.current !== null) {\n cancelAnimationFrame(showFrameRef.current);\n showFrameRef.current = null;\n }\n }, []);\n\n const scheduleVisible = () => {\n // Two steps so the portal mounts hidden first and the fade-in transition\n // still runs on the very first show. The frame is tracked so leave/blur/\n // unmount can cancel a show that is already past its delay.\n setHasShown(true);\n if (showFrameRef.current !== null) {\n cancelAnimationFrame(showFrameRef.current);\n }\n showFrameRef.current = requestAnimationFrame(() => {\n showFrameRef.current = null;\n setIsVisible(true);\n });\n };\n const tooltipRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLDivElement>(null);\n\n // Tied to visibility, not mount: the node is latched into the DOM after its first show, and\n // re-entering on each show keeps a tooltip above the panel it is annotating.\n useTopLayer(tooltipRef, isVisible);\n\n const tooltipId = useId();\n\n const hasText = text !== null && text !== undefined && text !== '' && text !== false;\n\n const handleMouseEnter = (e: React.MouseEvent) => {\n e.stopPropagation();\n\n if (!hasText || suppressed || (shouldShow && !shouldShow())) {\n return;\n }\n\n cancelPendingShow();\n\n timeoutRef.current = setTimeout(() => {\n scheduleVisible();\n }, delay * 1000);\n };\n\n const handleMouseLeave = (e: React.MouseEvent) => {\n e.stopPropagation();\n\n cancelPendingShow();\n setIsVisible(false);\n };\n\n const handleFocus = () => {\n if (!showOnFocus || !hasText || suppressed || (shouldShow && !shouldShow())) {\n return;\n }\n\n cancelPendingShow();\n scheduleVisible();\n };\n\n const handleBlur = () => {\n cancelPendingShow();\n setIsVisible(false);\n };\n\n // Turning on while the trigger already holds focus fires no focus event to open on.\n const showOnFocusRef = useRef(showOnFocus);\n useEffect(() => {\n const switchedOn = showOnFocus && !showOnFocusRef.current;\n showOnFocusRef.current = showOnFocus;\n if (switchedOn && triggerRef.current?.matches(':focus-within')) {\n handleFocus();\n }\n });\n\n const [wasSuppressed, setWasSuppressed] = useState(suppressed);\n if (suppressed !== wasSuppressed) {\n setWasSuppressed(suppressed);\n if (suppressed) {\n setIsVisible(false);\n }\n }\n\n useEffect(() => {\n if (suppressed) {\n cancelPendingShow();\n }\n }, [suppressed, cancelPendingShow]);\n\n const [, forceUpdate] = useState({});\n\n const hideWithTrigger = useCallback(() => {\n cancelPendingShow();\n setIsVisible(false);\n }, [cancelPendingShow]);\n\n useFollowTrigger(isVisible, triggerRef, () => forceUpdate({}), hideWithTrigger);\n\n useEffect(() => {\n // Only a VISIBLE tooltip needs to track resize; keeping global listeners per mounted\n // instance made every event fan out across every tooltip on the page. Scrolling is\n // followed by useFollowTrigger.\n if (!isVisible) {\n return () => {\n cancelPendingShow();\n };\n }\n const handleUpdate = () => {\n forceUpdate({});\n };\n\n window.addEventListener('resize', handleUpdate);\n\n return () => {\n cancelPendingShow();\n window.removeEventListener('resize', handleUpdate);\n };\n }, [isVisible, cancelPendingShow]);\n\n // The first render that mounts the tooltip has no measured width yet, so the clamp below\n // cannot run on it. One extra pass once it is in the DOM gives the clamp its measurement\n // — before the opacity transition finishes, so nothing is seen sliding into place.\n useEffect(() => {\n if (isVisible) {\n forceUpdate({});\n }\n }, [isVisible]);\n\n const getTooltipStyles = (): React.CSSProperties => {\n if (!triggerRef.current) {\n return { display: 'none' };\n }\n\n const rect = triggerRef.current.getBoundingClientRect();\n\n const baseStyles: React.CSSProperties = {\n position: 'fixed',\n display: 'flex',\n width: 'max-content',\n maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth,\n minWidth: '32px',\n minHeight: '32px',\n padding: '8px 12px',\n alignItems: 'center',\n gap: '8px',\n borderRadius: '12px',\n backgroundColor: 'var(--malachite-tooltip-background, rgb(59, 59, 59))',\n color: 'var(--malachite-tooltip-foreground, rgb(255, 255, 255))',\n boxShadow: 'var(--malachite-tooltip-shadow, 0px 0px 10px 0px rgba(0, 0, 0, 0.20))',\n fontSize: '14px',\n lineHeight: '1.4',\n whiteSpace: 'normal',\n textAlign: 'left',\n pointerEvents: 'none',\n opacity: isVisible ? 1 : 0,\n visibility: isVisible ? 'visible' : 'hidden',\n transition:\n 'opacity 150ms ease-in-out, transform 150ms ease-in-out, visibility 150ms ease-in-out',\n };\n\n // A trigger near the viewport edge would otherwise centre a wide tooltip half off\n // screen, where the panel or the window crops it. Clamping the CENTRE keeps the\n // `translateX(-50%)` placement honest: the box stays put, it just stops short.\n const centeredLeft = (): number => {\n const desired = rect.left + rect.width / 2;\n const width = tooltipRef.current?.getBoundingClientRect().width ?? 0;\n\n if (width === 0) {\n return desired;\n }\n\n const half = width / 2;\n const min = VIEWPORT_MARGIN + half;\n const max = window.innerWidth - VIEWPORT_MARGIN - half;\n\n // A tooltip wider than the viewport has no in-bounds centre; leave it centred\n // rather than pinning it to a nonsensical one.\n return min > max ? desired : Math.min(Math.max(desired, min), max);\n };\n\n switch (placement) {\n case 'top':\n return {\n ...baseStyles,\n top: rect.top - 8,\n left: centeredLeft(),\n transform: `translate(-50%, -100%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'bottom':\n return {\n ...baseStyles,\n top: rect.bottom + 8,\n left: centeredLeft(),\n transform: `translateX(-50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'left':\n return {\n ...baseStyles,\n top: rect.top + rect.height / 2,\n left: rect.left - 8,\n transform: `translate(-100%, -50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'right':\n return {\n ...baseStyles,\n top: rect.top + rect.height / 2,\n left: rect.right + 8,\n transform: `translateY(-50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n default:\n return {\n ...baseStyles,\n top: rect.top - 8,\n left: centeredLeft(),\n transform: `translate(-50%, -100%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n }\n };\n\n // Only reference the tooltip id once the portal can exist — a dangling\n // aria-describedby (text set, never shown) confuses assistive tech.\n const describedBy = hasText && hasShown && describesTrigger ? tooltipId : undefined;\n useInsertionEffect(() => {\n if (hasText && hasShown) {\n ensureOverlayStyles();\n }\n }, [hasText, hasShown]);\n const renderedChildren = focusableTrigger ? (\n children\n ) : wrapChildren || !React.isValidElement(children) ? (\n <span aria-describedby={describedBy} style={fill ? FILL_STYLE : undefined}>\n {children}\n </span>\n ) : (\n React.cloneElement(children as React.ReactElement, {\n 'aria-describedby':\n [(children as React.ReactElement).props['aria-describedby'], describedBy]\n .filter(Boolean)\n .join(' ') || undefined,\n })\n );\n\n const Trigger = inline ? 'span' : triggerAs;\n const isTabStop = focusableTrigger && hasText && !suppressed && showOnFocus;\n\n // Create the tooltip content without its own shadow root\n return (\n <>\n <Trigger\n ref={triggerRef}\n className={`relative ${inline ? 'inline-flex max-w-full align-middle' : 'flex'} items-center${isTabStop ? ` ${FOCUS_RING}` : ''}`}\n style={triggerStyle}\n tabIndex={isTabStop ? 0 : undefined}\n aria-describedby={focusableTrigger ? describedBy : undefined}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleFocus}\n onBlur={handleBlur}\n >\n {renderedChildren}\n </Trigger>\n\n {hasText &&\n hasShown &&\n createPortal(\n <div\n ref={tooltipRef}\n id={tooltipId}\n role=\"tooltip\"\n // Nothing references it, and the sentence is already on screen and\n // described: left in the tree it is a second copy to read past.\n aria-hidden={describesTrigger ? undefined : true}\n {...overlayIdentity('tooltip')}\n style={getTooltipStyles()}\n >\n {/* min-w-0 + overflow-wrap let long values wrap within maxWidth. */}\n <span\n style={{\n minWidth: 0,\n overflowWrap: 'anywhere',\n }}\n >\n {typeof text === 'string' ? withBreakOpportunities(text) : text}\n </span>\n </div>,\n document.body,\n )}\n </>\n );\n};\n\nexport default Tooltip;\n"],"names":["WRAP_AFTER","withBreakOpportunities","value","chunk","i","jsxs","React","SHRINKABLE_STYLE","FILL_STYLE","VIEWPORT_MARGIN","Tooltip","text","children","delay","wrapChildren","triggerAs","inline","placement","isShrinkable","maxWidth","fill","shouldShow","suppressed","describesTrigger","showOnFocus","focusableTrigger","triggerStyle","isVisible","setIsVisible","useState","hasShown","setHasShown","timeoutRef","useRef","showFrameRef","cancelPendingShow","useCallback","scheduleVisible","tooltipRef","triggerRef","useTopLayer","tooltipId","useId","hasText","handleMouseEnter","handleMouseLeave","handleFocus","handleBlur","showOnFocusRef","useEffect","switchedOn","_a","wasSuppressed","setWasSuppressed","forceUpdate","hideWithTrigger","useFollowTrigger","handleUpdate","getTooltipStyles","rect","baseStyles","centeredLeft","desired","width","half","min","max","describedBy","useInsertionEffect","ensureOverlayStyles","renderedChildren","jsx","Trigger","isTabStop","Fragment","FOCUS_RING","createPortal","overlayIdentity"],"mappings":";;;;;;;AAUA,MAAMA,KAAa,WAAA,yBAAA,GACbC,KAAyB,CAACC,MAC5BA,EAAM,MAAMF,EAAU,EAAE,IAAI,CAACG,GAAOC,MAChC,gBAAAC,EAACC,EAAM,UAAN,EACI,UAAA;AAAA,EAAAH;AAAA,oBACA,OAAA,CAAA,CAAI;AAAA,EAAA,GAFYC,CAGrB,CACH,GA4BCG,KAAwC;AAAA,EAC1C,UAAU;AAAA,EACV,UAAU;AACd,GAEMC,IAAkC;AAAA,EACpC,MAAM;AAAA,EACN,UAAU;AACd,GAGMC,IAAkB,GAElBC,KAAkC,CAAC;AAAA,EACrC,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,cAAAC,IAAe;AAAA,EACf,WAAAC,IAAY;AAAA,EACZ,QAAAC,IAAS;AAAA,EACT,WAAAC,IAAY;AAAA,EACZ,cAAAC,IAAe;AAA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,CAACrB,KAAcE;AAGhE,SACI,gBAAAnB,EAAAqE,IAAA,EACI,UAAA;AAAA,IAAA,gBAAAH;AAAA,MAACC;AAAA,MAAA;AAAA,QACG,KAAKjC;AAAA,QACL,WAAW,YAAYvB,IAAS,wCAAwC,MAAM,gBAAgByD,IAAY,IAAIE,EAAU,KAAK,EAAE;AAAA,QAC/H,OAAOjD;AAAA,QACP,UAAU+C,IAAY,IAAI;AAAA,QAC1B,oBAAkBhD,IAAmB0C,IAAc;AAAA,QACnD,cAAcvB;AAAA,QACd,cAAcC;AAAA,QACd,SAASC;AAAA,QACT,QAAQC;AAAA,QAEP,UAAAuB;AAAA,MAAA;AAAA,IAAA;AAAA,IAGJ3B,KACGb,KACA8C;AAAA,MACI,gBAAAL;AAAA,QAAC;AAAA,QAAA;AAAA,UACG,KAAKjC;AAAA,UACL,IAAIG;AAAA,UACJ,MAAK;AAAA,UAGL,eAAalB,IAAmB,SAAY;AAAA,UAC3C,GAAGsD,GAAgB,SAAS;AAAA,UAC7B,OAAOnB,GAAA;AAAA,UAGP,UAAA,gBAAAa;AAAA,YAAC;AAAA,YAAA;AAAA,cACG,OAAO;AAAA,gBACH,UAAU;AAAA,gBACV,cAAc;AAAA,cAAA;AAAA,cAGjB,UAAA,OAAO5D,KAAS,WAAWV,GAAuBU,CAAI,IAAIA;AAAA,YAAA;AAAA,UAAA;AAAA,QAC/D;AAAA,MAAA;AAAA,MAEJ,SAAS;AAAA,IAAA;AAAA,EACb,GACR;AAER;"}
1
+ {"version":3,"file":"Tooltip.js","sources":["../../src/components/Tooltip.tsx"],"sourcesContent":["import React, { useState, useRef, useEffect, useId, useInsertionEffect, useCallback } from 'react';\nimport { createPortal } from 'react-dom';\nimport { FOCUS_RING } from './focusRing';\nimport { ensureOverlayStyles, overlayIdentity } from './portalOverlay';\nimport { useTopLayer } from './topLayer';\nimport { useFollowTrigger } from './useFollowTrigger';\n\n// Split after each delimiter so long values (URLs, dotted paths) wrap at \"/\" or \".\"\n// instead of mid-token. <wbr> is copy-safe (a zero-width space would corrupt a copied\n// URL); overflow-wrap still handles a single run too long to fit.\nconst WRAP_AFTER = /(?<=[/\\\\.\\-_?&#=:@])/;\nconst withBreakOpportunities = (value: string): React.ReactNode =>\n value.split(WRAP_AFTER).map((chunk, i) => (\n <React.Fragment key={i}>\n {chunk}\n <wbr />\n </React.Fragment>\n ));\n\ninterface TooltipProps {\n text: React.ReactNode | string;\n children: React.ReactNode;\n delay?: number;\n wrapChildren?: boolean;\n placement?: 'top' | 'bottom' | 'left' | 'right';\n isShrinkable?: boolean;\n fill?: boolean;\n /** Max width of tooltip. Default: 320px */\n maxWidth?: number | string;\n /** Called synchronously when the trigger is hovered/focused; return false to\n * suppress the tooltip for this interaction. Lets wrappers defer expensive\n * checks (e.g. truncation measurement) to interaction time instead of mount. */\n shouldShow?: () => boolean;\n suppressed?: boolean;\n triggerAs?: 'div' | 'span';\n inline?: boolean;\n /** Whether the tooltip acts as the trigger's accessible description. False where the\n * trigger already points at the same sentence on screen, so it is not announced twice. */\n describesTrigger?: boolean;\n /** False to open on hover only, e.g. where script moves focus onto the trigger. */\n showOnFocus?: boolean;\n /** Makes a trigger that cannot take focus a tab stop. Not for focusable children. */\n focusableTrigger?: boolean;\n}\n\nconst SHRINKABLE_STYLE: React.CSSProperties = {\n minWidth: 0,\n overflow: 'hidden',\n};\n\nconst FILL_STYLE: React.CSSProperties = {\n flex: 1,\n minWidth: 0,\n};\n\n/** Kept clear of the viewport edge so a clamped tooltip does not sit flush against it. */\nconst VIEWPORT_MARGIN = 8;\n\nconst Tooltip: React.FC<TooltipProps> = ({\n text,\n children,\n delay = 1,\n wrapChildren = false,\n triggerAs = 'div',\n inline = false,\n placement = 'top',\n isShrinkable = false,\n maxWidth = '320px',\n fill = false,\n shouldShow,\n suppressed = false,\n describesTrigger = true,\n showOnFocus = true,\n focusableTrigger = false,\n}) => {\n const triggerStyle =\n isShrinkable || fill\n ? { ...(isShrinkable ? SHRINKABLE_STYLE : {}), ...(fill ? FILL_STYLE : {}) }\n : undefined;\n\n const [isVisible, setIsVisible] = useState(false);\n // Portal mounts on first show, not on mount: an at-rest tooltip otherwise\n // costs a hidden document.body node plus a getBoundingClientRect per render —\n // multiplied by every row in a large table.\n // Mounted up front so a focusable trigger is described on first focus.\n const [hasShown, setHasShown] = useState(false);\n const isMounted = hasShown || focusableTrigger;\n const timeoutRef = useRef<NodeJS.Timeout | null>(null);\n const showFrameRef = useRef<number | null>(null);\n\n const cancelPendingShow = useCallback(() => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n if (showFrameRef.current !== null) {\n cancelAnimationFrame(showFrameRef.current);\n showFrameRef.current = null;\n }\n }, []);\n\n const scheduleVisible = () => {\n // Two steps so the portal mounts hidden first and the fade-in transition\n // still runs on the very first show. The frame is tracked so leave/blur/\n // unmount can cancel a show that is already past its delay.\n setHasShown(true);\n if (showFrameRef.current !== null) {\n cancelAnimationFrame(showFrameRef.current);\n }\n showFrameRef.current = requestAnimationFrame(() => {\n showFrameRef.current = null;\n setIsVisible(true);\n });\n };\n const tooltipRef = useRef<HTMLDivElement>(null);\n const triggerRef = useRef<HTMLDivElement>(null);\n\n // Tied to visibility, not mount: the node is latched into the DOM after its first show, and\n // re-entering on each show keeps a tooltip above the panel it is annotating.\n useTopLayer(tooltipRef, isVisible);\n\n const tooltipId = useId();\n\n const hasText = text !== null && text !== undefined && text !== '' && text !== false;\n\n const handleMouseEnter = (e: React.MouseEvent) => {\n e.stopPropagation();\n\n if (!hasText || suppressed || (shouldShow && !shouldShow())) {\n return;\n }\n\n cancelPendingShow();\n\n timeoutRef.current = setTimeout(() => {\n scheduleVisible();\n }, delay * 1000);\n };\n\n const handleMouseLeave = (e: React.MouseEvent) => {\n e.stopPropagation();\n\n cancelPendingShow();\n setIsVisible(false);\n };\n\n const handleFocus = () => {\n if (!showOnFocus || !hasText || suppressed || (shouldShow && !shouldShow())) {\n return;\n }\n\n cancelPendingShow();\n scheduleVisible();\n };\n\n const handleBlur = () => {\n cancelPendingShow();\n setIsVisible(false);\n };\n\n // Turning on while the trigger already holds focus fires no focus event to open on.\n const showOnFocusRef = useRef(showOnFocus);\n useEffect(() => {\n const switchedOn = showOnFocus && !showOnFocusRef.current;\n showOnFocusRef.current = showOnFocus;\n if (switchedOn && triggerRef.current?.matches(':focus-within')) {\n handleFocus();\n }\n });\n\n const [wasSuppressed, setWasSuppressed] = useState(suppressed);\n if (suppressed !== wasSuppressed) {\n setWasSuppressed(suppressed);\n if (suppressed) {\n setIsVisible(false);\n }\n }\n\n useEffect(() => {\n if (suppressed) {\n cancelPendingShow();\n }\n }, [suppressed, cancelPendingShow]);\n\n const [, forceUpdate] = useState({});\n\n const hideWithTrigger = useCallback(() => {\n cancelPendingShow();\n setIsVisible(false);\n }, [cancelPendingShow]);\n\n useFollowTrigger(isVisible, triggerRef, () => forceUpdate({}), hideWithTrigger);\n\n useEffect(() => {\n // Only a VISIBLE tooltip needs to track resize; keeping global listeners per mounted\n // instance made every event fan out across every tooltip on the page. Scrolling is\n // followed by useFollowTrigger.\n if (!isVisible) {\n return () => {\n cancelPendingShow();\n };\n }\n const handleUpdate = () => {\n forceUpdate({});\n };\n\n window.addEventListener('resize', handleUpdate);\n\n return () => {\n cancelPendingShow();\n window.removeEventListener('resize', handleUpdate);\n };\n }, [isVisible, cancelPendingShow]);\n\n // The first render that mounts the tooltip has no measured width yet, so the clamp below\n // cannot run on it. One extra pass once it is in the DOM gives the clamp its measurement\n // — before the opacity transition finishes, so nothing is seen sliding into place.\n useEffect(() => {\n if (isVisible) {\n forceUpdate({});\n }\n }, [isVisible]);\n\n const getTooltipStyles = (): React.CSSProperties => {\n if (!triggerRef.current) {\n return { display: 'none' };\n }\n\n const rect = triggerRef.current.getBoundingClientRect();\n\n const baseStyles: React.CSSProperties = {\n position: 'fixed',\n display: 'flex',\n width: 'max-content',\n maxWidth: typeof maxWidth === 'number' ? `${maxWidth}px` : maxWidth,\n minWidth: '32px',\n minHeight: '32px',\n padding: '8px 12px',\n alignItems: 'center',\n gap: '8px',\n borderRadius: '12px',\n backgroundColor: 'var(--malachite-tooltip-background, rgb(59, 59, 59))',\n color: 'var(--malachite-tooltip-foreground, rgb(255, 255, 255))',\n boxShadow: 'var(--malachite-tooltip-shadow, 0px 0px 10px 0px rgba(0, 0, 0, 0.20))',\n fontSize: '14px',\n lineHeight: '1.4',\n whiteSpace: 'normal',\n textAlign: 'left',\n pointerEvents: 'none',\n opacity: isVisible ? 1 : 0,\n visibility: isVisible ? 'visible' : 'hidden',\n transition:\n 'opacity 150ms ease-in-out, transform 150ms ease-in-out, visibility 150ms ease-in-out',\n };\n\n // A trigger near the viewport edge would otherwise centre a wide tooltip half off\n // screen, where the panel or the window crops it. Clamping the CENTRE keeps the\n // `translateX(-50%)` placement honest: the box stays put, it just stops short.\n const centeredLeft = (): number => {\n const desired = rect.left + rect.width / 2;\n const width = tooltipRef.current?.getBoundingClientRect().width ?? 0;\n\n if (width === 0) {\n return desired;\n }\n\n const half = width / 2;\n const min = VIEWPORT_MARGIN + half;\n const max = window.innerWidth - VIEWPORT_MARGIN - half;\n\n // A tooltip wider than the viewport has no in-bounds centre; leave it centred\n // rather than pinning it to a nonsensical one.\n return min > max ? desired : Math.min(Math.max(desired, min), max);\n };\n\n switch (placement) {\n case 'top':\n return {\n ...baseStyles,\n top: rect.top - 8,\n left: centeredLeft(),\n transform: `translate(-50%, -100%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'bottom':\n return {\n ...baseStyles,\n top: rect.bottom + 8,\n left: centeredLeft(),\n transform: `translateX(-50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'left':\n return {\n ...baseStyles,\n top: rect.top + rect.height / 2,\n left: rect.left - 8,\n transform: `translate(-100%, -50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n case 'right':\n return {\n ...baseStyles,\n top: rect.top + rect.height / 2,\n left: rect.right + 8,\n transform: `translateY(-50%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n default:\n return {\n ...baseStyles,\n top: rect.top - 8,\n left: centeredLeft(),\n transform: `translate(-50%, -100%) ${isVisible ? 'scale(1)' : 'scale(0.95)'}`,\n };\n }\n };\n\n // Only reference the tooltip id once the portal can exist — a dangling\n // aria-describedby (text set, never shown) confuses assistive tech.\n const describedBy = hasText && isMounted && describesTrigger ? tooltipId : undefined;\n useInsertionEffect(() => {\n if (hasText && isMounted) {\n ensureOverlayStyles();\n }\n }, [hasText, isMounted]);\n const renderedChildren = focusableTrigger ? (\n children\n ) : wrapChildren || !React.isValidElement(children) ? (\n <span aria-describedby={describedBy} style={fill ? FILL_STYLE : undefined}>\n {children}\n </span>\n ) : (\n React.cloneElement(children as React.ReactElement, {\n 'aria-describedby':\n [(children as React.ReactElement).props['aria-describedby'], describedBy]\n .filter(Boolean)\n .join(' ') || undefined,\n })\n );\n\n const Trigger = inline ? 'span' : triggerAs;\n const isTabStop = focusableTrigger && hasText && !suppressed && showOnFocus;\n\n // Create the tooltip content without its own shadow root\n return (\n <>\n <Trigger\n ref={triggerRef}\n className={`relative ${inline ? 'inline-flex max-w-full align-middle' : 'flex'} items-center${isTabStop ? ` ${FOCUS_RING}` : ''}`}\n style={triggerStyle}\n tabIndex={isTabStop ? 0 : undefined}\n aria-describedby={focusableTrigger ? describedBy : undefined}\n onMouseEnter={handleMouseEnter}\n onMouseLeave={handleMouseLeave}\n onFocus={handleFocus}\n onBlur={handleBlur}\n >\n {renderedChildren}\n </Trigger>\n\n {hasText &&\n isMounted &&\n createPortal(\n <div\n ref={tooltipRef}\n id={tooltipId}\n role=\"tooltip\"\n // Nothing references it, and the sentence is already on screen and\n // described: left in the tree it is a second copy to read past.\n aria-hidden={describesTrigger ? undefined : true}\n {...overlayIdentity('tooltip')}\n style={getTooltipStyles()}\n >\n {/* min-w-0 + overflow-wrap let long values wrap within maxWidth. */}\n <span\n style={{\n minWidth: 0,\n overflowWrap: 'anywhere',\n }}\n >\n {typeof text === 'string' ? withBreakOpportunities(text) : text}\n </span>\n </div>,\n document.body,\n )}\n </>\n );\n};\n\nexport default Tooltip;\n"],"names":["WRAP_AFTER","withBreakOpportunities","value","chunk","i","jsxs","React","SHRINKABLE_STYLE","FILL_STYLE","VIEWPORT_MARGIN","Tooltip","text","children","delay","wrapChildren","triggerAs","inline","placement","isShrinkable","maxWidth","fill","shouldShow","suppressed","describesTrigger","showOnFocus","focusableTrigger","triggerStyle","isVisible","setIsVisible","useState","hasShown","setHasShown","isMounted","timeoutRef","useRef","showFrameRef","cancelPendingShow","useCallback","scheduleVisible","tooltipRef","triggerRef","useTopLayer","tooltipId","useId","hasText","handleMouseEnter","handleMouseLeave","handleFocus","handleBlur","showOnFocusRef","useEffect","switchedOn","_a","wasSuppressed","setWasSuppressed","forceUpdate","hideWithTrigger","useFollowTrigger","handleUpdate","getTooltipStyles","rect","baseStyles","centeredLeft","desired","width","half","min","max","describedBy","useInsertionEffect","ensureOverlayStyles","renderedChildren","jsx","Trigger","isTabStop","Fragment","FOCUS_RING","createPortal","overlayIdentity"],"mappings":";;;;;;;AAUA,MAAMA,KAAa,WAAA,yBAAA,GACbC,KAAyB,CAACC,MAC5BA,EAAM,MAAMF,EAAU,EAAE,IAAI,CAACG,GAAOC,MAChC,gBAAAC,EAACC,EAAM,UAAN,EACI,UAAA;AAAA,EAAAH;AAAA,oBACA,OAAA,CAAA,CAAI;AAAA,EAAA,GAFYC,CAGrB,CACH,GA4BCG,KAAwC;AAAA,EAC1C,UAAU;AAAA,EACV,UAAU;AACd,GAEMC,IAAkC;AAAA,EACpC,MAAM;AAAA,EACN,UAAU;AACd,GAGMC,IAAkB,GAElBC,KAAkC,CAAC;AAAA,EACrC,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,OAAAC,IAAQ;AAAA,EACR,cAAAC,IAAe;AAAA,EACf,WAAAC,IAAY;AAAA,EACZ,QAAAC,IAAS;AAAA,EACT,WAAAC,IAAY;AAA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zD,IAAS,SAASD,GAC5B2D,IAAYjD,KAAoBmB,KAAW,CAACtB,KAAcE;AAGhE,SACI,gBAAAnB,EAAAsE,IAAA,EACI,UAAA;AAAA,IAAA,gBAAAH;AAAA,MAACC;AAAA,MAAA;AAAA,QACG,KAAKjC;AAAA,QACL,WAAW,YAAYxB,IAAS,wCAAwC,MAAM,gBAAgB0D,IAAY,IAAIE,EAAU,KAAK,EAAE;AAAA,QAC/H,OAAOlD;AAAA,QACP,UAAUgD,IAAY,IAAI;AAAA,QAC1B,oBAAkBjD,IAAmB2C,IAAc;AAAA,QACnD,cAAcvB;AAAA,QACd,cAAcC;AAAA,QACd,SAASC;AAAA,QACT,QAAQC;AAAA,QAEP,UAAAuB;AAAA,MAAA;AAAA,IAAA;AAAA,IAGJ3B,KACGZ,KACA6C;AAAA,MACI,gBAAAL;AAAA,QAAC;AAAA,QAAA;AAAA,UACG,KAAKjC;AAAA,UACL,IAAIG;AAAA,UACJ,MAAK;AAAA,UAGL,eAAanB,IAAmB,SAAY;AAAA,UAC3C,GAAGuD,GAAgB,SAAS;AAAA,UAC7B,OAAOnB,GAAA;AAAA,UAGP,UAAA,gBAAAa;AAAA,YAAC;AAAA,YAAA;AAAA,cACG,OAAO;AAAA,gBACH,UAAU;AAAA,gBACV,cAAc;AAAA,cAAA;AAAA,cAGjB,UAAA,OAAO7D,KAAS,WAAWV,GAAuBU,CAAI,IAAIA;AAAA,YAAA;AAAA,UAAA;AAAA,QAC/D;AAAA,MAAA;AAAA,MAEJ,SAAS;AAAA,IAAA;AAAA,EACb,GACR;AAER;"}
@@ -1,48 +1,52 @@
1
- import { jsx as n } from "react/jsx-runtime";
2
- import { useRef as x } from "react";
3
- import S from "../Tooltip.js";
4
- import { getFontWeight as g, getFontSize as w, getTextColor as v } from "./textStyles.js";
5
- const k = ({
6
- children: s,
1
+ import { jsx as s } from "react/jsx-runtime";
2
+ import { useRef as S } from "react";
3
+ import w from "../Tooltip.js";
4
+ import { getFontWeight as y, getFontSize as v, getTextColor as b } from "./textStyles.js";
5
+ const R = ({
6
+ children: f,
7
7
  tooltip: t,
8
- maxWidth: p = "100%",
9
- color: c = "primary",
10
- size: o,
11
- fontWeight: l,
12
- tooltipWhenTruncated: f = !1,
8
+ maxWidth: c = "100%",
9
+ color: p = "primary",
10
+ size: l,
11
+ fontWeight: o,
12
+ tooltipWhenTruncated: r = !1,
13
13
  tooltipPlacement: a,
14
- inline: m = !1,
15
- className: d = "",
16
- style: h = {}
14
+ tooltipDelay: m,
15
+ focusableTrigger: d,
16
+ inline: u = !1,
17
+ className: h = "",
18
+ style: x = {}
17
19
  }) => {
18
- const u = {
19
- color: v(c),
20
- ...o ? { fontSize: w(o) } : {},
21
- ...l ? { fontWeight: g(l) } : {},
22
- maxWidth: p,
20
+ const g = {
21
+ color: b(p),
22
+ ...l ? { fontSize: v(l) } : {},
23
+ ...o ? { fontWeight: y(o) } : {},
24
+ maxWidth: c,
23
25
  overflow: "hidden",
24
26
  whiteSpace: "nowrap",
25
27
  textOverflow: "ellipsis",
26
28
  display: "inline-block",
27
29
  verticalAlign: "top",
28
- ...h
29
- }, r = x(null), i = /* @__PURE__ */ n("span", { ref: r, className: d, style: u, children: s });
30
- return t ? /* @__PURE__ */ n(
31
- S,
30
+ ...x
31
+ }, i = S(null), n = /* @__PURE__ */ s("span", { ref: i, className: h, style: g, children: f });
32
+ return t ? /* @__PURE__ */ s(
33
+ w,
32
34
  {
33
35
  text: t,
34
36
  placement: a,
35
- inline: m,
37
+ delay: m,
38
+ focusableTrigger: d && !r,
39
+ inline: u,
36
40
  isShrinkable: !0,
37
- shouldShow: f ? () => {
38
- const e = r.current;
41
+ shouldShow: r ? () => {
42
+ const e = i.current;
39
43
  return !!e && e.scrollWidth > e.clientWidth;
40
44
  } : void 0,
41
- children: i
45
+ children: n
42
46
  }
43
- ) : i;
47
+ ) : n;
44
48
  };
45
49
  export {
46
- k as default
50
+ R as default
47
51
  };
48
52
  //# sourceMappingURL=EllipsisText.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EllipsisText.js","sources":["../../../src/components/Typography/EllipsisText.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport Tooltip from '../Tooltip';\nimport type { TextColor } from './Text';\nimport type { FontSize, FontWeight } from './textStyles';\nimport { getFontSize, getFontWeight, getTextColor } from './textStyles';\n\nexport interface EllipsisTextProps {\n children: React.ReactNode;\n tooltip?: React.ReactNode | string;\n /**\n * Defaults to filling the container. Pass a fixed width only when the text should\n * truncate before its container runs out of room (e.g. a column with a hard cap).\n */\n maxWidth?: string;\n color?: TextColor;\n size?: FontSize;\n fontWeight?: FontWeight;\n /**\n * Show `tooltip` only when the text is actually cut off. Opt-in, because `tooltip` is any\n * node: a caller repeating the label wants this, and one supplying something the label does\n * not say — a full path, a timestamp — would lose it.\n */\n tooltipWhenTruncated?: boolean;\n tooltipPlacement?: 'top' | 'bottom' | 'left' | 'right';\n /** A span around the text, for a place a div may not go, such as inside a clickable `Surface.Row`. */\n inline?: boolean;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst EllipsisText: React.FC<EllipsisTextProps> = ({\n children,\n tooltip,\n maxWidth = '100%',\n color = 'primary',\n size,\n fontWeight,\n tooltipWhenTruncated = false,\n tooltipPlacement,\n inline = false,\n className = '',\n style = {},\n}) => {\n const ellipsisStyles: React.CSSProperties = {\n color: getTextColor(color),\n ...(size ? { fontSize: getFontSize(size) } : {}),\n ...(fontWeight ? { fontWeight: getFontWeight(fontWeight) } : {}),\n maxWidth,\n overflow: 'hidden',\n whiteSpace: 'nowrap',\n textOverflow: 'ellipsis',\n display: 'inline-block',\n verticalAlign: 'top',\n ...style,\n };\n\n const textRef = useRef<HTMLSpanElement>(null);\n\n const textElement = (\n <span ref={textRef} className={className} style={ellipsisStyles}>\n {children}\n </span>\n );\n\n if (tooltip) {\n // Measured on hover, not at mount: what fits depends on the container and on webfonts\n // that land after `DOMContentLoaded`, so a value read once is wrong for the rest of the\n // page's life.\n // Without `isShrinkable` the tooltip wrapper is floored at min-content and a percentage `maxWidth` never truncates.\n return (\n <Tooltip\n text={tooltip}\n placement={tooltipPlacement}\n inline={inline}\n isShrinkable\n shouldShow={\n tooltipWhenTruncated\n ? () => {\n const node = textRef.current;\n return !!node && node.scrollWidth > node.clientWidth;\n }\n : undefined\n }\n >\n {textElement}\n </Tooltip>\n );\n }\n\n return textElement;\n};\n\nexport default EllipsisText;\n"],"names":["EllipsisText","children","tooltip","maxWidth","color","size","fontWeight","tooltipWhenTruncated","tooltipPlacement","inline","className","style","ellipsisStyles","getTextColor","getFontSize","getFontWeight","textRef","useRef","textElement","jsx","Tooltip","node"],"mappings":";;;;AA8BA,MAAMA,IAA4C,CAAC;AAAA,EAC/C,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,OAAAC,IAAQ;AAAA,EACR,MAAAC;AAAA,EACA,YAAAC;AAAA,EACA,sBAAAC,IAAuB;AAAA,EACvB,kBAAAC;AAAA,EACA,QAAAC,IAAS;AAAA,EACT,WAAAC,IAAY;AAAA,EACZ,OAAAC,IAAQ,CAAA;AACZ,MAAM;AACF,QAAMC,IAAsC;AAAA,IACxC,OAAOC,EAAaT,CAAK;AAAA,IACzB,GAAIC,IAAO,EAAE,UAAUS,EAAYT,CAAI,EAAA,IAAM,CAAA;AAAA,IAC7C,GAAIC,IAAa,EAAE,YAAYS,EAAcT,CAAU,EAAA,IAAM,CAAA;AAAA,IAC7D,UAAAH;AAAA,IACA,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,SAAS;AAAA,IACT,eAAe;AAAA,IACf,GAAGQ;AAAA,EAAA,GAGDK,IAAUC,EAAwB,IAAI,GAEtCC,sBACD,QAAA,EAAK,KAAKF,GAAS,WAAAN,GAAsB,OAAOE,GAC5C,UAAAX,GACL;AAGJ,SAAIC,IAMI,gBAAAiB;AAAA,IAACC;AAAA,IAAA;AAAA,MACG,MAAMlB;AAAA,MACN,WAAWM;AAAA,MACX,QAAAC;AAAA,MACA,cAAY;AAAA,MACZ,YACIF,IACM,MAAM;AACF,cAAMc,IAAOL,EAAQ;AACrB,eAAO,CAAC,CAACK,KAAQA,EAAK,cAAcA,EAAK;AAAA,MAC7C,IACA;AAAA,MAGT,UAAAH;AAAA,IAAA;AAAA,EAAA,IAKNA;AACX;"}
1
+ {"version":3,"file":"EllipsisText.js","sources":["../../../src/components/Typography/EllipsisText.tsx"],"sourcesContent":["import React, { useRef } from 'react';\nimport Tooltip from '../Tooltip';\nimport type { TextColor } from './Text';\nimport type { FontSize, FontWeight } from './textStyles';\nimport { getFontSize, getFontWeight, getTextColor } from './textStyles';\n\nexport interface EllipsisTextProps {\n children: React.ReactNode;\n tooltip?: React.ReactNode | string;\n /**\n * Defaults to filling the container. Pass a fixed width only when the text should\n * truncate before its container runs out of room (e.g. a column with a hard cap).\n */\n maxWidth?: string;\n color?: TextColor;\n size?: FontSize;\n fontWeight?: FontWeight;\n /**\n * Show `tooltip` only when the text is actually cut off. Opt-in, because `tooltip` is any\n * node: a caller repeating the label wants this, and one supplying something the label does\n * not say — a full path, a timestamp — would lose it.\n */\n tooltipWhenTruncated?: boolean;\n tooltipPlacement?: 'top' | 'bottom' | 'left' | 'right';\n /** Seconds before the tooltip opens. */\n tooltipDelay?: number;\n /** Makes the text a tab stop that opens the tooltip. Ignored with `tooltipWhenTruncated`. */\n focusableTrigger?: boolean;\n /** A span around the text, for a place a div may not go, such as inside a clickable `Surface.Row`. */\n inline?: boolean;\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst EllipsisText: React.FC<EllipsisTextProps> = ({\n children,\n tooltip,\n maxWidth = '100%',\n color = 'primary',\n size,\n fontWeight,\n tooltipWhenTruncated = false,\n tooltipPlacement,\n tooltipDelay,\n focusableTrigger,\n inline = false,\n className = '',\n style = {},\n}) => {\n const ellipsisStyles: React.CSSProperties = {\n color: getTextColor(color),\n ...(size ? { fontSize: getFontSize(size) } : {}),\n ...(fontWeight ? { fontWeight: getFontWeight(fontWeight) } : {}),\n maxWidth,\n overflow: 'hidden',\n whiteSpace: 'nowrap',\n textOverflow: 'ellipsis',\n display: 'inline-block',\n verticalAlign: 'top',\n ...style,\n };\n\n const textRef = useRef<HTMLSpanElement>(null);\n\n const textElement = (\n <span ref={textRef} className={className} style={ellipsisStyles}>\n {children}\n </span>\n );\n\n if (tooltip) {\n // Measured on hover, not at mount: what fits depends on the container and on webfonts\n // that land after `DOMContentLoaded`, so a value read once is wrong for the rest of the\n // page's life.\n // Without `isShrinkable` the tooltip wrapper is floored at min-content and a percentage `maxWidth` never truncates.\n return (\n <Tooltip\n text={tooltip}\n placement={tooltipPlacement}\n delay={tooltipDelay}\n focusableTrigger={focusableTrigger && !tooltipWhenTruncated}\n inline={inline}\n isShrinkable\n shouldShow={\n tooltipWhenTruncated\n ? () => {\n const node = textRef.current;\n return !!node && node.scrollWidth > node.clientWidth;\n }\n : undefined\n }\n >\n {textElement}\n </Tooltip>\n );\n }\n\n return textElement;\n};\n\nexport default EllipsisText;\n"],"names":["EllipsisText","children","tooltip","maxWidth","color","size","fontWeight","tooltipWhenTruncated","tooltipPlacement","tooltipDelay","focusableTrigger","inline","className","style","ellipsisStyles","getTextColor","getFontSize","getFontWeight","textRef","useRef","textElement","jsx","Tooltip","node"],"mappings":";;;;AAkCA,MAAMA,IAA4C,CAAC;AAAA,EAC/C,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,OAAAC,IAAQ;AAAA,EACR,MAAAC;AAAA,EACA,YAAAC;AAAA,EACA,sBAAAC,IAAuB;AAAA,EACvB,kBAAAC;AAAA,EACA,cAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,QAAAC,IAAS;AAAA,EACT,WAAAC,IAAY;AAAA,EACZ,OAAAC,IAAQ,CAAA;AACZ,MAAM;AACF,QAAMC,IAAsC;AAAA,IACxC,OAAOC,EAAaX,CAAK;AAAA,IACzB,GAAIC,IAAO,EAAE,UAAUW,EAAYX,CAAI,EAAA,IAAM,CAAA;AAAA,IAC7C,GAAIC,IAAa,EAAE,YAAYW,EAAcX,CAAU,EAAA,IAAM,CAAA;AAAA,IAC7D,UAAAH;AAAA,IACA,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,cAAc;AAAA,IACd,SAAS;AAAA,IACT,eAAe;AAAA,IACf,GAAGU;AAAA,EAAA,GAGDK,IAAUC,EAAwB,IAAI,GAEtCC,sBACD,QAAA,EAAK,KAAKF,GAAS,WAAAN,GAAsB,OAAOE,GAC5C,UAAAb,GACL;AAGJ,SAAIC,IAMI,gBAAAmB;AAAA,IAACC;AAAA,IAAA;AAAA,MACG,MAAMpB;AAAA,MACN,WAAWM;AAAA,MACX,OAAOC;AAAA,MACP,kBAAkBC,KAAoB,CAACH;AAAA,MACvC,QAAAI;AAAA,MACA,cAAY;AAAA,MACZ,YACIJ,IACM,MAAM;AACF,cAAMgB,IAAOL,EAAQ;AACrB,eAAO,CAAC,CAACK,KAAQA,EAAK,cAAcA,EAAK;AAAA,MAC7C,IACA;AAAA,MAGT,UAAAH;AAAA,IAAA;AAAA,EAAA,IAKNA;AACX;"}