@stackone/malachite 2.27.2 → 2.28.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.
@@ -1,205 +1,202 @@
1
- import { jsx as e, jsxs as R } from "react/jsx-runtime";
2
- import A from "react";
3
- import { DisclosureArrow as j } from "./DisclosureArrow.js";
1
+ import { jsx as o, jsxs as k } from "react/jsx-runtime";
2
+ import B from "react";
3
+ import { paintOnChild as j } from "./asChild.js";
4
+ import { DisclosureArrow as F } from "./DisclosureArrow.js";
4
5
  import { FOCUS_RING_INSET as _ } from "./focusRing.js";
5
- import { isRenderableNode as F } from "./renderableNode.js";
6
- import { FOREGROUND_RESET as I, SELECTED_TEXT_CONTEXT as G, SELECTED_ROW_ACCENT as P, SELECTED_ROW_FOREGROUND as U, SELECTED_ROW_BACKGROUND as y } from "./selectedRow.js";
7
- const W = {
6
+ import { isRenderableNode as I } from "./renderableNode.js";
7
+ import { FOREGROUND_RESET as G, SELECTED_TEXT_CONTEXT as P, SELECTED_ROW_ACCENT as U, SELECTED_ROW_FOREGROUND as W, SELECTED_ROW_BACKGROUND as w } from "./selectedRow.js";
8
+ const X = {
8
9
  default: "",
9
10
  muted: "bg-[var(--malachite-card-dimmed-background)]",
10
11
  success: "bg-[var(--malachite-tag-success-background)]",
11
12
  error: "bg-[var(--malachite-tag-error-background)]"
12
- }, B = {
13
+ }, z = {
13
14
  success: "var(--malachite-tag-success-foreground)",
14
15
  error: "var(--malachite-tag-error-foreground)"
15
- }, X = "0px 0px 4px 0px rgba(0,0,0,0.08), 0px 4px 4px 0px rgba(0,0,0,0.08), 0px 4px 10px 0px rgba(0,0,0,0.05)", C = ({
16
- children: t,
17
- divider: n = !1,
18
- disabled: a = !1,
19
- onClick: r,
20
- href: l,
21
- selected: c,
22
- selection: b,
23
- trailing: u,
24
- tone: p = "default",
25
- role: o,
26
- "aria-label": i,
27
- "aria-labelledby": s,
28
- className: d = "",
29
- style: v
30
- }) => {
31
- const g = !!(r || l), k = a && g ? "" : "transition-colors hover:bg-[var(--malachite-buttonlist-hover-background)]", $ = p !== "default", S = [
16
+ }, H = "0px 0px 4px 0px rgba(0,0,0,0.08), 0px 4px 4px 0px rgba(0,0,0,0.08), 0px 4px 10px 0px rgba(0,0,0,0.05)", O = (t) => {
17
+ const {
18
+ children: a,
19
+ divider: r = !1,
20
+ disabled: e = !1,
21
+ selected: n,
22
+ selection: u,
23
+ tone: c = "default",
24
+ className: m = "",
25
+ style: g
26
+ } = t, d = t.asChild === !0, { onClick: i, href: s, trailing: b, role: l } = d ? {} : t, p = d ? void 0 : t["aria-label"], h = d ? void 0 : t["aria-labelledby"], C = !!(i || s), T = e && (C || d) ? "" : "transition-colors hover:bg-[var(--malachite-buttonlist-hover-background)]", D = c !== "default", R = [
32
27
  "w-full text-left border-0",
33
- W[p],
34
- n ? "border-b border-solid border-[var(--malachite-card-border)]" : "",
35
- k
36
- ].filter(Boolean).join(" "), h = [
37
- g ? `appearance-none ${$ ? "" : "bg-transparent"} p-0 ${_}` : "",
38
- g && !a ? "cursor-pointer" : ""
39
- ].filter(Boolean).join(" "), E = [S, h, d].filter(Boolean).join(" "), T = c && (b ? b === "highlight" : o !== "checkbox") ? {
40
- backgroundImage: `linear-gradient(${y}, ${y})`,
41
- color: U,
42
- boxShadow: `inset 2px 0 0 ${P}`,
43
- ...G
44
- } : {}, N = B[p], x = { ...N ? {
28
+ X[c],
29
+ r ? "border-b border-solid border-[var(--malachite-card-border)]" : "",
30
+ T
31
+ ].filter(Boolean).join(" "), y = [
32
+ C ? `appearance-none ${D ? "" : "bg-transparent"} p-0 ${_}` : "",
33
+ C && !e ? "cursor-pointer" : ""
34
+ ].filter(Boolean).join(" "), E = [R, y, m].filter(Boolean).join(" "), L = n && (u ? u === "highlight" : l !== "checkbox") ? {
35
+ backgroundImage: `linear-gradient(${w}, ${w})`,
36
+ color: W,
37
+ boxShadow: `inset 2px 0 0 ${U}`,
38
+ ...P
39
+ } : {}, N = z[c], x = { ...N ? {
45
40
  color: N,
46
41
  "--malachite-ctx-text-primary": N
47
- } : {}, ...T, ...v }, m = o === "radio" || o === "checkbox" ? !!c : void 0, f = m === void 0 && c ? !0 : void 0, w = {
48
- role: o,
49
- "aria-checked": m,
50
- "aria-current": f,
51
- "aria-label": i,
52
- "aria-labelledby": s,
53
- "aria-disabled": o && a ? !0 : void 0
42
+ } : {}, ...L, ...g }, f = l === "radio" || l === "checkbox" ? !!n : void 0, v = f === void 0 && n ? !0 : void 0, S = {
43
+ role: l,
44
+ "aria-checked": f,
45
+ "aria-current": v,
46
+ "aria-label": p,
47
+ "aria-labelledby": h,
48
+ "aria-disabled": l && e ? !0 : void 0
54
49
  };
55
- if (F(u)) {
56
- const D = l && !a ? /* @__PURE__ */ e(
50
+ if (d)
51
+ return j(a, E, x);
52
+ if (I(b)) {
53
+ const A = s && !e ? /* @__PURE__ */ o(
57
54
  "a",
58
55
  {
59
- href: l,
60
- onClick: r,
61
- className: `${h} border-0 flex-1 min-w-0 text-left no-underline text-inherit`,
62
- role: o,
63
- "aria-checked": m,
64
- "aria-current": f,
65
- "aria-label": i,
66
- "aria-labelledby": s,
67
- children: t
56
+ href: s,
57
+ onClick: i,
58
+ className: `${y} border-0 flex-1 min-w-0 text-left no-underline text-inherit`,
59
+ role: l,
60
+ "aria-checked": f,
61
+ "aria-current": v,
62
+ "aria-label": p,
63
+ "aria-labelledby": h,
64
+ children: a
68
65
  }
69
- ) : r ? /* @__PURE__ */ e(
66
+ ) : i ? /* @__PURE__ */ o(
70
67
  "button",
71
68
  {
72
69
  type: "button",
73
- onClick: r,
74
- disabled: a,
75
- className: `${h} border-0 flex-1 min-w-0 text-left`,
76
- role: o,
77
- "aria-checked": m,
78
- "aria-current": f,
79
- "aria-label": i,
80
- "aria-labelledby": s,
81
- children: t
70
+ onClick: i,
71
+ disabled: e,
72
+ className: `${y} border-0 flex-1 min-w-0 text-left`,
73
+ role: l,
74
+ "aria-checked": f,
75
+ "aria-current": v,
76
+ "aria-label": p,
77
+ "aria-labelledby": h,
78
+ children: a
82
79
  }
83
80
  ) : (
84
81
  // The set goes here, not on the wrapper: `radio` and `checkbox` make their
85
82
  // descendants presentational, which would bury a control in the trailing slot.
86
- /* @__PURE__ */ e("div", { className: "flex-1 min-w-0", ...w, children: t })
83
+ /* @__PURE__ */ o("div", { className: "flex-1 min-w-0", ...S, children: a })
87
84
  );
88
- return /* @__PURE__ */ R(
85
+ return /* @__PURE__ */ k(
89
86
  "div",
90
87
  {
91
- className: [S, "flex items-center", d].filter(Boolean).join(" "),
88
+ className: [R, "flex items-center", m].filter(Boolean).join(" "),
92
89
  style: x,
93
90
  children: [
94
- D,
95
- /* @__PURE__ */ e("div", { className: "shrink-0 flex items-center", children: u })
91
+ A,
92
+ /* @__PURE__ */ o("div", { className: "shrink-0 flex items-center", children: b })
96
93
  ]
97
94
  }
98
95
  );
99
96
  }
100
- return l && !a ? /* @__PURE__ */ e(
97
+ return s && !e ? /* @__PURE__ */ o(
101
98
  "a",
102
99
  {
103
- href: l,
104
- onClick: r,
100
+ href: s,
101
+ onClick: i,
105
102
  className: `${E} no-underline text-inherit`,
106
103
  style: x,
107
- role: o,
108
- "aria-checked": m,
109
- "aria-current": f,
110
- "aria-label": i,
111
- "aria-labelledby": s,
112
- children: t
104
+ role: l,
105
+ "aria-checked": f,
106
+ "aria-current": v,
107
+ "aria-label": p,
108
+ "aria-labelledby": h,
109
+ children: a
113
110
  }
114
- ) : r ? /* @__PURE__ */ e(
111
+ ) : i ? /* @__PURE__ */ o(
115
112
  "button",
116
113
  {
117
114
  type: "button",
118
- onClick: r,
119
- disabled: a,
115
+ onClick: i,
116
+ disabled: e,
120
117
  className: E,
121
118
  style: x,
122
- role: o,
123
- "aria-checked": m,
124
- "aria-current": f,
125
- "aria-label": i,
126
- "aria-labelledby": s,
127
- children: t
119
+ role: l,
120
+ "aria-checked": f,
121
+ "aria-current": v,
122
+ "aria-label": p,
123
+ "aria-labelledby": h,
124
+ children: a
128
125
  }
129
- ) : /* @__PURE__ */ e("div", { className: E, style: x, ...w, children: t });
130
- }, z = ({ children: t, className: n = "", style: a }) => /* @__PURE__ */ e("div", { className: n, style: a, onClick: (r) => r.stopPropagation(), children: t }), aa = 39, H = Object.assign(
126
+ ) : /* @__PURE__ */ o("div", { className: E, style: x, ...S, children: a });
127
+ }, K = ({ children: t, className: a = "", style: r }) => /* @__PURE__ */ o("div", { className: a, style: r, onClick: (e) => e.stopPropagation(), children: t }), te = 39, q = Object.assign(
131
128
  ({
132
129
  header: t,
133
- children: n,
134
- expanded: a,
135
- onToggle: r,
136
- sticky: l = !1,
137
- stickyTopOffset: c = 0,
138
- divider: b = !1,
139
- tone: u = "default",
140
- "aria-label": p,
141
- className: o = "",
130
+ children: a,
131
+ expanded: r,
132
+ onToggle: e,
133
+ sticky: n = !1,
134
+ stickyTopOffset: u = 0,
135
+ divider: c = !1,
136
+ tone: m = "default",
137
+ "aria-label": g,
138
+ className: d = "",
142
139
  style: i
143
140
  }) => {
144
- const s = A.useId(), d = r ? () => r(!a) : void 0;
145
- return /* @__PURE__ */ R(C, { divider: b, tone: u, className: o, style: i, children: [
146
- /* @__PURE__ */ R(
141
+ const s = B.useId(), b = e ? () => e(!r) : void 0;
142
+ return /* @__PURE__ */ k(O, { divider: c, tone: m, className: d, style: i, children: [
143
+ /* @__PURE__ */ k(
147
144
  "div",
148
145
  {
149
- className: `group flex items-center w-full ${d ? "cursor-pointer" : ""} ${l && a ? "sticky z-[1] bg-[var(--malachite-card-background)]" : ""}`,
150
- style: l && a ? { top: c } : void 0,
151
- onClick: d,
146
+ className: `group flex items-center w-full ${b ? "cursor-pointer" : ""} ${n && r ? "sticky z-[1] bg-[var(--malachite-card-background)]" : ""}`,
147
+ style: n && r ? { top: u } : void 0,
148
+ onClick: b,
152
149
  role: "presentation",
153
150
  children: [
154
- /* @__PURE__ */ e("span", { className: "shrink-0 flex items-center pl-[16px] pr-[12px]", children: d && /* @__PURE__ */ e(
151
+ /* @__PURE__ */ o("span", { className: "shrink-0 flex items-center pl-[16px] pr-[12px]", children: b && /* @__PURE__ */ o(
155
152
  "button",
156
153
  {
157
154
  type: "button",
158
155
  className: `appearance-none bg-transparent border-0 p-0 flex items-center cursor-pointer ${_}`,
159
- "aria-expanded": a,
156
+ "aria-expanded": r,
160
157
  "aria-controls": s,
161
- "aria-label": p,
162
- onClick: (v) => {
163
- v.stopPropagation(), d();
158
+ "aria-label": g,
159
+ onClick: (l) => {
160
+ l.stopPropagation(), b();
164
161
  },
165
- children: /* @__PURE__ */ e(j, { expanded: a })
162
+ children: /* @__PURE__ */ o(F, { expanded: r })
166
163
  }
167
164
  ) }),
168
165
  t
169
166
  ]
170
167
  }
171
168
  ),
172
- a && /* @__PURE__ */ e("div", { id: s, children: n })
169
+ r && /* @__PURE__ */ o("div", { id: s, children: a })
173
170
  ] });
174
171
  },
175
- { Controls: z }
176
- ), O = ({
172
+ { Controls: K }
173
+ ), $ = ({
177
174
  children: t,
178
- padding: n = !1,
179
- overflow: a = "hidden",
180
- role: r,
181
- "aria-label": l,
182
- "aria-labelledby": c,
183
- className: b = "",
184
- style: u
185
- }) => /* @__PURE__ */ e(
175
+ padding: a = !1,
176
+ overflow: r = "hidden",
177
+ role: e,
178
+ "aria-label": n,
179
+ "aria-labelledby": u,
180
+ className: c = "",
181
+ style: m
182
+ }) => /* @__PURE__ */ o(
186
183
  "div",
187
184
  {
188
- className: `w-full rounded-[var(--malachite-radius-xxl,14px)] ${a === "clip" ? "overflow-clip" : a === "visible" ? "overflow-visible" : "overflow-hidden"} bg-[var(--malachite-card-background)] border border-solid border-[var(--malachite-card-border)] ${n ? "py-3 px-4" : ""} ${b}`,
189
- style: { boxShadow: X, ...I, ...u },
190
- role: r,
191
- "aria-label": l,
192
- "aria-labelledby": c,
185
+ className: `w-full rounded-[var(--malachite-radius-xxl,14px)] ${r === "clip" ? "overflow-clip" : r === "visible" ? "overflow-visible" : "overflow-hidden"} bg-[var(--malachite-card-background)] border border-solid border-[var(--malachite-card-border)] ${a ? "py-3 px-4" : ""} ${c}`,
186
+ style: { boxShadow: H, ...G, ...m },
187
+ role: e,
188
+ "aria-label": n,
189
+ "aria-labelledby": u,
193
190
  children: t
194
191
  }
195
192
  );
196
- O.Row = C;
197
- O.ExpandableRow = H;
193
+ $.Row = O;
194
+ $.ExpandableRow = q;
198
195
  export {
199
- aa as EXPANDABLE_ROW_LEAD_PX,
200
- O as Surface,
201
- H as SurfaceExpandableRow,
202
- C as SurfaceRow,
203
- O as default
196
+ te as EXPANDABLE_ROW_LEAD_PX,
197
+ $ as Surface,
198
+ q as SurfaceExpandableRow,
199
+ O as SurfaceRow,
200
+ $ as default
204
201
  };
205
202
  //# sourceMappingURL=Surface.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Surface.js","sources":["../../src/components/Surface.tsx"],"sourcesContent":["import React from 'react';\nimport DisclosureArrow from './DisclosureArrow';\nimport { FOCUS_RING_INSET } from './focusRing';\nimport { isRenderableNode } from './renderableNode';\nimport {\n FOREGROUND_RESET,\n SELECTED_ROW_ACCENT,\n SELECTED_ROW_BACKGROUND,\n SELECTED_ROW_FOREGROUND,\n SELECTED_TEXT_CONTEXT,\n} from './selectedRow';\n\nexport interface SurfaceProps {\n children?: React.ReactNode;\n padding?: boolean;\n /**\n * Content overflow. Defaults to `hidden` so children are clipped to the rounded\n * corners. Use `clip` to keep the rounded clipping WITHOUT creating a scroll\n * container — so a `position: sticky` descendant still pins (unlike `hidden`,\n * which traps it). `visible` disables clipping entirely.\n */\n overflow?: 'hidden' | 'visible' | 'clip';\n role?: React.AriaRole;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n style?: React.CSSProperties;\n}\n\nexport interface SurfaceRowProps {\n children?: React.ReactNode;\n /** Renders a bottom divider — omit on the last row in a Surface. */\n divider?: boolean;\n /** Removes the hover affordance / disables the control (e.g. while loading/busy). */\n disabled?: boolean;\n /**\n * When provided, the whole row becomes clickable: it renders as a `<button>`\n * (or `<a>` when `href` is set), so the entire row is the click target with\n * native focus + Enter/Space — no manual tabIndex/key handlers. For a\n * selectable row, put a presentational `<Radio>`/`<Checkbox>` inside as the\n * visual indicator; do NOT nest an interactive control (invalid + double tab stop).\n */\n onClick?: (event: React.MouseEvent) => void;\n /** Renders the clickable row as an anchor instead of a button. */\n href?: string;\n /** Announces the row as selected — `aria-checked` under a `radio`/`checkbox` role,\n * `aria-current` otherwise — and paints `Table`'s selected treatment unless `selection`\n * says not to. */\n selected?: boolean;\n /** How a `selected` row shows it. `highlight` paints the treatment; `announce` leaves the\n * visual to a control inside the row and only sets the ARIA state. Defaults to `announce`\n * under `role=\"checkbox\"` and `highlight` otherwise. */\n selection?: 'highlight' | 'announce';\n /** Content pinned right, outside the row button, so it may hold its own control. */\n trailing?: React.ReactNode;\n /**\n * Tints the whole row by what it reports. `muted` is a row whose subject is inactive —\n * not disabled: it stays interactive. `success` and `error` are for a row that carries\n * an outcome, where the result belongs to the whole line rather than to one cell in it.\n */\n tone?: 'default' | 'muted' | 'success' | 'error';\n /** ARIA role for a clickable row, e.g. `radio`/`checkbox` (wrap the list in a `radiogroup`). */\n role?: React.AriaRole;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n style?: React.CSSProperties;\n}\n\n/**\n * The outcome tones reuse the tag tokens rather than minting row ones, so a row saying \"this\n * passed\" and a tag saying it are the same green wherever the two sit together.\n */\nconst TONE_CLASSES: Record<NonNullable<SurfaceRowProps['tone']>, string> = {\n default: '',\n muted: 'bg-[var(--malachite-card-dimmed-background)]',\n success: 'bg-[var(--malachite-tag-success-background)]',\n error: 'bg-[var(--malachite-tag-error-background)]',\n};\n\n/**\n * The text an outcome tone carries with it, through the same context channel a selected row\n * uses, so `Typography` inside the row follows the tint instead of staying near-black on it.\n * `color` as well, for row content that is not Typography.\n *\n * Only the outcome tones. `muted` dims its subject rather than recolouring it, and its\n * foreground is the ordinary one.\n */\nconst TONE_FOREGROUNDS: Partial<Record<NonNullable<SurfaceRowProps['tone']>, string>> = {\n success: 'var(--malachite-tag-success-foreground)',\n error: 'var(--malachite-tag-error-foreground)',\n};\n\nconst TRIPLE_SHADOW =\n '0px 0px 4px 0px rgba(0,0,0,0.08), 0px 4px 4px 0px rgba(0,0,0,0.08), 0px 4px 10px 0px rgba(0,0,0,0.05)';\n\n/**\n * A single full-bleed row inside a <Surface>. Owns the row chrome — hover\n * highlight, colour transition and an optional bottom divider — so consumers\n * compose their own content inside without re-implementing design-system styling.\n * Pass `onClick`/`href` to make the entire row clickable (rendered as a real\n * button/anchor, so keyboard navigation works natively).\n */\nconst SurfaceRow: React.FC<SurfaceRowProps> = ({\n children,\n divider = false,\n disabled = false,\n onClick,\n href,\n selected,\n selection,\n trailing,\n tone = 'default',\n role,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n style,\n}) => {\n const interactive = Boolean(onClick || href);\n const hover =\n disabled && interactive\n ? ''\n : 'transition-colors hover:bg-[var(--malachite-buttonlist-hover-background)]';\n\n // A class, not an inline colour, which would outrank the hover utility. It replaces the\n // button reset's `bg-transparent` rather than joining it: same specificity, so the winner\n // would be whichever Tailwind emitted last.\n const tinted = tone !== 'default';\n const toneClass = TONE_CLASSES[tone];\n\n const chromeClasses = [\n 'w-full text-left border-0',\n toneClass,\n divider ? 'border-b border-solid border-[var(--malachite-card-border)]' : '',\n hover,\n ]\n .filter(Boolean)\n .join(' ');\n\n const controlClasses = [\n interactive\n ? `appearance-none ${tinted ? '' : 'bg-transparent'} p-0 ${FOCUS_RING_INSET}`\n : '',\n interactive && !disabled ? 'cursor-pointer' : '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const classes = [chromeClasses, controlClasses, className].filter(Boolean).join(' ');\n\n const paints = selection ? selection === 'highlight' : role !== 'checkbox';\n\n // A gradient layer so the tint composites over hover, and an inset shadow because\n // `ring-*` silently doesn't paint in a shadow root.\n const selectedStyle: React.CSSProperties =\n selected && paints\n ? {\n backgroundImage: `linear-gradient(${SELECTED_ROW_BACKGROUND}, ${SELECTED_ROW_BACKGROUND})`,\n color: SELECTED_ROW_FOREGROUND,\n boxShadow: `inset 2px 0 0 ${SELECTED_ROW_ACCENT}`,\n ...SELECTED_TEXT_CONTEXT,\n }\n : {};\n\n const toneForeground = TONE_FOREGROUNDS[tone];\n const toneStyle: React.CSSProperties = toneForeground\n ? ({\n color: toneForeground,\n '--malachite-ctx-text-primary': toneForeground,\n } as React.CSSProperties)\n : {};\n\n // `selected` last of the two: a row can be both, and selection is the state the reader is\n // acting on, so it wins the colour.\n const rowStyle = { ...toneStyle, ...selectedStyle, ...style };\n\n const ariaChecked = role === 'radio' || role === 'checkbox' ? Boolean(selected) : undefined;\n // `aria-current`, not `aria-pressed`: a selected row is one of many choices, not a toggle\n // (same call as `Dropdown`'s options). A role that carries its own state uses that instead.\n const ariaCurrent = ariaChecked === undefined && selected ? true : undefined;\n\n // Everything a control would have carried, for the branches that render none: the row\n // element is then the only thing assistive tech sees. `aria-disabled` because there is no\n // control to be natively disabled — and it is inert without a role, like the name.\n const rowFallbackAria = {\n role,\n 'aria-checked': ariaChecked,\n 'aria-current': ariaCurrent,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-disabled': role && disabled ? true : undefined,\n };\n\n if (isRenderableNode(trailing)) {\n const control =\n href && !disabled ? (\n <a\n href={href}\n onClick={onClick}\n className={`${controlClasses} border-0 flex-1 min-w-0 text-left no-underline text-inherit`}\n role={role}\n aria-checked={ariaChecked}\n aria-current={ariaCurrent}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n {children}\n </a>\n ) : onClick ? (\n <button\n type=\"button\"\n onClick={onClick}\n disabled={disabled}\n className={`${controlClasses} border-0 flex-1 min-w-0 text-left`}\n role={role}\n aria-checked={ariaChecked}\n aria-current={ariaCurrent}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n {children}\n </button>\n ) : (\n // The set goes here, not on the wrapper: `radio` and `checkbox` make their\n // descendants presentational, which would bury a control in the trailing slot.\n <div className=\"flex-1 min-w-0\" {...rowFallbackAria}>\n {children}\n </div>\n );\n\n return (\n <div\n className={[chromeClasses, 'flex items-center', className]\n .filter(Boolean)\n .join(' ')}\n style={rowStyle}\n >\n {control}\n <div className=\"shrink-0 flex items-center\">{trailing}</div>\n </div>\n );\n }\n\n if (href && !disabled) {\n return (\n <a\n href={href}\n onClick={onClick}\n className={`${classes} no-underline text-inherit`}\n style={rowStyle}\n role={role}\n aria-checked={ariaChecked}\n aria-current={ariaCurrent}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n {children}\n </a>\n );\n }\n\n if (onClick) {\n return (\n <button\n type=\"button\"\n onClick={onClick}\n disabled={disabled}\n className={classes}\n style={rowStyle}\n role={role}\n aria-checked={ariaChecked}\n aria-current={ariaCurrent}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n {children}\n </button>\n );\n }\n\n return (\n <div className={classes} style={rowStyle} {...rowFallbackAria}>\n {children}\n </div>\n );\n};\n\nexport interface SurfaceExpandableRowProps {\n /** The row itself, laid out across the line. May hold its own controls. */\n header: React.ReactNode;\n /** The body, rendered beneath the row while it is open. */\n children?: React.ReactNode;\n expanded: boolean;\n /** Omit for a row that cannot open. The arrow's space is still reserved, so a list of\n * rows stays in one column whether or not each one has a body. */\n onToggle?: (expanded: boolean) => void;\n /**\n * Pins the row while its body scrolls, so a long body never leaves the reader without\n * the line it belongs to. Offset by whatever is already pinned above it.\n */\n sticky?: boolean;\n stickyTopOffset?: number;\n divider?: boolean;\n tone?: SurfaceRowProps['tone'];\n /** Names the disclosure control, which is otherwise only an arrow. */\n 'aria-label'?: string;\n className?: string;\n style?: React.CSSProperties;\n}\n\n/**\n * Stops a click inside it from toggling the row, for the cells that hold controls.\n *\n * Explicit rather than sniffing the event's target for an interactive ancestor: a control\n * rendering into a shadow root retargets the event to its host, so the sniff would miss\n * exactly the components most likely to sit in a row.\n */\nconst ExpandableRowControls: React.FC<{\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n}> = ({ children, className = '', style }) => (\n <div className={className} style={style} onClick={(event) => event.stopPropagation()}>\n {children}\n </div>\n);\n\n/**\n * A row that opens to reveal a body, for a line that carries its own controls.\n *\n * Not `Accordion`: that puts its header inside the toggle button, so a header holding a\n * dropdown or a second button is invalid. Here the row surface takes the click and a cell\n * opts out with `ExpandableRow.Controls`, while the arrow stays a real button so the\n * keyboard reaches it.\n */\n/**\n * The space before the header: the arrow's own inset, its glyph and the gap after it.\n * Exported so a consumer aligning a column header above these rows offsets by the same\n * amount instead of guessing at it.\n */\nexport const EXPANDABLE_ROW_LEAD_PX = 39;\n\nconst SurfaceExpandableRow: React.FC<SurfaceExpandableRowProps> & {\n Controls: typeof ExpandableRowControls;\n} = Object.assign(\n ({\n header,\n children,\n expanded,\n onToggle,\n sticky = false,\n stickyTopOffset = 0,\n divider = false,\n tone = 'default',\n 'aria-label': ariaLabel,\n className = '',\n style,\n }: SurfaceExpandableRowProps) => {\n const bodyId = React.useId();\n const toggle = onToggle ? () => onToggle(!expanded) : undefined;\n\n return (\n <SurfaceRow divider={divider} tone={tone} className={className} style={style}>\n {/* `group` so the arrow takes its hover state from the whole row. */}\n <div\n className={`group flex items-center w-full ${toggle ? 'cursor-pointer' : ''} ${\n sticky && expanded\n ? 'sticky z-[1] bg-[var(--malachite-card-background)]'\n : ''\n }`}\n style={sticky && expanded ? { top: stickyTopOffset } : undefined}\n // Presentational: the arrow below is the keyboard control, and this only\n // widens the pointer target.\n onClick={toggle}\n role=\"presentation\"\n >\n {/* Reserved whether or not this row opens, so a list stays in one column.\n The inset and gap match Accordion's header. */}\n <span className=\"shrink-0 flex items-center pl-[16px] pr-[12px]\">\n {toggle && (\n <button\n type=\"button\"\n className={`appearance-none bg-transparent border-0 p-0 flex items-center cursor-pointer ${FOCUS_RING_INSET}`}\n aria-expanded={expanded}\n aria-controls={bodyId}\n aria-label={ariaLabel}\n onClick={(event) => {\n event.stopPropagation();\n toggle();\n }}\n >\n <DisclosureArrow expanded={expanded} />\n </button>\n )}\n </span>\n {header}\n </div>\n {expanded && <div id={bodyId}>{children}</div>}\n </SurfaceRow>\n );\n },\n { Controls: ExpandableRowControls },\n);\n\ninterface SurfaceComponent extends React.FC<SurfaceProps> {\n Row: React.FC<SurfaceRowProps>;\n ExpandableRow: typeof SurfaceExpandableRow;\n}\n\nconst Surface = (({\n children,\n padding = false,\n overflow = 'hidden',\n role,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n style,\n}: SurfaceProps) => {\n // Literal class names (not interpolated) so Tailwind's JIT emits them.\n const overflowClass =\n overflow === 'clip'\n ? 'overflow-clip'\n : overflow === 'visible'\n ? 'overflow-visible'\n : 'overflow-hidden';\n return (\n <div\n className={`w-full rounded-[var(--malachite-radius-xxl,14px)] ${overflowClass} bg-[var(--malachite-card-background)] border border-solid border-[var(--malachite-card-border)] ${padding ? 'py-3 px-4' : ''} ${className}`}\n style={{ boxShadow: TRIPLE_SHADOW, ...FOREGROUND_RESET, ...style }}\n role={role}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n {children}\n </div>\n );\n}) as SurfaceComponent;\n\nSurface.Row = SurfaceRow;\nSurface.ExpandableRow = SurfaceExpandableRow;\n\nexport default Surface;\nexport { Surface, SurfaceRow, SurfaceExpandableRow };\n"],"names":["TONE_CLASSES","TONE_FOREGROUNDS","TRIPLE_SHADOW","SurfaceRow","children","divider","disabled","onClick","href","selected","selection","trailing","tone","role","ariaLabel","ariaLabelledBy","className","style","interactive","hover","tinted","chromeClasses","controlClasses","FOCUS_RING_INSET","classes","selectedStyle","SELECTED_ROW_BACKGROUND","SELECTED_ROW_FOREGROUND","SELECTED_ROW_ACCENT","SELECTED_TEXT_CONTEXT","toneForeground","rowStyle","ariaChecked","ariaCurrent","rowFallbackAria","isRenderableNode","control","jsx","jsxs","ExpandableRowControls","event","EXPANDABLE_ROW_LEAD_PX","SurfaceExpandableRow","header","expanded","onToggle","sticky","stickyTopOffset","bodyId","React","toggle","DisclosureArrow","Surface","padding","overflow","FOREGROUND_RESET"],"mappings":";;;;;;AAyEA,MAAMA,IAAqE;AAAA,EACvE,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AACX,GAUMC,IAAkF;AAAA,EACpF,SAAS;AAAA,EACT,OAAO;AACX,GAEMC,IACF,yGASEC,IAAwC,CAAC;AAAA,EAC3C,UAAAC;AAAA,EACA,SAAAC,IAAU;AAAA,EACV,UAAAC,IAAW;AAAA,EACX,SAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,MAAAC;AAAA,EACA,cAAcC;AAAA,EACd,mBAAmBC;AAAA,EACnB,WAAAC,IAAY;AAAA,EACZ,OAAAC;AACJ,MAAM;AACF,QAAMC,IAAc,GAAQX,KAAWC,IACjCW,IACFb,KAAYY,IACN,KACA,6EAKJE,IAASR,MAAS,WAGlBS,IAAgB;AAAA,IAClB;AAAA,IAHcrB,EAAaY,CAAI;AAAA,IAK/BP,IAAU,gEAAgE;AAAA,IAC1Ec;AAAA,EAAA,EAEC,OAAO,OAAO,EACd,KAAK,GAAG,GAEPG,IAAiB;AAAA,IACnBJ,IACM,mBAAmBE,IAAS,KAAK,gBAAgB,QAAQG,CAAgB,KACzE;AAAA,IACNL,KAAe,CAACZ,IAAW,mBAAmB;AAAA,EAAA,EAE7C,OAAO,OAAO,EACd,KAAK,GAAG,GAEPkB,IAAU,CAACH,GAAeC,GAAgBN,CAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,GAM7ES,IACFhB,MALWC,IAAYA,MAAc,cAAcG,MAAS,cAMtD;AAAA,IACI,iBAAiB,mBAAmBa,CAAuB,KAAKA,CAAuB;AAAA,IACvF,OAAOC;AAAA,IACP,WAAW,iBAAiBC,CAAmB;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AAU;AAAA,EACV,UAAAC,IAAW;AAAA,EACX,MAAAzC;AAAA,EACA,cAAcC;AAAA,EACd,mBAAmBC;AAAA,EACnB,WAAAC,IAAY;AAAA,EACZ,OAAAC;AACJ,MASQ,gBAAAoB;AAAA,EAAC;AAAA,EAAA;AAAA,IACG,WAAW,qDAPfiB,MAAa,SACP,kBACAA,MAAa,YACX,qBACA,iBAGyE,oGAAoGD,IAAU,cAAc,EAAE,IAAIrC,CAAS;AAAA,IACxN,OAAO,EAAE,WAAWd,GAAe,GAAGqD,GAAkB,GAAGtC,EAAA;AAAA,IAC3D,MAAAJ;AAAA,IACA,cAAYC;AAAA,IACZ,mBAAiBC;AAAA,IAEhB,UAAAX;AAAA,EAAA;AAAA;AAKbgD,EAAQ,MAAMjD;AACdiD,EAAQ,gBAAgBV;"}
1
+ {"version":3,"file":"Surface.js","sources":["../../src/components/Surface.tsx"],"sourcesContent":["import React from 'react';\nimport { paintOnChild } from './asChild';\nimport DisclosureArrow from './DisclosureArrow';\nimport { FOCUS_RING_INSET } from './focusRing';\nimport { isRenderableNode } from './renderableNode';\nimport {\n FOREGROUND_RESET,\n SELECTED_ROW_ACCENT,\n SELECTED_ROW_BACKGROUND,\n SELECTED_ROW_FOREGROUND,\n SELECTED_TEXT_CONTEXT,\n} from './selectedRow';\n\nexport interface SurfaceProps {\n children?: React.ReactNode;\n padding?: boolean;\n /**\n * Content overflow. Defaults to `hidden` so children are clipped to the rounded\n * corners. Use `clip` to keep the rounded clipping WITHOUT creating a scroll\n * container — so a `position: sticky` descendant still pins (unlike `hidden`,\n * which traps it). `visible` disables clipping entirely.\n */\n overflow?: 'hidden' | 'visible' | 'clip';\n role?: React.AriaRole;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n style?: React.CSSProperties;\n}\n\ninterface SurfaceRowChromeProps {\n children?: React.ReactNode;\n /** Renders a bottom divider — omit on the last row in a Surface. */\n divider?: boolean;\n /** Removes the hover affordance / disables the control (e.g. while loading/busy). */\n disabled?: boolean;\n /** Announces the row as selected — `aria-checked` under a `radio`/`checkbox` role,\n * `aria-current` otherwise — and paints `Table`'s selected treatment unless `selection`\n * says not to. */\n selected?: boolean;\n /** How a `selected` row shows it. `highlight` paints the treatment; `announce` leaves the\n * visual to a control inside the row and only sets the ARIA state. Defaults to `announce`\n * under `role=\"checkbox\"` and `highlight` otherwise. */\n selection?: 'highlight' | 'announce';\n /**\n * Tints the whole row by what it reports. `muted` is a row whose subject is inactive —\n * not disabled: it stays interactive. `success` and `error` are for a row that carries\n * an outcome, where the result belongs to the whole line rather than to one cell in it.\n */\n tone?: 'default' | 'muted' | 'success' | 'error';\n className?: string;\n style?: React.CSSProperties;\n}\n\n/** Stays an interface under its original name: a consumer may `extends` it. */\nexport interface SurfaceRowProps extends SurfaceRowChromeProps {\n asChild?: false;\n /**\n * When provided, the whole row becomes clickable: it renders as a `<button>`\n * (or `<a>` when `href` is set), so the entire row is the click target with\n * native focus + Enter/Space — no manual tabIndex/key handlers. For a\n * selectable row, put a presentational `<Radio>`/`<Checkbox>` inside as the\n * visual indicator; do NOT nest an interactive control (invalid + double tab stop).\n */\n onClick?: (event: React.MouseEvent) => void;\n /** Renders the clickable row as an anchor instead of a button. */\n href?: string;\n /** Content pinned right, outside the row button, so it may hold its own control. */\n trailing?: React.ReactNode;\n /** ARIA role for a clickable row, e.g. `radio`/`checkbox` (wrap the list in a `radiogroup`). */\n role?: React.AriaRole;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n}\n\n/**\n * The outcome tones reuse the tag tokens rather than minting row ones, so a row saying \"this\n * passed\" and a tag saying it are the same green wherever the two sit together.\n */\nconst TONE_CLASSES: Record<NonNullable<SurfaceRowProps['tone']>, string> = {\n default: '',\n muted: 'bg-[var(--malachite-card-dimmed-background)]',\n success: 'bg-[var(--malachite-tag-success-background)]',\n error: 'bg-[var(--malachite-tag-error-background)]',\n};\n\n/**\n * The text an outcome tone carries with it, through the same context channel a selected row\n * uses, so `Typography` inside the row follows the tint instead of staying near-black on it.\n * `color` as well, for row content that is not Typography.\n *\n * Only the outcome tones. `muted` dims its subject rather than recolouring it, and its\n * foreground is the ordinary one.\n */\nconst TONE_FOREGROUNDS: Partial<Record<NonNullable<SurfaceRowProps['tone']>, string>> = {\n success: 'var(--malachite-tag-success-foreground)',\n error: 'var(--malachite-tag-error-foreground)',\n};\n\nexport interface SurfaceRowAsChildProps extends SurfaceRowChromeProps {\n asChild: true;\n children: React.ReactElement;\n}\n\nexport type AnySurfaceRowProps = SurfaceRowProps | SurfaceRowAsChildProps;\n\nconst TRIPLE_SHADOW =\n '0px 0px 4px 0px rgba(0,0,0,0.08), 0px 4px 4px 0px rgba(0,0,0,0.08), 0px 4px 10px 0px rgba(0,0,0,0.05)';\n\n/**\n * A single full-bleed row inside a <Surface>. Owns the row chrome — hover\n * highlight, colour transition and an optional bottom divider — so consumers\n * compose their own content inside without re-implementing design-system styling.\n * Pass `onClick`/`href` to make the entire row clickable (rendered as a real\n * button/anchor, so keyboard navigation works natively).\n */\nconst SurfaceRow: React.FC<AnySurfaceRowProps> = (props) => {\n const {\n children,\n divider = false,\n disabled = false,\n selected,\n selection,\n tone = 'default',\n className = '',\n style,\n } = props;\n const asChild = props.asChild === true;\n const { onClick, href, trailing, role } = asChild\n ? ({} as SurfaceRowProps)\n : (props as SurfaceRowProps);\n const ariaLabel = asChild ? undefined : (props as SurfaceRowProps)['aria-label'];\n const ariaLabelledBy = asChild ? undefined : (props as SurfaceRowProps)['aria-labelledby'];\n const interactive = Boolean(onClick || href);\n // `asChild` is interactive for the hover affordance only, not the focus/reset classes.\n const hover =\n disabled && (interactive || asChild)\n ? ''\n : 'transition-colors hover:bg-[var(--malachite-buttonlist-hover-background)]';\n\n // A class, not an inline colour, which would outrank the hover utility. It replaces the\n // button reset's `bg-transparent` rather than joining it: same specificity, so the winner\n // would be whichever Tailwind emitted last.\n const tinted = tone !== 'default';\n const toneClass = TONE_CLASSES[tone];\n\n const chromeClasses = [\n 'w-full text-left border-0',\n toneClass,\n divider ? 'border-b border-solid border-[var(--malachite-card-border)]' : '',\n hover,\n ]\n .filter(Boolean)\n .join(' ');\n\n const controlClasses = [\n interactive\n ? `appearance-none ${tinted ? '' : 'bg-transparent'} p-0 ${FOCUS_RING_INSET}`\n : '',\n interactive && !disabled ? 'cursor-pointer' : '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const classes = [chromeClasses, controlClasses, className].filter(Boolean).join(' ');\n\n const paints = selection ? selection === 'highlight' : role !== 'checkbox';\n\n // A gradient layer so the tint composites over hover, and an inset shadow because\n // `ring-*` silently doesn't paint in a shadow root.\n const selectedStyle: React.CSSProperties =\n selected && paints\n ? {\n backgroundImage: `linear-gradient(${SELECTED_ROW_BACKGROUND}, ${SELECTED_ROW_BACKGROUND})`,\n color: SELECTED_ROW_FOREGROUND,\n boxShadow: `inset 2px 0 0 ${SELECTED_ROW_ACCENT}`,\n ...SELECTED_TEXT_CONTEXT,\n }\n : {};\n\n const toneForeground = TONE_FOREGROUNDS[tone];\n const toneStyle: React.CSSProperties = toneForeground\n ? ({\n color: toneForeground,\n '--malachite-ctx-text-primary': toneForeground,\n } as React.CSSProperties)\n : {};\n\n // `selected` last of the two: a row can be both, and selection is the state the reader is\n // acting on, so it wins the colour.\n const rowStyle = { ...toneStyle, ...selectedStyle, ...style };\n\n const ariaChecked = role === 'radio' || role === 'checkbox' ? Boolean(selected) : undefined;\n // `aria-current`, not `aria-pressed`: a selected row is one of many choices, not a toggle\n // (same call as `Dropdown`'s options). A role that carries its own state uses that instead.\n const ariaCurrent = ariaChecked === undefined && selected ? true : undefined;\n\n // Everything a control would have carried, for the branches that render none: the row\n // element is then the only thing assistive tech sees. `aria-disabled` because there is no\n // control to be natively disabled — and it is inert without a role, like the name.\n const rowFallbackAria = {\n role,\n 'aria-checked': ariaChecked,\n 'aria-current': ariaCurrent,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n 'aria-disabled': role && disabled ? true : undefined,\n };\n\n if (asChild) {\n return paintOnChild(children, classes, rowStyle);\n }\n\n if (isRenderableNode(trailing)) {\n const control =\n href && !disabled ? (\n <a\n href={href}\n onClick={onClick}\n className={`${controlClasses} border-0 flex-1 min-w-0 text-left no-underline text-inherit`}\n role={role}\n aria-checked={ariaChecked}\n aria-current={ariaCurrent}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n {children}\n </a>\n ) : onClick ? (\n <button\n type=\"button\"\n onClick={onClick}\n disabled={disabled}\n className={`${controlClasses} border-0 flex-1 min-w-0 text-left`}\n role={role}\n aria-checked={ariaChecked}\n aria-current={ariaCurrent}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n {children}\n </button>\n ) : (\n // The set goes here, not on the wrapper: `radio` and `checkbox` make their\n // descendants presentational, which would bury a control in the trailing slot.\n <div className=\"flex-1 min-w-0\" {...rowFallbackAria}>\n {children}\n </div>\n );\n\n return (\n <div\n className={[chromeClasses, 'flex items-center', className]\n .filter(Boolean)\n .join(' ')}\n style={rowStyle}\n >\n {control}\n <div className=\"shrink-0 flex items-center\">{trailing}</div>\n </div>\n );\n }\n\n if (href && !disabled) {\n return (\n <a\n href={href}\n onClick={onClick}\n className={`${classes} no-underline text-inherit`}\n style={rowStyle}\n role={role}\n aria-checked={ariaChecked}\n aria-current={ariaCurrent}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n {children}\n </a>\n );\n }\n\n if (onClick) {\n return (\n <button\n type=\"button\"\n onClick={onClick}\n disabled={disabled}\n className={classes}\n style={rowStyle}\n role={role}\n aria-checked={ariaChecked}\n aria-current={ariaCurrent}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n {children}\n </button>\n );\n }\n\n return (\n <div className={classes} style={rowStyle} {...rowFallbackAria}>\n {children}\n </div>\n );\n};\n\nexport interface SurfaceExpandableRowProps {\n /** The row itself, laid out across the line. May hold its own controls. */\n header: React.ReactNode;\n /** The body, rendered beneath the row while it is open. */\n children?: React.ReactNode;\n expanded: boolean;\n /** Omit for a row that cannot open. The arrow's space is still reserved, so a list of\n * rows stays in one column whether or not each one has a body. */\n onToggle?: (expanded: boolean) => void;\n /**\n * Pins the row while its body scrolls, so a long body never leaves the reader without\n * the line it belongs to. Offset by whatever is already pinned above it.\n */\n sticky?: boolean;\n stickyTopOffset?: number;\n divider?: boolean;\n tone?: SurfaceRowProps['tone'];\n /** Names the disclosure control, which is otherwise only an arrow. */\n 'aria-label'?: string;\n className?: string;\n style?: React.CSSProperties;\n}\n\n/**\n * Stops a click inside it from toggling the row, for the cells that hold controls.\n *\n * Explicit rather than sniffing the event's target for an interactive ancestor: a control\n * rendering into a shadow root retargets the event to its host, so the sniff would miss\n * exactly the components most likely to sit in a row.\n */\nconst ExpandableRowControls: React.FC<{\n children?: React.ReactNode;\n className?: string;\n style?: React.CSSProperties;\n}> = ({ children, className = '', style }) => (\n <div className={className} style={style} onClick={(event) => event.stopPropagation()}>\n {children}\n </div>\n);\n\n/**\n * A row that opens to reveal a body, for a line that carries its own controls.\n *\n * Not `Accordion`: that puts its header inside the toggle button, so a header holding a\n * dropdown or a second button is invalid. Here the row surface takes the click and a cell\n * opts out with `ExpandableRow.Controls`, while the arrow stays a real button so the\n * keyboard reaches it.\n */\n/**\n * The space before the header: the arrow's own inset, its glyph and the gap after it.\n * Exported so a consumer aligning a column header above these rows offsets by the same\n * amount instead of guessing at it.\n */\nexport const EXPANDABLE_ROW_LEAD_PX = 39;\n\nconst SurfaceExpandableRow: React.FC<SurfaceExpandableRowProps> & {\n Controls: typeof ExpandableRowControls;\n} = Object.assign(\n ({\n header,\n children,\n expanded,\n onToggle,\n sticky = false,\n stickyTopOffset = 0,\n divider = false,\n tone = 'default',\n 'aria-label': ariaLabel,\n className = '',\n style,\n }: SurfaceExpandableRowProps) => {\n const bodyId = React.useId();\n const toggle = onToggle ? () => onToggle(!expanded) : undefined;\n\n return (\n <SurfaceRow divider={divider} tone={tone} className={className} style={style}>\n {/* `group` so the arrow takes its hover state from the whole row. */}\n <div\n className={`group flex items-center w-full ${toggle ? 'cursor-pointer' : ''} ${\n sticky && expanded\n ? 'sticky z-[1] bg-[var(--malachite-card-background)]'\n : ''\n }`}\n style={sticky && expanded ? { top: stickyTopOffset } : undefined}\n // Presentational: the arrow below is the keyboard control, and this only\n // widens the pointer target.\n onClick={toggle}\n role=\"presentation\"\n >\n {/* Reserved whether or not this row opens, so a list stays in one column.\n The inset and gap match Accordion's header. */}\n <span className=\"shrink-0 flex items-center pl-[16px] pr-[12px]\">\n {toggle && (\n <button\n type=\"button\"\n className={`appearance-none bg-transparent border-0 p-0 flex items-center cursor-pointer ${FOCUS_RING_INSET}`}\n aria-expanded={expanded}\n aria-controls={bodyId}\n aria-label={ariaLabel}\n onClick={(event) => {\n event.stopPropagation();\n toggle();\n }}\n >\n <DisclosureArrow expanded={expanded} />\n </button>\n )}\n </span>\n {header}\n </div>\n {expanded && <div id={bodyId}>{children}</div>}\n </SurfaceRow>\n );\n },\n { Controls: ExpandableRowControls },\n);\n\ninterface SurfaceComponent extends React.FC<SurfaceProps> {\n Row: React.FC<AnySurfaceRowProps>;\n ExpandableRow: typeof SurfaceExpandableRow;\n}\n\nconst Surface = (({\n children,\n padding = false,\n overflow = 'hidden',\n role,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n style,\n}: SurfaceProps) => {\n // Literal class names (not interpolated) so Tailwind's JIT emits them.\n const overflowClass =\n overflow === 'clip'\n ? 'overflow-clip'\n : overflow === 'visible'\n ? 'overflow-visible'\n : 'overflow-hidden';\n return (\n <div\n className={`w-full rounded-[var(--malachite-radius-xxl,14px)] ${overflowClass} bg-[var(--malachite-card-background)] border border-solid border-[var(--malachite-card-border)] ${padding ? 'py-3 px-4' : ''} ${className}`}\n style={{ boxShadow: TRIPLE_SHADOW, ...FOREGROUND_RESET, ...style }}\n role={role}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n >\n {children}\n </div>\n );\n}) as SurfaceComponent;\n\nSurface.Row = SurfaceRow;\nSurface.ExpandableRow = SurfaceExpandableRow;\n\nexport default Surface;\nexport { Surface, SurfaceRow, SurfaceExpandableRow };\n"],"names":["TONE_CLASSES","TONE_FOREGROUNDS","TRIPLE_SHADOW","SurfaceRow","props","children","divider","disabled","selected","selection","tone","className","style","asChild","onClick","href","trailing","role","ariaLabel","ariaLabelledBy","interactive","hover","tinted","chromeClasses","controlClasses","FOCUS_RING_INSET","classes","selectedStyle","SELECTED_ROW_BACKGROUND","SELECTED_ROW_FOREGROUND","SELECTED_ROW_ACCENT","SELECTED_TEXT_CONTEXT","toneForeground","rowStyle","ariaChecked","ariaCurrent","rowFallbackAria","paintOnChild","isRenderableNode","control","jsx","jsxs","ExpandableRowControls","event","EXPANDABLE_ROW_LEAD_PX","SurfaceExpandableRow","header","expanded","onToggle","sticky","stickyTopOffset","bodyId","React","toggle","DisclosureArrow","Surface","padding","overflow","FOREGROUND_RESET"],"mappings":";;;;;;;AA+EA,MAAMA,IAAqE;AAAA,EACvE,SAAS;AAAA,EACT,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AACX,GAUMC,IAAkF;AAAA,EACpF,SAAS;AAAA,EACT,OAAO;AACX,GASMC,IACF,yGASEC,IAA2C,CAACC,MAAU;AACxD,QAAM;AAAA,IACF,UAAAC;AAAA,IACA,SAAAC,IAAU;AAAA,IACV,UAAAC,IAAW;AAAA,IACX,UAAAC;AAAA,IACA,WAAAC;AAAA,IACA,MAAAC,IAAO;AAAA,IACP,WAAAC,IAAY;AAAA,IACZ,OAAAC;AAAA,EAAA,IACAR,GACES,IAAUT,EAAM,YAAY,IAC5B,EAAE,SAAAU,GAAS,MAAAC,GAAM,UAAAC,GAAU,MAAAC,MAASJ,IACnC,CAAA,IACAT,GACDc,IAAYL,IAAU,SAAaT,EAA0B,YAAY,GACzEe,IAAiBN,IAAU,SAAaT,EAA0B,iBAAiB,GACnFgB,IAAc,GAAQN,KAAWC,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=> {
3
+ const o = l.Children.only(t);
4
+ return l.cloneElement(o, {
5
+ className: [n, o.props.className].filter(Boolean).join(" "),
6
+ style: { ...s, ...o.props.style },
7
+ ...e === void 0 ? {} : { children: e }
8
+ });
9
+ };
10
+ export {
11
+ r as paintOnChild
12
+ };
13
+ //# sourceMappingURL=asChild.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asChild.js","sources":["../../src/components/asChild.tsx"],"sourcesContent":["import React from 'react';\n\n/** A colliding Tailwind utility on the child may lose; override through `style`. */\nexport const paintOnChild = (\n children: React.ReactNode,\n className: string,\n style?: React.CSSProperties,\n replaceChildren?: React.ReactNode,\n): React.ReactElement => {\n const child = React.Children.only(children) as React.ReactElement<{\n className?: string;\n style?: React.CSSProperties;\n children?: React.ReactNode;\n }>;\n return React.cloneElement(child, {\n className: [className, child.props.className].filter(Boolean).join(' '),\n style: { ...style, ...child.props.style },\n ...(replaceChildren === undefined ? {} : { children: replaceChildren }),\n });\n};\n"],"names":["paintOnChild","children","className","style","replaceChildren","child","React"],"mappings":";AAGO,MAAMA,IAAe,CACxBC,GACAC,GACAC,GACAC,MACqB;AACrB,QAAMC,IAAQC,EAAM,SAAS,KAAKL,CAAQ;AAK1C,SAAOK,EAAM,aAAaD,GAAO;AAAA,IAC7B,WAAW,CAACH,GAAWG,EAAM,MAAM,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG;AAAA,IACtE,OAAO,EAAE,GAAGF,GAAO,GAAGE,EAAM,MAAM,MAAA;AAAA,IAClC,GAAID,MAAoB,SAAY,KAAK,EAAE,UAAUA,EAAA;AAAA,EAAgB,CACxE;AACL;"}