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`.
|
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)
|
### Tactical "dossier" style (Battlefield-style UI)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,6 @@ import {
|
||||||
} from "@/components/ui/dialog";
|
} from "@/components/ui/dialog";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
import { Label } from "@/components/ui/label";
|
import { Label } from "@/components/ui/label";
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from "@/components/ui/select";
|
|
||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
|
@ -72,11 +65,24 @@ const INITIAL_BRIEF: DialogueBrief = {
|
||||||
mustInclude: "",
|
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 brief that seeds a generated conversation.
|
||||||
*
|
*
|
||||||
* The fields are deliberately narrow: a 9B model asked for "a conversation" with
|
* The fields are deliberately narrow: a model asked for "a conversation" with no
|
||||||
* no shape produces something generic, while a brief that names the purpose, the
|
* shape produces something generic, while a brief that names the purpose, the
|
||||||
* takeaway and the outcome produces something an author can edit rather than
|
* takeaway and the outcome produces something an author can edit rather than
|
||||||
* rewrite. Nothing here reaches the database. Cancelling leaves the canvas as it
|
* rewrite. Nothing here reaches the database. Cancelling leaves the canvas as it
|
||||||
* was, and generating only touches unsaved field state.
|
* was, and generating only touches unsaved field state.
|
||||||
|
|
@ -155,60 +161,65 @@ export function GenerateDraftDialog({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={(next) => (busy ? undefined : onOpenChange(next))}>
|
<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>
|
<DialogHeader>
|
||||||
<DialogTitle className="flex items-center gap-2">
|
<DialogTitle className="flex items-center gap-2 text-base text-white">
|
||||||
<Sparkles className="size-4" />
|
<Sparkles className="size-4 shrink-0 text-fuchsia-300" />
|
||||||
Draft a conversation
|
Draft a conversation
|
||||||
</DialogTitle>
|
</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
|
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.
|
draft, so nothing reaches players until you review it and save.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</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="grid grid-cols-2 gap-3">
|
||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
<Label htmlFor="draft-purpose">Purpose</Label>
|
<Label className={FIELD_LABEL} htmlFor="draft-purpose">
|
||||||
<Select
|
Purpose
|
||||||
|
</Label>
|
||||||
|
<select
|
||||||
|
id="draft-purpose"
|
||||||
|
className={SELECT_CLASS}
|
||||||
value={brief.purpose}
|
value={brief.purpose}
|
||||||
onValueChange={(value) => set("purpose", value as BriefPurpose)}
|
onChange={(e) => set("purpose", e.target.value as BriefPurpose)}
|
||||||
>
|
>
|
||||||
<SelectTrigger id="draft-purpose">
|
{BRIEF_PURPOSES.map((purpose) => (
|
||||||
<SelectValue />
|
<option key={purpose} value={purpose}>
|
||||||
</SelectTrigger>
|
{PURPOSE_LABELS[purpose]}
|
||||||
<SelectContent>
|
</option>
|
||||||
{BRIEF_PURPOSES.map((purpose) => (
|
))}
|
||||||
<SelectItem key={purpose} value={purpose}>
|
</select>
|
||||||
{PURPOSE_LABELS[purpose]}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
<Label htmlFor="draft-tone">Tone</Label>
|
<Label className={FIELD_LABEL} htmlFor="draft-tone">
|
||||||
<Select value={brief.tone} onValueChange={(value) => set("tone", value as BriefTone)}>
|
Tone
|
||||||
<SelectTrigger id="draft-tone">
|
</Label>
|
||||||
<SelectValue />
|
<select
|
||||||
</SelectTrigger>
|
id="draft-tone"
|
||||||
<SelectContent>
|
className={SELECT_CLASS}
|
||||||
{BRIEF_TONES.map((tone) => (
|
value={brief.tone}
|
||||||
<SelectItem key={tone} value={tone}>
|
onChange={(e) => set("tone", e.target.value as BriefTone)}
|
||||||
{TONE_LABELS[tone]}
|
>
|
||||||
</SelectItem>
|
{BRIEF_TONES.map((tone) => (
|
||||||
))}
|
<option key={tone} value={tone}>
|
||||||
</SelectContent>
|
{TONE_LABELS[tone]}
|
||||||
</Select>
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-1.5">
|
<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
|
<Textarea
|
||||||
id="draft-goal"
|
id="draft-goal"
|
||||||
|
className={TEXT_INPUT_CLASS}
|
||||||
value={brief.goal}
|
value={brief.goal}
|
||||||
onChange={(e) => set("goal", e.target.value)}
|
onChange={(e) => set("goal", e.target.value)}
|
||||||
placeholder="Learn that the quartermaster is short on rifle magazines, and that the next resupply is delayed."
|
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="grid grid-cols-2 gap-3">
|
||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
<Label htmlFor="draft-outcome">Outcome</Label>
|
<Label className={FIELD_LABEL} htmlFor="draft-outcome">
|
||||||
<Select
|
Outcome
|
||||||
|
</Label>
|
||||||
|
<select
|
||||||
|
id="draft-outcome"
|
||||||
|
className={SELECT_CLASS}
|
||||||
value={brief.outcome}
|
value={brief.outcome}
|
||||||
onValueChange={(value) => set("outcome", value as BriefOutcome)}
|
onChange={(e) => set("outcome", e.target.value as BriefOutcome)}
|
||||||
>
|
>
|
||||||
<SelectTrigger id="draft-outcome">
|
{BRIEF_OUTCOMES.map((outcome) => (
|
||||||
<SelectValue />
|
<option key={outcome} value={outcome}>
|
||||||
</SelectTrigger>
|
{OUTCOME_LABELS[outcome]}
|
||||||
<SelectContent>
|
</option>
|
||||||
{BRIEF_OUTCOMES.map((outcome) => (
|
))}
|
||||||
<SelectItem key={outcome} value={outcome}>
|
</select>
|
||||||
{OUTCOME_LABELS[outcome]}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
<Label htmlFor="draft-size">Length</Label>
|
<Label className={FIELD_LABEL} htmlFor="draft-size">
|
||||||
<Select
|
Length
|
||||||
|
</Label>
|
||||||
|
<select
|
||||||
|
id="draft-size"
|
||||||
|
className={SELECT_CLASS}
|
||||||
value={String(brief.size)}
|
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">
|
{DRAFT_SIZES.map((size) => (
|
||||||
<SelectValue />
|
<option key={size} value={String(size)}>
|
||||||
</SelectTrigger>
|
About {size} nodes
|
||||||
<SelectContent>
|
</option>
|
||||||
{DRAFT_SIZES.map((size) => (
|
))}
|
||||||
<SelectItem key={size} value={String(size)}>
|
</select>
|
||||||
About {size} nodes
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{brief.outcome === "set-flag" && (
|
{brief.outcome === "set-flag" && (
|
||||||
<div className="flex flex-col gap-1.5">
|
<div className="flex flex-col gap-1.5">
|
||||||
<Label htmlFor="draft-flag">Flag to set</Label>
|
<Label className={FIELD_LABEL} htmlFor="draft-flag">
|
||||||
<Select value={brief.flagKey} onValueChange={(value) => set("flagKey", value)}>
|
Flag to set
|
||||||
<SelectTrigger id="draft-flag">
|
</Label>
|
||||||
<SelectValue placeholder="Choose a flag" />
|
<select
|
||||||
</SelectTrigger>
|
id="draft-flag"
|
||||||
<SelectContent>
|
className={SELECT_CLASS}
|
||||||
{flags.map((flag) => (
|
value={brief.flagKey}
|
||||||
<SelectItem key={flag.key} value={flag.key}>
|
onChange={(e) => set("flagKey", e.target.value)}
|
||||||
{flag.key} ({flag.flagType})
|
>
|
||||||
</SelectItem>
|
<option value="">Choose a flag</option>
|
||||||
))}
|
{flags.map((flag) => (
|
||||||
</SelectContent>
|
<option key={flag.key} value={flag.key}>
|
||||||
</Select>
|
{flag.key} ({flag.flagType})
|
||||||
<p className="text-xs text-muted-foreground">
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<p className="text-[10px] text-white/40">
|
||||||
{flagsError ??
|
{flagsError ??
|
||||||
(flags.length === 0
|
(flags.length === 0
|
||||||
? "No player flags exist yet, so nothing can be set."
|
? "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">
|
<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
|
<Input
|
||||||
id="draft-must-include"
|
id="draft-must-include"
|
||||||
|
className={`h-9 ${TEXT_INPUT_CLASS}`}
|
||||||
value={brief.mustInclude}
|
value={brief.mustInclude}
|
||||||
onChange={(e) => set("mustInclude", e.target.value)}
|
onChange={(e) => set("mustInclude", e.target.value)}
|
||||||
placeholder="A place, a name, or a number the line has to mention"
|
placeholder="A place, a name, or a number the line has to mention"
|
||||||
|
|
@ -291,20 +306,35 @@ export function GenerateDraftDialog({
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{nodeCount > 0 && (
|
{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
|
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.
|
document is not saved until you save it, so closing without saving undoes this.
|
||||||
</p>
|
</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>
|
</div>
|
||||||
|
|
||||||
<DialogFooter>
|
<DialogFooter className="gap-2 sm:gap-2">
|
||||||
<Button variant="outline" onClick={() => onOpenChange(false)} disabled={busy}>
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
className="border-white/20 text-white hover:bg-zinc-800"
|
||||||
|
onClick={() => onOpenChange(false)}
|
||||||
|
disabled={busy}
|
||||||
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</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 ? (
|
{busy ? (
|
||||||
<>
|
<>
|
||||||
<Loader2 className="size-4 animate-spin" />
|
<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
|
- The model is reachable only through `src/lib/ai/generate.ts`. Do not call
|
||||||
`fetch` against Unsloth anywhere else.
|
`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
|
||||||
|
|
||||||
`tests/int/npc-dialogue-*.int.spec.ts`: interpolate, attachments, condition
|
`tests/int/npc-dialogue-*.int.spec.ts`: interpolate, attachments, condition
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue