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:
parent
f60aab4717
commit
ca84079a21
5 changed files with 94 additions and 35 deletions
|
|
@ -34,7 +34,9 @@
|
||||||
"./jobq-rollup.css": "./src/jobq-rollup/jobq-rollup.css",
|
"./jobq-rollup.css": "./src/jobq-rollup/jobq-rollup.css",
|
||||||
"./api-error.js": "./src/api-error.ts",
|
"./api-error.js": "./src/api-error.ts",
|
||||||
"./api-error-panel.js": "./src/api-error-panel/ApiErrorPanel.tsx",
|
"./api-error-panel.js": "./src/api-error-panel/ApiErrorPanel.tsx",
|
||||||
"./api-error-panel.css": "./src/api-error-panel/api-error-panel.css"
|
"./api-error-panel.css": "./src/api-error-panel/api-error-panel.css",
|
||||||
|
"./warn-banner.js": "./src/warn-banner/WarnBanner.tsx",
|
||||||
|
"./warn-banner.css": "./src/warn-banner/WarnBanner.css"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src/"
|
"src/"
|
||||||
|
|
|
||||||
|
|
@ -8,22 +8,20 @@
|
||||||
// *that string was the entire diagnosis* — truncating it defeats the
|
// *that string was the entire diagnosis* — truncating it defeats the
|
||||||
// point) — plus a copy button for pasting straight into a bug report.
|
// point) — plus a copy button for pasting straight into a bug report.
|
||||||
//
|
//
|
||||||
// Deliberately NOT built on `<hive-warn>`, despite matching its visual
|
// Composed from `WarnBanner` (../warn-banner/WarnBanner.js) rather than
|
||||||
// language, because that custom element's CSS-as-text import only
|
// owning the border/colour/pulse styling itself — mara, on review: "i
|
||||||
// resolves under a build with `loader: 'text'` for `.css` (dashboard's);
|
// want each component to import its own css file itself[;] if you need
|
||||||
// swarm-ui's default `css` loader leaves its shadow `<style>` empty,
|
// a bunch of extra css externally, its not a proper component". This
|
||||||
// rendering unstyled with no build error (filed separately as a forge
|
// file's own `.css` only lays out what's specific to it (heading, copy
|
||||||
// issue against swarm-ui's build config). This component
|
// button, detail text); the banner "shape" belongs to `WarnBanner` and
|
||||||
// is self-contained light-DOM instead, so it needs nothing beyond a
|
// stays there so any future error/warning surface reuses it too, rather
|
||||||
// normal `.css` import either build already handles, matching
|
// than every caller growing its own copy of the same rules.
|
||||||
// `JobqRollup`'s pattern. Colour semantics are still copied from
|
|
||||||
// `hive-warn.css`'s `level="error"` rule on purpose — same look, no
|
|
||||||
// shared shadow root.
|
|
||||||
//
|
//
|
||||||
// Same shared-component shape as `JobqRollup`/`JobqGraph`:
|
// Same shared-component shape as `JobqRollup`/`JobqGraph`:
|
||||||
// `render(h(ApiErrorPanel, { problem }), container)` from vanilla JS, or
|
// `render(h(ApiErrorPanel, { problem }), container)` from vanilla JS, or
|
||||||
// `<ApiErrorPanel problem={...} />` from swarm-ui's JSX.
|
// `<ApiErrorPanel problem={...} />` from swarm-ui's JSX.
|
||||||
import { useState } from 'preact/hooks';
|
import { useState } from 'preact/hooks';
|
||||||
|
import { WarnBanner } from '../warn-banner/WarnBanner.js';
|
||||||
import type { ProblemDetails } from '../api-error.js';
|
import type { ProblemDetails } from '../api-error.js';
|
||||||
import './api-error-panel.css';
|
import './api-error-panel.css';
|
||||||
|
|
||||||
|
|
@ -61,7 +59,7 @@ export function ApiErrorPanel({ problem, context }: ApiErrorPanelProps) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="api-error-panel" role="alert">
|
<WarnBanner level="error" class="api-error-panel">
|
||||||
<div class="api-error-heading">
|
<div class="api-error-heading">
|
||||||
<span class="api-error-title">
|
<span class="api-error-title">
|
||||||
{context ? `${context}: ` : ''}
|
{context ? `${context}: ` : ''}
|
||||||
|
|
@ -72,6 +70,6 @@ export function ApiErrorPanel({ problem, context }: ApiErrorPanelProps) {
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{problem.detail ? <p class="api-error-detail">{problem.detail}</p> : null}
|
{problem.detail ? <p class="api-error-detail">{problem.detail}</p> : null}
|
||||||
</div>
|
</WarnBanner>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,12 @@
|
||||||
/* api-error-panel.css — `<ApiErrorPanel>`'s own styling, colour + layout
|
/* api-error-panel.css — layout for `<ApiErrorPanel>`'s content, plus the
|
||||||
both. Not slotted into `<hive-warn>` (see the component's own header
|
one spacing concern that's genuinely this component's own (the top
|
||||||
for why) — the border/background/pulse below are deliberately copied
|
margin — `WarnBanner` only sets `margin-bottom`, tuned for a banner
|
||||||
from `hive-warn.css`'s `level="error"` rule rather than invented fresh,
|
that's the first thing in a page, not a panel that usually follows a
|
||||||
so this still reads as "the same error banner" everywhere it appears,
|
form or a table). Colour/border/pulse belong to `WarnBanner`
|
||||||
just declared locally instead of shared through a shadow root. Reuses
|
(../warn-banner/WarnBanner.css) — not duplicated here. */
|
||||||
theme.css's own documented semantics (`--red` = "errors, fail state"),
|
|
||||||
same as `hive-warn.css` does. */
|
|
||||||
|
|
||||||
.api-error-panel {
|
.api-error-panel {
|
||||||
display: block;
|
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
margin-bottom: 0.6em;
|
|
||||||
border: 1px solid var(--red);
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 0.5em 0.8em;
|
|
||||||
color: var(--red);
|
|
||||||
background: color-mix(in srgb, var(--red) 8%, transparent);
|
|
||||||
text-shadow: 0 0 6px color-mix(in srgb, currentColor 40%, transparent);
|
|
||||||
animation: api-error-panel-pulse 2.4s ease-in-out infinite;
|
|
||||||
}
|
|
||||||
@keyframes api-error-panel-pulse {
|
|
||||||
0%, 100% { box-shadow: 0 0 12px -4px color-mix(in srgb, currentColor 55%, transparent); }
|
|
||||||
50% { box-shadow: 0 0 22px -2px color-mix(in srgb, currentColor 95%, transparent); }
|
|
||||||
}
|
}
|
||||||
.api-error-heading {
|
.api-error-heading {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
||||||
36
frontend/packages/shared/src/warn-banner/WarnBanner.css
Normal file
36
frontend/packages/shared/src/warn-banner/WarnBanner.css
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* WarnBanner.css — three levels, not an open-ended severity+modifier
|
||||||
|
combination (same rule `hive-warn.css` states, copied faithfully since
|
||||||
|
this is that component's visual language, just reached through a
|
||||||
|
class instead of a `:host([level])` attribute selector). Colours reuse
|
||||||
|
theme.css's own documented semantics: --cyan = "info accents", --amber
|
||||||
|
= "warnings", --red = "errors, fail state". */
|
||||||
|
|
||||||
|
.warn-banner {
|
||||||
|
display: block;
|
||||||
|
border: 1px solid var(--amber);
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 0.5em 0.8em;
|
||||||
|
margin-bottom: 0.6em;
|
||||||
|
color: var(--amber);
|
||||||
|
background: color-mix(in srgb, var(--amber) 8%, transparent);
|
||||||
|
}
|
||||||
|
.warn-banner-info {
|
||||||
|
border-color: var(--cyan);
|
||||||
|
color: var(--cyan);
|
||||||
|
background: color-mix(in srgb, var(--cyan) 8%, transparent);
|
||||||
|
}
|
||||||
|
.warn-banner-error {
|
||||||
|
border-color: var(--red);
|
||||||
|
color: var(--red);
|
||||||
|
background: color-mix(in srgb, var(--red) 8%, transparent);
|
||||||
|
/* Only `error` pulses — an active incident, not a standing caveat. */
|
||||||
|
text-shadow: 0 0 6px color-mix(in srgb, currentColor 40%, transparent);
|
||||||
|
animation: warn-banner-pulse 2.4s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
@keyframes warn-banner-pulse {
|
||||||
|
0%, 100% { box-shadow: 0 0 12px -4px color-mix(in srgb, currentColor 55%, transparent); }
|
||||||
|
50% { box-shadow: 0 0 22px -2px color-mix(in srgb, currentColor 95%, transparent); }
|
||||||
|
}
|
||||||
|
.warn-banner strong {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
38
frontend/packages/shared/src/warn-banner/WarnBanner.tsx
Normal file
38
frontend/packages/shared/src/warn-banner/WarnBanner.tsx
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
// WarnBanner.tsx — <WarnBanner>, the Preact-component successor to the
|
||||||
|
// shadow-DOM <hive-warn> custom element (../hive-warn/hive-warn.js).
|
||||||
|
// Same three-tier visual language (mara, on `hive-warn`'s own review:
|
||||||
|
// "there should be distinction between info, warning, error — all
|
||||||
|
// warnings should be styled identically") — built as a plain Preact
|
||||||
|
// component instead so it composes cleanly wherever this package's other
|
||||||
|
// shared components do (JobqRollup, JobqGraph, ApiErrorPanel), rather
|
||||||
|
// than needing a shadow root + CSS-as-text build step that only resolves
|
||||||
|
// under one of the two consuming packages' esbuild configs. `ApiErrorPanel`
|
||||||
|
// is the first consumer — compose from this instead of duplicating the
|
||||||
|
// banner's own border/colour/pulse rules locally.
|
||||||
|
//
|
||||||
|
// `level` defaults to 'warning', matching `hive-warn.js`'s own default.
|
||||||
|
// Only `error` pulses — an active incident, not a standing caveat, same
|
||||||
|
// rule `hive-warn.css`'s own comment states.
|
||||||
|
import type { ComponentChildren } from 'preact';
|
||||||
|
import './WarnBanner.css';
|
||||||
|
|
||||||
|
export type WarnLevel = 'info' | 'warning' | 'error';
|
||||||
|
|
||||||
|
export interface WarnBannerProps {
|
||||||
|
level?: WarnLevel;
|
||||||
|
// Passed straight through to the root element's `class` list —
|
||||||
|
// for a caller-specific concern the banner itself has no opinion on
|
||||||
|
// (e.g. `ApiErrorPanel` adding a top margin for the context it usually
|
||||||
|
// sits in), not for re-styling the banner's own look.
|
||||||
|
class?: string;
|
||||||
|
children?: ComponentChildren;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function WarnBanner({ level = 'warning', class: extraClass, children }: WarnBannerProps) {
|
||||||
|
const classes = ['warn-banner', `warn-banner-${level}`, extraClass].filter(Boolean).join(' ');
|
||||||
|
return (
|
||||||
|
<div class={classes} role={level === 'error' ? 'alert' : undefined}>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue