-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implements change color, line-width, pen-mode function (#39)
* feat: Update canvas store about pensetting 'mode, color, lineWidth' * feat: Update MainCanvas with penSetting * feat: Create DrawingComponent and CanvasToolbar * feat: Implements change color and line-width and pen-mode * style: Change DrawingComponent to DrawingArea and Use button instead div for clickable element * style: Renaming DrawingComponent to DrawingArea
- Loading branch information
Showing
6 changed files
with
117 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { ChangeEvent } from 'react'; | ||
import { LINEWIDTH_VARIABLE, PENMODE } from '@/constants/canvasConstants'; | ||
import { useCanvasStore } from '@/stores/useCanvasStore'; | ||
import { CanvasStore, PenModeType } from '@/types/canvas.types'; | ||
|
||
const CV = ['#000', '#f257c9', '#e2f724', '#4eb4c2', '#d9d9d9']; | ||
//임시 색상 코드 | ||
|
||
const CanvasToolBar = () => { | ||
const lineWidth = useCanvasStore((state: CanvasStore) => state.penSetting.lineWidth); | ||
const setPenSetting = useCanvasStore((state: CanvasStore) => state.action.setPenSetting); | ||
const setPenMode = useCanvasStore((state: CanvasStore) => state.action.setPenMode); | ||
|
||
const handleChangeToolColor = (colorNum: number) => { | ||
setPenSetting({ colorNum }); | ||
}; | ||
const handleChangeLineWidth = (lineWidth: string) => { | ||
setPenSetting({ lineWidth: Number(lineWidth) }); | ||
}; | ||
const handleChangeToolMode = (modeNum: PenModeType) => { | ||
setPenMode(modeNum); | ||
}; | ||
|
||
return ( | ||
<section> | ||
<section> | ||
{CV.map((color, i) => { | ||
return ( | ||
<button key={i} className={`bg-canvas-${i} h-16 w-16`} onClick={() => handleChangeToolColor(i)}> | ||
{color} | ||
</button> | ||
); | ||
})} | ||
</section> | ||
<section> | ||
<input | ||
type="range" | ||
min={LINEWIDTH_VARIABLE.MIN_WIDTH} | ||
max={LINEWIDTH_VARIABLE.MAX_WIDTH} | ||
step={LINEWIDTH_VARIABLE.STEP_WIDTH} | ||
value={lineWidth} | ||
onChange={(e: ChangeEvent<HTMLInputElement>) => handleChangeLineWidth(e.target.value)} | ||
/> | ||
</section> | ||
<section> | ||
<button onClick={() => handleChangeToolMode(PENMODE.PEN)}>펜</button> | ||
<button onClick={() => handleChangeToolMode(PENMODE.PAINTER)}>페인팅</button> | ||
</section> | ||
</section> | ||
); | ||
}; | ||
|
||
export default CanvasToolBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import CanvasToolBar from './CanvasToolbar'; | ||
import MainCanvas from './MainCanvas'; | ||
|
||
const DrawingArea = () => { | ||
return ( | ||
<section> | ||
<MainCanvas /> | ||
<CanvasToolBar /> | ||
</section> | ||
); | ||
}; | ||
|
||
export default DrawingArea; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const PENMODE = { | ||
PEN: 0, | ||
PAINTER: 1, | ||
}; | ||
|
||
export const LINEWIDTH_VARIABLE = { | ||
MIN_WIDTH: 2, | ||
MAX_WIDTH: 10, | ||
STEP_WIDTH: 2, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
import { PENMODE } from '@/constants/canvasConstants'; | ||
|
||
interface PenOptions { | ||
mode: number; | ||
colorNum: number; | ||
lineWidth: number; //짝수 단위가 좋음 | ||
} | ||
|
||
export type SelectingPenOptions = Partial<PenOptions>; | ||
|
||
export type PenModeType = (typeof PENMODE)[keyof typeof PENMODE]; | ||
|
||
export interface CanvasStore { | ||
canDrawing: boolean; | ||
penSetting: PenOptions; | ||
action: { | ||
setCanDrawing: (canDrawing: boolean) => void; | ||
setPenSetting: (penSetting: SelectingPenOptions) => void; | ||
setPenMode: (penMode: PenModeType) => void; | ||
}; | ||
} |