fix(npc-dialogue): style the draft dialog for the admin panel
The admin bundle never loads src/app/(frontend)/styles.css, so the shadcn theme variables (--background, --popover, --border-input) do not exist inside a custom admin field. The brief dialog rendered transparent, and its portaled Radix Select could not take pointer events, so the dropdowns were keyboard only. - describe every surface explicitly in zinc, as NodeEditDialog already does - replace the four Radix Selects with native selects, which need no theme scope and work with mouse and keyboard - scroll the form body at 62vh instead of letting it collide with the footer - note the rule in src/lib/npc-dialogue/AGENTS.md and correct the root AGENTS.md shadcn sentence, which claimed the admin panel handles styling
This commit is contained in:
parent
8ad7c412e4
commit
916040eb70
3 changed files with 137 additions and 91 deletions
|
|
@ -188,7 +188,9 @@ In development, `postgresAdapter` uses `push: false` — run `bun run payload mi
|
|||
|
||||
shadcn/ui components live in `src/components/ui/`. Use `bunx shadcn@latest add <component>` to add new ones. Frontend components in `src/components/frontend/`. Payload admin custom components referenced in `payload.config.ts` under `admin.components`.
|
||||
|
||||
**Rule**: always prefer shadcn/ui components (Dialog, Button, Input, Textarea, Select, etc.) over raw HTML elements or custom-built alternatives. Only build new components when no existing shadcn component fits the need. Do not override shadcn's default dark theme classes with custom `bg-*` `border-*` overrides — the admin panel's theme handles styling.
|
||||
**Rule**: always prefer shadcn/ui components (Dialog, Button, Input, Textarea, Select, etc.) over raw HTML elements or custom-built alternatives. Only build new components when no existing shadcn component fits the need. Do not override shadcn's default dark theme classes with custom `bg-*` `border-*` overrides on the **frontend**; the site theme handles styling.
|
||||
|
||||
**Exception, custom admin field components**: the admin bundle never loads `src/app/(frontend)/styles.css`, so `--background`, `--popover`, `--border-input` and friends do not exist there. Inside the admin panel, style every surface explicitly in zinc (`bg-zinc-800`/`bg-zinc-900`, `border-white/20`, `text-white`) as `src/components/admin/npc-dialogue/NodeEditDialog.tsx` does. A portaled Radix `Select` is worse than unstyled there: it renders transparent and swallows pointer events, so it can only be driven with the keyboard. Use a native `<select>` in admin field components.
|
||||
|
||||
### Tactical "dossier" style (Battlefield-style UI)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,13 +14,6 @@ import {
|
|||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
|
||||
import {
|
||||
|
|
@ -72,11 +65,24 @@ const INITIAL_BRIEF: DialogueBrief = {
|
|||
mustInclude: "",
|
||||
};
|
||||
|
||||
/**
|
||||
* Admin-panel surface: the Payload admin bundle does not load the frontend's
|
||||
* shadcn theme variables, so every surface here is styled explicitly in zinc,
|
||||
* the same way `NodeEditDialog` does it. Native selects are deliberate too: a
|
||||
* portaled Radix Select inherits nothing inside the admin panel's theme scope,
|
||||
* which leaves it transparent and unable to take pointer events.
|
||||
*/
|
||||
const FIELD_LABEL = "text-[10px] uppercase tracking-wider text-white/50";
|
||||
const SELECT_CLASS =
|
||||
"w-full rounded border border-white/20 bg-zinc-800 px-2 py-1.5 text-sm text-white outline-none focus:border-white/40";
|
||||
const TEXT_INPUT_CLASS =
|
||||
"bg-zinc-800 border-white/20 text-white placeholder:text-white/30 focus-visible:ring-0 focus-visible:border-white/40";
|
||||
|
||||
/**
|
||||
* The brief that seeds a generated conversation.
|
||||
*
|
||||
* The fields are deliberately narrow: a 9B model asked for "a conversation" with
|
||||
* no shape produces something generic, while a brief that names the purpose, the
|
||||
* The fields are deliberately narrow: a model asked for "a conversation" with no
|
||||
* shape produces something generic, while a brief that names the purpose, the
|
||||
* takeaway and the outcome produces something an author can edit rather than
|
||||
* rewrite. Nothing here reaches the database. Cancelling leaves the canvas as it
|
||||
* was, and generating only touches unsaved field state.
|
||||
|
|
@ -155,60 +161,65 @@ export function GenerateDraftDialog({
|
|||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={(next) => (busy ? undefined : onOpenChange(next))}>
|
||||
<DialogContent className="sm:max-w-lg">
|
||||
<DialogContent className="sm:max-w-lg bg-zinc-900 border-white/15 text-white">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
<Sparkles className="size-4" />
|
||||
<DialogTitle className="flex items-center gap-2 text-base text-white">
|
||||
<Sparkles className="size-4 shrink-0 text-fuchsia-300" />
|
||||
Draft a conversation
|
||||
</DialogTitle>
|
||||
<DialogDescription>
|
||||
<DialogDescription className="text-xs text-white/60">
|
||||
Describe the beat you want. The model writes a flowchart into the canvas as an unsaved
|
||||
draft, so nothing reaches players until you review it and save.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="flex flex-col gap-3">
|
||||
{/* Scrolls instead of growing past the viewport on a short screen. */}
|
||||
<div className="flex max-h-[62vh] flex-col gap-3 overflow-y-auto pr-1">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="draft-purpose">Purpose</Label>
|
||||
<Select
|
||||
<Label className={FIELD_LABEL} htmlFor="draft-purpose">
|
||||
Purpose
|
||||
</Label>
|
||||
<select
|
||||
id="draft-purpose"
|
||||
className={SELECT_CLASS}
|
||||
value={brief.purpose}
|
||||
onValueChange={(value) => set("purpose", value as BriefPurpose)}
|
||||
onChange={(e) => set("purpose", e.target.value as BriefPurpose)}
|
||||
>
|
||||
<SelectTrigger id="draft-purpose">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{BRIEF_PURPOSES.map((purpose) => (
|
||||
<SelectItem key={purpose} value={purpose}>
|
||||
{PURPOSE_LABELS[purpose]}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{BRIEF_PURPOSES.map((purpose) => (
|
||||
<option key={purpose} value={purpose}>
|
||||
{PURPOSE_LABELS[purpose]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="draft-tone">Tone</Label>
|
||||
<Select value={brief.tone} onValueChange={(value) => set("tone", value as BriefTone)}>
|
||||
<SelectTrigger id="draft-tone">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{BRIEF_TONES.map((tone) => (
|
||||
<SelectItem key={tone} value={tone}>
|
||||
{TONE_LABELS[tone]}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Label className={FIELD_LABEL} htmlFor="draft-tone">
|
||||
Tone
|
||||
</Label>
|
||||
<select
|
||||
id="draft-tone"
|
||||
className={SELECT_CLASS}
|
||||
value={brief.tone}
|
||||
onChange={(e) => set("tone", e.target.value as BriefTone)}
|
||||
>
|
||||
{BRIEF_TONES.map((tone) => (
|
||||
<option key={tone} value={tone}>
|
||||
{TONE_LABELS[tone]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="draft-goal">What should the player learn or do?</Label>
|
||||
<Label className={FIELD_LABEL} htmlFor="draft-goal">
|
||||
What should the player learn or do?
|
||||
</Label>
|
||||
<Textarea
|
||||
id="draft-goal"
|
||||
className={TEXT_INPUT_CLASS}
|
||||
value={brief.goal}
|
||||
onChange={(e) => set("goal", e.target.value)}
|
||||
placeholder="Learn that the quartermaster is short on rifle magazines, and that the next resupply is delayed."
|
||||
|
|
@ -218,60 +229,61 @@ export function GenerateDraftDialog({
|
|||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="draft-outcome">Outcome</Label>
|
||||
<Select
|
||||
<Label className={FIELD_LABEL} htmlFor="draft-outcome">
|
||||
Outcome
|
||||
</Label>
|
||||
<select
|
||||
id="draft-outcome"
|
||||
className={SELECT_CLASS}
|
||||
value={brief.outcome}
|
||||
onValueChange={(value) => set("outcome", value as BriefOutcome)}
|
||||
onChange={(e) => set("outcome", e.target.value as BriefOutcome)}
|
||||
>
|
||||
<SelectTrigger id="draft-outcome">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{BRIEF_OUTCOMES.map((outcome) => (
|
||||
<SelectItem key={outcome} value={outcome}>
|
||||
{OUTCOME_LABELS[outcome]}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{BRIEF_OUTCOMES.map((outcome) => (
|
||||
<option key={outcome} value={outcome}>
|
||||
{OUTCOME_LABELS[outcome]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="draft-size">Length</Label>
|
||||
<Select
|
||||
<Label className={FIELD_LABEL} htmlFor="draft-size">
|
||||
Length
|
||||
</Label>
|
||||
<select
|
||||
id="draft-size"
|
||||
className={SELECT_CLASS}
|
||||
value={String(brief.size)}
|
||||
onValueChange={(value) => set("size", Number(value) as DraftSize)}
|
||||
onChange={(e) => set("size", Number(e.target.value) as DraftSize)}
|
||||
>
|
||||
<SelectTrigger id="draft-size">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{DRAFT_SIZES.map((size) => (
|
||||
<SelectItem key={size} value={String(size)}>
|
||||
About {size} nodes
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{DRAFT_SIZES.map((size) => (
|
||||
<option key={size} value={String(size)}>
|
||||
About {size} nodes
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{brief.outcome === "set-flag" && (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="draft-flag">Flag to set</Label>
|
||||
<Select value={brief.flagKey} onValueChange={(value) => set("flagKey", value)}>
|
||||
<SelectTrigger id="draft-flag">
|
||||
<SelectValue placeholder="Choose a flag" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{flags.map((flag) => (
|
||||
<SelectItem key={flag.key} value={flag.key}>
|
||||
{flag.key} ({flag.flagType})
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
<Label className={FIELD_LABEL} htmlFor="draft-flag">
|
||||
Flag to set
|
||||
</Label>
|
||||
<select
|
||||
id="draft-flag"
|
||||
className={SELECT_CLASS}
|
||||
value={brief.flagKey}
|
||||
onChange={(e) => set("flagKey", e.target.value)}
|
||||
>
|
||||
<option value="">Choose a flag</option>
|
||||
{flags.map((flag) => (
|
||||
<option key={flag.key} value={flag.key}>
|
||||
{flag.key} ({flag.flagType})
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<p className="text-[10px] text-white/40">
|
||||
{flagsError ??
|
||||
(flags.length === 0
|
||||
? "No player flags exist yet, so nothing can be set."
|
||||
|
|
@ -281,9 +293,12 @@ export function GenerateDraftDialog({
|
|||
)}
|
||||
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<Label htmlFor="draft-must-include">Must include (optional)</Label>
|
||||
<Label className={FIELD_LABEL} htmlFor="draft-must-include">
|
||||
Must include (optional)
|
||||
</Label>
|
||||
<Input
|
||||
id="draft-must-include"
|
||||
className={`h-9 ${TEXT_INPUT_CLASS}`}
|
||||
value={brief.mustInclude}
|
||||
onChange={(e) => set("mustInclude", e.target.value)}
|
||||
placeholder="A place, a name, or a number the line has to mention"
|
||||
|
|
@ -291,20 +306,35 @@ export function GenerateDraftDialog({
|
|||
</div>
|
||||
|
||||
{nodeCount > 0 && (
|
||||
<p className="rounded-md border border-amber-900/50 bg-amber-950/40 px-3 py-2 text-xs text-amber-200">
|
||||
<p className="rounded border border-amber-900/50 bg-amber-950/40 px-2 py-1.5 text-[11px] leading-snug text-amber-200">
|
||||
Generating replaces the {nodeCount} node{nodeCount === 1 ? "" : "s"} on the canvas. The
|
||||
document is not saved until you save it, so closing without saving undoes this.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{error && <p className="text-sm text-red-400">{error}</p>}
|
||||
{error && (
|
||||
<p className="rounded border border-red-900/50 bg-red-950/40 px-2 py-1.5 text-[11px] leading-snug text-red-300">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => onOpenChange(false)} disabled={busy}>
|
||||
<DialogFooter className="gap-2 sm:gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
className="border-white/20 text-white hover:bg-zinc-800"
|
||||
onClick={() => onOpenChange(false)}
|
||||
disabled={busy}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button onClick={() => void handleGenerate()} disabled={busy}>
|
||||
<Button
|
||||
type="button"
|
||||
className="inline-flex items-center gap-1.5 border border-fuchsia-700 bg-fuchsia-950 text-fuchsia-200 hover:bg-fuchsia-900"
|
||||
onClick={() => void handleGenerate()}
|
||||
disabled={busy}
|
||||
>
|
||||
{busy ? (
|
||||
<>
|
||||
<Loader2 className="size-4 animate-spin" />
|
||||
|
|
|
|||
|
|
@ -87,6 +87,20 @@ pass server-side, so a flag value can never smuggle in another token.
|
|||
- The model is reachable only through `src/lib/ai/generate.ts`. Do not call
|
||||
`fetch` against Unsloth anywhere else.
|
||||
|
||||
## Admin panel styling
|
||||
|
||||
The admin bundle does not load the frontend's shadcn theme variables, so
|
||||
`bg-background`, `bg-popover`, `border-input`, `text-muted-foreground` and the
|
||||
rest resolve to nothing inside a custom admin field. A surface styled only with
|
||||
those tokens comes out transparent, and a portaled Radix `Select` becomes
|
||||
transparent *and* unable to take pointer events, so it can only be driven with
|
||||
the arrow keys.
|
||||
|
||||
So: style every admin-panel element explicitly in zinc (`bg-zinc-800` /
|
||||
`bg-zinc-900`, `border-white/20`, `text-white`), as `NodeEditDialog` does, and
|
||||
prefer a native `<select>` over the shadcn one. `GenerateDraftDialog` follows
|
||||
both rules.
|
||||
|
||||
## Tests
|
||||
|
||||
`tests/int/npc-dialogue-*.int.spec.ts`: interpolate, attachments, condition
|
||||
|
|
|
|||
Loading…
Reference in a new issue