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.
This commit is contained in:
parent
ca9961bf19
commit
e92580bbe4
3 changed files with 150 additions and 15 deletions
|
|
@ -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 (
|
||||
<div className="field-type json flex flex-col gap-3">
|
||||
|
|
@ -54,19 +63,30 @@ export default function RibbonDesigner() {
|
|||
|
||||
<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>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<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>
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleOrientation}
|
||||
className="text-[11px] px-3 py-1.5 rounded border w-fit transition-colors cursor-pointer bg-zinc-800 border-zinc-700 text-zinc-400 hover:bg-zinc-700"
|
||||
title="Toggle whether stripe bands run vertically or horizontally"
|
||||
>
|
||||
{design.stripeOrientation === "horizontal" ? "\u2195 Horizontal bands" : "\u2194 Vertical bands"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<StripeEditor stripes={design.stripes} onChange={setStripes} />
|
||||
<LineEditor lines={design.lines ?? []} onChange={setLines} />
|
||||
<DeviceEditor devices={design.devices} onChange={setDevices} />
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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<RibbonLine>) =>
|
||||
onChange(lines.map((l, i) => (i === idx ? { ...l, ...patch } : l)));
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-xs font-medium text-zinc-400 uppercase tracking-wider">Horizontal lines</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={addLine}
|
||||
disabled={lines.length >= MAX_DESIGN_LINES}
|
||||
className="text-[11px] px-2 py-0.5 rounded bg-emerald-950 border border-emerald-700 text-emerald-200 hover:bg-emerald-900 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed"
|
||||
>
|
||||
+ Add line
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-[10px] text-zinc-500">
|
||||
Thin overlay bars across the stripes, drawn under devices. Up to {MAX_DESIGN_LINES}.
|
||||
</p>
|
||||
{lines.map((line, idx) => (
|
||||
<div key={line.id} className="flex flex-wrap items-center gap-2 bg-zinc-800/60 rounded px-2 py-1.5">
|
||||
<input
|
||||
type="color"
|
||||
value={line.color}
|
||||
onChange={(e) => 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`}
|
||||
/>
|
||||
<div className="flex min-w-0 flex-1 items-center gap-1.5">
|
||||
<label className="text-[10px] text-zinc-500 uppercase" htmlFor={`line-pos-${line.id}`}>
|
||||
Pos
|
||||
</label>
|
||||
<input
|
||||
id={`line-pos-${line.id}`}
|
||||
type="range"
|
||||
min={0}
|
||||
max={100}
|
||||
value={line.positionY}
|
||||
onChange={(e) => updateLine(idx, { positionY: Number(e.target.value) })}
|
||||
className="h-1 flex-1 accent-amber-500"
|
||||
/>
|
||||
<span className="w-8 text-right font-mono text-[10px] text-zinc-400">{line.positionY}%</span>
|
||||
</div>
|
||||
<div className="flex min-w-0 flex-1 items-center gap-1.5">
|
||||
<label className="text-[10px] text-zinc-500 uppercase" htmlFor={`line-size-${line.id}`}>
|
||||
Size
|
||||
</label>
|
||||
<input
|
||||
id={`line-size-${line.id}`}
|
||||
type="range"
|
||||
min={1}
|
||||
max={100}
|
||||
value={line.thickness}
|
||||
onChange={(e) => updateLine(idx, { thickness: Number(e.target.value) })}
|
||||
className="h-1 flex-1 accent-amber-500"
|
||||
/>
|
||||
<span className="w-8 text-right font-mono text-[10px] text-zinc-400">{line.thickness}%</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeLine(line.id)}
|
||||
className="px-1 py-1 text-zinc-500 hover:text-red-400 text-sm cursor-pointer"
|
||||
aria-label={`Remove line ${idx + 1}`}
|
||||
>
|
||||
{"\u00D7"}
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Device Editor ──────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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() {
|
|||
<p className="text-xs text-muted-foreground">
|
||||
Reflect the pattern across the center for a balanced ribbon.
|
||||
</p>
|
||||
<div className="flex items-center gap-3 pt-1">
|
||||
<Label htmlFor="ribbon-orientation" className="text-xs">
|
||||
Stripe direction
|
||||
</Label>
|
||||
<ToggleGroup
|
||||
id="ribbon-orientation"
|
||||
type="single"
|
||||
variant="outline"
|
||||
value={design.stripeOrientation ?? "vertical"}
|
||||
onValueChange={(value) => {
|
||||
if (value === "vertical" || value === "horizontal") {
|
||||
setDesign((current) => ({ ...current, stripeOrientation: value }));
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ToggleGroupItem value="vertical" className="text-xs">
|
||||
Vertical
|
||||
</ToggleGroupItem>
|
||||
<ToggleGroupItem value="horizontal" className="text-xs">
|
||||
Horizontal
|
||||
</ToggleGroupItem>
|
||||
</ToggleGroup>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -120,6 +144,10 @@ export function RibbonStudio() {
|
|||
stripes={design.stripes}
|
||||
onChange={(stripes) => setDesign((current) => ({ ...current, stripes }))}
|
||||
/>
|
||||
<LineEditor
|
||||
lines={design.lines ?? []}
|
||||
onChange={(lines) => setDesign((current) => ({ ...current, lines }))}
|
||||
/>
|
||||
<DeviceEditor
|
||||
devices={design.devices}
|
||||
onChange={(devices) => setDesign((current) => ({ ...current, devices }))}
|
||||
|
|
|
|||
Loading…
Reference in a new issue