1.2.6 • Published 14 days ago

react-infinite-canvas v1.2.6

Weekly downloads
-
License
MIT
Repository
github
Last release
14 days ago

React-Infinite-Canvas

An Infinite Canvas Component for React where you can place your component anywhere on the canvas with zoom in, zoom out and panning functionality. It also supports custom components to control the canvas.

Screen Recording 2024-04-17 at 12 25 16 PM

Contents

Installation

npm install react-infinite-canvas

Usage

StackBlitz Example: https://stackblitz.com/edit/react-infinite-canvas-workflow?file=src/App.tsx&terminal=dev

import { useRef } from "react";
import { ReactInfiniteCanvas, ReactInfiniteCanvasHandle } from "react-infinite-canvas";

import { COMPONENT_POSITIONS } from "./helpers/constants";
import ReactDOM from "react-dom";

const InfiniteCanvas = () => {
  const canvasRef = useRef<ReactInfiniteCanvasHandle>();
  return (
    <>
      <div style={{ width: "700px", height: "400px", border: "1px solid red" }}>
        <ReactInfiniteCanvas
          ref={canvasRef}
          onCanvasMount={(mountFunc: ReactInfiniteCanvasHandle) => {
            mountFunc.fitContentToView({ scale: 1 });
          }}
          customComponents={[
            {
              component: (
                <button
                  onClick={() => {
                    canvasRef.current?.fitContentToView({ scale: 1 });
                  }}
                >
                  fitToView
                </button>
              ),
              position: COMPONENT_POSITIONS.TOP_LEFT,
              offset: { x: 120, y: 10 },
            },
          ]}
        >
          <div style={{ width: "200px", height: "200px", background: "red" }}>
            asdasdsdas
          </div>
        </ReactInfiniteCanvas>
      </div>
    </>
  );
};

ReactDOM.render(<InfiniteCanvas />, document.getElementById("root"));

API

PropertyTypeDefaultDescription
childrenReactNode-Element to be placed inside the canvas
minZoomnumber0.1minimum limit for zooming
maxZoomnumber4maximum limit for zooming
panOnScrollbooleantruewhen user scrolls in canvas, instead of zooming, the content scrolls
renderScrollBarbooleantruea custom built scroll-bar will be rendered on canvas
scrollBarConfigobject{ startingPosition: { x: 0, y: 0}, offset: { x: 0, y: 0}, color: "grey", thickness: "8px", minSize: "15px }To style the scrollbar to your preference
customComponentsobject-An array of components you can pass to render on canvas at any position
onCanvasMountfunction-A function that is triggered once the canvas is mounted
1.2.6

14 days ago

1.2.5

22 days ago

1.2.4

22 days ago

1.2.3

23 days ago

1.2.2

26 days ago

1.1.1

1 month ago

1.2.1

1 month ago

1.1.0

1 month ago

1.0.9

1 month ago

1.0.2

1 month ago

1.0.8

1 month ago

1.0.7

1 month ago

1.0.6

1 month ago

1.0.5

1 month ago

1.0.4

1 month ago

1.0.3

1 month ago

1.0.1

2 months ago

1.0.0

2 months ago