prototype color selector

This commit is contained in:
Michael Peters 2024-01-27 13:39:10 -08:00
parent 1f3895a025
commit 0961ba41fd
3 changed files with 112 additions and 2 deletions

View File

@ -1,8 +1,15 @@
import { FC } from 'react';
import { FC, useState } from 'react';
import Grid from '../grid/grid';
import GridConfig from '../grid/grid-config';
const App: FC = () => {
return <Grid />;
const [color, setColor] = useState('#ffffff');
return (
<>
<Grid />
<GridConfig color={color} setColor={setColor} />
</>
);
};
export default App;

View File

@ -0,0 +1,6 @@
.grid-config {
position: absolute;
top: 0;
left: 0;
display: flex;
}

View File

@ -0,0 +1,97 @@
import { FC } from 'react';
import './grid-config.scss';
interface ColorOptionProps {
color: string;
currentColor: string;
setCurrentColor: (newColor: string) => void;
}
const ColorOption: FC<ColorOptionProps> = (props: ColorOptionProps) => {
const { color, currentColor, setCurrentColor } = props;
return (
<div
className={
color === currentColor ? 'color-option active' : 'color-option'
}
onClick={() => setCurrentColor(color)}
>
{color}
</div>
);
};
interface ColorConfigProps {
color: string;
setColor: (newColor: string) => void;
}
const ColorConfig: FC<ColorConfigProps> = (props: ColorConfigProps) => {
const { color, setColor } = props;
return (
<div className="color-config">
<div>Color: {color}</div>
<div className="color-options">
<ColorOption
color="#ffffff"
currentColor={color}
setCurrentColor={setColor}
/>
<ColorOption
color="#ff0000"
currentColor={color}
setCurrentColor={setColor}
/>
<ColorOption
color="#00ff00"
currentColor={color}
setCurrentColor={setColor}
/>
<ColorOption
color="#3cccff"
currentColor={color}
setCurrentColor={setColor}
/>
<ColorOption
color="#eeee00"
currentColor={color}
setCurrentColor={setColor}
/>
<ColorOption
color="#ff8800"
currentColor={color}
setCurrentColor={setColor}
/>
<ColorOption
color="#ee66ee"
currentColor={color}
setCurrentColor={setColor}
/>
<ColorOption
color="#2e8c41"
currentColor={color}
setCurrentColor={setColor}
/>
</div>
</div>
);
};
interface GridConfigProps {
color: string;
setColor: (newColor: string) => void;
}
const GridConfig: FC<GridConfigProps> = (props: GridConfigProps) => {
const { color, setColor } = props;
return (
<div className="grid-config">
<ColorConfig color={color} setColor={setColor} />
</div>
);
};
export default GridConfig;