import { Icon } from "@iconify/react" import { Button, IconButton, Popover } from "@ivtui/base" import type { Editor } from "@tiptap/react" import { useEffect, useState } from "react" interface ColorControlProps { editor: Editor } const predefinedColors = [ "#000000", "#333333", "#666666", "#999999", "#cccccc", "#ffffff", "#ff0000", "#ff6600", "#ffcc00", "#00ff00", "#0066ff", "#6600ff", "#ff0066", "#ff3366", "#ff6699", "#66ff00", "#00ff66", "#0066cc", "#6600cc", "#cc00ff", "#ff00cc", "#cc6600", "#ffcc66", "#66ccff", ] export function ColorControl({ editor }: React.PropsWithChildren) { const [currentColor, setCurrentColor] = useState("#000000") const [open, setOpen] = useState(false) // Get current text color from editor useEffect(() => { const updateColor = () => { const colorMark = editor.getAttributes("textStyle") if (colorMark.color) { setCurrentColor(colorMark.color) } } editor.on("selectionUpdate", updateColor) updateColor() return () => { editor.off("selectionUpdate", updateColor) } }, [editor]) const handleColorChange = (color: string) => { setCurrentColor(color) editor.chain().focus().setColor(color).run() setOpen(false) } const handleRemoveColor = () => { setCurrentColor("#000000") editor.chain().focus().unsetColor().run() setOpen(false) } return (
{predefinedColors.map(color => ( handleColorChange(color)} title={color} className=" hover:!scale-110 transition-transform" style={{ backgroundColor: color }} /> ))}
) }