Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(settings): add random color option to label and property color pickers (MUL-4786) (#5437)

Jiayuan Zhang07e2d378bd6d
diff --git a/packages/views/common/color-picker.test.tsx b/packages/views/common/color-picker.test.tsx
new file mode 100644
index 0000000000..232553941a
--- /dev/null
+++ b/packages/views/common/color-picker.test.tsx
@@ -0,0 +1,60 @@
+// @vitest-environment jsdom
+
+import { cleanup, fireEvent, screen } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import { renderWithI18n } from "../test/i18n";
+import { ColorPickerPanel, COLOR_PICKER_PRESETS } from "./color-picker";
+
+afterEach(cleanup);
+
+describe("ColorPickerPanel", () => {
+ it("shows the current color in the hex input and marks the matching preset", () => {
+ renderWithI18n(<ColorPickerPanel value="#3b82f6" onChange={() => {}} />);
+ expect(screen.getByLabelText("Hex color")).toHaveValue("#3B82F6");
+ expect(screen.getByLabelText("#3b82f6")).toHaveAttribute(
+ "aria-pressed",
+ "true",
+ );
+ });
+
+ it("emits the preset color when a palette swatch is clicked", () => {
+ const onChange = vi.fn();
+ renderWithI18n(<ColorPickerPanel value="#3b82f6" onChange={onChange} />);
+ fireEvent.click(screen.getByLabelText("#ec4899"));
+ expect(onChange).toHaveBeenCalledWith("#ec4899");
+ });
+
+ it("emits a valid random color different from the current one", () => {
+ const onChange = vi.fn();
+ renderWithI18n(<ColorPickerPanel value="#3b82f6" onChange={onChange} />);
+ fireEvent.click(screen.getByRole("button", { name: "Random" }));
+ const emitted = onChange.mock.calls[0]?.[0] as string;
+ expect(emitted).toMatch(/^#[0-9a-f]{6}$/);
+ expect(emitted).not.toBe("#3b82f6");
+ });
+
+ it("emits typed hex values once they are complete and valid", () => {
+ const onChange = vi.fn();
+ renderWithI18n(<ColorPickerPanel value="#3b82f6" onChange={onChange} />);
+ const input = screen.getByLabelText("Hex color");
+ fireEvent.change(input, { target: { value: "#ec48" } });
+ expect(onChange).not.toHaveBeenCalled();
+ fireEvent.change(input, { target: { value: "#EC4899" } });
+ expect(onChange).toHaveBeenCalledWith("#ec4899");
+ });
+
+ it("renders every default preset exactly once", () => {
+ renderWithI18n(<ColorPickerPanel value="#3b82f6" onChange={() => {}} />);
+ for (const preset of COLOR_PICKER_PRESETS) {
+ expect(screen.getAllByLabelText(preset)).toHaveLength(1);
+ }
+ });
+
+ it("uses localized labels", () => {
+ renderWithI18n(<ColorPickerPanel value="#3b82f6" onChange={() => {}} />, {
+ locale: "zh-Hans",
+ });
+ expect(screen.getByRole("button", { name: "随机" })).toBeInTheDocument();
+ expect(screen.getByText("预设颜色")).toBeInTheDocument();
+ });
+});
diff --git a/packages/views/common/color-picker.tsx b/packages/views/common/color-picker.tsx
new file mode 100644
index 0000000000..c10577052a
--- /dev/null
+++ b/packages/views/common/color-picker.tsx
@@ -0,0 +1,312 @@
+"use client";
+
+import { useEffect, useState } from "react";
+import { Dices, Pipette } from "lucide-react";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@multica/ui/components/ui/popover";
+import { Button } from "@multica/ui/components/ui/button";
+import { Input } from "@multica/ui/components/ui/input";
+import { cn } from "@multica/ui/lib/utils";
+import { useT } from "../i18n";
+import {
+ type Hsv,
+ hexToHsv,
+ hsvToHex,
+ normalizeHex,
+ randomOptionColor,
+} from "./color-utils";
+
+/**
+ * Default palette shared by every color-picking surface (labels, property
+ * options). Keeping one list is what makes colors look consistent across
+ * the product — pick from here first, reach for the area/hex only when a
+ * specific color is needed.
+ */
+export const COLOR_PICKER_PRESETS = [
+ "#6b7280",
+ "#ef4444",
+ "#f97316",
+ "#eab308",
+ "#22c55e",
+ "#14b8a6",
+ "#3b82f6",
+ "#6366f1",
+ "#a855f7",
+ "#ec4899",
+] as const;
+
+const HUE_GRADIENT =
+ "linear-gradient(to right, #f00, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, #f00)";
+
+function clamp01(value: number): number {
+ return Math.min(1, Math.max(0, value));
+}
+
+/**
+ * Shared color picker: saturation/value area, hue slider, eyedropper
+ * (where the browser supports it), hex input, and the default palette with
+ * a one-click Random action. Values travel as `#rrggbb` hex strings.
+ *
+ * `trigger` is the element that opens the popover (usually a swatch button),
+ * passed through Base UI's render prop like the other pickers.
+ */
+export function ColorPicker({
+ value,
+ onChange,
+ trigger,
+ align = "start",
+}: {
+ value: string;
+ onChange: (color: string) => void;
+ trigger: React.ReactElement;
+ align?: "start" | "center" | "end";
+}) {
+ return (
+ <Popover>
+ <PopoverTrigger render={trigger} />
+ <PopoverContent align={align} className="w-72 p-3">
+ <ColorPickerPanel value={value} onChange={onChange} />
+ </PopoverContent>
+ </Popover>
+ );
+}
+
+/** Popover-less panel — exported for tests and future inline embedding. */
+export function ColorPickerPanel({
+ value,
+ onChange,
+}: {
+ value: string;
+ onChange: (color: string) => void;
+}) {
+ const { t } = useT("common");
+ const [hsv, setHsv] = useState<Hsv>(
+ () => hexToHsv(value) ?? { h: 217, s: 0.72, v: 0.96 },
+ );
+ // Local hex text while the user is typing; null mirrors `value`.
+ const [hexDraft, setHexDraft] = useState<string | null>(null);
+ const [eyedropperSupported] = useState(
+ () => typeof window !== "undefined" && "EyeDropper" in window,
+ );
+
+ // Sync internal HSV when the color changes from outside the area/slider
+ // (preset click, random, hex input, caller updates). Hex can't express hue
+ // for achromatic colors nor saturation for black, so preserve those parts
+ // and keep the area/slider from snapping.
+ useEffect(() => {
+ setHsv((previous) => {
+ if (hsvToHex(previous) === normalizeHex(value)) return previous;
+ const next = hexToHsv(value);
+ if (!next) return previous;
+ return {
+ h: next.s === 0 || next.v === 0 ? previous.h : next.h,
+ s: next.v === 0 ? previous.s : next.s,
+ v: next.v,
+ };
+ });
+ }, [value]);
+
+ const commit = (next: Hsv) => {
+ setHsv(next);
+ setHexDraft(null);
+ onChange(hsvToHex(next));
+ };
+
+ const handleAreaPointer = (event: React.PointerEvent<HTMLDivElement>) => {
+ const rect = event.currentTarget.getBoundingClientRect();
+ commit({
+ h: hsv.h,
+ s: clamp01((event.clientX - rect.left) / rect.width),
+ v: 1 - clamp01((event.clientY - rect.top) / rect.height),
+ });
+ };
+
+ const handleHuePointer = (event: React.PointerEvent<HTMLDivElement>) => {
+ const rect = event.currentTarget.getBoundingClientRect();
+ commit({
+ ...hsv,
+ h: 360 * clamp01((event.clientX - rect.left) / rect.width),
+ });
+ };
+
+ const pickFromScreen = async () => {
+ const EyeDropperCtor = (
+ window as unknown as {
+ EyeDropper?: new () => { open: () => Promise<{ sRGBHex: string }> };
+ }
+ ).EyeDropper;
+ if (!EyeDropperCtor) return;
+ try {
+ const result = await new EyeDropperCtor().open();
+ const normalized = normalizeHex(result.sRGBHex);
+ if (normalized) {
+ setHexDraft(null);
+ onChange(normalized);
+ }
+ } catch {
+ // user cancelled the eyedropper
+ }
+ };
+
+ const currentHex = normalizeHex(value) ?? hsvToHex(hsv);
+
+ return (
+ <div className="flex flex-col gap-2.5">
+ {/* Saturation / value area */}
+ <div
+ role="slider"
+ tabIndex={0}
+ aria-label={t(($) => $.color_picker.saturation)}
+ aria-valuemin={0}
+ aria-valuemax={100}
+ aria-valuenow={Math.round(hsv.v * 100)}
+ aria-valuetext={`${Math.round(hsv.s * 100)}%, ${Math.round(hsv.v * 100)}%`}
+ className="relative h-36 w-full cursor-crosshair touch-none rounded-md ring-1 ring-inset ring-black/10"
+ style={{
+ backgroundColor: `hsl(${hsv.h} 100% 50%)`,
+ backgroundImage:
+ "linear-gradient(to top, #000, transparent), linear-gradient(to right, #fff, transparent)",
+ }}
+ onPointerDown={(event) => {
+ event.currentTarget.setPointerCapture(event.pointerId);
+ handleAreaPointer(event);
+ }}
+ onPointerMove={(event) => {
+ if (event.buttons & 1) handleAreaPointer(event);
+ }}
+ onKeyDown={(event) => {
+ const step = event.shiftKey ? 0.1 : 0.02;
+ if (event.key === "ArrowLeft") commit({ ...hsv, s: clamp01(hsv.s - step) });
+ else if (event.key === "ArrowRight") commit({ ...hsv, s: clamp01(hsv.s + step) });
+ else if (event.key === "ArrowUp") commit({ ...hsv, v: clamp01(hsv.v + step) });
+ else if (event.key === "ArrowDown") commit({ ...hsv, v: clamp01(hsv.v - step) });
+ else return;
+ event.preventDefault();
+ }}
+ >
+ <span
+ className="pointer-events-none absolute size-3.5 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0_0_0_1px_rgba(0,0,0,0.2)]"
+ style={{
+ left: `${hsv.s * 100}%`,
+ top: `${(1 - hsv.v) * 100}%`,
+ backgroundColor: currentHex,
+ }}
+ />
+ </div>
+
+ {/* Eyedropper + hue slider */}
+ <div className="flex items-center gap-2.5">
+ {eyedropperSupported && (
+ <Button
+ type="button"
+ variant="outline"
+ size="icon-sm"
+ aria-label={t(($) => $.color_picker.eyedropper)}
+ title={t(($) => $.color_picker.eyedropper)}
+ onClick={pickFromScreen}
+ >
+ <Pipette className="size-3.5" />
+ </Button>
+ )}
+ <div
+ role="slider"
+ tabIndex={0}
+ aria-label={t(($) => $.color_picker.hue)}
+ aria-valuemin={0}
+ aria-valuemax={360}
+ aria-valuenow={Math.round(hsv.h)}
+ className="relative h-3 min-w-0 flex-1 cursor-pointer touch-none rounded-full ring-1 ring-inset ring-black/10"
+ style={{ background: HUE_GRADIENT }}
+ onPointerDown={(event) => {
+ event.currentTarget.setPointerCapture(event.pointerId);
+ handleHuePointer(event);
+ }}
+ onPointerMove={(event) => {
+ if (event.buttons & 1) handleHuePointer(event);
+ }}
+ onKeyDown={(event) => {
+ const step = event.shiftKey ? 15 : 3;
+ if (event.key === "ArrowLeft" || event.key === "ArrowDown")
+ commit({ ...hsv, h: Math.max(0, hsv.h - step) });
+ else if (event.key === "ArrowRight" || event.key === "ArrowUp")
+ commit({ ...hsv, h: Math.min(360, hsv.h + step) });
+ else return;
+ event.preventDefault();
+ }}
+ >
+ <span
+ className="pointer-events-none absolute top-1/2 size-3.5 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-white shadow-[0_0_0_1px_rgba(0,0,0,0.2)]"
+ style={{
+ left: `${(hsv.h / 360) * 100}%`,
+ backgroundColor: `hsl(${hsv.h} 100% 50%)`,
+ }}
+ />
+ </div>
+ </div>
+
+ {/* Hex input */}
+ <div className="flex items-center gap-2.5">
+ <span
+ className="size-6 shrink-0 rounded-full ring-1 ring-inset ring-black/10"
+ style={{ backgroundColor: currentHex }}
+ />
+ <Input
+ value={hexDraft ?? currentHex.toUpperCase()}
+ aria-label={t(($) => $.color_picker.hex)}
+ spellCheck={false}
+ className="h-8 font-mono text-xs"
+ onChange={(event) => {
+ setHexDraft(event.target.value);
+ const normalized = normalizeHex(event.target.value);
+ if (normalized) onChange(normalized);
+ }}
+ onBlur={() => setHexDraft(null)}
+ onKeyDown={(event) => {
+ if (event.key === "Enter") setHexDraft(null);
+ }}
+ />
+ </div>
+
+ {/* Default palette + random */}
+ <div className="flex items-center justify-between">
+ <span className="text-xs font-medium text-muted-foreground">
+ {t(($) => $.color_picker.presets)}
+ </span>
+ <button
+ type="button"
+ className="flex items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground"
+ onClick={() => {
+ setHexDraft(null);
+ onChange(randomOptionColor(value));
+ }}
+ >
+ <Dices className="size-3.5" />
+ {t(($) => $.color_picker.random)}
+ </button>
+ </div>
+ <div className="flex items-center justify-between">
+ {COLOR_PICKER_PRESETS.map((preset) => (
+ <button
+ key={preset}
+ type="button"
+ aria-label={preset}
+ aria-pressed={currentHex === preset}
+ onClick={() => {
+ setHexDraft(null);
+ onChange(preset);
+ }}
+ className={cn(
+ "size-5 rounded-full transition-transform hover:scale-110",
+ currentHex === preset &&
+ "ring-2 ring-ring ring-offset-2 ring-offset-surface-raised",
+ )}
+ style={{ backgroundColor: preset }}
+ />
+ ))}
+ </div>
+ </div>
+ );
+}
diff --git a/packages/views/common/color-utils.test.ts b/packages/views/common/color-utils.test.ts
new file mode 100644
index 0000000000..779a091975
--- /dev/null
+++ b/packages/views/common/color-utils.test.ts
@@ -0,0 +1,116 @@
+import { describe, it, expect } from "vitest";
+import {
+ hexToHsv,
+ hsvToHex,
+ normalizeHex,
+ randomOptionColor,
+} from "./color-utils";
+
+const RUNS = 200;
+
+function hexToHsl(hex: string): { h: number; s: number; l: number } {
+ const r = parseInt(hex.slice(1, 3), 16) / 255;
+ const g = parseInt(hex.slice(3, 5), 16) / 255;
+ const b = parseInt(hex.slice(5, 7), 16) / 255;
+ const max = Math.max(r, g, b);
+ const min = Math.min(r, g, b);
+ const delta = max - min;
+ const l = (max + min) / 2;
+ if (delta === 0) return { h: 0, s: 0, l };
+ const s = delta / (1 - Math.abs(2 * l - 1));
+ let h: number;
+ if (max === r) h = ((g - b) / delta) % 6;
+ else if (max === g) h = (b - r) / delta + 2;
+ else h = (r - g) / delta + 4;
+ return { h: (h * 60 + 360) % 360, s, l };
+}
+
+function hueDistance(a: number, b: number): number {
+ const diff = Math.abs(a - b) % 360;
+ return Math.min(diff, 360 - diff);
+}
+
+describe("normalizeHex", () => {
+ it("normalizes case and missing hash", () => {
+ expect(normalizeHex("#3B82F6")).toBe("#3b82f6");
+ expect(normalizeHex("3b82f6")).toBe("#3b82f6");
+ expect(normalizeHex(" #3b82f6 ")).toBe("#3b82f6");
+ });
+
+ it("rejects anything that is not a 6-digit hex color", () => {
+ for (const bad of ["#fff", "3b82f", "#3b82f6ff", "red", ""]) {
+ expect(normalizeHex(bad)).toBeNull();
+ }
+ });
+});
+
+describe("hexToHsv / hsvToHex", () => {
+ it("converts primaries and grays to the expected HSV", () => {
+ expect(hexToHsv("#ff0000")).toEqual({ h: 0, s: 1, v: 1 });
+ expect(hexToHsv("#00ff00")).toEqual({ h: 120, s: 1, v: 1 });
+ expect(hexToHsv("#0000ff")).toEqual({ h: 240, s: 1, v: 1 });
+ expect(hexToHsv("#000000")).toEqual({ h: 0, s: 0, v: 0 });
+ expect(hexToHsv("#ffffff")).toEqual({ h: 0, s: 0, v: 1 });
+ });
+
+ it("returns null for invalid input", () => {
+ expect(hexToHsv("nope")).toBeNull();
+ });
+
+ it("round-trips every representable color it produces", () => {
+ for (const hex of [
+ "#6b7280",
+ "#ef4444",
+ "#f97316",
+ "#eab308",
+ "#22c55e",
+ "#14b8a6",
+ "#3b82f6",
+ "#6366f1",
+ "#a855f7",
+ "#ec4899",
+ "#000000",
+ "#ffffff",
+ ]) {
+ const hsv = hexToHsv(hex);
+ expect(hsv).not.toBeNull();
+ expect(hsvToHex(hsv!)).toBe(hex);
+ }
+ });
+});
+
+describe("randomOptionColor", () => {
+ it("returns a lowercase #rrggbb hex string", () => {
+ for (let i = 0; i < RUNS; i++) {
+ expect(randomOptionColor()).toMatch(/^#[0-9a-f]{6}$/);
+ }
+ });
+
+ it("stays inside the vivid saturation/lightness band", () => {
+ for (let i = 0; i < RUNS; i++) {
+ const { s, l } = hexToHsl(randomOptionColor());
+ // Rounding hex channels shifts HSL slightly; allow a small tolerance
+ // around the generator's [0.62, 0.9] / [0.46, 0.62] sampling ranges.
+ expect(s).toBeGreaterThan(0.55);
+ expect(s).toBeLessThan(0.95);
+ expect(l).toBeGreaterThan(0.42);
+ expect(l).toBeLessThan(0.66);
+ }
+ });
+
+ it("keeps a visible hue distance from the avoided color", () => {
+ const avoid = "#f97316"; // orange preset, hue ~25
+ const avoidHue = hexToHsl(avoid).h;
+ for (let i = 0; i < RUNS; i++) {
+ const next = randomOptionColor(avoid);
+ expect(next).not.toBe(avoid);
+ expect(hueDistance(hexToHsl(next).h, avoidHue)).toBeGreaterThanOrEqual(30);
+ }
+ });
+
+ it("still returns a valid color when avoid is achromatic or malformed", () => {
+ for (const avoid of ["#808080", "#000000", "not-a-color", "#fff", ""]) {
+ expect(randomOptionColor(avoid)).toMatch(/^#[0-9a-f]{6}$/);
+ }
+ });
+});
diff --git a/packages/views/common/color-utils.ts b/packages/views/common/color-utils.ts
new file mode 100644
index 0000000000..0f226d3d45
--- /dev/null
+++ b/packages/views/common/color-utils.ts
@@ -0,0 +1,92 @@
+// Color math behind the shared color picker (see color-picker.tsx).
+//
+// Values travel as `#rrggbb` hex strings (what the API stores); the picker
+// edits in HSV because saturation/value map directly onto its 2D area.
+
+export interface Hsv {
+ /** Hue in degrees, 0–360. */
+ h: number;
+ /** Saturation 0–1. */
+ s: number;
+ /** Value (brightness) 0–1. */
+ v: number;
+}
+
+/** Normalizes to lowercase `#rrggbb`, or null when not a 6-digit hex color. */
+export function normalizeHex(input: string): string | null {
+ const match = /^#?([0-9a-f]{6})$/i.exec(input.trim());
+ return match ? `#${match[1]?.toLowerCase()}` : null;
+}
+
+export function hexToHsv(hex: string): Hsv | null {
+ const normalized = normalizeHex(hex);
+ if (!normalized) return null;
+ const r = parseInt(normalized.slice(1, 3), 16) / 255;
+ const g = parseInt(normalized.slice(3, 5), 16) / 255;
+ const b = parseInt(normalized.slice(5, 7), 16) / 255;
+ const max = Math.max(r, g, b);
+ const delta = max - Math.min(r, g, b);
+ let h = 0;
+ if (delta !== 0) {
+ if (max === r) h = ((g - b) / delta) % 6;
+ else if (max === g) h = (b - r) / delta + 2;
+ else h = (r - g) / delta + 4;
+ h = (h * 60 + 360) % 360;
+ }
+ return { h, s: max === 0 ? 0 : delta / max, v: max };
+}
+
+export function hsvToHex({ h, s, v }: Hsv): string {
+ const channel = (n: number): string => {
+ const k = (n + h / 60) % 6;
+ const value = v - v * s * Math.max(0, Math.min(k, 4 - k, 1));
+ return Math.round(value * 255)
+ .toString(16)
+ .padStart(2, "0");
+ };
+ return `#${channel(5)}${channel(3)}${channel(1)}`;
+}
+
+// Random picks are sampled in HSL and constrained to the vivid band the
+// preset palette lives in, so a random color never lands on near-white,
+// near-black, or a washed-out gray. When the current color is passed as
+// `avoid`, the new hue keeps a minimum circular distance from it so every
+// click produces a visibly different color.
+
+const MIN_HUE_DISTANCE = 40;
+const SATURATION_RANGE: readonly [number, number] = [0.62, 0.9];
+const LIGHTNESS_RANGE: readonly [number, number] = [0.46, 0.62];
+
+function randomIn([min, max]: readonly [number, number]): number {
+ return min + Math.random() * (max - min);
+}
+
+function hslToHex(hue: number, saturation: number, lightness: number): string {
+ const channel = (n: number): string => {
+ const k = (n + hue / 30) % 12;
+ const a = saturation * Math.min(lightness, 1 - lightness);
+ const value = lightness - a * Math.max(-1, Math.min(k - 3, 9 - k, 1));
+ return Math.round(value * 255)
+ .toString(16)
+ .padStart(2, "0");
+ };
+ return `#${channel(0)}${channel(8)}${channel(4)}`;
+}
+
+/**
+ * Returns a random vivid color as `#rrggbb`. Pass the current color via
+ * `avoid` to guarantee the result reads as a different color.
+ */
+export function randomOptionColor(avoid?: string): string {
+ const avoidHsv = avoid ? hexToHsv(avoid) : null;
+ const avoidHue =
+ avoidHsv && avoidHsv.s > 0 && avoidHsv.v > 0 ? avoidHsv.h : null;
+ const hue =
+ avoidHue === null
+ ? Math.random() * 360
+ : (avoidHue +
+ MIN_HUE_DISTANCE +
+ Math.random() * (360 - MIN_HUE_DISTANCE * 2)) %
+ 360;
+ return hslToHex(hue, randomIn(SATURATION_RANGE), randomIn(LIGHTNESS_RANGE));
+}
diff --git a/packages/views/locales/en/common.json b/packages/views/locales/en/common.json
index 2fe0739d5e..b6b934d592 100644
--- a/packages/views/locales/en/common.json
+++ b/packages/views/locales/en/common.json
@@ -19,6 +19,14 @@
"loading": "Loading…",
"load_failed": "Couldn't load image"
},
+ "color_picker": {
+ "saturation": "Saturation and brightness",
+ "hue": "Hue",
+ "hex": "Hex color",
+ "eyedropper": "Pick a color from the screen",
+ "presets": "Presets",
+ "random": "Random"
+ },
"save": "Save",
"cancel": "Cancel",
"delete": "Delete",
diff --git a/packages/views/locales/en/settings.json b/packages/views/locales/en/settings.json
index f9b86b6c20..2a39b7b94b 100644
--- a/packages/views/locales/en/settings.json
+++ b/packages/views/locales/en/settings.json
@@ -214,7 +214,6 @@
"description": "Description",
"description_placeholder": "Describe when this label should be used",
"color": "Color",
- "custom_color": "Choose a custom color",
"cancel": "Cancel",
"save": "Save label",
"saving": "Saving..."
diff --git a/packages/views/locales/ja/common.json b/packages/views/locales/ja/common.json
index 06e8b2c1a9..85b1bca9f8 100644
--- a/packages/views/locales/ja/common.json
+++ b/packages/views/locales/ja/common.json
@@ -19,6 +19,14 @@
"loading": "読み込み中…",
"load_failed": "画像を読み込めませんでした"
},
+ "color_picker": {
+ "saturation": "彩度と明度",
+ "hue": "色相",
+ "hex": "16進カラー",
+ "eyedropper": "画面から色を取得",
+ "presets": "プリセット",
+ "random": "ランダム"
+ },
"save": "保存",
"cancel": "キャンセル",
"delete": "削除",
diff --git a/packages/views/locales/ja/settings.json b/packages/views/locales/ja/settings.json
index ca6109f44f..452c917893 100644
--- a/packages/views/locales/ja/settings.json
+++ b/packages/views/locales/ja/settings.json
@@ -206,7 +206,6 @@
"description": "説明",
"description_placeholder": "このラベルを使用する条件を説明",
"color": "色",
- "custom_color": "カスタム色を選択",
"cancel": "キャンセル",
"save": "ラベルを保存",
"saving": "保存中..."
diff --git a/packages/views/locales/ko/common.json b/packages/views/locales/ko/common.json
index abbaa784de..fb27cea659 100644
--- a/packages/views/locales/ko/common.json
+++ b/packages/views/locales/ko/common.json
@@ -19,6 +19,14 @@
"loading": "불러오는 중…",
"load_failed": "이미지를 불러오지 못했어요"
},
+ "color_picker": {
+ "saturation": "채도와 명도",
+ "hue": "색조",
+ "hex": "16진수 색상",
+ "eyedropper": "화면에서 색상 선택",
+ "presets": "프리셋",
+ "random": "무작위"
+ },
"save": "저장",
"cancel": "취소",
"delete": "삭제",
diff --git a/packages/views/locales/ko/settings.json b/packages/views/locales/ko/settings.json
index d4659111e4..ca4e3c2be4 100644
--- a/packages/views/locales/ko/settings.json
+++ b/packages/views/locales/ko/settings.json
@@ -206,7 +206,6 @@
"description": "설명",
"description_placeholder": "이 레이블을 사용할 때를 설명하세요",
"color": "색상",
- "custom_color": "사용자 지정 색상 선택",
"cancel": "취소",
"save": "레이블 저장",
"saving": "저장 중..."
diff --git a/packages/views/locales/zh-Hans/common.json b/packages/views/locales/zh-Hans/common.json
index f753a09288..7da92f9b61 100644
--- a/packages/views/locales/zh-Hans/common.json
+++ b/packages/views/locales/zh-Hans/common.json
@@ -19,6 +19,14 @@
"loading": "加载中…",
"load_failed": "图片加载失败"
},
+ "color_picker": {
+ "saturation": "饱和度与明度",
+ "hue": "色相",
+ "hex": "十六进制颜色",
+ "eyedropper": "从屏幕取色",
+ "presets": "预设颜色",
+ "random": "随机"
+ },
"save": "保存",
"cancel": "取消",
"delete": "删除",
diff --git a/packages/views/locales/zh-Hans/settings.json b/packages/views/locales/zh-Hans/settings.json
index 3377bb5814..f4e7ec2b21 100644
--- a/packages/views/locales/zh-Hans/settings.json
+++ b/packages/views/locales/zh-Hans/settings.json
@@ -213,7 +213,6 @@
"description": "描述",
"description_placeholder": "说明什么时候应使用这个标签",
"color": "颜色",
- "custom_color": "选择自定义颜色",
"cancel": "取消",
"save": "保存标签",
"saving": "保存中..."
diff --git a/packages/views/settings/components/labels-tab.tsx b/packages/views/settings/components/labels-tab.tsx
index 3b0338f9ed..d2955470dc 100644
--- a/packages/views/settings/components/labels-tab.tsx
+++ b/packages/views/settings/components/labels-tab.tsx
@@ -43,23 +43,12 @@ import {
DropdownMenuTrigger,
} from "@multica/ui/components/ui/dropdown-menu";
import { cn } from "@multica/ui/lib/utils";
+import { ColorPicker, COLOR_PICKER_PRESETS } from "../../common/color-picker";
import { useT } from "../../i18n";
import { SettingsTab } from "./settings-layout";
const RESOURCE_TYPES: LabelResourceType[] = ["issue", "agent", "skill"];
const ISSUE_RESOURCE_TYPES: LabelResourceType[] = ["issue"];
-const LABEL_COLORS = [
- "#6b7280",
- "#ef4444",
- "#f97316",
- "#eab308",
- "#22c55e",
- "#14b8a6",
- "#3b82f6",
- "#6366f1",
- "#a855f7",
- "#ec4899",
-] as const;
interface LabelDraft {
name: string;
@@ -70,7 +59,7 @@ interface LabelDraft {
const EMPTY_DRAFT: LabelDraft = {
name: "",
description: "",
- color: LABEL_COLORS[6],
+ color: COLOR_PICKER_PRESETS[6],
};
export function LabelsTab() {
@@ -360,37 +349,25 @@ function LabelEditorDialog({
</div>
<div className="space-y-2">
<FieldLabel>{t(($) => $.labels.editor.color)}</FieldLabel>
- <div className="flex flex-wrap items-center gap-2">
- {LABEL_COLORS.map((color) => (
+ <ColorPicker
+ value={draft.color}
+ onChange={(color) => setDraft((current) => ({ ...current, color }))}
+ trigger={
<button
- key={color}
type="button"
- aria-label={color}
- aria-pressed={draft.color === color}
- onClick={() => setDraft((current) => ({ ...current, color }))}
- className={cn(
- "size-7 rounded-full border-2 border-background ring-offset-2 transition-transform hover:scale-110",
- draft.color === color && "ring-2 ring-ring",
- )}
- style={{ backgroundColor: color }}
- />
- ))}
- <label
- className="relative size-7 cursor-pointer overflow-hidden rounded-full border border-surface-border"
- title={t(($) => $.labels.editor.custom_color)}
- style={{ backgroundColor: draft.color }}
- >
- <input
- type="color"
- value={draft.color}
- onChange={(event) =>
- setDraft((current) => ({ ...current, color: event.target.value }))
- }
- className="absolute inset-0 cursor-pointer opacity-0"
- aria-label={t(($) => $.labels.editor.custom_color)}
- />
- </label>
- </div>
+ aria-label={t(($) => $.labels.editor.color)}
+ className="flex h-9 items-center gap-2.5 rounded-md border border-surface-border px-2.5 transition-colors hover:bg-surface-hover"
+ >
+ <span
+ className="size-5 rounded-full"
+ style={{ backgroundColor: draft.color }}
+ />
+ <span className="font-mono text-xs uppercase text-muted-foreground">
+ {draft.color}
+ </span>
+ </button>
+ }
+ />
</div>
</div>
<DialogFooter>
diff --git a/packages/views/settings/components/properties-tab.tsx b/packages/views/settings/components/properties-tab.tsx
index 468b2c35e8..0f5fa77085 100644
--- a/packages/views/settings/components/properties-tab.tsx
+++ b/packages/views/settings/components/properties-tab.tsx
@@ -65,22 +65,11 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from "@multica/ui/components/ui/dropdown-menu";
+import { ColorPicker, COLOR_PICKER_PRESETS } from "../../common/color-picker";
import { useT } from "../../i18n";
import { SettingsTab } from "./settings-layout";
const MAX_ACTIVE_PROPERTIES = 20;
-const OPTION_COLORS = [
- "#6b7280",
- "#ef4444",
- "#f97316",
- "#eab308",
- "#22c55e",
- "#14b8a6",
- "#3b82f6",
- "#6366f1",
- "#a855f7",
- "#ec4899",
-] as const;
interface OptionDraft {
id?: string;
@@ -99,7 +88,7 @@ const EMPTY_DRAFT: PropertyDraft = {
name: "",
type: "select",
description: "",
- options: [{ name: "", color: OPTION_COLORS[6] }],
+ options: [{ name: "", color: COLOR_PICKER_PRESETS[6] }],
};
function typeHasOptions(type: string): boolean {
@@ -488,7 +477,7 @@ function PropertyEditorDialog({
type: value as IssuePropertyType,
options:
typeHasOptions(value) && current.options.length === 0
- ? [{ name: "", color: OPTION_COLORS[6] }]
+ ? [{ name: "", color: COLOR_PICKER_PRESETS[6] }]
: current.options,
}))
}
@@ -528,18 +517,18 @@ function PropertyEditorDialog({
{draft.options.map((option, index) => (
<div key={option.id ?? index} className="flex items-center gap-2">
<GripVertical className="size-4 shrink-0 text-muted-foreground/40" />
- <label
- className="relative size-6 shrink-0 cursor-pointer overflow-hidden rounded-full border border-surface-border"
- style={{ backgroundColor: option.color }}
- >
- <input
- type="color"
- value={option.color}
- onChange={(event) => setOption(index, { color: event.target.value })}
- className="absolute inset-0 cursor-pointer opacity-0"
- aria-label={option.color}
- />
- </label>
+ <ColorPicker
+ value={option.color}
+ onChange={(color) => setOption(index, { color })}
+ trigger={
+ <button
+ type="button"
+ aria-label={option.color}
+ className="size-6 shrink-0 cursor-pointer rounded-full border border-surface-border transition-transform hover:scale-110"
+ style={{ backgroundColor: option.color }}
+ />
+ }
+ />
<Input
value={option.name}
maxLength={32}
@@ -575,7 +564,7 @@ function PropertyEditorDialog({
...current.options,
{
name: "",
- color: OPTION_COLORS[current.options.length % OPTION_COLORS.length] ?? OPTION_COLORS[6],
+ color: COLOR_PICKER_PRESETS[current.options.length % COLOR_PICKER_PRESETS.length] ?? COLOR_PICKER_PRESETS[6],
},
],
}))