1.1.3 • Published 1 year ago

react-canvas-resize v1.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
1 year ago

React Canvas Resize

Do you use a lot of canvas but find it difficult in React? Is tracking resizing elements causing your canvas to stretch? Do you want to maintain a ratio for your canvas scene?

React Canvas Resize makes canvases easy!

Installation

npm i react-canvas-resize

Usage

More examples on Github Pages

Basic

import React from 'react';
import CanvasResize from 'react-canvas-resize';

const App = () => {
	const handleDraw = ({ canvas }) => {
		// Do your stuff here
	}

	return (
		<CanvasResize
			play
			ratio={[4, 3]}
			onDraw={handleDraw}
			style={{
				height: 100,
				width: 100,
			}}
		/>
	);
};

Layer

Layer allows for stages of drawing and multiple callbacks of the onDraw function. Each Layer will be called in child order starting with the CanvasBase.onDraw.

return (
	<CanvasBase
		onDraw={handleDraw}
	>
		<Layer onDraw={handleLayer1} />
		<Layer onDraw={handleLayer2} />
	</CanvasBase>
);

Crop

Crop will create a subframe canvas that will limit any children to a smaller area.

return (
	<CanvasBase
		onDraw={handleDraw}
		width={50}
		height={50}
	>
		<Crop left={10} top={10} width={20} height={20}>
			<Layer onDraw={handleLayer} />
		</Crop>
	</CanvasBase>
);

License

Copyright (c) 2022, Michael Szmadzinski. (MIT License)

1.1.3

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

1.1.2

2 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.9

3 years ago

0.3.8

3 years ago

0.3.7

3 years ago

0.3.6

3 years ago

0.3.5

4 years ago

0.3.4

4 years ago

0.3.3

4 years ago

0.3.2

4 years ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago