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.
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
"use client";
|
|
|
|
import { DEFAULT_RIBBON } from "@/components/awards/ribbonDesign/constants";
|
|
import { RibbonArt } from "@/components/awards/ribbonDesign/RibbonArt";
|
|
import type { RibbonDesign } from "@/components/awards/ribbonDesign/types";
|
|
import { useState } from "react";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
/**
|
|
* Production ribbon renderer. Thin wrapper around the shared `RibbonArt` so
|
|
* the live site and the admin/studio previews cannot drift apart. Pass an
|
|
* award's `advancement.tier` to let the device cluster derive its count from
|
|
* the tier (service-star convention); omit it to show the authored devices.
|
|
*/
|
|
export const RibbonViewer = ({
|
|
ribbonDesign,
|
|
showRibbonOnly,
|
|
tier,
|
|
}: {
|
|
ribbonDesign: RibbonDesign;
|
|
showRibbonOnly?: boolean;
|
|
tier?: number | null;
|
|
}) => {
|
|
const initial: RibbonDesign =
|
|
ribbonDesign && typeof ribbonDesign === "object" && Array.isArray((ribbonDesign as RibbonDesign).stripes)
|
|
? (ribbonDesign as RibbonDesign)
|
|
: DEFAULT_RIBBON;
|
|
|
|
const [design] = useState<RibbonDesign>(initial);
|
|
|
|
return (
|
|
<RibbonArt
|
|
design={design}
|
|
tier={tier}
|
|
className={cn("h-auto max-h-20", {
|
|
"w-full rounded border border-zinc-700 bg-zinc-950": !showRibbonOnly,
|
|
})}
|
|
/>
|
|
);
|
|
};
|