import { Modal, ModalContent, ModalFooter } from "pentatrion-design/modal"; import { useState } from "react"; import { Field, FieldProps } from "pentatrion-design/fields/field"; import { NamedColorGrid } from "./NamedColorGrid"; import { Button } from "pentatrion-design/button"; import { ColorPreview } from "./ColorPreview"; import { Color, BrandPalette, RawColor } from "./config"; import { Tabs } from "pentatrion-design/tabs"; import { HexColorInput, HexColorPicker } from "react-colorful"; import { inputConfig } from "pentatrion-design/fields/text"; import clsx from "clsx"; import { useTranslate } from "../i18n"; import { RawColorGrid } from "./RawColorGrid"; import { HarmonyColorGrid } from "./HarmonyColorGrid"; interface Props extends Omit { palette?: BrandPalette; value: Color | null; refColor?: RawColor; onChange: (value: Color | null) => void; allowInherit?: boolean; variants?: number | number[]; } export function ColorPicker({ palette, value, refColor, onChange, variants, allowInherit = false, ...rest }: Props) { const t = useTranslate(); const [isOpen, setIsOpen] = useState(false); const [tempValue, setTempValue] = useState(null); const [tabId, setTabId] = useState( value?.type === "raw" ? "custom" : palette ? "palette" : "swatches", ); function handleSubmit() { onChange(tempValue); setIsOpen(false); } function handleInherit() { onChange(null); setIsOpen(false); } const tabs = [ ...(palette ? [ { id: "palette", title: t?.("common.brandPalette") ?? "Couleurs du thème", content: ( ), }, ] : []), ...(refColor ? [ { id: "harmony", title: t?.("common.harmonyColors") ?? "Harmonies", content: ( ), }, ] : []), { id: "swatches", title: t?.("common.colorSwatches") ?? "Nuancier", content: ( ), }, { id: "custom", title: t?.("common.colorCustom") ?? "Sur mesure", content: (
{ setTempValue({ type: "raw", hex }); }} />
setTempValue({ type: "raw", hex })} />
), }, ]; return ( <> { setIsOpen(true); setTempValue(value); }} /> !modalKeepOpen && setIsOpen(false)} >
setIsOpen(false)}> } />
{allowInherit && ( )}
); }