-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9006402
commit 5de9915
Showing
10 changed files
with
117 additions
and
86 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
15 changes: 4 additions & 11 deletions
15
src/components/diary/Editor.tsx → src/components/diary/editor/Editor.tsx
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
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
4 changes: 2 additions & 2 deletions
4
src/components/diary/Title.tsx → src/components/diary/editor/Title.tsx
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,65 @@ | ||
import { | ||
MouseEventHandler, | ||
RefObject, | ||
useEffect, | ||
useRef, | ||
useState, | ||
} from "react"; | ||
import { useRecoilState } from "recoil"; | ||
import { bgImage } from "../../../recoil/diary"; | ||
|
||
interface ITemplate { | ||
width: number; | ||
height: number; | ||
} | ||
const Template = ({ width, height }: ITemplate) => { | ||
const canvasRef: RefObject<HTMLCanvasElement> = | ||
useRef<HTMLCanvasElement>(null); | ||
const [context, setContext] = useState<CanvasRenderingContext2D>(); | ||
const templateImg = useRecoilState<string>(bgImage); | ||
const [isDrawing, SetIsDrawing] = useState<boolean>(false); | ||
const [imgg, setImgg] = useState<string>(""); | ||
useEffect(() => { | ||
const canvas = canvasRef.current; | ||
const ctx = canvas?.getContext("2d"); | ||
if (ctx) { | ||
ctx.strokeStyle = "black"; | ||
ctx.lineWidth = 2.5; | ||
setContext(ctx); | ||
} | ||
|
||
const img = new Image(); | ||
img.onload = () => { | ||
context?.drawImage(img, 0, 0, width, height); | ||
}; | ||
img.src = templateImg[0]; | ||
}, [templateImg]); | ||
|
||
const drawing = (event: React.MouseEvent<HTMLCanvasElement, MouseEvent>) => { | ||
const { offsetX, offsetY } = event.nativeEvent; | ||
|
||
if (!isDrawing) { | ||
context?.beginPath(); | ||
context?.moveTo(offsetX, offsetY); | ||
} else { | ||
context?.lineTo(offsetX, offsetY); | ||
context?.stroke(); | ||
} | ||
}; | ||
|
||
return ( | ||
<div> | ||
<canvas | ||
ref={canvasRef} | ||
width={width} | ||
height={height} | ||
onMouseMove={drawing} | ||
onMouseDown={() => SetIsDrawing(true)} | ||
onMouseUp={() => SetIsDrawing(false)} | ||
onMouseLeave={() => SetIsDrawing(false)} | ||
></canvas> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Template; |
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