diff --git a/src/atoms.ts b/src/atoms.ts index f64d0ba..e727f00 100644 --- a/src/atoms.ts +++ b/src/atoms.ts @@ -17,5 +17,5 @@ export const lineColorState = atom(COLORS[0]!); export const drawModeState = atom('line'); -export const drawGridWidthState = atom(4); -export const drawGridHeightState = atom(4); +export const drawGridWidthState = atom(4); +export const drawGridHeightState = atom(4); diff --git a/src/components/grid/grid-config.scss b/src/components/grid/grid-config.scss index 20ead13..afbdf4e 100644 --- a/src/components/grid/grid-config.scss +++ b/src/components/grid/grid-config.scss @@ -21,6 +21,33 @@ border-radius: 5px; padding: 5px; display: flex; + + .grid.option { + display: flex; + align-items: center; + + svg.icon { + width: 12px; + height: 12px; + margin-right: 8px; + } + + .x { + margin: 0 4px; + } + + input.grid-size { + width: 18px; + height: 20px; + border: none; + padding: 2px 0 4px 0; + border-radius: 3px; + text-align: center; + line-height: 1; + background-color: #131b23; + color: #fff; + } + } } .color-options, diff --git a/src/components/grid/grid-config.tsx b/src/components/grid/grid-config.tsx index 45b9bd1..5791120 100644 --- a/src/components/grid/grid-config.tsx +++ b/src/components/grid/grid-config.tsx @@ -1,5 +1,5 @@ -import { FC } from 'react'; -import { useAtom, Atom } from 'jotai'; +import { ChangeEvent, FC, useCallback } from 'react'; +import { PrimitiveAtom, useAtom, WritableAtom } from 'jotai'; import { COLORS, drawGridHeightState, @@ -46,17 +46,16 @@ const GridIcon = ( - - - + + + - - - + + ); @@ -86,17 +85,36 @@ const ColorOption: FC = (props: ColorOptionProps) => { }; interface StateInputProps { - state: Atom; + state: PrimitiveAtom; + className?: string; } -const NumberStateInput: FC> = ( - props: StateInputProps +const NumberStateInput: FC> = ( + props: StateInputProps ) => { - const { state } = props; + const { state, className } = props; const [number, setNumber] = useAtom(state); - // TODO - return null; + const handleChange = useCallback( + (e: ChangeEvent) => { + const re = /^\d*$/; + const v = e.target.value; + if (v === '') { + setNumber(null); + } else if (re.test(v)) { + setNumber(parseInt(v)); + } + }, + [setNumber] + ); + + return ( + + ); }; const ColorConfig: FC = () => ( @@ -109,12 +127,11 @@ const ColorConfig: FC = () => ( const ModeConfig: FC = () => { const [drawMode, setDrawMode] = useAtom(drawModeState); - const [drawGridWidth, setDrawGridWidth] = useAtom(drawGridWidthState); - const [drawGridHeight, setDrawGridHeight] = useAtom(drawGridHeightState); const lineClassName = drawMode === 'line' ? 'option active' : 'option'; const trashClassName = drawMode === 'trash' ? 'option active' : 'option'; - const gridClassName = drawMode === 'grid' ? 'option active' : 'option'; + const gridClassName = + drawMode === 'grid' ? 'option active grid' : 'option grid'; return ( <>
@@ -137,9 +154,15 @@ const ModeConfig: FC = () => { onClick={() => setDrawMode('grid')} > {GridIcon} - - x - + + x +