-
Notifications
You must be signed in to change notification settings - Fork 85
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
b798782
commit bcbb141
Showing
13 changed files
with
334 additions
and
8 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
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,15 @@ | ||
--- | ||
title: Background | ||
description: Setting up background of the canvas. | ||
sidebar: | ||
order: 5 | ||
--- | ||
import { LiveCode } from "../../../components/LiveCode"; | ||
import Background from "../../../examples/Background.tsx?raw"; | ||
import BackgroundDataURI from "../../../examples/BackgroundDataURI.tsx?raw"; | ||
|
||
<LiveCode client:load previewClassName="h-96" files={{ "App.tsx": Background }} /> | ||
|
||
## Data URI as Background | ||
|
||
<LiveCode client:load previewClassName="h-96" files={{ "App.tsx": BackgroundDataURI }} /> |
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,11 @@ | ||
--- | ||
title: Sketching time | ||
description: Measuring sketching time | ||
sidebar: | ||
order: 6 | ||
--- | ||
|
||
import { LiveCode } from "../../../components/LiveCode"; | ||
import SketchingTime from "../../../examples/SketchingTime.tsx?raw"; | ||
|
||
<LiveCode client:load files={{ "App.tsx": SketchingTime }} /> |
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 @@ | ||
--- | ||
title: Undo, Redo, Clear, and Reset | ||
description: Undo, Redo, Clear, and Reset the canvas. | ||
sidebar: | ||
order: 4 | ||
--- | ||
import { LiveCode } from "../../../components/LiveCode"; | ||
import UndoRedo from "../../../examples/UndoRedo.tsx?raw"; | ||
|
||
<LiveCode client:load previewClassName="h-96" files={{ "App.tsx": UndoRedo }} /> |
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,79 @@ | ||
import { ReactSketchCanvas } from "react-sketch-canvas"; | ||
import { type ChangeEvent, useState } from "react"; | ||
|
||
const somePreserveAspectRatio = [ | ||
"none", | ||
"xMinYMin", | ||
"xMidYMin", | ||
"xMaxYMin", | ||
"xMinYMid", | ||
"xMidYMid", | ||
"xMaxYMid", | ||
"xMinYMax", | ||
"xMidYMax", | ||
"xMaxYMax", | ||
] as const; | ||
|
||
type SomePreserveAspectRatio = (typeof somePreserveAspectRatio)[number]; | ||
|
||
export default function App() { | ||
const [backgroundImage, setBackgroundImage] = useState( | ||
"https://images.pexels.com/photos/1193743/pexels-photo-1193743.jpeg?cs=srgb&fm=jpg", | ||
); | ||
const [preserveAspectRatio, setPreserveAspectRatio] = | ||
useState<SomePreserveAspectRatio>("none"); | ||
|
||
const handlePreserveAspectRatioChange = ( | ||
event: ChangeEvent<HTMLSelectElement>, | ||
) => { | ||
setPreserveAspectRatio(event.target.value as SomePreserveAspectRatio); | ||
}; | ||
|
||
const handleBackgroundImageChange = ( | ||
event: ChangeEvent<HTMLInputElement>, | ||
) => { | ||
setBackgroundImage(event.target.value); | ||
}; | ||
|
||
return ( | ||
<div className="d-flex flex-column gap-2 p-2"> | ||
<h1>Tools</h1> | ||
<div className="d-flex gap-2 flex-column"> | ||
<div className="mb-3"> | ||
<label htmlFor="backgroundImage" className="form-label"> | ||
Background Image | ||
</label> | ||
<input | ||
type="text" | ||
className="form-control" | ||
id="backgroundImage" | ||
placeholder="URL of the image to use as a background" | ||
value={backgroundImage} | ||
onChange={handleBackgroundImageChange} | ||
/> | ||
</div> | ||
<label htmlFor="preserveAspectRatio" className="form-label"> | ||
Preserve Aspect Ratio | ||
</label> | ||
<select | ||
id="preserveAspectRatio" | ||
className="form-select form-select-sm" | ||
aria-label="Preserve Aspect Ratio options" | ||
value={preserveAspectRatio} | ||
onChange={handlePreserveAspectRatioChange} | ||
> | ||
{somePreserveAspectRatio.map((value) => ( | ||
<option key={value} value={value}> | ||
{value} | ||
</option> | ||
))} | ||
</select> | ||
</div> | ||
<h1>Canvas</h1> | ||
<ReactSketchCanvas | ||
backgroundImage={backgroundImage} | ||
preserveBackgroundImageAspectRatio={preserveAspectRatio} | ||
/> | ||
</div> | ||
); | ||
} |
Large diffs are not rendered by default.
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
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,35 @@ | ||
import { | ||
ReactSketchCanvas, | ||
type ReactSketchCanvasRef, | ||
} from "react-sketch-canvas"; | ||
import { useRef, useState } from "react"; | ||
|
||
export default function App() { | ||
const canvasRef = useRef<ReactSketchCanvasRef>(null); | ||
const [sketchingTime, setSketchingTime] = useState(0); | ||
|
||
const handleSketchingTime = async () => { | ||
const time = (await canvasRef.current?.getSketchingTime()) || 0; | ||
setSketchingTime(time); | ||
}; | ||
|
||
const sketchingTimeInSeconds = (sketchingTime / 1_000).toLocaleString(); | ||
|
||
return ( | ||
<div className="d-flex flex-column gap-2 p-2"> | ||
<h1>Tools</h1> | ||
<div className="d-flex gap-2 align-items-center "> | ||
<button | ||
type="button" | ||
className="btn btn-sm btn-outline-primary" | ||
onClick={handleSketchingTime} | ||
> | ||
Get Sketching Time | ||
</button> | ||
<span>{sketchingTimeInSeconds} seconds</span> | ||
</div> | ||
<h1>Canvas</h1> | ||
<ReactSketchCanvas ref={canvasRef} withTimestamp /> | ||
</div> | ||
); | ||
} |
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,91 @@ | ||
import { | ||
ReactSketchCanvas, | ||
type ReactSketchCanvasRef, | ||
} from "react-sketch-canvas"; | ||
import { useRef, useState } from "react"; | ||
|
||
export default function App() { | ||
const canvasRef = useRef<ReactSketchCanvasRef>(null); | ||
const [eraseMode, setEraseMode] = useState(false); | ||
|
||
const handleEraserClick = () => { | ||
setEraseMode(true); | ||
canvasRef.current?.eraseMode(true); | ||
}; | ||
|
||
const handlePenClick = () => { | ||
setEraseMode(false); | ||
canvasRef.current?.eraseMode(false); | ||
}; | ||
|
||
const handleUndoClick = () => { | ||
canvasRef.current?.undo(); | ||
}; | ||
|
||
const handleRedoClick = () => { | ||
canvasRef.current?.redo(); | ||
}; | ||
|
||
const handleClearClick = () => { | ||
canvasRef.current?.clearCanvas(); | ||
}; | ||
|
||
const handleResetClick = () => { | ||
canvasRef.current?.resetCanvas(); | ||
}; | ||
|
||
return ( | ||
<div className="d-flex flex-column gap-2 p-2"> | ||
<h1>Tools</h1> | ||
<div className="d-flex gap-2 align-items-center "> | ||
<button | ||
type="button" | ||
className="btn btn-sm btn-outline-primary" | ||
disabled={!eraseMode} | ||
onClick={handlePenClick} | ||
> | ||
Pen | ||
</button> | ||
<button | ||
type="button" | ||
className="btn btn-sm btn-outline-primary" | ||
disabled={eraseMode} | ||
onClick={handleEraserClick} | ||
> | ||
Eraser | ||
</button> | ||
<div className="vr" /> | ||
<button | ||
type="button" | ||
className="btn btn-sm btn-outline-primary" | ||
onClick={handleUndoClick} | ||
> | ||
Undo | ||
</button> | ||
<button | ||
type="button" | ||
className="btn btn-sm btn-outline-primary" | ||
onClick={handleRedoClick} | ||
> | ||
Redo | ||
</button> | ||
<button | ||
type="button" | ||
className="btn btn-sm btn-outline-primary" | ||
onClick={handleClearClick} | ||
> | ||
Clear | ||
</button> | ||
<button | ||
type="button" | ||
className="btn btn-sm btn-outline-primary" | ||
onClick={handleResetClick} | ||
> | ||
Reset | ||
</button> | ||
</div> | ||
<h1>Canvas</h1> | ||
<ReactSketchCanvas ref={canvasRef} /> | ||
</div> | ||
); | ||
} |
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