From e92580bbe496aa17494a4997a9b54ff48fb615a6 Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Tue, 1 Dec 2026 09:29:14 -0500 Subject: [PATCH] feat(ribbon): add stripe direction toggle and line editor to builders Shared LineEditor (color, position, thickness sliders) and a vertical / horizontal segmented control in RibbonStudio, plus an equivalent orientation button and the same editor in the admin RibbonDesigner. Review-queue previews pick both features up through RibbonArt. --- .../admin/awards/RibbonDesigner.tsx | 46 +++++++--- src/components/awards/ribbonDesign/parts.tsx | 89 ++++++++++++++++++- .../frontend/awards/RibbonStudio.tsx | 30 ++++++- 3 files changed, 150 insertions(+), 15 deletions(-) diff --git a/src/components/admin/awards/RibbonDesigner.tsx b/src/components/admin/awards/RibbonDesigner.tsx index d44c101e..f65b3076 100644 --- a/src/components/admin/awards/RibbonDesigner.tsx +++ b/src/components/admin/awards/RibbonDesigner.tsx @@ -4,8 +4,8 @@ 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"; +import { RibbonPreview, StripeEditor, DeviceEditor, LineEditor } from "@/components/awards/ribbonDesign/parts"; +import type { RibbonDesign, Stripe, Device, RibbonLine } from "@/components/awards/ribbonDesign/types"; export type { RibbonDesign, @@ -44,6 +44,15 @@ export default function RibbonDesigner() { 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 })), []); + const toggleOrientation = useCallback( + () => + setDesign((d) => ({ + ...d, + stripeOrientation: d.stripeOrientation === "horizontal" ? "vertical" : "horizontal", + })), + [], + ); + const setLines = useCallback((lines: RibbonLine[]) => setDesign((d) => ({ ...d, lines })), []); return (
@@ -54,19 +63,30 @@ export default function RibbonDesigner() { - +
+ + +
+
); diff --git a/src/components/awards/ribbonDesign/parts.tsx b/src/components/awards/ribbonDesign/parts.tsx index 7e447657..39c54fa8 100644 --- a/src/components/awards/ribbonDesign/parts.tsx +++ b/src/components/awards/ribbonDesign/parts.tsx @@ -3,7 +3,7 @@ import { useState } from "react"; import { RIBBON_DEVICE_INFO } from "./constants"; import { DeviceGlyph, MAX_TIER_DEVICES, RibbonArt } from "./RibbonArt"; -import type { Device, DeviceType, RibbonDesign, Stripe } from "./types"; +import type { Device, DeviceType, RibbonDesign, RibbonLine, Stripe } from "./types"; // ─── Preview ──────────────────────────────────────────────────────── @@ -129,6 +129,93 @@ export function StripeEditor({ ); } +// ─── Accent line editor ───────────────────────────────────────────── + +/** The overlay-line cap enforced by ribbonValidation; keeps the add button honest. */ +export const MAX_DESIGN_LINES = 5; + +/** + * Edit the horizontal accent lines drawn over the stripe pattern (independent + * of stripe orientation). Each row picks a color, a vertical center position, + * and a thickness, all as percentages of ribbon height so the preview stays + * faithful at any scale. + */ +export function LineEditor({ lines, onChange }: { lines: RibbonLine[]; onChange: (l: RibbonLine[]) => void }) { + const addLine = () => + onChange([...lines, { id: crypto.randomUUID(), color: "#ca8a04", positionY: 50, thickness: 6 }]); + const removeLine = (id: string) => onChange(lines.filter((line) => line.id !== id)); + const updateLine = (idx: number, patch: Partial) => + onChange(lines.map((l, i) => (i === idx ? { ...l, ...patch } : l))); + + return ( +
+
+ Horizontal lines + +
+

+ Thin overlay bars across the stripes, drawn under devices. Up to {MAX_DESIGN_LINES}. +

+ {lines.map((line, idx) => ( +
+ updateLine(idx, { color: e.target.value })} + className="h-6 w-8 cursor-pointer rounded border border-zinc-700 bg-transparent" + aria-label={`Line ${idx + 1} color`} + /> +
+ + updateLine(idx, { positionY: Number(e.target.value) })} + className="h-1 flex-1 accent-amber-500" + /> + {line.positionY}% +
+
+ + updateLine(idx, { thickness: Number(e.target.value) })} + className="h-1 flex-1 accent-amber-500" + /> + {line.thickness}% +
+ +
+ ))} +
+ ); +} + // ─── Device Editor ────────────────────────────────────────────────── /** diff --git a/src/components/frontend/awards/RibbonStudio.tsx b/src/components/frontend/awards/RibbonStudio.tsx index 58a6be62..be686685 100644 --- a/src/components/frontend/awards/RibbonStudio.tsx +++ b/src/components/frontend/awards/RibbonStudio.tsx @@ -6,7 +6,7 @@ import { toast } from "sonner"; import { submitRibbonDesign } from "@/app/(frontend)/awards/design/actions"; import { DEFAULT_RIBBON } from "@/components/awards/ribbonDesign/constants"; -import { DeviceEditor, RibbonPreview, StripeEditor } from "@/components/awards/ribbonDesign/parts"; +import { DeviceEditor, LineEditor, RibbonPreview, StripeEditor } from "@/components/awards/ribbonDesign/parts"; import type { RibbonDesign } from "@/components/awards/ribbonDesign/types"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; @@ -14,6 +14,7 @@ import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; +import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"; import { validateRibbonDesign } from "@/lib/awards/ribbonValidation"; export function RibbonStudio() { @@ -107,6 +108,29 @@ export function RibbonStudio() {

Reflect the pattern across the center for a balanced ribbon.

+
+ + { + if (value === "vertical" || value === "horizontal") { + setDesign((current) => ({ ...current, stripeOrientation: value })); + } + }} + > + + Vertical + + + Horizontal + + +
@@ -120,6 +144,10 @@ export function RibbonStudio() { stripes={design.stripes} onChange={(stripes) => setDesign((current) => ({ ...current, stripes }))} /> + setDesign((current) => ({ ...current, lines }))} + /> setDesign((current) => ({ ...current, devices }))}