import { CopyOutlined } from "@ant-design/icons"; import { message, Tooltip } from "antd"; import { useTranslate } from "@refinedev/core"; import "./spoolIcon.css"; interface Props { color: string | { colors: string[]; vertical: boolean }; size?: "small" | "large"; no_margin?: boolean; showHex?: boolean; } export default function SpoolIcon(props: Readonly) { const t = useTranslate(); let dirClass = "vertical"; let cols: string[] = []; const size = props.size ? props.size : "small"; const no_margin = props.no_margin ? "no-margin" : ""; if (typeof props.color === "string") { cols = [props.color]; } else { dirClass = props.color.vertical ? "vertical" : "horizontal"; cols = props.color.colors; } // Normalize hex codes (remove # if present, uppercase) const normalizedCols = cols.map((col) => col.replace("#", "").toUpperCase()); const hexDisplay = normalizedCols.length === 1 ? `#${normalizedCols[0]}` : normalizedCols.map((c) => `#${c}`).join(", "); const copyToClipboard = async () => { try { await navigator.clipboard.writeText(hexDisplay); message.success(t("color.copied", { color: hexDisplay })); } catch { message.error(t("color.copy_failed")); } }; const swatchContent = (
{normalizedCols.map((col) => (
))}
); if (props.showHex) { return (
{swatchContent} {hexDisplay}
); } return swatchContent; }