import { ComponentProps, RefObject, useImperativeHandle, useRef } from "react"; import clsx from "clsx"; import { useRipple } from "pentatrion-design/hooks"; import { Color, defaultBrandPalette, BrandPalette } from "./config"; import { getColorValue } from "./util"; import { ThemeColor } from "../../types"; import { useTranslate } from "../i18n"; export interface ColorPreviewProps extends Omit, "color" | "value"> { withRipple?: boolean; value?: Color | null | string; color?: ThemeColor; label?: string; palette?: BrandPalette; showValue?: boolean; className?: string; ref?: RefObject; } export function ColorPreview({ value: unknownColor, withRipple = true, color = "yellow", label, showValue = false, palette = defaultBrandPalette, className, ref, ...rest }: ColorPreviewProps) { const t = useTranslate(); const value: Color | null = typeof unknownColor === "string" ? { type: "raw", hex: unknownColor } : (unknownColor ?? null); const valueLabel = label ?? (value ? showValue ? value.type === "raw" ? value.hex : value.name : null : (t?.("form.values.color.inherit") ?? "Par défault")); const buttonRef = useRef(null!); useImperativeHandle( ref, () => buttonRef.current, ); const ripples = useRipple(buttonRef); return ( ); }