Skip to content

Instantly share code, notes, and snippets.

@duongdam
Last active December 7, 2021 08:24
Show Gist options
  • Save duongdam/45a838aeb55af2cee72726c0167f3d1a to your computer and use it in GitHub Desktop.
Save duongdam/45a838aeb55af2cee72726c0167f3d1a to your computer and use it in GitHub Desktop.
import React from "react";
// use usePanter2D.js to drawing
interface Props {
canvasRef?: React.MutableRefObject<HTMLCanvasElement | undefined>;
width?: number;
}
export const Canvas: React.FC<Props> = ({ canvasRef, width }) => {
const widthHalf = width ? width / 2 : 0;
const cursor = `url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="%23000000" opacity="0.3" height="${width}" viewBox="0 0 ${width} ${width}" width="${width}"><circle cx="${widthHalf}" cy="${widthHalf}" r="${widthHalf}" fill="%23000000" /></svg>') ${widthHalf} ${widthHalf}, auto`;
return (
<section>
<canvas style={{ cursor }} ref={canvasRef as any} />
</section>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment