feat: change colors in png

This commit is contained in:
Ibrahima G. Coulibaly
2024-06-24 03:57:52 +01:00
parent ee6c0293bf
commit ff61712923
10 changed files with 265 additions and 68 deletions

View File

@@ -0,0 +1,48 @@
import React, { useState, ChangeEvent, useRef } from 'react';
import { Box, Stack, TextField } from '@mui/material';
import PaletteIcon from '@mui/icons-material/Palette';
import IconButton from '@mui/material/IconButton';
import Typography from '@mui/material/Typography';
import { descriptionFontSize } from '../../config/uiConfig';
interface ColorSelectorProps {
value: string;
onChange: (val: string) => void;
description: string;
}
const ColorSelector: React.FC<ColorSelectorProps> = ({
value = '#ffffff',
onChange,
description
}) => {
const [color, setColor] = useState<string>(value);
const inputRef = useRef<HTMLInputElement>(null);
const handleColorChange = (event: ChangeEvent<HTMLInputElement>) => {
const val = event.target.value;
setColor(val);
onChange(val);
};
return (
<Box mb={1}>
<Stack direction={'row'}>
<TextField value={color} onChange={handleColorChange} />
<IconButton onClick={() => inputRef.current?.click()}>
<PaletteIcon />
</IconButton>
<TextField
style={{ display: 'none' }}
inputRef={inputRef}
type="color"
value={color}
onChange={handleColorChange}
/>
</Stack>
<Typography fontSize={descriptionFontSize}>{description}</Typography>
</Box>
);
};
export default ColorSelector;