@spunto/design-system 0.79.0 → 0.80.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/README.md
CHANGED
|
@@ -99,7 +99,9 @@ const nextConfig = { transpilePackages: ["@spunto/design-system"] }
|
|
|
99
99
|
- _Overlays_ (plug into the `SpuntoProvider` umbrella) — `Dialog`, `AlertDialog`
|
|
100
100
|
(a confirmation variant, non-dismissible), `Sheet`, `Tooltip`. Their portals render
|
|
101
101
|
into the provider's overlay container; `Tooltip`'s shared delay group is mounted by
|
|
102
|
-
the provider too.
|
|
102
|
+
the provider too. An app's own overlay portals there as well
|
|
103
|
+
(`useOverlayContainer()`, `null` without a provider): left in `document.body`, it
|
|
104
|
+
covers the `Select` or the menu opened from inside it.
|
|
103
105
|
- _ActionMenu_ — `ActionMenu` (+`ActionMenuItem`, `ActionMenuEntry`), the `⋯` menu
|
|
104
106
|
**described instead of assembled**: `items` is a list of `{ label, icon?, onClick }`
|
|
105
107
|
(or `href`, for a real `<a>` via Base UI's `Menu.LinkItem`) and the component builds
|
package/package.json
CHANGED
|
@@ -71,7 +71,9 @@ const OverlayContainerContext = createContext<HTMLElement | null>(null)
|
|
|
71
71
|
/**
|
|
72
72
|
* Container element the design-system overlays portal into, provided by the
|
|
73
73
|
* nearest `SpuntoProvider` (or `null` → Base UI's `document.body` default).
|
|
74
|
-
*
|
|
74
|
+
* An app's own overlay portals into it too (`<Portal container={… ?? undefined}>`):
|
|
75
|
+
* left in `document.body`, it sits after this node and covers, at the same
|
|
76
|
+
* z-index, every `Select` or menu opened from inside it.
|
|
75
77
|
*/
|
|
76
78
|
export function useOverlayContainer(): HTMLElement | null {
|
|
77
79
|
return useContext(OverlayContainerContext)
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the cockpit's panel says about the sandbox it shows, and an error that can be read to its
|
|
3
|
+
* end. jsdom has no layout: "the text is cut" is what `scrollHeight`/`clientHeight` are made to say.
|
|
4
|
+
*/
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest"
|
|
6
|
+
import { fireEvent, render, screen } from "@testing-library/react"
|
|
7
|
+
|
|
8
|
+
import { WorkerCockpit, type WorkerCockpitProps } from "./worker-cockpit"
|
|
9
|
+
|
|
10
|
+
const cockpit = (over: Partial<WorkerCockpitProps> = {}) => (
|
|
11
|
+
<WorkerCockpit
|
|
12
|
+
worker={{ id: "sb1", name: "box", state: "ready", dockerState: "running", containerId: "3f9a8c1d2b7e4a55" }}
|
|
13
|
+
activeTab="logs"
|
|
14
|
+
onTabChange={() => {}}
|
|
15
|
+
logsContent={null}
|
|
16
|
+
terminalContent={null}
|
|
17
|
+
{...over}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
/** The panel is drawn in the sidebar and in the mobile drawer: the first one is enough. */
|
|
22
|
+
const first = (text: string) => screen.getAllByText(text)[0]
|
|
23
|
+
|
|
24
|
+
function layout(scrollHeight: number, clientHeight: number) {
|
|
25
|
+
vi.spyOn(HTMLElement.prototype, "scrollHeight", "get").mockReturnValue(scrollHeight)
|
|
26
|
+
vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockReturnValue(clientHeight)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
afterEach(() => vi.restoreAllMocks())
|
|
30
|
+
|
|
31
|
+
describe("WorkerCockpit", () => {
|
|
32
|
+
it("names the sandbox, and the directory a rebuild keeps", () => {
|
|
33
|
+
render(cockpit({ onRebuild: () => {}, onDelete: () => {} }))
|
|
34
|
+
expect(first("Delete sandbox")).toBeTruthy()
|
|
35
|
+
expect(first("keeps /workspace")).toBeTruthy()
|
|
36
|
+
expect(first("Sandbox").nextElementSibling?.textContent).toBe("3f9a8c1d2b7e")
|
|
37
|
+
expect(screen.queryByText("Delete workspace")).toBeNull()
|
|
38
|
+
expect(screen.queryByText("Container")).toBeNull()
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it("unfolds an error that is cut, and folds it back", () => {
|
|
42
|
+
layout(48, 32)
|
|
43
|
+
const error = "stopped by the platform: its task dqfopoo1fi4qvt2izrdym is accepted (done)"
|
|
44
|
+
render(cockpit({ error }))
|
|
45
|
+
expect(first(error).className).toContain("line-clamp-2")
|
|
46
|
+
|
|
47
|
+
fireEvent.click(screen.getAllByRole("button", { name: "Show full error" })[0])
|
|
48
|
+
expect(first(error).className).not.toContain("line-clamp-2")
|
|
49
|
+
|
|
50
|
+
fireEvent.click(screen.getAllByRole("button", { name: "Show less" })[0])
|
|
51
|
+
expect(first(error).className).toContain("line-clamp-2")
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it("offers nothing to unfold when the error fits", () => {
|
|
55
|
+
layout(32, 32)
|
|
56
|
+
render(cockpit({ error: "disk almost full" }))
|
|
57
|
+
expect(first("disk almost full")).toBeTruthy()
|
|
58
|
+
expect(screen.queryByRole("button", { name: "Show full error" })).toBeNull()
|
|
59
|
+
})
|
|
60
|
+
})
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// same cockpit be driven by the dashboard's react-query hooks today and by
|
|
13
13
|
// hand-written fixtures in the showcase.
|
|
14
14
|
|
|
15
|
-
import { useState, type ComponentType, type ReactNode } from "react"
|
|
15
|
+
import { useEffect, useRef, useState, type ComponentType, type ReactNode } from "react"
|
|
16
16
|
import { Drawer as DrawerPrimitive } from "vaul"
|
|
17
17
|
import {
|
|
18
18
|
AlertTriangleIcon,
|
|
@@ -187,6 +187,51 @@ function Banner({ tone, children }: { tone: keyof typeof BANNER_TONES; children:
|
|
|
187
187
|
)
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
/**
|
|
191
|
+
* The sandbox's error, readable. Two lines so a long one doesn't push the panel down, expandable
|
|
192
|
+
* because what matters ("…its task X is done") is often past the cut. Whether it is cut is
|
|
193
|
+
* measured, not guessed from its length: the panel is narrow, and how much fits depends on it.
|
|
194
|
+
*/
|
|
195
|
+
function ErrorBanner({ text, onDismiss }: { text: string; onDismiss?: () => void }) {
|
|
196
|
+
const [open, setOpen] = useState(false)
|
|
197
|
+
const [clamped, setClamped] = useState(false)
|
|
198
|
+
const ref = useRef<HTMLSpanElement>(null)
|
|
199
|
+
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
const el = ref.current
|
|
202
|
+
if (!el || open) return
|
|
203
|
+
const measure = () => setClamped(el.scrollHeight > el.clientHeight + 1)
|
|
204
|
+
measure()
|
|
205
|
+
if (typeof ResizeObserver === "undefined") return
|
|
206
|
+
const observer = new ResizeObserver(measure)
|
|
207
|
+
observer.observe(el)
|
|
208
|
+
return () => observer.disconnect()
|
|
209
|
+
}, [text, open])
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<Banner tone="error">
|
|
213
|
+
<div className="min-w-0 flex-1">
|
|
214
|
+
<span ref={ref} className={cn("font-mono break-words", open ? "block whitespace-pre-wrap" : "line-clamp-2")}>{text}</span>
|
|
215
|
+
{(clamped || open) && (
|
|
216
|
+
<button
|
|
217
|
+
type="button"
|
|
218
|
+
aria-expanded={open}
|
|
219
|
+
onClick={() => setOpen((v) => !v)}
|
|
220
|
+
className="mt-1 cursor-pointer text-[10px] font-medium text-destructive/80 transition-colors hover:text-destructive"
|
|
221
|
+
>
|
|
222
|
+
{open ? "Show less" : "Show full error"}
|
|
223
|
+
</button>
|
|
224
|
+
)}
|
|
225
|
+
</div>
|
|
226
|
+
{onDismiss && (
|
|
227
|
+
<button type="button" onClick={onDismiss} aria-label="Dismiss error" className="mt-px shrink-0 cursor-pointer self-start opacity-60 transition-opacity hover:opacity-100">
|
|
228
|
+
<XIcon className="h-3.5 w-3.5" />
|
|
229
|
+
</button>
|
|
230
|
+
)}
|
|
231
|
+
</Banner>
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
|
|
190
235
|
function InfoRow({ label, children }: { label: string; children: ReactNode }) {
|
|
191
236
|
return (
|
|
192
237
|
<div className="flex items-center justify-between px-3 py-2">
|
|
@@ -286,16 +331,8 @@ export function WorkerCockpit({
|
|
|
286
331
|
|
|
287
332
|
const controlPanel = (
|
|
288
333
|
<>
|
|
289
|
-
{error
|
|
290
|
-
|
|
291
|
-
<span className="line-clamp-2 min-w-0 flex-1 font-mono break-words">{error}</span>
|
|
292
|
-
{onDismissError && (
|
|
293
|
-
<button type="button" onClick={onDismissError} aria-label="Dismiss error" className="shrink-0 cursor-pointer opacity-60 transition-opacity hover:opacity-100">
|
|
294
|
-
<XIcon className="h-3.5 w-3.5" />
|
|
295
|
-
</button>
|
|
296
|
-
)}
|
|
297
|
-
</Banner>
|
|
298
|
-
)}
|
|
334
|
+
{/* Keyed by its text: another error starts folded. */}
|
|
335
|
+
{error && <ErrorBanner key={error} text={error} onDismiss={onDismissError} />}
|
|
299
336
|
{inFlight && inFlightMessage[status.key] && (
|
|
300
337
|
<Banner tone="busy">
|
|
301
338
|
<span className="flex min-w-0 items-center gap-2">
|
|
@@ -447,13 +484,13 @@ export function WorkerCockpit({
|
|
|
447
484
|
<button type="button" disabled={rebuilding || inFlight} onClick={onRebuild} className="flex w-full items-center gap-2 rounded-lg border border-border/50 bg-muted/20 px-3 py-2.5 text-xs text-foreground transition-colors hover:bg-muted/40 disabled:opacity-50">
|
|
448
485
|
<RefreshCwIcon className={cn("h-3.5 w-3.5 text-muted-foreground", rebuilding && "animate-spin")} />
|
|
449
486
|
<span className="font-medium">Rebuild container</span>
|
|
450
|
-
<span className="ml-auto text-[10px] text-muted-foreground/50">keeps workspace</span>
|
|
487
|
+
<span className="ml-auto text-[10px] text-muted-foreground/50">keeps /workspace</span>
|
|
451
488
|
</button>
|
|
452
489
|
)}
|
|
453
490
|
{(hasContainer || isDeleting) && nodeOnline !== false && onDelete && (
|
|
454
491
|
<button type="button" disabled={deleting || inFlight} onClick={onDelete} className="flex w-full items-center gap-2 rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2.5 text-xs text-destructive transition-colors hover:bg-destructive/10 disabled:opacity-50">
|
|
455
492
|
{isDeleting ? <LoaderIcon className="h-3.5 w-3.5 animate-spin" /> : <Trash2Icon className="h-3.5 w-3.5" />}
|
|
456
|
-
<span className="font-medium">Delete
|
|
493
|
+
<span className="font-medium">Delete sandbox</span>
|
|
457
494
|
<span className="ml-auto text-[10px] opacity-60">permanent</span>
|
|
458
495
|
</button>
|
|
459
496
|
)}
|
|
@@ -496,7 +533,7 @@ export function WorkerCockpit({
|
|
|
496
533
|
</InfoRow>
|
|
497
534
|
)}
|
|
498
535
|
{worker.createdAt && <InfoRow label="Created"><span className="text-[11px] text-muted-foreground">{formatRelativeTime(worker.createdAt)}</span></InfoRow>}
|
|
499
|
-
{worker.containerId && <InfoRow label="
|
|
536
|
+
{worker.containerId && <InfoRow label="Sandbox"><span className="font-mono text-[11px] text-muted-foreground">{worker.containerId.slice(0, 12)}</span></InfoRow>}
|
|
500
537
|
</div>
|
|
501
538
|
</div>
|
|
502
539
|
</>
|
package/src/index.ts
CHANGED
|
@@ -309,7 +309,7 @@ export type { KbdProps } from "./components/kbd"
|
|
|
309
309
|
// Toasts — imperative `toast()` API + the umbrella client provider that renders
|
|
310
310
|
// them. `SpuntoProvider` mounts the toast viewport, the tooltip delay group, and
|
|
311
311
|
// the overlay portal container that dialogs/selects render into.
|
|
312
|
-
export { SpuntoProvider } from "./components/spunto-provider"
|
|
312
|
+
export { SpuntoProvider, useOverlayContainer } from "./components/spunto-provider"
|
|
313
313
|
export type { SpuntoProviderProps, ToastPosition } from "./components/spunto-provider"
|
|
314
314
|
export { toast } from "./components/toast"
|
|
315
315
|
export type { ToastFn, ToastOptions, ToastVariant, ToastAction } from "./components/toast"
|