npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-konva-interactive-stage

v1.0.3

Published

A React component for interactive and zoomable Konva stage

Downloads

1,078

Readme

React Konva Interactive Stage

A React component for creating interactive and zoomable Konva stages with smooth pan and zoom capabilities.

Built on top of Konva and React-Konva.

Live demo here

Features

  • 🖱️ Smooth pan and zoom interactions
  • 🎯 Click-to-zoom on specific elements
  • 🔄 Automatic bounds calculation
  • 📱 Responsive container
  • 🎯 TypeScript support

Installation

npm install react-konva-interactive-stage
# or
yarn add react-konva-interactive-stage
# or
pnpm add react-konva-interactive-stage
# or
bun add react-konva-interactive-stage

Usage

import InteractiveStage from 'react-konva-interactive-stage';
import { Circle } from 'react-konva';

function App() {
  return (
    <InteractiveStage
      options={{
        minZoom: 1,
        maxZoom: 5,
        panSpeed: 1.5,
      }}
    >
      {({ zoomToElement }) => (
        <Circle
          x={100}
          y={100}
          radius={50}
          fill="red"
          onClick={(e) => zoomToElement(e.target)}
        />
      )}
    </InteractiveStage>
  );
}

Props

| Prop | Type | Description | |------|------|-------------| | options | InteractiveStageOptions | Configuration options for the stage | | width | number | Optional width in canvas units | | height | number | Optional height in canvas units | | className | string | CSS class name for the container | | style | CSSProperties | Inline styles for the container | | children | ReactNode \| ((props: InteractiveStageRenderProps) => ReactNode) | Stage content |

If width and/or height are not provided, the stage will automatically resize to fit its children.

Options

interface InteractiveStageOptions {
  minZoom?: number;         // Minimum zoom level (default: 1)
  maxZoom?: number;         // Maximum zoom level (default: 100)
  zoomSpeed?: number;       // Zoom speed in [0.1, 10] (default: 5)
  panSpeed?: number;        // Pan speed in [1, 10] (default: 1)
  clampPosition?: boolean;  // Prevent panning outside bounds (default: true)
  debug?: boolean;          // Show debug overlay (default: false)
}

Render Props

interface InteractiveStageRenderProps {
  zoomToElement: (element: Konva.Node, options?: ZoomOptions) => void;
  resetZoom: () => void; 
  updateBounds: () => void;
  loading: boolean;
  scale: number;
  position: Point;
  bounds: Bounds;
  visibleRect: VisibleRect;
  options: Required<InteractiveStageOptions>;
}

Those are available in the children prop:

function App() {
  return (
    <InteractiveStage>
      {({ zoomToElement, resetZoom, scale, position, bounds }) => (
          ... your konva content here ...
      )}
    </InteractiveStage>
  );
}

Controls

  • Pan: Click and drag or use the mouse wheel
  • Zoom: Use Cmd/Ctrl + mouse wheel
  • Reset Zoom: Double-click

Examples

Check out the examples directory for a full demo application showcasing all features.

To run the examples locally:

cd examples
pnpm install
pnpm dev

Development

# Install dependencies
pnpm install

# Build the library
pnpm build

# Run tests
pnpm test

# Lint code
pnpm lint

# Type check
pnpm typecheck

License

MIT © Pierre Borckmans