import { Popover, Group, ColorSwatch, Text, Tooltip, ColorPicker, TextInput, } from '@mantine/core'; import React, { useEffect, useState } from 'react'; import { IconInfoCircle } from '@tabler/icons-react'; function ButtonTheme(props: any): JSX.Element { const [colorValue, setColorValue] = useState('rgba(47, 119, 150, 0.7)'); const [inputValue, setInputValue] = useState(colorValue); useEffect(() => { // Update state if props.background changes if (props.background) { setColorValue(props.background); setInputValue(props.background); } }, [props.background]); const handleCustomStyles = (value: string) => { setColorValue(value); setInputValue(value); // Sync input field with ColorPicker props.customStyles(value, props.type, props.label); }; const handleInputChange = (event: React.ChangeEvent) => { const value = event.target.value; setInputValue(value); // Validate and apply the color value only if it's valid if ( /^#[0-9A-Fa-f]{6}$|^rgba?\((\d{1,3},\s?){2,3}(\d?\.?\d+)?\)$/.test( value ) ) { handleCustomStyles(value); props.customStyles(value, props.label); } }; return ( {props.label} {props.description && ( )} ); } export { ButtonTheme };