1
0
Fork 0
polaris-task-force/src/components/admin/awards/RibbonDesigner.tsx
Z8MB1E 7430251adf feat(awards): render ribbon devices as vectors with tier-driven auto-layout
Introduce RibbonArt, a single shared SVG renderer used by both the production viewer and admin/studio preview so they can no longer diverge. Devices are now vector glyphs (star/oak leaf/campaign clasp/arrow up) instead of Unicode text, laid out as one centered cluster that shrinks to fit. Device count derives from advancement tier using the service-star convention (tier N shows N-1, cap 6; bare ribbon at tier 1 or for non-tiered awards). Legacy per-device x/y positions are stored but ignored, so no schema change. Designers add/remove/reorder device types and preview tiers.
2026-10-26 22:21:10 -04:00

73 lines
2.6 KiB
TypeScript

"use client";
import { useCallback, useEffect, useRef, useState } from "react";
import { useField } from "@payloadcms/ui";
import { DEFAULT_RIBBON } from "@/components/awards/ribbonDesign/constants";
import { RibbonPreview, StripeEditor, DeviceEditor } from "@/components/awards/ribbonDesign/parts";
import type { RibbonDesign, Stripe, Device } from "@/components/awards/ribbonDesign/types";
export type {
RibbonDesign,
Stripe,
Device,
DeviceType,
} from "@/components/awards/ribbonDesign/types";
export {
DEFAULT_RIBBON,
MILITARY_COLORS,
RIBBON_CONSTANTS,
RIBBON_DEVICE_INFO,
} from "@/components/awards/ribbonDesign/constants";
// ─── Main Designer ──────────────────────────────────────────────────
export default function RibbonDesigner() {
const { value, setValue } = useField<RibbonDesign>();
const initial: RibbonDesign =
value && typeof value === "object" && Array.isArray((value as RibbonDesign).stripes)
? (value as RibbonDesign)
: DEFAULT_RIBBON;
const [design, setDesign] = useState<RibbonDesign>(initial);
const lastSaved = useRef<string>("");
useEffect(() => {
const serialized = JSON.stringify(design);
if (serialized !== lastSaved.current) {
lastSaved.current = serialized;
setValue(design);
}
}, [design, setValue]);
const setStripes = useCallback((stripes: Stripe[]) => setDesign((d) => ({ ...d, stripes })), []);
const setDevices = useCallback((devices: Device[]) => setDesign((d) => ({ ...d, devices })), []);
const toggleMirror = useCallback(() => setDesign((d) => ({ ...d, mirrored: !d.mirrored })), []);
return (
<div className="field-type json flex flex-col gap-3">
<label className="text-sm font-medium text-zinc-300">Ribbon Design</label>
<p className="text-xs text-zinc-500 -mt-1">
Configure the ribbon colors, stripes, and device attachments for this award.
</p>
<RibbonPreview design={design} allowTierPreview />
<button
type="button"
onClick={toggleMirror}
className={`text-[11px] px-3 py-1.5 rounded border w-fit transition-colors cursor-pointer ${
design.mirrored
? "bg-amber-950 border-amber-700 text-amber-200"
: "bg-zinc-800 border-zinc-700 text-zinc-400 hover:bg-zinc-700"
}`}
>
{design.mirrored ? "\u21C4 Mirrored" : "\u2194 Mirror Stripes"}
</button>
<StripeEditor stripes={design.stripes} onChange={setStripes} />
<DeviceEditor devices={design.devices} onChange={setDevices} />
</div>
);
}