import clsx from "clsx"; import { colord, extend } from "colord"; import harmoniesPlugin, { type HarmonyType } from "colord/plugins/harmonies"; import { RawColor } from "./config"; import { colorButtonStyle } from "./NamedColorGrid"; import { useTranslate } from "../i18n"; extend([harmoniesPlugin]); const harmonyLabels: Record = { complementary: "Complémentaire", analogous: "Analogue", triadic: "Triadique", "split-complementary": "Complémentaire divisée", rectangle: "Rectangle", tetradic: "Tétradique", "double-split-complementary": "Double complémentaire divisée", }; const harmonyTypes = Object.keys(harmonyLabels) as HarmonyType[]; interface Props { refColor: RawColor; value: RawColor | null; onChange: (value: RawColor) => void; } export function HarmonyColorGrid({ refColor, value, onChange }: Props) { const t = useTranslate(); const baseColor = colord(refColor.hex); return (
{harmonyTypes.map((harmonyType) => (
{t?.(`form.values.colorHarmony.${harmonyType}`) ?? harmonyLabels[harmonyType]}
{baseColor.harmonies(harmonyType).map((harmonyColor, index) => { const hex = harmonyColor.toHex(); return (
))}
); }