frontend: add WarnBanner Preact component, compose ApiErrorPanel from it

mara, on review: "i want each component to import its own css file
itself[;] if you need a bunch of extra css externally, its not a proper
component ... you may need to migrate other components that you would
want to use first".

WarnBanner is the Preact-component successor to the shadow-DOM
<hive-warn> custom element (same three-tier info/warning/error visual
language, colours copied faithfully from hive-warn.css). ApiErrorPanel
now composes it instead of owning a copy of the border/colour/pulse
rules itself — its own CSS is back down to just the layout that's
actually specific to it (heading, copy button, detail text).

Re-verified with a fresh mock-server screenshot: same rendered output as
before, now via composition instead of a duplicated banner shape.
This commit is contained in:
iris 2026-08-17 21:25:51 +02:00 committed by mara
commit ca84079a21
5 changed files with 94 additions and 35 deletions

View file

@ -8,22 +8,20 @@
// *that string was the entire diagnosis* — truncating it defeats the
// point) — plus a copy button for pasting straight into a bug report.
//
// Deliberately NOT built on `<hive-warn>`, despite matching its visual
// language, because that custom element's CSS-as-text import only
// resolves under a build with `loader: 'text'` for `.css` (dashboard's);
// swarm-ui's default `css` loader leaves its shadow `<style>` empty,
// rendering unstyled with no build error (filed separately as a forge
// issue against swarm-ui's build config). This component
// is self-contained light-DOM instead, so it needs nothing beyond a
// normal `.css` import either build already handles, matching
// `JobqRollup`'s pattern. Colour semantics are still copied from
// `hive-warn.css`'s `level="error"` rule on purpose — same look, no
// shared shadow root.
// Composed from `WarnBanner` (../warn-banner/WarnBanner.js) rather than
// owning the border/colour/pulse styling itself — mara, on review: "i
// want each component to import its own css file itself[;] if you need
// a bunch of extra css externally, its not a proper component". This
// file's own `.css` only lays out what's specific to it (heading, copy
// button, detail text); the banner "shape" belongs to `WarnBanner` and
// stays there so any future error/warning surface reuses it too, rather
// than every caller growing its own copy of the same rules.
//
// Same shared-component shape as `JobqRollup`/`JobqGraph`:
// `render(h(ApiErrorPanel, { problem }), container)` from vanilla JS, or
// `<ApiErrorPanel problem={...} />` from swarm-ui's JSX.
import { useState } from 'preact/hooks';
import { WarnBanner } from '../warn-banner/WarnBanner.js';
import type { ProblemDetails } from '../api-error.js';
import './api-error-panel.css';
@ -61,7 +59,7 @@ export function ApiErrorPanel({ problem, context }: ApiErrorPanelProps) {
}
return (
<div class="api-error-panel" role="alert">
<WarnBanner level="error" class="api-error-panel">
<div class="api-error-heading">
<span class="api-error-title">
{context ? `${context}: ` : ''}
@ -72,6 +70,6 @@ export function ApiErrorPanel({ problem, context }: ApiErrorPanelProps) {
</button>
</div>
{problem.detail ? <p class="api-error-detail">{problem.detail}</p> : null}
</div>
</WarnBanner>
);
}