import { Popover, Group, ColorSwatch, Text, Tooltip, ColorPicker, TextInput, } from '@mantine/core'; import React, { useState, useEffect } from 'react'; import { IconInfoCircle } from '@tabler/icons-react'; function BannerTheme(props: any): JSX.Element { const initialColor = props.background || '#FFFFFF'; // Default to white if no background color is provided const [colorValue, setColorValue] = useState(initialColor); const [inputValue, setInputValue] = useState(initialColor); 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 value with color picker props.customStyles(value, props.name); }; 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 { BannerTheme };