@stackone/malachite 2.80.0 → 2.81.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 +2 -1
- package/dist/components/Surface.js +90 -86
- package/dist/components/Surface.js.map +1 -1
- package/dist/components/ZoomableImage.js +67 -0
- package/dist/components/ZoomableImage.js.map +1 -0
- package/dist/index.d.ts +35 -1
- package/dist/index.js +393 -391
- package/dist/index.js.map +1 -1
- package/dist/tailwind.css.js +1 -1
- package/package.json +1 -1
package/COMPONENTS.md
CHANGED
|
@@ -7,7 +7,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
7
7
|
## Layout & containers
|
|
8
8
|
|
|
9
9
|
- **`Chat`** — A chat column: `Chat.Thread` scrolls and pins itself to the newest message, `Chat.Composer` keeps its own height and owns the Enter/Shift+Enter convention, and `Chat.Message`, `Chat.ToolCall` and `Chat.Thinking` render one turn each. A user turn sits right and hugs its text; an assistant turn runs full width, and `variant="card"` frames it with its state, copy and rating controls, and a token/model line. `variant="bubble"` is a third treatment, not a repaint of either: tinted bubbles whose flattened corner points at whoever spoke, so authorship reads before the words do. `Chat.Context` lists what the conversation can see — a removable chip per source, and an add affordance only when a handler is given. `Chat.Thinking` and a loading turn draw bars in the shape of the answer rather than a spinner. The row under a composer is `ComposerChip`, `ContextMeter` and `ModelPicker` — PillButton tabs, so it reads as attached to the field; `ModelPicker` opens a portalled menu with a submenu per model. The transcript is a live `log` region, so a streamed reply is announced, and it shows a centred empty state until the first turn. _Key props:_ `Chat`: `children`, `className`. `Thread`: `aria-label`, `emptyTitle`, `emptyDescription`, `emptyIcon`. `Message`: `role`, `variant` (`plain` | `card`), `content`, `children`, `name`, `avatarSrc`, `status` (`streaming` | `completed` | `error`), `loading`, `onCopy`, `onFeedback`, `usage`. `ToolCall`: `name`, `status` (`running` | `completed` | `error`), `callId`, `input`, `output`, `defaultExpanded`. `Thinking`: `label`. `Composer`: `value`, `onChange`, `onSend`, `onStop`, `busy`, `disabled`, `placeholder`, `maxLength`, `rows`, `children`. `ComposerChip`: `label`, `icon`, `trailingIcon`, `onClick`, `disabled`. `ContextMeter`: `used`, `limit`, `cached`, `label`. `ModelPicker`: `models`, `value`, `optionValue`, `onChange`, `openUp`, `disabled`. `Context`: `label`, `items` (`{id, label, onRemove?}`), `onAdd`, `className`.
|
|
10
|
-
- **`Surface`** — Rounded, bordered card container with the standard elevation shadow. Use `overflow="clip"` to keep the rounded clipping while letting a `position: sticky` descendant still pin (`hidden` would trap it); `visible` disables clipping. _Key props:_ `children`, `padding`, `overflow`, `shadow` (`false` sits the card flat, without the elevation shadow), `className`, `style`.
|
|
10
|
+
- **`Surface`** — Rounded, bordered card container with the standard elevation shadow. Use `overflow="clip"` to keep the rounded clipping while letting a `position: sticky` descendant still pin (`hidden` would trap it); `visible` disables clipping. _Key props:_ `children`, `padding`, `overflow`, `shadow` (`false` sits the card flat, without the elevation shadow), `tone` (`default` | `highlight`; `highlight` paints the warm ground with no border, and sits flat unless `shadow` is passed, for a static block that stands out from the page, such as a hero or a guide's section header; its ground is too close to `Surface.Row`'s hover for clickable rows inside it), `className`, `style`.
|
|
11
11
|
- **`SurfaceRow`** — A full-bleed row inside a Surface (used as `Surface.Row`). Owns hover highlight, colour transition and an optional bottom divider. Pass `onClick`/`href` to make the whole row clickable (renders as a real button/anchor, so keyboard nav works). For a selectable row use `role="radio"` + `selected` and put a presentational `<Radio>` inside as the indicator; `selected` then paints the same treatment `Table` gives `selectedRowKey`. Under `role="checkbox"` it only announces — a multi-select row carries its own checkbox, and a highlight marking one of many says nothing when most rows are checked. `selection` overrides that either way (`highlight` / `announce`). `selected="mixed"` marks a partly selected checkbox row (`aria-checked="mixed"`); it never paints or marks a row current, and counts as not selected under any other role. Use `trailing` for a control that must stay interactive — it renders outside the row button, which a nested control could not be. `revealTrailing` shows that control only on hover, keyboard focus or while a menu it opened is open, keeping it in the tab order and always showing it on a touch screen. `tone="muted"` tints a row whose subject is inactive, which `disabled` does not: a muted row stays clickable. _Key props:_ `divider`, `disabled`, `tone` (`default` | `muted`), `inset` (`none` | `compact` — the row owns an 8px by 16px inset, wrapping `trailing` too, so its content needs no padding wrapper), `onClick`, `href`, `target`, `rel`, `selected` (`boolean` | `"mixed"`), `selection` (`highlight` | `tint` | `announce`; `tint` paints the selected treatment without the accent bar, for a menu whose choice is already marked inside the row), `trailing`, `revealTrailing`, `role`, `className`, `style`.
|
|
12
12
|
- **`SurfaceExpandableRow`** — A row that opens to reveal a body (used as `Surface.ExpandableRow`), for a line that carries its own controls. Not `Accordion`, which puts its header inside the toggle button, so a header holding a dropdown or a second button would be invalid: here the row surface takes the click and a cell opts out by wrapping its controls in `ExpandableRow.Controls`, while the arrow stays a real button so the keyboard reaches it. That opt-out is explicit rather than sniffing the event target for an interactive ancestor, because a control rendering into a shadow root retargets the event to its host. `sticky` pins the row while its body scrolls, offset by `stickyTopOffset` for whatever is already pinned above it; it only pins while open, since a closed row has nothing to scroll past. _Key props:_ `header`, `children`, `expanded`, `onToggle`, `sticky`, `stickyTopOffset`, `divider`, `tone`, `aria-label`, `className`, `style`.
|
|
13
13
|
- **`DisclosureArrow`** — The expand/collapse triangle disclosure UI shares (`Accordion`, `Surface.ExpandableRow`). Owns its colour states so they never drift between usages: `text-primary` when expanded, `text-placeholder` otherwise, and dark on hover inside a `group` ancestor — put `group` on the clickable header or row so that hover state activates. _Key props:_ `expanded`, `size`, `className`.
|
|
@@ -118,6 +118,7 @@ The catalog of components exported from `@stackone/malachite`. **Reach for one o
|
|
|
118
118
|
- **`Table`** — Data table with columns, sizing, pagination and row selection. `column.align` places a column's header as well as its cells. What lands on the aligned edge is the last thing in the header row rather than the title: the sort caret on a sortable column, the info icon on one carrying `info` without a sorter. `headerVariant` picks the header layout, and only `inline` lines header and body up exactly, because both are cells of one `<table>`. `detached` builds them from flex rows, where a sortable header cell is 32px narrower than a non-sortable one — its padding sits on the inner button rather than on the flex item — so its header cells sit 15–17px off their column at any alignment; reach for `inline` where exact alignment matters. Sorting is internal, so the array passed as `data` is not the order rendered once a column is sorted: `onVisibleOrderChange` reports the rows in render order — the whole of `data`, compared by `rowKey` so an equal order never re-fires — for a consumer stepping a master-detail view the way the user sees it. _Key props:_ `TableColumns` (incl. `align`), `TableSize`, `TableType`, `TableRowSelection`, `TablePaginationPosition`, `headerVariant`, `onVisibleOrderChange`.
|
|
119
119
|
- **`Statistic`** — Displays a statistic value with a label; primary/secondary sizes. _Key props:_ `StatisticValueSize`.
|
|
120
120
|
- **`Avatar`** — Logo/initial avatar. Renders the image when available, otherwise a coloured tile with the first letter of `name`, or with `fallback="placeholder"` the generic "no logo available" tile. Encapsulates the fallback colour. _Key props:_ `src`, `name`, `size`, `shape="square" | "circle"`, `fallback="initial" | "placeholder"`.
|
|
121
|
+
- **`ZoomableImage`** — An image shown inline as a button that enlarges it, for a screenshot too detailed to read at its inline size. The thumbnail is shown at its own width up to the width of its container, never stretched, and stops at 240px tall, cropping a tall image to its top. The enlarged image sits on the scrim with no card, as large as the window allows at its own aspect ratio, up to its natural size, and a click anywhere or ESC closes it. The thumbnail is named `Enlarge image: <alt>` and the dialog is named by `title`, or by `alt` when `title` is missing or empty, so `alt` must be non-empty. `onError` reports a thumbnail that failed to load, so the caller can leave it out rather than show a broken image. The thumbnail loads lazily, so for one below the fold that report comes once it nears the viewport, not on render. _Key props:_ `src`, `alt`, `title`, `onError`.
|
|
121
122
|
- **`AvatarGroup`** — A horizontal stack of overlapping `Avatar`s, first on top, for a "these apps" cluster beside a label or in a button. The gap between tiles is cut out of the tile beneath rather than painted, so it shows whatever ground the group sits on. Past `max` the rest fold into a `+N` tile. One image to assistive tech, named by its items joined with ", " unless `aria-label` says otherwise. _Key props:_ `items` (`{src?, name, fallback?}[]`), `size` (px, default 24), `shape` (`square` | `circle`), `max` (default 4), `overlap` (fraction of `size`, 0 to 0.5, default 0.3), `aria-label`, `className`, `style`.
|
|
122
123
|
- **`AppLogo`** — A connector's mark, optionally with its name and version tag. Builds on `Avatar`, so a missing or broken logo falls back to the generic "no logo available" placeholder, a neutral grey tile with a darker square, the same mark stackone-logos.com serves. The gap tightens below 18px so the mark and label still read as one unit. _Key props:_ `src`, `name`, `showName`, `size`, `nameSize`, `nameWeight`, `version`, `truncate`, `className`.
|
|
123
124
|
- **`ConnectionHeader`** — Two tilted logo tiles (from → to) showing a connection between apps. _Key props:_ `from`, `to` (`ConnectionEndpoint`: `icon`, `label`, `background`).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as t, jsxs as O } from "react/jsx-runtime";
|
|
2
2
|
import q from "react";
|
|
3
3
|
import { DisclosureArrow as J } from "./DisclosureArrow.js";
|
|
4
4
|
import { paintOnChild as M } from "./asChild.js";
|
|
@@ -7,11 +7,11 @@ import { resolveRel as I } from "./linkRel.js";
|
|
|
7
7
|
import { isRenderableNode as Q } from "./renderableNode.js";
|
|
8
8
|
import { safeHref as Y } from "./safeHref.js";
|
|
9
9
|
import { FOREGROUND_RESET as Z, SELECTED_TEXT_CONTEXT as ee, SELECTED_ROW_ACCENT as ae, SELECTED_ROW_FOREGROUND as re, SELECTED_ROW_BACKGROUND as B } from "./selectedRow.js";
|
|
10
|
-
const
|
|
10
|
+
const te = {
|
|
11
11
|
none: "",
|
|
12
12
|
// The 16px is ROW_INSET_PX in accordionBodyInset.ts too; Accordion's bodyIndent gives it back.
|
|
13
13
|
compact: "px-[16px] py-[8px]"
|
|
14
|
-
},
|
|
14
|
+
}, oe = {
|
|
15
15
|
default: "",
|
|
16
16
|
muted: "bg-[var(--malachite-card-dimmed-background)]",
|
|
17
17
|
success: "bg-[var(--malachite-tag-success-background)]",
|
|
@@ -19,105 +19,105 @@ const oe = {
|
|
|
19
19
|
}, le = {
|
|
20
20
|
success: "var(--malachite-tag-success-foreground)",
|
|
21
21
|
error: "var(--malachite-tag-error-foreground)"
|
|
22
|
-
}, ie = "opacity-0 transition-opacity group-[:hover]/row:opacity-100 group-focus-within/row:opacity-100 has-[[aria-expanded=true]]:opacity-100 [@media(hover:none)]:opacity-100", ne = "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)", F = (
|
|
22
|
+
}, ie = "opacity-0 transition-opacity group-[:hover]/row:opacity-100 group-focus-within/row:opacity-100 has-[[aria-expanded=true]]:opacity-100 [@media(hover:none)]:opacity-100", ne = "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)", F = (o) => {
|
|
23
23
|
const {
|
|
24
24
|
children: a,
|
|
25
25
|
divider: r = !1,
|
|
26
26
|
disabled: e = !1,
|
|
27
|
-
selected:
|
|
27
|
+
selected: c,
|
|
28
28
|
selection: s,
|
|
29
29
|
tone: d = "default",
|
|
30
30
|
inset: f = "none",
|
|
31
31
|
className: b = "",
|
|
32
|
-
style:
|
|
33
|
-
} =
|
|
34
|
-
onClick:
|
|
32
|
+
style: h
|
|
33
|
+
} = o, l = o.asChild === !0, {
|
|
34
|
+
onClick: i,
|
|
35
35
|
href: u,
|
|
36
36
|
target: m,
|
|
37
37
|
rel: T,
|
|
38
38
|
trailing: $,
|
|
39
|
-
revealTrailing:
|
|
40
|
-
role:
|
|
41
|
-
} =
|
|
39
|
+
revealTrailing: A,
|
|
40
|
+
role: n
|
|
41
|
+
} = l ? {} : o, x = Y(u), g = l ? void 0 : o["aria-label"], v = l ? void 0 : o["aria-labelledby"], C = l ? void 0 : o.tabIndex, S = !!(i || x), U = e && (S || l) ? "" : "transition-colors hover:bg-[var(--malachite-buttonlist-hover-background)]", G = d !== "default", W = oe[d], w = !l && Q($), R = te[f], X = R && !w ? "" : "p-0", D = [
|
|
42
42
|
"w-full text-left border-0",
|
|
43
43
|
W,
|
|
44
44
|
r ? "border-b border-solid border-[var(--malachite-card-border)]" : "",
|
|
45
|
-
|
|
45
|
+
U
|
|
46
46
|
].filter(Boolean).join(" "), k = [
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
].filter(Boolean).join(" "), N = [
|
|
47
|
+
S ? `appearance-none ${G ? "" : "bg-transparent"} ${X} ${j}` : "",
|
|
48
|
+
S && !e ? "cursor-pointer" : ""
|
|
49
|
+
].filter(Boolean).join(" "), N = [D, k, w ? "" : R, b].filter(Boolean).join(" "), H = s ? s !== "announce" : n !== "checkbox", z = s !== "tint", K = c === !0 && H ? {
|
|
50
50
|
backgroundImage: `linear-gradient(${B}, ${B})`,
|
|
51
51
|
color: re,
|
|
52
52
|
...z ? { boxShadow: `inset 2px 0 0 ${ae}` } : {},
|
|
53
53
|
...ee
|
|
54
|
-
} : {}, _ = le[d],
|
|
54
|
+
} : {}, _ = le[d], E = { ..._ ? {
|
|
55
55
|
color: _,
|
|
56
56
|
"--malachite-ctx-text-primary": _
|
|
57
|
-
} : {}, ...K, ...
|
|
58
|
-
role:
|
|
57
|
+
} : {}, ...K, ...h }, p = n === "checkbox" && c === "mixed" ? "mixed" : n === "radio" || n === "checkbox" ? c === !0 : void 0, y = p === void 0 && c === !0 ? !0 : void 0, L = {
|
|
58
|
+
role: n,
|
|
59
59
|
"aria-checked": p,
|
|
60
|
-
"aria-current":
|
|
61
|
-
"aria-label":
|
|
60
|
+
"aria-current": y,
|
|
61
|
+
"aria-label": g,
|
|
62
62
|
"aria-labelledby": v,
|
|
63
|
-
"aria-disabled":
|
|
63
|
+
"aria-disabled": n && e ? !0 : void 0
|
|
64
64
|
};
|
|
65
|
-
if (
|
|
66
|
-
return M(a, N,
|
|
67
|
-
if (
|
|
68
|
-
const V =
|
|
65
|
+
if (l)
|
|
66
|
+
return M(a, N, E);
|
|
67
|
+
if (w) {
|
|
68
|
+
const V = x && !e ? /* @__PURE__ */ t(
|
|
69
69
|
"a",
|
|
70
70
|
{
|
|
71
|
-
href:
|
|
71
|
+
href: x,
|
|
72
72
|
target: m,
|
|
73
73
|
rel: I(T, m),
|
|
74
|
-
onClick:
|
|
74
|
+
onClick: i,
|
|
75
75
|
className: `${k} border-0 flex-1 min-w-0 text-left no-underline text-inherit`,
|
|
76
|
-
role:
|
|
76
|
+
role: n,
|
|
77
77
|
tabIndex: C,
|
|
78
78
|
"aria-checked": p,
|
|
79
|
-
"aria-current":
|
|
80
|
-
"aria-label":
|
|
79
|
+
"aria-current": y,
|
|
80
|
+
"aria-label": g,
|
|
81
81
|
"aria-labelledby": v,
|
|
82
82
|
children: a
|
|
83
83
|
}
|
|
84
|
-
) :
|
|
84
|
+
) : i ? /* @__PURE__ */ t(
|
|
85
85
|
"button",
|
|
86
86
|
{
|
|
87
87
|
type: "button",
|
|
88
|
-
onClick:
|
|
88
|
+
onClick: i,
|
|
89
89
|
disabled: e,
|
|
90
90
|
className: `${k} border-0 flex-1 min-w-0 text-left`,
|
|
91
|
-
role:
|
|
91
|
+
role: n,
|
|
92
92
|
tabIndex: C,
|
|
93
93
|
"aria-checked": p,
|
|
94
|
-
"aria-current":
|
|
95
|
-
"aria-label":
|
|
94
|
+
"aria-current": y,
|
|
95
|
+
"aria-label": g,
|
|
96
96
|
"aria-labelledby": v,
|
|
97
97
|
children: a
|
|
98
98
|
}
|
|
99
99
|
) : (
|
|
100
100
|
// The set goes here, not on the wrapper: `radio` and `checkbox` make their
|
|
101
101
|
// descendants presentational, which would bury a control in the trailing slot.
|
|
102
|
-
/* @__PURE__ */
|
|
102
|
+
/* @__PURE__ */ t("div", { className: "flex-1 min-w-0", ...L, children: a })
|
|
103
103
|
);
|
|
104
104
|
return /* @__PURE__ */ O(
|
|
105
105
|
"div",
|
|
106
106
|
{
|
|
107
107
|
className: [
|
|
108
|
-
|
|
108
|
+
D,
|
|
109
109
|
"flex items-center",
|
|
110
110
|
R,
|
|
111
|
-
|
|
111
|
+
A ? "group/row" : "",
|
|
112
112
|
b
|
|
113
113
|
].filter(Boolean).join(" "),
|
|
114
|
-
style:
|
|
114
|
+
style: E,
|
|
115
115
|
children: [
|
|
116
116
|
V,
|
|
117
|
-
/* @__PURE__ */
|
|
117
|
+
/* @__PURE__ */ t(
|
|
118
118
|
"div",
|
|
119
119
|
{
|
|
120
|
-
className: `shrink-0 flex items-center ${
|
|
120
|
+
className: `shrink-0 flex items-center ${A ? ie : ""}`,
|
|
121
121
|
children: $
|
|
122
122
|
}
|
|
123
123
|
)
|
|
@@ -125,115 +125,119 @@ const oe = {
|
|
|
125
125
|
}
|
|
126
126
|
);
|
|
127
127
|
}
|
|
128
|
-
return
|
|
128
|
+
return x && !e ? /* @__PURE__ */ t(
|
|
129
129
|
"a",
|
|
130
130
|
{
|
|
131
|
-
href:
|
|
131
|
+
href: x,
|
|
132
132
|
target: m,
|
|
133
133
|
rel: I(T, m),
|
|
134
|
-
onClick:
|
|
134
|
+
onClick: i,
|
|
135
135
|
className: `${N} no-underline text-inherit`,
|
|
136
|
-
style:
|
|
137
|
-
role:
|
|
136
|
+
style: E,
|
|
137
|
+
role: n,
|
|
138
138
|
tabIndex: C,
|
|
139
139
|
"aria-checked": p,
|
|
140
|
-
"aria-current":
|
|
141
|
-
"aria-label":
|
|
140
|
+
"aria-current": y,
|
|
141
|
+
"aria-label": g,
|
|
142
142
|
"aria-labelledby": v,
|
|
143
143
|
children: a
|
|
144
144
|
}
|
|
145
|
-
) :
|
|
145
|
+
) : i ? /* @__PURE__ */ t(
|
|
146
146
|
"button",
|
|
147
147
|
{
|
|
148
148
|
type: "button",
|
|
149
|
-
onClick:
|
|
149
|
+
onClick: i,
|
|
150
150
|
disabled: e,
|
|
151
151
|
className: N,
|
|
152
|
-
style:
|
|
153
|
-
role:
|
|
152
|
+
style: E,
|
|
153
|
+
role: n,
|
|
154
154
|
tabIndex: C,
|
|
155
155
|
"aria-checked": p,
|
|
156
|
-
"aria-current":
|
|
157
|
-
"aria-label":
|
|
156
|
+
"aria-current": y,
|
|
157
|
+
"aria-label": g,
|
|
158
158
|
"aria-labelledby": v,
|
|
159
159
|
children: a
|
|
160
160
|
}
|
|
161
|
-
) : /* @__PURE__ */
|
|
162
|
-
}, ce = ({ children:
|
|
161
|
+
) : /* @__PURE__ */ t("div", { className: N, style: E, ...L, children: a });
|
|
162
|
+
}, ce = ({ children: o, className: a = "", style: r }) => /* @__PURE__ */ t("div", { className: a, style: r, onClick: (e) => e.stopPropagation(), children: o }), ye = 39, se = Object.assign(
|
|
163
163
|
({
|
|
164
|
-
header:
|
|
164
|
+
header: o,
|
|
165
165
|
children: a,
|
|
166
166
|
expanded: r,
|
|
167
167
|
onToggle: e,
|
|
168
|
-
sticky:
|
|
168
|
+
sticky: c = !1,
|
|
169
169
|
stickyTopOffset: s = 0,
|
|
170
170
|
divider: d = !1,
|
|
171
171
|
tone: f = "default",
|
|
172
172
|
"aria-label": b,
|
|
173
|
-
className:
|
|
174
|
-
style:
|
|
173
|
+
className: h = "",
|
|
174
|
+
style: l
|
|
175
175
|
}) => {
|
|
176
|
-
const
|
|
177
|
-
return /* @__PURE__ */ O(F, { divider: d, tone: f, className:
|
|
176
|
+
const i = q.useId(), u = e ? () => e(!r) : void 0;
|
|
177
|
+
return /* @__PURE__ */ O(F, { divider: d, tone: f, className: h, style: l, children: [
|
|
178
178
|
/* @__PURE__ */ O(
|
|
179
179
|
"div",
|
|
180
180
|
{
|
|
181
|
-
className: `group flex items-center w-full ${u ? "cursor-pointer" : ""} ${
|
|
182
|
-
style:
|
|
181
|
+
className: `group flex items-center w-full ${u ? "cursor-pointer" : ""} ${c && r ? "sticky z-[1] bg-[var(--malachite-card-background)]" : ""}`,
|
|
182
|
+
style: c && r ? { top: s } : void 0,
|
|
183
183
|
onClick: u,
|
|
184
184
|
role: "presentation",
|
|
185
185
|
children: [
|
|
186
|
-
/* @__PURE__ */
|
|
186
|
+
/* @__PURE__ */ t("span", { className: "shrink-0 flex items-center pl-[16px] pr-[12px]", children: u && /* @__PURE__ */ t(
|
|
187
187
|
"button",
|
|
188
188
|
{
|
|
189
189
|
type: "button",
|
|
190
190
|
className: `appearance-none bg-transparent border-0 p-0 flex items-center cursor-pointer ${j}`,
|
|
191
191
|
"aria-expanded": r,
|
|
192
|
-
"aria-controls":
|
|
192
|
+
"aria-controls": i,
|
|
193
193
|
"aria-label": b,
|
|
194
194
|
onClick: (m) => {
|
|
195
195
|
m.stopPropagation(), u();
|
|
196
196
|
},
|
|
197
|
-
children: /* @__PURE__ */
|
|
197
|
+
children: /* @__PURE__ */ t(J, { expanded: r })
|
|
198
198
|
}
|
|
199
199
|
) }),
|
|
200
|
-
|
|
200
|
+
o
|
|
201
201
|
]
|
|
202
202
|
}
|
|
203
203
|
),
|
|
204
|
-
r && /* @__PURE__ */
|
|
204
|
+
r && /* @__PURE__ */ t("div", { id: i, children: a })
|
|
205
205
|
] });
|
|
206
206
|
},
|
|
207
207
|
{ Controls: ce }
|
|
208
|
-
),
|
|
209
|
-
|
|
208
|
+
), de = {
|
|
209
|
+
default: "bg-[var(--malachite-card-background)] border border-solid border-[var(--malachite-card-border)]",
|
|
210
|
+
highlight: "bg-[var(--malachite-card-warm-background,rgb(244,242,240))]"
|
|
211
|
+
}, P = ({
|
|
212
|
+
children: o,
|
|
210
213
|
padding: a = !1,
|
|
211
214
|
overflow: r = "hidden",
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
"aria-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
215
|
+
tone: e = "default",
|
|
216
|
+
shadow: c = e !== "highlight",
|
|
217
|
+
role: s,
|
|
218
|
+
"aria-label": d,
|
|
219
|
+
"aria-labelledby": f,
|
|
220
|
+
className: b = "",
|
|
221
|
+
style: h
|
|
222
|
+
}) => /* @__PURE__ */ t(
|
|
219
223
|
"div",
|
|
220
224
|
{
|
|
221
|
-
className: `w-full rounded-[var(--malachite-radius-xxl,14px)] ${r === "clip" ? "overflow-clip" : r === "visible" ? "overflow-visible" : "overflow-hidden"}
|
|
225
|
+
className: `w-full rounded-[var(--malachite-radius-xxl,14px)] ${r === "clip" ? "overflow-clip" : r === "visible" ? "overflow-visible" : "overflow-hidden"} ${de[e]} ${a ? "py-3 px-4" : ""} ${b}`,
|
|
222
226
|
style: {
|
|
223
|
-
...
|
|
227
|
+
...c ? { boxShadow: ne } : {},
|
|
224
228
|
...Z,
|
|
225
|
-
...
|
|
229
|
+
...h
|
|
226
230
|
},
|
|
227
|
-
role:
|
|
228
|
-
"aria-label":
|
|
229
|
-
"aria-labelledby":
|
|
230
|
-
children:
|
|
231
|
+
role: s,
|
|
232
|
+
"aria-label": d,
|
|
233
|
+
"aria-labelledby": f,
|
|
234
|
+
children: o
|
|
231
235
|
}
|
|
232
236
|
);
|
|
233
237
|
P.Row = F;
|
|
234
238
|
P.ExpandableRow = se;
|
|
235
239
|
export {
|
|
236
|
-
|
|
240
|
+
ye as EXPANDABLE_ROW_LEAD_PX,
|
|
237
241
|
P as Surface,
|
|
238
242
|
se as SurfaceExpandableRow,
|
|
239
243
|
F as SurfaceRow,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Surface.js","sources":["../../src/components/Surface.tsx"],"sourcesContent":["import React from 'react';\nimport DisclosureArrow from './DisclosureArrow';\nimport { paintOnChild } from './asChild';\nimport { FOCUS_RING_INSET } from './focusRing';\nimport { resolveRel } from './linkRel';\nimport { isRenderableNode } from './renderableNode';\nimport { safeHref } from './safeHref';\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 /** `false` drops the elevation shadow, for a card that sits flat on its ground. */\n shadow?: boolean;\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. `'mixed'` is for a `checkbox` row that is partly selected: it announces\n * `aria-checked=\"mixed\"` there, never paints and never marks the row current, and counts\n * as not selected under any other role. */\n selected?: boolean | 'mixed';\n /** How a `selected` row shows it. `highlight` paints the treatment; `tint` paints it\n * without the accent bar, for a menu whose choice is already marked inside the row;\n * `announce` leaves the visual to a control inside the row and only sets the ARIA state.\n * Defaults to `announce` under `role=\"checkbox\"` and `highlight` otherwise. */\n selection?: 'highlight' | 'tint' | '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 /** `compact` is an 8px by 16px inset the row owns. */\n inset?: 'none' | 'compact';\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst INSET_CLASSES: Record<NonNullable<SurfaceRowChromeProps['inset']>, string> = {\n none: '',\n // The 16px is ROW_INSET_PX in accordionBodyInset.ts too; Accordion's bodyIndent gives it back.\n compact: 'px-[16px] py-[8px]',\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 target?: React.HTMLAttributeAnchorTarget;\n rel?: string;\n /** Content pinned right, outside the row button, so it may hold its own control. */\n trailing?: React.ReactNode;\n /**\n * Shows `trailing` only while the row is hovered or holds focus, and while a menu\n * it opened is still open. Hidden by opacity, so it stays in the tab order; a touch screen,\n * which has no hover, always shows it.\n */\n revealTrailing?: boolean;\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 /** `-1` takes the row out of the Tab order, for a roving radio group. */\n tabIndex?: number;\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\n// Not `group-hover` or `group-has-[:focus-visible]`: WebKit never applies the first (its\n// `@media (hover: hover)` nested in the group selector) nor the second inside a shadow root,\n// so the control stayed hidden in Safari. An open menu takes focus out of the row into a\n// portal, and would otherwise lose its trigger.\nconst REVEALED_ON_INTERACTION =\n 'opacity-0 transition-opacity group-[:hover]/row:opacity-100 group-focus-within/row:opacity-100 has-[[aria-expanded=true]]:opacity-100 [@media(hover:none)]:opacity-100';\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 inset = 'none',\n className = '',\n style,\n } = props;\n const asChild = props.asChild === true;\n const {\n onClick,\n href: rawHref,\n target,\n rel,\n trailing,\n revealTrailing,\n role,\n } = asChild ? ({} as SurfaceRowProps) : (props as SurfaceRowProps);\n // A rejected href (e.g. `javascript:`) leaves the row a button or a plain row, never an anchor.\n const href = safeHref(rawHref);\n const ariaLabel = asChild ? undefined : (props as SurfaceRowProps)['aria-label'];\n const ariaLabelledBy = asChild ? undefined : (props as SurfaceRowProps)['aria-labelledby'];\n const tabIndex = asChild ? undefined : (props as SurfaceRowProps).tabIndex;\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 hasTrailing = !asChild && isRenderableNode(trailing);\n const insetClass = INSET_CLASSES[inset];\n const controlPadding = insetClass && !hasTrailing ? '' : 'p-0';\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'} ${controlPadding} ${FOCUS_RING_INSET}`\n : '',\n interactive && !disabled ? 'cursor-pointer' : '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const classes = [chromeClasses, controlClasses, hasTrailing ? '' : insetClass, className]\n .filter(Boolean)\n .join(' ');\n\n const paints = selection ? selection !== 'announce' : role !== 'checkbox';\n const accent = selection !== 'tint';\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 === true && paints\n ? {\n backgroundImage: `linear-gradient(${SELECTED_ROW_BACKGROUND}, ${SELECTED_ROW_BACKGROUND})`,\n color: SELECTED_ROW_FOREGROUND,\n ...(accent ? { 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 // Only a checkbox has a partly-checked state; a radio is chosen or not.\n const ariaChecked =\n role === 'checkbox' && selected === 'mixed'\n ? ('mixed' as const)\n : role === 'radio' || role === 'checkbox'\n ? selected === true\n : 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 ? 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 (hasTrailing) {\n const control =\n href && !disabled ? (\n <a\n href={href}\n target={target}\n rel={resolveRel(rel, target)}\n onClick={onClick}\n className={`${controlClasses} border-0 flex-1 min-w-0 text-left no-underline text-inherit`}\n role={role}\n tabIndex={tabIndex}\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 tabIndex={tabIndex}\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={[\n chromeClasses,\n 'flex items-center',\n insetClass,\n revealTrailing ? 'group/row' : '',\n className,\n ]\n .filter(Boolean)\n .join(' ')}\n style={rowStyle}\n >\n {control}\n <div\n className={`shrink-0 flex items-center ${revealTrailing ? REVEALED_ON_INTERACTION : ''}`}\n >\n {trailing}\n </div>\n </div>\n );\n }\n\n if (href && !disabled) {\n return (\n <a\n href={href}\n target={target}\n rel={resolveRel(rel, target)}\n onClick={onClick}\n className={`${classes} no-underline text-inherit`}\n style={rowStyle}\n role={role}\n tabIndex={tabIndex}\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 tabIndex={tabIndex}\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 shadow = true,\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={{\n ...(shadow ? { boxShadow: TRIPLE_SHADOW } : {}),\n ...FOREGROUND_RESET,\n ...style,\n }}\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":["INSET_CLASSES","TONE_CLASSES","TONE_FOREGROUNDS","REVEALED_ON_INTERACTION","TRIPLE_SHADOW","SurfaceRow","props","children","divider","disabled","selected","selection","tone","inset","className","style","asChild","onClick","rawHref","target","rel","trailing","revealTrailing","role","href","safeHref","ariaLabel","ariaLabelledBy","tabIndex","interactive","hover","tinted","toneClass","hasTrailing","isRenderableNode","insetClass","controlPadding","chromeClasses","controlClasses","FOCUS_RING_INSET","classes","paints","accent","selectedStyle","SELECTED_ROW_BACKGROUND","SELECTED_ROW_FOREGROUND","SELECTED_ROW_ACCENT","SELECTED_TEXT_CONTEXT","toneForeground","rowStyle","ariaChecked","ariaCurrent","rowFallbackAria","paintOnChild","control","jsx","resolveRel","jsxs","ExpandableRowControls","event","EXPANDABLE_ROW_LEAD_PX","SurfaceExpandableRow","header","expanded","onToggle","sticky","stickyTopOffset","bodyId","React","toggle","DisclosureArrow","Surface","padding","overflow","shadow","FOREGROUND_RESET"],"mappings":";;;;;;;;;AA+DA,MAAMA,KAA6E;AAAA,EAC/E,MAAM;AAAA;AAAA,EAEN,SAAS;AACb,GAqCMC,KAAqE;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uE;AAAA,MACH,GAAG5D;AAAA,IAAA;AAAA,IAEP,MAAAQ;AAAA,IACA,cAAYG;AAAA,IACZ,mBAAiBC;AAAA,IAEhB,UAAApB;AAAA,EAAA;AAAA;AAKbgE,EAAQ,MAAMlE;AACdkE,EAAQ,gBAAgBV;"}
|
|
1
|
+
{"version":3,"file":"Surface.js","sources":["../../src/components/Surface.tsx"],"sourcesContent":["import React from 'react';\nimport DisclosureArrow from './DisclosureArrow';\nimport { paintOnChild } from './asChild';\nimport { FOCUS_RING_INSET } from './focusRing';\nimport { resolveRel } from './linkRel';\nimport { isRenderableNode } from './renderableNode';\nimport { safeHref } from './safeHref';\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 type SurfaceTone = 'default' | 'highlight';\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 /**\n * `false` drops the elevation shadow, for a card that sits flat on its ground.\n * Default: `true`, or `false` with `tone=\"highlight\"`.\n */\n shadow?: boolean;\n /**\n * `highlight` paints the warm ground with no border and no shadow, for a static block that\n * stands out from the page, such as a hero or a guide's section header. Its ground is too\n * close to `Surface.Row`'s hover for clickable rows inside it.\n */\n tone?: SurfaceTone;\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. `'mixed'` is for a `checkbox` row that is partly selected: it announces\n * `aria-checked=\"mixed\"` there, never paints and never marks the row current, and counts\n * as not selected under any other role. */\n selected?: boolean | 'mixed';\n /** How a `selected` row shows it. `highlight` paints the treatment; `tint` paints it\n * without the accent bar, for a menu whose choice is already marked inside the row;\n * `announce` leaves the visual to a control inside the row and only sets the ARIA state.\n * Defaults to `announce` under `role=\"checkbox\"` and `highlight` otherwise. */\n selection?: 'highlight' | 'tint' | '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 /** `compact` is an 8px by 16px inset the row owns. */\n inset?: 'none' | 'compact';\n className?: string;\n style?: React.CSSProperties;\n}\n\nconst INSET_CLASSES: Record<NonNullable<SurfaceRowChromeProps['inset']>, string> = {\n none: '',\n // The 16px is ROW_INSET_PX in accordionBodyInset.ts too; Accordion's bodyIndent gives it back.\n compact: 'px-[16px] py-[8px]',\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 target?: React.HTMLAttributeAnchorTarget;\n rel?: string;\n /** Content pinned right, outside the row button, so it may hold its own control. */\n trailing?: React.ReactNode;\n /**\n * Shows `trailing` only while the row is hovered or holds focus, and while a menu\n * it opened is still open. Hidden by opacity, so it stays in the tab order; a touch screen,\n * which has no hover, always shows it.\n */\n revealTrailing?: boolean;\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 /** `-1` takes the row out of the Tab order, for a roving radio group. */\n tabIndex?: number;\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\n// Not `group-hover` or `group-has-[:focus-visible]`: WebKit never applies the first (its\n// `@media (hover: hover)` nested in the group selector) nor the second inside a shadow root,\n// so the control stayed hidden in Safari. An open menu takes focus out of the row into a\n// portal, and would otherwise lose its trigger.\nconst REVEALED_ON_INTERACTION =\n 'opacity-0 transition-opacity group-[:hover]/row:opacity-100 group-focus-within/row:opacity-100 has-[[aria-expanded=true]]:opacity-100 [@media(hover:none)]:opacity-100';\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 inset = 'none',\n className = '',\n style,\n } = props;\n const asChild = props.asChild === true;\n const {\n onClick,\n href: rawHref,\n target,\n rel,\n trailing,\n revealTrailing,\n role,\n } = asChild ? ({} as SurfaceRowProps) : (props as SurfaceRowProps);\n // A rejected href (e.g. `javascript:`) leaves the row a button or a plain row, never an anchor.\n const href = safeHref(rawHref);\n const ariaLabel = asChild ? undefined : (props as SurfaceRowProps)['aria-label'];\n const ariaLabelledBy = asChild ? undefined : (props as SurfaceRowProps)['aria-labelledby'];\n const tabIndex = asChild ? undefined : (props as SurfaceRowProps).tabIndex;\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 hasTrailing = !asChild && isRenderableNode(trailing);\n const insetClass = INSET_CLASSES[inset];\n const controlPadding = insetClass && !hasTrailing ? '' : 'p-0';\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'} ${controlPadding} ${FOCUS_RING_INSET}`\n : '',\n interactive && !disabled ? 'cursor-pointer' : '',\n ]\n .filter(Boolean)\n .join(' ');\n\n const classes = [chromeClasses, controlClasses, hasTrailing ? '' : insetClass, className]\n .filter(Boolean)\n .join(' ');\n\n const paints = selection ? selection !== 'announce' : role !== 'checkbox';\n const accent = selection !== 'tint';\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 === true && paints\n ? {\n backgroundImage: `linear-gradient(${SELECTED_ROW_BACKGROUND}, ${SELECTED_ROW_BACKGROUND})`,\n color: SELECTED_ROW_FOREGROUND,\n ...(accent ? { 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 // Only a checkbox has a partly-checked state; a radio is chosen or not.\n const ariaChecked =\n role === 'checkbox' && selected === 'mixed'\n ? ('mixed' as const)\n : role === 'radio' || role === 'checkbox'\n ? selected === true\n : 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 ? 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 (hasTrailing) {\n const control =\n href && !disabled ? (\n <a\n href={href}\n target={target}\n rel={resolveRel(rel, target)}\n onClick={onClick}\n className={`${controlClasses} border-0 flex-1 min-w-0 text-left no-underline text-inherit`}\n role={role}\n tabIndex={tabIndex}\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 tabIndex={tabIndex}\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={[\n chromeClasses,\n 'flex items-center',\n insetClass,\n revealTrailing ? 'group/row' : '',\n className,\n ]\n .filter(Boolean)\n .join(' ')}\n style={rowStyle}\n >\n {control}\n <div\n className={`shrink-0 flex items-center ${revealTrailing ? REVEALED_ON_INTERACTION : ''}`}\n >\n {trailing}\n </div>\n </div>\n );\n }\n\n if (href && !disabled) {\n return (\n <a\n href={href}\n target={target}\n rel={resolveRel(rel, target)}\n onClick={onClick}\n className={`${classes} no-underline text-inherit`}\n style={rowStyle}\n role={role}\n tabIndex={tabIndex}\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 tabIndex={tabIndex}\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_TONE_CLASSES: Record<SurfaceTone, string> = {\n default:\n 'bg-[var(--malachite-card-background)] border border-solid border-[var(--malachite-card-border)]',\n highlight: 'bg-[var(--malachite-card-warm-background,rgb(244,242,240))]',\n};\n\nconst Surface = (({\n children,\n padding = false,\n overflow = 'hidden',\n tone = 'default',\n shadow = tone !== 'highlight',\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} ${SURFACE_TONE_CLASSES[tone]} ${padding ? 'py-3 px-4' : ''} ${className}`}\n style={{\n ...(shadow ? { boxShadow: TRIPLE_SHADOW } : {}),\n ...FOREGROUND_RESET,\n ...style,\n }}\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":["INSET_CLASSES","TONE_CLASSES","TONE_FOREGROUNDS","REVEALED_ON_INTERACTION","TRIPLE_SHADOW","SurfaceRow","props","children","divider","disabled","selected","selection","tone","inset","className","style","asChild","onClick","rawHref","target","rel","trailing","revealTrailing","role","href","safeHref","ariaLabel","ariaLabelledBy","tabIndex","interactive","hover","tinted","toneClass","hasTrailing","isRenderableNode","insetClass","controlPadding","chromeClasses","controlClasses","FOCUS_RING_INSET","classes","paints","accent","selectedStyle","SELECTED_ROW_BACKGROUND","SELECTED_ROW_FOREGROUND","SELECTED_ROW_ACCENT","SELECTED_TEXT_CONTEXT","toneForeground","rowStyle","ariaChecked","ariaCurrent","rowFallbackAria","paintOnChild","control","jsx","resolveRel","jsxs","ExpandableRowControls","event","EXPANDABLE_ROW_LEAD_PX","SurfaceExpandableRow","header","expanded","onToggle","sticky","stickyTopOffset","bodyId","React","toggle","DisclosureArrow","SURFACE_TONE_CLASSES","Surface","padding","overflow","shadow","FOREGROUND_RESET"],"mappings":";;;;;;;;;AA0EA,MAAMA,KAA6E;AAAA,EAC/E,MAAM;AAAA;AAAA,EAEN,SAAS;AACb,GAqCMC,KAAqE;AAAA,EACvE,SAAS;AAAA,EAC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,IACtJ,OAAO;AAAA,MACH,GAAI6D,IAAS,EAAE,WAAWvE,GAAA,IAAkB,CAAA;AAAA,MAC5C,GAAGwE;AAAA,MACH,GAAG7D;AAAA,IAAA;AAAA,IAEP,MAAAQ;AAAA,IACA,cAAYG;AAAA,IACZ,mBAAiBC;AAAA,IAEhB,UAAApB;AAAA,EAAA;AAAA;AAKbiE,EAAQ,MAAMnE;AACdmE,EAAQ,gBAAgBX;"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsxs as t, Fragment as f, jsx as e } from "react/jsx-runtime";
|
|
2
|
+
import { useState as s } from "react";
|
|
3
|
+
import { Modal as g } from "./Modal.js";
|
|
4
|
+
import { FOCUS_RING as b, FOCUS_RING_INSET as p } from "./focusRing.js";
|
|
5
|
+
const C = ({ src: l, alt: o, title: i, onError: a }) => {
|
|
6
|
+
const [d, r] = s(!1), [c, m] = s(!1), n = () => r(!1), u = () => {
|
|
7
|
+
m(!0), r(!0);
|
|
8
|
+
};
|
|
9
|
+
return /* @__PURE__ */ t(f, { children: [
|
|
10
|
+
/* @__PURE__ */ e(
|
|
11
|
+
"button",
|
|
12
|
+
{
|
|
13
|
+
type: "button",
|
|
14
|
+
"aria-label": `Enlarge image: ${o}`,
|
|
15
|
+
onClick: u,
|
|
16
|
+
className: `block max-h-[240px] w-fit max-w-full cursor-zoom-in overflow-hidden rounded-lg border border-solid border-[var(--malachite-card-border)] bg-transparent p-0 ${b}`,
|
|
17
|
+
children: /* @__PURE__ */ e(
|
|
18
|
+
"img",
|
|
19
|
+
{
|
|
20
|
+
src: l,
|
|
21
|
+
alt: o,
|
|
22
|
+
loading: "lazy",
|
|
23
|
+
decoding: "async",
|
|
24
|
+
onError: a ? () => a() : void 0,
|
|
25
|
+
className: "block h-auto w-full"
|
|
26
|
+
},
|
|
27
|
+
l
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
),
|
|
31
|
+
c && /* @__PURE__ */ e(
|
|
32
|
+
g,
|
|
33
|
+
{
|
|
34
|
+
open: d,
|
|
35
|
+
onClose: n,
|
|
36
|
+
title: i || o,
|
|
37
|
+
size: "fullscreen",
|
|
38
|
+
surface: "none",
|
|
39
|
+
children: /* @__PURE__ */ t("div", { className: "relative flex h-full w-full items-center justify-center", children: [
|
|
40
|
+
/* @__PURE__ */ e(
|
|
41
|
+
"button",
|
|
42
|
+
{
|
|
43
|
+
type: "button",
|
|
44
|
+
"aria-label": "Close enlarged image",
|
|
45
|
+
onClick: n,
|
|
46
|
+
className: `absolute inset-0 z-10 cursor-zoom-out border-0 bg-transparent p-0 ${p}`
|
|
47
|
+
}
|
|
48
|
+
),
|
|
49
|
+
/* @__PURE__ */ e(
|
|
50
|
+
"img",
|
|
51
|
+
{
|
|
52
|
+
src: l,
|
|
53
|
+
alt: o,
|
|
54
|
+
className: "max-h-full max-w-full rounded-lg object-contain"
|
|
55
|
+
},
|
|
56
|
+
l
|
|
57
|
+
)
|
|
58
|
+
] })
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
] });
|
|
62
|
+
};
|
|
63
|
+
export {
|
|
64
|
+
C as ZoomableImage,
|
|
65
|
+
C as default
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=ZoomableImage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ZoomableImage.js","sources":["../../src/components/ZoomableImage.tsx"],"sourcesContent":["import type React from 'react';\nimport { useState } from 'react';\nimport Modal from './Modal';\nimport { FOCUS_RING, FOCUS_RING_INSET } from './focusRing';\n\nexport interface ZoomableImageProps {\n src: string;\n /**\n * Describes the image. Required and non-empty: it names the thumbnail's button and the\n * enlarged view, so an empty `alt` leaves both unnamed.\n */\n alt: string;\n /** Names the enlarged view for assistive tech. Default: `alt`, also when `title` is empty. */\n title?: string;\n /**\n * The thumbnail failed to load, so the caller can leave the image out. A thumbnail loads\n * lazily, so for one below the fold this fires once it nears the viewport, not on render.\n */\n onError?: () => void;\n}\n\n/**\n * An image that enlarges on click, for a screenshot too detailed to read inline. The enlarged\n * image is as large as the window allows at its own aspect ratio, up to its natural size, and a\n * click anywhere closes it.\n */\nconst ZoomableImage: React.FC<ZoomableImageProps> = ({ src, alt, title, onError }) => {\n const [isEnlarged, setIsEnlarged] = useState(false);\n // Latched on first enlarge, so an idle thumbnail mounts no Modal; never reset, so the exit transition still plays.\n const [hasEnlarged, setHasEnlarged] = useState(false);\n const close = () => setIsEnlarged(false);\n const enlarge = () => {\n setHasEnlarged(true);\n setIsEnlarged(true);\n };\n\n return (\n <>\n <button\n type=\"button\"\n aria-label={`Enlarge image: ${alt}`}\n onClick={enlarge}\n className={`block max-h-[240px] w-fit max-w-full cursor-zoom-in overflow-hidden rounded-lg border border-solid border-[var(--malachite-card-border)] bg-transparent p-0 ${FOCUS_RING}`}\n >\n {/* At its own width up to the container's, never stretched. The button, not the image,\n caps the height and clips a tall image to its top: a `max-h` on the image would\n narrow it instead, and the button would fit that narrower width.\n Keyed on `src`: a reused <img> keeps drawing the old image until the new one loads. */}\n <img\n key={src}\n src={src}\n alt={alt}\n loading=\"lazy\"\n decoding=\"async\"\n onError={onError ? () => onError() : undefined}\n className=\"block h-auto w-full\"\n />\n </button>\n {hasEnlarged && (\n <Modal\n open={isEnlarged}\n onClose={close}\n title={title || alt}\n size=\"fullscreen\"\n surface=\"none\"\n >\n {/* The image sits beside the close button, not inside it: a button's children are\n presentational, so an image inside it would never reach assistive tech. */}\n <div className=\"relative flex h-full w-full items-center justify-center\">\n <button\n type=\"button\"\n aria-label=\"Close enlarged image\"\n onClick={close}\n className={`absolute inset-0 z-10 cursor-zoom-out border-0 bg-transparent p-0 ${FOCUS_RING_INSET}`}\n />\n <img\n key={src}\n src={src}\n alt={alt}\n className=\"max-h-full max-w-full rounded-lg object-contain\"\n />\n </div>\n </Modal>\n )}\n </>\n );\n};\n\nexport { ZoomableImage };\nexport default ZoomableImage;\n"],"names":["ZoomableImage","src","alt","title","onError","isEnlarged","setIsEnlarged","useState","hasEnlarged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