From 1ecfcb2f88fb6a89be4585301398a6bc74eba4ab Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Sat, 27 Jan 2024 15:26:35 -0800 Subject: [PATCH] ui for mode support --- src/atoms.ts | 11 +++- src/components/grid/grid-config.scss | 40 ++++++++------- src/components/grid/grid-config.tsx | 76 ++++++++++++++++++++++------ src/components/grid/grid.tsx | 4 +- 4 files changed, 93 insertions(+), 38 deletions(-) diff --git a/src/atoms.ts b/src/atoms.ts index d7fd17d..3867bcc 100644 --- a/src/atoms.ts +++ b/src/atoms.ts @@ -2,7 +2,16 @@ import { atom } from 'recoil'; export const DEFAULT_COLOR = '#339ad6'; -export const currentColorState = atom({ +type DrawMode = 'line' | 'trash'; +export const MODE_LINE = 'line'; +export const MODE_TRASH = 'trash'; + +export const lineColorState = atom({ key: 'colorState', default: DEFAULT_COLOR, }); + +export const drawModeState = atom({ + key: 'drawModeState', + default: MODE_LINE, +}); diff --git a/src/components/grid/grid-config.scss b/src/components/grid/grid-config.scss index 45b6f84..e8fdb73 100644 --- a/src/components/grid/grid-config.scss +++ b/src/components/grid/grid-config.scss @@ -7,32 +7,34 @@ margin: 20px; } - .color-config { + .options { background-color: #000; border-radius: 5px; padding: 5px; + display: grid; + grid-template-columns: auto auto; - .color-options { - display: grid; - grid-template-columns: auto auto; + .option { + margin: 5px; + padding: 7px; + background-color: #283f56; + border: 2px solid #283f56; + border-radius: 5px; - .color-option { - margin: 5px; - padding: 7px; - background-color: #283f56; - border: 2px solid #283f56; - border-radius: 5px; + &.active { + background-color: #265584; + border-color: #458bd1; + } - &.active { - background-color: #265584; - border-color: #458bd1; - } + .sample { + width: 24px; + height: 13px; + border-radius: 3px; + } - .sample { - width: 24px; - height: 13px; - border-radius: 3px; - } + svg.icon { + width: 24px; + height: 13px; } } } diff --git a/src/components/grid/grid-config.tsx b/src/components/grid/grid-config.tsx index 8d94f98..e91e63a 100644 --- a/src/components/grid/grid-config.tsx +++ b/src/components/grid/grid-config.tsx @@ -1,6 +1,6 @@ import { FC } from 'react'; import { useRecoilState } from 'recoil'; -import { currentColorState, DEFAULT_COLOR } from '../../atoms'; +import { DEFAULT_COLOR, drawModeState, lineColorState } from '../../atoms'; import './grid-config.scss'; @@ -10,14 +10,12 @@ interface ColorOptionProps { const ColorOption: FC = (props: ColorOptionProps) => { const { color } = props; - const [currentColor, setCurrentColor] = useRecoilState(currentColorState); + const [lineColor, setLineColor] = useRecoilState(lineColorState); return (
setCurrentColor(color)} + className={color === lineColor ? 'option active' : 'option'} + onClick={() => setLineColor(color)} >
@@ -26,16 +24,61 @@ const ColorOption: FC = (props: ColorOptionProps) => { const ColorConfig: FC = () => { return ( -
-
- - - - - - - - +
+ + + + + + + + +
+ ); +}; + +const ModeConfig: FC = () => { + const [drawMode, setDrawMode] = useRecoilState(drawModeState); + + const lineClassName = drawMode === 'line' ? 'option active' : 'option'; + const trashClassName = drawMode === 'trash' ? 'option active' : 'option'; + return ( +
+
setDrawMode('line')}> + + + + + +
+
setDrawMode('trash')} + > + + +
); @@ -45,6 +88,7 @@ const GridConfig: FC = () => { return (
+
); }; diff --git a/src/components/grid/grid.tsx b/src/components/grid/grid.tsx index 233ba14..b992b84 100644 --- a/src/components/grid/grid.tsx +++ b/src/components/grid/grid.tsx @@ -13,7 +13,7 @@ import './grid.scss'; import * as lodash from 'lodash'; import { useRecoilValue } from 'recoil'; -import { currentColorState } from '../../atoms'; +import { lineColorState } from '../../atoms'; interface Point { x: number; @@ -127,7 +127,7 @@ const Grid: FC = () => { const [userLines, setUserLines] = useState([]); const [userRedoLines, setUserRedoLines] = useState([]); const [userStartPoint, setUserStartPoint] = useState(null); - const userLineColor = useRecoilValue(currentColorState); + const userLineColor = useRecoilValue(lineColorState); // mouse clicks create lines const onGridClick = useCallback(